message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
276
109k
cluster
float64
23
23
__index_level_0__
int64
552
217k
Provide tags and a correct Python 3 solution for this coding contest problem. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image>
instruction
0
19,456
23
38,912
Tags: implementation, math Correct Solution: ``` def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) # A. Connect Three a = [tuple(mi()) for i in range(3)] a.sort() up1 = a[1][1] >= a[0][1] up2 = a[2][1] >= a[0][1] ans = {a[0]} x, y = a[0] if up1 and up2: while y < min(a[1][1], a[2][1]): y += 1 ans.add((x, y)) while x < a[2][0]: x += 1 ans.add((x, y)) hx, hy = a[2] if a[2][1] > a[1][1] else a[1] while hy > y: ans.add((hx, hy)) hy -= 1 else: dn1 = a[1][1] <= a[0][1] dn2 = a[2][1] <= a[0][1] ans = {a[0]} x, y = a[0] if dn1 and dn2: while y > max(a[1][1], a[2][1]): y -= 1 ans.add((x, y)) while x < a[2][0]: x += 1 ans.add((x, y)) lx, ly = a[2] if a[2][1] < a[1][1] else a[1] while ly < y: ans.add((lx, ly)) ly += 1 else: x, y = a[0] ans = {a[0]} while x < a[2][0]: x += 1 ans.add((x, y)) dy = 1 if a[1][1] <= a[0][1] else -1 xx, yy = a[1] while yy != a[0][1]: ans.add((xx, yy)) yy += dy dy = 1 if a[2][1] <= a[0][1] else -1 xx, yy = a[2] while yy != a[0][1]: ans.add((xx, yy)) yy += dy ans = sorted(ans) print(len(ans)) print('\n'.join('%d %d' % (x, y) for x, y in ans)) ```
output
1
19,456
23
38,913
Provide tags and a correct Python 3 solution for this coding contest problem. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image>
instruction
0
19,457
23
38,914
Tags: implementation, math Correct Solution: ``` a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a, b, c = sorted([a,b,c]) ans = [] for i in range(min(a[1],b[1],c[1]),max(a[1],b[1],c[1])+1): ans.append((b[0],i)) for i in range(a[0],b[0]+1): ans.append((i,a[1])) for i in range(b[0],c[0]+1): ans.append((i,c[1])) ans=set(ans) print(len(ans)) for i in ans: print(*i) ```
output
1
19,457
23
38,915
Provide tags and a correct Python 3 solution for this coding contest problem. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image>
instruction
0
19,458
23
38,916
Tags: implementation, math Correct Solution: ``` xa, ya = map(int, input().split()) xb, yb = map(int, input().split()) xc, yc = map(int, input().split()) xs = [xa, xb, xc] xs.sort() ys = [ya, yb, yc] ys.sort() mx, my = xs[1], ys[1] field = [[False]*1001 for _ in range(1001)] for sx, sy in [(xa, ya), (xb, yb), (xc, yc)]: for x in range(min(sx, mx), max(sx, mx)+1): field[x][sy] = True for y in range(min(sy, my), max(sy, my)+1): field[mx][y] = True ans = [] for x in range(1001): for y in range(1001): if field[x][y]: ans.append((x, y)) print(len(ans)) for x, y in ans: print(x, y) ```
output
1
19,458
23
38,917
Provide tags and a correct Python 3 solution for this coding contest problem. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image>
instruction
0
19,459
23
38,918
Tags: implementation, math Correct Solution: ``` def doWay(x, y, x1, y1, x2, y2): global answer while x < x1 and x < x2: x += 1 answer.add((x, y)) while y < y1 and y < y2: y += 1 answer.add((x, y)) while x > x1 and x > x2: x -= 1 answer.add((x, y)) while y > y1 and y > y2: y -= 1 answer.add((x, y)) xy = list() xy.append(tuple(map(int, input().split()))) xy.append(tuple(map(int, input().split()))) xy.append(tuple(map(int, input().split()))) answer = set(xy) doWay(xy[0][0], xy[0][1], xy[1][0], xy[1][1], xy[2][0], xy[2][1]) doWay(xy[1][0], xy[1][1], xy[0][0], xy[0][1], xy[2][0], xy[2][1]) doWay(xy[2][0], xy[2][1], xy[0][0], xy[0][1], xy[1][0], xy[1][1]) print(len(answer)) for x, y in answer: print(x, y) ```
output
1
19,459
23
38,919
Provide tags and a correct Python 3 solution for this coding contest problem. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image>
instruction
0
19,460
23
38,920
Tags: implementation, math Correct Solution: ``` def main(): a = tuple(map(int, input().split())) b = tuple(map(int, input().split())) c = tuple(map(int, input().split())) a, b, c = sorted((a, b, c)) (x1, y1) = a (x2, y2) = b (x3, y3) = c dy2 = y2 - y1 dy3 = y3 - y1 sy2 = 1 if dy2 >= 0 else -1 sy3 = 1 if dy3 >= 0 else -1 ay2 = abs(dy2) ay3 = abs(dy3) c = 0 res = [] if sy2 == sy3: for i in range(x1, x2 + 1): c += 1 res.append((i, y1)) for i in range(1, max(ay2, ay3) + 1): c += 1 res.append((x2, y1 + sy2 * i)) for i in range(x2 + 1, x3 + 1): c += 1 res.append((i, y3)) else: for i in range(x1, x3 + 1): c += 1 res.append((i, y1)) for i in range(1, ay2 + 1): c += 1 res.append((x2, y1 + sy2 * i)) for i in range(1, ay3 + 1): c += 1 res.append((x3, y1 + sy3 * i)) print(c) for (x, y) in res: print(x, y) main() ```
output
1
19,460
23
38,921
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image> Submitted Solution: ``` def prov(y1, y2, y3): if (abs(y1 - y2), abs(y1 - y3)) <= (abs(y2 - y1), abs(y2 - y3)) and (abs(y1 - y2), abs(y1 - y3)) <= (abs(y3 - y2), abs(y3 - y1)): return y1 if(abs(y2 - y1), abs(y2 - y3)) <= (abs(y1 - y2), abs(y1 - y3)) and (abs(y2 - y1), abs(y2 - y3)) <= (abs(y3 - y2), abs(y3 - y1)): return y2 if (abs(y3 - y2), abs(y3 - y1)) <= (abs(y1 - y2), abs(y1 - y3)) and (abs(y3 - y2), abs(y3 - y1)) <= (abs(y2 - y1), abs(y2 - y3)): return y3 x1, y1 = list(map(int, input().split())) x2, y2 = list(map(int, input().split())) x3, y3 = list(map(int, input().split())) arr = [] for i in range(max(y1, y2, y3) + 1): arr.append([-1] * (max(x1, x2, x3) +1)) xj = prov(x1, x2, x3) yi = prov(y1, y2, y3) stx1 = min(x1, xj) fix1 = max(x1, xj) se = set() for i in range(stx1, fix1+1): se.add((i, y1)) sty1 = min(y1, yi) fiy1= max(y1, yi) for i in range(sty1, fiy1+1): se.add((xj, i)) stx2 = min(x2, xj) fix2 = max(x2, xj) for i in range(stx2, fix2+1): se.add((i, y2)) sty2 = min(y2, yi) fiy2= max(y2, yi) for i in range(sty2, fiy2+1): se.add((xj, i)) stx3 = min(x3, xj) fix3 = max(x3, xj) for i in range(stx3, fix3+1): se.add((i, y3)) sty3 = min(y3, yi) fiy3= max(y3, yi) for i in range(sty3, fiy3+1): se.add((xj, i)) print(len(se)) se = list(se) for i in range(len(se)): print(se[i][0], se[i][1]) ```
instruction
0
19,461
23
38,922
Yes
output
1
19,461
23
38,923
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image> Submitted Solution: ``` xa, ya = map(int, input().split()) xb, yb = map(int, input().split()) xc, yc= map(int, input().split()) srx = xa+xb+xc-min(xa, xb, xc)-max(xa, xb, xc) sry = ya +yb+yc - min(ya, yb, yc)- max(ya, yb,yc) l = max(xa, xb, xc)-min(xa, xb, xc)+max(ya, yb, yc)-min(ya, yb, yc)+1 print(l) for i in range(min(xa, xb, xc), max(xa, xb, xc)+1): print(i, sry) if (ya!=sry): i = ya while (i!=sry): print(xa, i) i+=int((sry-ya)/abs(sry-ya)) if (yb!=sry): i = yb while (i!=sry): print(xb, i) i+=int((sry-yb)/abs(sry-yb)) if (yc!=sry): i = yc while (i!=sry): print(xc, i) i+=int((sry-yc)/abs(sry-yc)) ```
instruction
0
19,462
23
38,924
Yes
output
1
19,462
23
38,925
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image> Submitted Solution: ``` def path(a,b): x,y = a fx,fy = b f1,f2 = 1,1 if(fx < x): f1 = -1 if(fy < y): f2 = -1 p1,p2 = [],[] for i in range(x,fx+f1,f1): p1.append([i,y]) for i in range(y+f2,fy+f2,f2): p1.append([fx,i]) for i in range(y,fy+f2,f2): p2.append([x,i]) for i in range(x+f1,fx+f1,f1): p2.append([i,fy]) return p1,p2 def merge(p1,p2): p3 = p1[:] for i in p2: if i not in p3: p3.append(i) return p3 l = [] for i in range(3): l.append(list(map(int,input().split()))) l.sort() p1,p2 = path(l[0],l[1]) p3,p4 = path(l[1],l[2]) p5 = merge(p1,p3) p6 = merge(p1,p4) if(len(p6) < len(p5)): p5 = p6[::] p6 = merge(p2,p3) if(len(p6) < len(p5)): p5 = p6[::] p6 = merge(p2,p4) if(len(p6) < len(p5)): p5 = p6[::] print(len(p5)) for i in p5: print(*i) ```
instruction
0
19,463
23
38,926
Yes
output
1
19,463
23
38,927
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image> Submitted Solution: ``` def solve(r, t): if r < k: for i in range(r, k + 1): matrix[i][t] = 1 else: for i in range(k, r + 1): matrix[i][t] = 1 if t < l: for i in range(t, l + 1): matrix[k][i] = 1 else: for i in range(l, t + 1): matrix[k][i] = 1 (a, b), (m, n), (x, y) = map(int, input().split()), map(int, input().split()), map(int, input().split()) hmax, hmin, wmax, wmin = max((a, m, x)), min((a, m, x)), max((b, n, y)), min((b, n, y)) matrix = [[0 for i in range(wmax + 1)] for j in range(hmax + 1)] print(hmax - hmin + wmax - wmin + 1) k, l = (a + m + x) - (hmax + hmin), (b + n + y) - (wmax + wmin) solve(a, b) solve(m, n) solve(x, y) for i in range(len(matrix)): for j in range(len(matrix[i])): if matrix[i][j]: print(i, j) ```
instruction
0
19,464
23
38,928
Yes
output
1
19,464
23
38,929
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image> Submitted Solution: ``` x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) x3, y3 = map(int, input().split()) x = (x1 + x2 + x3) // 3 y = (y1 + y2 + y3) // 3 print(abs(x - x1) + abs(x - x2) + abs(x - x3) + abs(y - y1) + abs(y - y2) + abs(y - y3) + 1) x0 = x1 y0 = y1 for j in range(abs(x - x1)): if x > x1: print(x0, y0) x0 += 1 else: print(x0, y0) x0 -= 1 for j in range(abs(y - y1)): if y > y1: print(x0, y0) y0 += 1 else: print(x0, y0) y0 -= 1 x0 = x2 y0 = y2 for j in range(abs(x - x2)): if x > x2: print(x0, y0) x0 += 1 else: print(x0, y0) x0 -= 1 for j in range(abs(y - y2)): if y > y2: print(x0, y0) y0 += 1 else: print(x0, y0) y0 -= 1 x0 = x3 y0 = y3 for j in range(abs(x - x3)): if x > x3: print(x0, y0) x0 += 1 else: print(x0, y0) x0 -= 1 for j in range(abs(y - y3)): if y > y3: print(x0, y0) y0 += 1 else: print(x0, y0) y0 -= 1 print(x, y) ```
instruction
0
19,465
23
38,930
No
output
1
19,465
23
38,931
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image> Submitted Solution: ``` def print_path(a, b, way='left'): corner = a if way == 'left': for i in range(a[1], b[1]): print(a[0], i + 1) corner = a[0], i + 1 for i in range(corner[0], b[0]): print(i + 1, corner[1]) else: for i in range(a[0], b[0]): print(i + 1, a[1]) corner = i + 1, a[1] for i in range(corner[1], b[1]): print(corner[0], i + 1) a1, a2 = map(int, input().split()) b1, b2 = map(int, input().split()) c1, c2 = map(int, input().split()) points = sorted([(a1, a2), (b1, b2), (c1, c2)], key=lambda x: pow(x[0], 2) + pow(x[1], 2)) print(points) a1, a2 = points[0] b1, b2 = points[1] c1, c2 = points[2] if a1 <= b1 <= c1 and a2 <= b2 <= c2: print(c1 - a1 + c2 - a2 + 1) print(a1, a2) print_path(points[0], points[1]) print_path(points[1], points[2]) else: print(a1, a2) print_path(points[0], points[2], 'right') print('here') if c1 <= b1 and c2 >= b2 >= a2: print_path((c1, b2), points[1]) elif b2 < a2 and a1 <= b1 <= c1: print_path(points[1], (b1, a2)) elif b1 < a1 and a2 <= b2 <= c2: print_path(points[1], (a1, b2)) elif b2 > c2 and a1 <= b1 <= c1: print_path((b1, c2), points[1]) ```
instruction
0
19,466
23
38,932
No
output
1
19,466
23
38,933
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image> Submitted Solution: ``` s_1 = input().split(' ') x_1 = int(s_1[0]) y_1 = int(s_1[1]) s_2 = input().split(' ') x_2 = int(s_2[0]) y_2 = int(s_2[1]) s_3 = input().split(' ') x_3 = int(s_3[0]) y_3 = int(s_3[1]) mas = [x_1,x_2,x_3] mas_x = sorted([x_1,x_2,x_3]) m = [mas_x.index(mas[0]),mas_x.index(mas[1]),mas_x.index(mas[2])] M = [0]*len(mas_x) M[m[0]] = y_1 M[m[1]] = y_2 M[m[2]] = y_3 #print(m) #mas_y = [y_1,y_2,y_3] mas_y = M #print(mas_x,M) #print(mas_y) X_1 = mas_x[0] X_2 = mas_x[1] X_3 = mas_x[2] Y_1 = mas_y[0] Y_2 = mas_y[1] Y_3 = mas_y[2] #print(X_1,X_2,X_3) a = [[i ,Y_1] for i in range(X_1,X_2+1)] b = [[Y_2,i] for i in range(min(X_1,X_2,X_3)+1,max(X_1,X_2,X_3))] c =[] if Y_1==Y_3: c =[[i,Y_3] for i in range(X_2+1,X_3+1)] else: c = [[i,Y_3] for i in range(X_2,X_3+1)] print(len(a)+len(b)+len(c)) for i in a: print(i[0],i[1]) for j in b: print(j[0],j[1]) for i in c: print(i[0],i[1]) ```
instruction
0
19,467
23
38,934
No
output
1
19,467
23
38,935
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C in the forest. Initially, all plots in the forest (including the plots A, B, C) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots A, B, C from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side. <image> For example, A=(0,0), B=(1,1), C=(2,2). The minimal number of plots to be cleared is 5. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees. Input The first line contains two integers x_A and y_A β€” coordinates of the plot A (0 ≀ x_A, y_A ≀ 1000). The following two lines describe coordinates (x_B, y_B) and (x_C, y_C) of plots B and C respectively in the same format (0 ≀ x_B, y_B, x_C, y_C ≀ 1000). It is guaranteed that all three plots are distinct. Output On the first line print a single integer k β€” the smallest number of plots needed to be cleaned from trees. The following k lines should contain coordinates of all plots needed to be cleaned. All k plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them. Examples Input 0 0 1 1 2 2 Output 5 0 0 1 0 1 1 1 2 2 2 Input 0 0 2 0 1 1 Output 4 0 0 1 0 1 1 2 0 Note The first example is shown on the picture in the legend. The second example is illustrated with the following image: <image> Submitted Solution: ``` def func1(a,b,c,d,e): j = max(c, d, e) k = min(c, d, e) print(j-k+1+abs(b-a)) for i in range(k,j+1): print(str(a)+" "+str(i)) if a<b: for i in range(a+1,b+1): print(str(i)+" "+str(e)) else: for i in range(b,a): print(str(i)+" "+str(e)) def func2(a,b,c,d,e): j = max(c, d, e) k = min(c, d, e) print(j-k+1+abs(b-a)) for i in range(k,j+1): print(str(i)+" "+str(a)) if a<b: for i in range(a+1,b+1): print(str(e)+" "+str(i)) else: for i in range(b,a): print(str(e)+" "+str(i)) ```
instruction
0
19,468
23
38,936
No
output
1
19,468
23
38,937
Provide tags and a correct Python 3 solution for this coding contest problem. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4.
instruction
0
19,469
23
38,938
Tags: implementation Correct Solution: ``` n = int(input()) s = [] for i in range(n): ip = input() s.append(ip) count = 0 for i in range(1,n-1): for j in range(1,n-1): if s[i][j] == 'X' and s[i-1][j-1] == 'X' and s[i-1][j+1] == 'X' and s[i+1][j-1] == 'X' and s[i+1][j+1] == 'X': count +=1 print(count) ```
output
1
19,469
23
38,939
Provide tags and a correct Python 3 solution for this coding contest problem. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4.
instruction
0
19,470
23
38,940
Tags: implementation Correct Solution: ``` import sys data = sys.stdin.read().splitlines() n = int(data[0]) grid = [line for line in data[1:]] cnt = 0 for i in range(1, n - 1): for j in range(1, n - 1): if grid[i][j] == grid[i - 1][j - 1] == grid[i - 1][j + 1] == grid[i + 1][j - 1] == grid[i + 1][j + 1] == 'X': cnt += 1 print(cnt) ```
output
1
19,470
23
38,941
Provide tags and a correct Python 3 solution for this coding contest problem. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4.
instruction
0
19,471
23
38,942
Tags: implementation Correct Solution: ``` n = int(input()) m = [] for _ in range(n): tmp = input() m.append(tmp) # print(n,m[0][0]) res = 0 def check(i,j): return m[i-1][j-1]=='X' and m[i-1][j+1]=='X' and m[i+1][j-1]== 'X' and m[i+1][j+1]=='X' for i in range(1,n-1): for j in range(1,n-1): if m[i][j] == 'X' and check(i,j): res+=1 # print(m[i][j],end='') # print('') print(res) ```
output
1
19,471
23
38,943
Provide tags and a correct Python 3 solution for this coding contest problem. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4.
instruction
0
19,472
23
38,944
Tags: implementation Correct Solution: ``` n=int(input()) M=[input() for i in range(n)] ANS=0 for i in range(1,n-1): for j in range(1,n-1): if M[i][j]==M[i-1][j-1]==M[i-1][j+1]==M[i+1][j-1]==M[i+1][j+1]=="X": ANS+=1 print(ANS) ```
output
1
19,472
23
38,945
Provide tags and a correct Python 3 solution for this coding contest problem. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4.
instruction
0
19,473
23
38,946
Tags: implementation Correct Solution: ``` n = int(input()) m = [ input() for i in range(n)] c=0 for i in range(1,n-1): for j in range(1,n-1): if m[i][j] == 'X' and m[i-1][j-1]=='X' and m[i+1][j-1]=='X' and m[i-1][j+1]=='X' and m[i+1][j+1]=='X': c+=1 print(c) ```
output
1
19,473
23
38,947
Provide tags and a correct Python 3 solution for this coding contest problem. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4.
instruction
0
19,474
23
38,948
Tags: implementation Correct Solution: ``` def rlist(): return list(map(int, input().split())) def rdi(): return int(input()) n = rdi() line = list() for i in range(n): line.append(input()) cnt = 0 for i in range(1, n - 1): for j in range(1, n - 1): if line[i][j] == line[i - 1][j - 1] == line[i - 1][j + 1] == line[i + 1][j - 1] == line[i + 1][j + 1] == 'X': cnt += 1 print(cnt) ```
output
1
19,474
23
38,949
Provide tags and a correct Python 3 solution for this coding contest problem. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4.
instruction
0
19,475
23
38,950
Tags: implementation Correct Solution: ``` from sys import stdin,stdout from itertools import combinations from collections import defaultdict def listIn(): return list((map(int,stdin.readline().strip().split()))) def stringListIn(): return([x for x in stdin.readline().split()]) def intIn(): return (int(stdin.readline())) def stringIn(): return (stdin.readline()) if __name__=="__main__": n=intIn() count=0 arr=[] for i in range(n): temp=list(stringIn()) arr.append(temp) for i in range(1,n-1): for j in range(1,n-1): if arr[i][j]==arr[i-1][j-1]==arr[i-1][j+1]==arr[i+1][j-1]==arr[i+1][j+1]=="X": count+=1 print(count) ```
output
1
19,475
23
38,951
Provide tags and a correct Python 3 solution for this coding contest problem. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4.
instruction
0
19,476
23
38,952
Tags: implementation Correct Solution: ``` #A - CrossCounting number = int(input()) mat = [] ans = 0 for i in range(number): mat.append(' '.join(input()).split()) for i in range(1,number-1): for j in range(1,number-1): if mat[i][j] == "X": if mat[i-1][j-1] == "X": if mat[i-1][j+1] == "X": if mat[i+1][j-1] == "X": if mat[i+1][j+1] == "X": ans+=1 print(ans) ```
output
1
19,476
23
38,953
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4. Submitted Solution: ``` n = int(input()) a = [[x=='X' for x in input()] for _ in range(n)] res = 0 for i in range(1,n-1): for j in range(1,n-1): if a[i][j] and a[i-1][j-1] and a[i-1][j+1] and a[i+1][j-1] and a[i+1][j+1]: res += 1 print(res) ```
instruction
0
19,477
23
38,954
Yes
output
1
19,477
23
38,955
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4. Submitted Solution: ``` n=int(input()) l=[] for i in range(n): l.append(input()) c=0 for i in range(1,n-1): for j in range(1,n-1): if(l[i][j]=='X'): if(l[i-1][j-1]=='X' and l[i-1][j+1]=='X' and l[i+1][j-1]=='X' and l[i+1][j+1]=='X'): c+=1 print(c) ```
instruction
0
19,478
23
38,956
Yes
output
1
19,478
23
38,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4. Submitted Solution: ``` #!/usr/bin/env python import os import sys from io import BytesIO, IOBase #from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) import math def main(): n=int(input()) a=[input() for x in range(n)] print(sum([a[x][y]=="X" and a[x][y+2]=="X" and a[x+1][y+1]=="X" and a[x+2][y]=="X" and a[x+2][y+2]=="X" for x in range(n-2) for y in range(n-2)])) #-----------------------------BOSS-------------------------------------! # region fastio 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") # endregion if __name__ == "__main__": main() ```
instruction
0
19,479
23
38,958
Yes
output
1
19,479
23
38,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4. Submitted Solution: ``` M=[] n=int(input()) for i in range(n): M.append(list(input())) count=0 for i in range(1,n-1): for j in range(1,n-1): if M[i][j]=="X" and M[i-1][j-1]=="X" and M[i-1][j+1]=="X" and M[i+1][j-1]=="X" and M[i+1][j+1]=="X":count+=1 print(count) ```
instruction
0
19,480
23
38,960
Yes
output
1
19,480
23
38,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4. Submitted Solution: ``` def answer(): n = int(input()) c=[] i=0 while i<n: c.append(list(input())) i+=1 i=1 ans=0 while i<len(c)-1: j=1 while j<len(c)-1: if c[i][j]=="X": if c[i-1][j+1]=="X" and c[i+1][j+1]=="X" and c[i-1][j+1]=="X" and c[i-1][j-1]=="X": ans+=1 j+=1 i+=1 print(ans) answer() ```
instruction
0
19,481
23
38,962
No
output
1
19,481
23
38,963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4. Submitted Solution: ``` n = int(input()) matrix = [] for i in range(n): x = input() matrix.append(x) cnt = 0 for i in range(1,n-1): for j in range(1,n-1): if(matrix[i-1][j-1] == 'X' and matrix[i+1][j-1] == 'X' and matrix[i-1][j+1] == 'X' and matrix[i+1][j+1] == 'X'): cnt += 1 print(cnt) ```
instruction
0
19,482
23
38,964
No
output
1
19,482
23
38,965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4. Submitted Solution: ``` n=int(input()) a=[] for i in range(n): a.append(list(input())) print(a) c=0 for i in range(1,n-1,1): for j in range(1,n-1,1): if(i+1>-1 and i+1<n and i-1>-1 and i-1<n and j+1>-1 and j+1<n and j-1>-1 and j-1<n): if(a[i][j] == a[i+1][j+1] == a[i-1][j+1] == a[i+1][j-1] == a[i-1][j-1]=='X'): c=c+1 print(c) ```
instruction
0
19,483
23
38,966
No
output
1
19,483
23
38,967
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i, j < n) if and only if M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = 'X'. The following figure illustrates a cross appearing at position (2, 2) in a 3 Γ— 3 matrix. X.X .X. X.X Your task is to find out the number of crosses in the given matrix M. Two crosses are different if and only if they appear in different rows or columns. Input The first line contains only one positive integer n (1 ≀ n ≀ 500), denoting the size of the matrix M. The following n lines illustrate the matrix M. Each line contains exactly n characters, each of them is 'X' or '.'. The j-th element in the i-th line represents M(i, j), where 1 ≀ i, j ≀ n. Output Output a single line containing only one integer number k β€” the number of crosses in the given matrix M. Examples Input 5 ..... .XXX. .XXX. .XXX. ..... Output 1 Input 2 XX XX Output 0 Input 6 ...... X.X.X. .X.X.X X.X.X. .X.X.X ...... Output 4 Note In the first sample, a cross appears at (3, 3), so the answer is 1. In the second sample, no crosses appear since n < 3, so the answer is 0. In the third sample, crosses appear at (3, 2), (3, 4), (4, 3), (4, 5), so the answer is 4. Submitted Solution: ``` n = int(input()) arr = [] for i in range(n): arr.append(list(input())) count = 0 if n <= 2: print(0) else: for i in range(n - 1): for j in range(1, n - 1): if arr[i][j] == arr[i - 1][j - 1] == arr[i - 1][j + 1] == arr[i + 1][j - 1] == arr[i + 1][j + 1] == 'X': count += 1 print(count) ```
instruction
0
19,484
23
38,968
No
output
1
19,484
23
38,969
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sereja painted n points on the plane, point number i (1 ≀ i ≀ n) has coordinates (i, 0). Then Sereja marked each point with a small or large English letter. Sereja don't like letter "x", so he didn't use it to mark points. Sereja thinks that the points are marked beautifully if the following conditions holds: * all points can be divided into pairs so that each point will belong to exactly one pair; * in each pair the point with the lesser abscissa will be marked with a small English letter and the point with the larger abscissa will be marked with the same large English letter; * if we built a square on each pair, the pair's points will be the square's opposite points and the segment between them will be the square's diagonal, then among the resulting squares there won't be any intersecting or touching ones. Little Petya erased some small and all large letters marking the points. Now Sereja wonders how many ways are there to return the removed letters so that the points were marked beautifully. Input The first line contains integer n the number of points (1 ≀ n ≀ 105). The second line contains a sequence consisting of n small English letters and question marks β€” the sequence of letters, that mark points, in order of increasing x-coordinate of points. Question marks denote the points without letters (Petya erased them). It is guaranteed that the input string doesn't contain letter "x". Output In a single line print the answer to the problem modulo 4294967296. If there is no way to return the removed letters, print number 0. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 4 a??? Output 50 Input 4 abc? Output 0 Input 6 abc??? Output 1 Submitted Solution: ``` def two(a,b): if a=='?': if b == '?': return 1 else: return 0 else: if b =='?': return 1 else: return 0 def answer1(n,s): if n & 1 ==1: return 0 if n < 2: return 0 kind = 0 ans = 0 start = 0 end = 1 while end < n : a = s[start] b = s[end] p = two(a,b) if p != 0: kind = 0 if end - start > 1: inner = answer1(end - start-1,s[start+1:end]) kind = inner else: kind = 1 if len(s[end+1:]) != 0: right = answer1(n-end-1,s[end+1:]) kind *= right ans += kind end += 2 return ans def finall(s,kind): ch_nums = len(s.replace('?','')) num = len(s) // 2 - ch_nums ans = kind*(25**num) ans = ans % 4294967296 return ans n = int(input()) s = input() kind = answer1(n,s) ans = finall(s,kind) print(ans) ```
instruction
0
19,730
23
39,460
No
output
1
19,730
23
39,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a circle. The i-th box contains A_i stones. Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation: * Select one box. Let the box be the i-th box. Then, for each j from 1 through N, remove exactly j stones from the (i+j)-th box. Here, the (N+k)-th box is identified with the k-th box. Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed. Constraints * 1 ≦ N ≦ 10^5 * 1 ≦ A_i ≦ 10^9 Input The input is given from Standard Input in the following format: N A_1 A_2 … A_N Output If it is possible to remove all the stones from the boxes, print `YES`. Otherwise, print `NO`. Examples Input 5 4 5 1 2 3 Output YES Input 5 6 9 12 10 8 Output YES Input 4 1 2 3 1 Output NO Submitted Solution: ``` #!/usr/bin/env python3 import sys N = int(input()) A = list(map(int, input().split())) S = N*(N+1) // 2 SA = sum(A) if SA % S != 0: print("NO") sys.exit(0) K = SA // S # B = [] C = [] for i in range(N): # B.append(A[i] - A[i-1] - K) b = A[i] - A[i-1] - K if (b > 0) or (-b % N != 0): print("NO") sys.exit(0) C.append(-b//N) print("YES") ```
instruction
0
20,155
23
40,310
Yes
output
1
20,155
23
40,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a circle. The i-th box contains A_i stones. Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation: * Select one box. Let the box be the i-th box. Then, for each j from 1 through N, remove exactly j stones from the (i+j)-th box. Here, the (N+k)-th box is identified with the k-th box. Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed. Constraints * 1 ≦ N ≦ 10^5 * 1 ≦ A_i ≦ 10^9 Input The input is given from Standard Input in the following format: N A_1 A_2 … A_N Output If it is possible to remove all the stones from the boxes, print `YES`. Otherwise, print `NO`. Examples Input 5 4 5 1 2 3 Output YES Input 5 6 9 12 10 8 Output YES Input 4 1 2 3 1 Output NO Submitted Solution: ``` #!/usr/bin/env python3 if __name__ == '__main__': N = int(input()) A = list(map(int, input().split())) q = (1+N)*N/2 mi = 1000000009 for i in range(0,N): mi = min(mi, A[i]) p = mi//q for i in range(0,N): A[i] -= p * q ans = False while True: mi = 0 ma = 0 for i in range(0,N): if A[i] > A[ma]: ma = i if A[i] < A[mi]: mi = i if A[mi] < 0: ans = False break elif A[ma] == 0: ans = True break for i in range(0, N): A[(ma+1+i)%N] -= i+1 # min(A) < 15 if ans: print("YES") else: print("NO") # 1 2 3 4 5 # 2 3 4 5 1 # 3 4 5 1 2 # 4 5 1 2 3 # 5 1 2 3 4 ```
instruction
0
20,158
23
40,316
No
output
1
20,158
23
40,317
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N boxes arranged in a circle. The i-th box contains A_i stones. Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation: * Select one box. Let the box be the i-th box. Then, for each j from 1 through N, remove exactly j stones from the (i+j)-th box. Here, the (N+k)-th box is identified with the k-th box. Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed. Constraints * 1 ≦ N ≦ 10^5 * 1 ≦ A_i ≦ 10^9 Input The input is given from Standard Input in the following format: N A_1 A_2 … A_N Output If it is possible to remove all the stones from the boxes, print `YES`. Otherwise, print `NO`. Examples Input 5 4 5 1 2 3 Output YES Input 5 6 9 12 10 8 Output YES Input 4 1 2 3 1 Output NO Submitted Solution: ``` n,*a=map(int,open(0).read().split()) q,m=divmod(sum(a),n*-~n//2) print('YNEOS'[any((y-x-q+m*7)%n or y-x>q for x,y in zip(a,a[1:]))::2]) ```
instruction
0
20,160
23
40,320
No
output
1
20,160
23
40,321
Provide tags and a correct Python 3 solution for this coding contest problem. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
instruction
0
20,264
23
40,528
Tags: brute force, implementation, math, sortings Correct Solution: ``` n = int(input()) a = [int(v) for v in input().split()] a.sort() ans = (a[-1] - a[n]) * (a[n - 1] - a[0]) for i in range(1, n): ans = min(ans, (a[-1] - a[0]) * (a[i + n - 1] - a[i])) print(ans) ```
output
1
20,264
23
40,529
Provide tags and a correct Python 3 solution for this coding contest problem. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
instruction
0
20,265
23
40,530
Tags: brute force, implementation, math, sortings Correct Solution: ``` n=int(input()) a=sorted(map(int,input().split())) print(min([(a[n-1]-a[0])*(a[-1]-a[n])]+[(a[-1]-a[0])*(y-x) for x,y in zip(a,a[n-1:])])) ```
output
1
20,265
23
40,531
Provide tags and a correct Python 3 solution for this coding contest problem. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
instruction
0
20,266
23
40,532
Tags: brute force, implementation, math, sortings Correct Solution: ``` n=int(input()) a=sorted(map(int,input().split())) r=0 if n>1:r=min((a[n-1]-a[0])*(a[-1]-a[n]),(a[-1]-a[0])*min(y-x for x,y in zip(a[1:],a[n:-1]))) print(r) ```
output
1
20,266
23
40,533
Provide tags and a correct Python 3 solution for this coding contest problem. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
instruction
0
20,267
23
40,534
Tags: brute force, implementation, math, sortings Correct Solution: ``` def main(): n = int(input()) a = [int(i) for i in input().split()] a.sort() x = a[n - 1] - a[0] y = a[2 * n - 1] - a[n] c1 = x * y x = a[2 * n - 1] - a[0] for i in range(1, n): c1 = min(c1, x * (a[i + n - 1] - a[i])) print(c1) if __name__ == '__main__': main() ```
output
1
20,267
23
40,535
Provide tags and a correct Python 3 solution for this coding contest problem. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
instruction
0
20,268
23
40,536
Tags: brute force, implementation, math, sortings Correct Solution: ``` n = int(input()) a = sorted(list(map(int, input().split()))) res = (a[n-1] - a[0])*(a[-1] - a[n]) for i in range(1, n): if (a[-1] - a[0])*(a[n + i - 1] - a[i]) < res: res = (a[-1] - a[0])*(a[n + i - 1] - a[i]) print(res) ```
output
1
20,268
23
40,537
Provide tags and a correct Python 3 solution for this coding contest problem. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
instruction
0
20,269
23
40,538
Tags: brute force, implementation, math, sortings Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) a.sort() s1 = (a[n-1]-a[0])*(a[-1]-a[n]) tmp = a[-1] - a[0] for i in range(1, n): if tmp * (a[n+i-1]-a[i]) < s1: s1 = tmp * (a[n+i-1]-a[i]) print(s1) ```
output
1
20,269
23
40,539
Provide tags and a correct Python 3 solution for this coding contest problem. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
instruction
0
20,270
23
40,540
Tags: brute force, implementation, math, sortings Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) a.sort() k=12122121212121 for i in range(1,n): k=min(k,a[i+n-1]-a[i]) k=k*(a[2*n-1]-a[0]) z=abs(a[0]-a[n-1])*abs(a[n]-a[2*n-1]) print(min(k,z)) ```
output
1
20,270
23
40,541
Provide tags and a correct Python 3 solution for this coding contest problem. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)).
instruction
0
20,271
23
40,542
Tags: brute force, implementation, math, sortings Correct Solution: ``` n = int(input()) records = list(map(int,input().split())) records.sort() diffArr = [] for i in range(n+1): if i == 0: diffArr.append([records[n-1]-records[0],records[-1]-records[n]]) elif i == n: diffArr.append([records[-1]-records[n],records[n-1]-records[0]]) else: diffArr.append([records[n+i-1] - records[i],records[-1]-records[0]]) minDiff = min(diffArr, key = lambda t: t[0]*t[1]) print(minDiff[0]*minDiff[1]) ```
output
1
20,271
23
40,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). Submitted Solution: ``` n=int(input()) CO=list(map(int,input().split())) CO.sort() area=(CO[n-1]-CO[0])*(CO[2*n-1]-CO[n]) for i in range(n+1): areax=(CO[i+n-1]-CO[i])*(CO[2*n-1]-CO[0]) if areax<area: area=areax print(area) ```
instruction
0
20,272
23
40,544
Yes
output
1
20,272
23
40,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). Submitted Solution: ``` N=int(input()) A=list(map(int,input().split())) A.sort() s=(A[N-1]-A[0])*(A[2*N-1]-A[N]) for i in range(1,N): s=min(s,(A[N-1+i]-A[i])*(A[2*N-1]-A[0])) print(s) ```
instruction
0
20,273
23
40,546
Yes
output
1
20,273
23
40,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). Submitted Solution: ``` import functools import time from collections import Counter def timer(func): @functools.wraps(func) def wrapper(*args, **kwargs): stime = time.perf_counter() res = func(*args, **kwargs) elapsed = time.perf_counter() - stime print(f"{func.__name__} in {elapsed:.4f} secs") return res return wrapper class solver: # @timer def __init__(self): pass def __call__(self): n = int(input()) a = list(map(int, input().strip().split())) a.sort() ans = 10**18 for i in range(n + 1): x1 = a[i] x2 = a[i + n - 1] y1 = a[0] if i > 0 else a[n] y2 = a[-1] if i < n else a[n - 1] ans = min(ans, (x2 - x1) * (y2 - y1)) print(ans) solver()() ```
instruction
0
20,274
23
40,548
Yes
output
1
20,274
23
40,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). Submitted Solution: ``` n = int(input()) arr = sorted(list(map(int,input().split()))) ans = (arr[n-1]-arr[0])*(arr[2*n-1]-arr[n]) for i in range(1,n): ans = min(ans,(arr[i+n-1]-arr[i])*(arr[2*n-1]-arr[0])) print(ans) ```
instruction
0
20,275
23
40,550
Yes
output
1
20,275
23
40,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). Submitted Solution: ``` if __name__ == "__main__": n = int(input()) data = map(int, input().split()) s = sorted(data) print((s[n-1] - s[0]) * (s[2*n - 1] - s[n])) ```
instruction
0
20,276
23
40,552
No
output
1
20,276
23
40,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). Submitted Solution: ``` n = int(input()) a = sorted(map(int, input().split())) best = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]) for i in range(1, n - 1): best = min(best, (a[n + i] - a[i]) * (a[2 * n - 1] - a[0])) print(best) ```
instruction
0
20,277
23
40,554
No
output
1
20,277
23
40,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). Submitted Solution: ``` n = 2*int(input()) arr = [int(i) for i in input().split()] arr.sort() first = (arr[0],arr[n//2]) last = (arr[n//2-1],arr[n-1]) #print(first,last) print(abs(first[0]-last[0]) * abs(first[1]-last[1])) ```
instruction
0
20,278
23
40,556
No
output
1
20,278
23
40,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≀ x ≀ x_2 and y_1 ≀ y ≀ y_2, where (x_1, y_1) and (x_2, y_2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero. After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky. Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points. Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. Input The first line of the input contains an only integer n (1 ≀ n ≀ 100 000), the number of points in Pavel's records. The second line contains 2 β‹… n integers a_1, a_2, ..., a_{2 β‹… n} (1 ≀ a_i ≀ 10^9), coordinates, written by Pavel in some order. Output Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. Examples Input 4 4 1 3 2 3 2 1 3 Output 1 Input 3 5 8 5 5 7 5 Output 0 Note In the first sample stars in Pavel's records can be (1, 3), (1, 3), (2, 3), (2, 4). In this case, the minimal area of the rectangle, which contains all these points is 1 (rectangle with corners at (1, 3) and (2, 4)). Submitted Solution: ``` n = int(input()) a = [int(x) for x in input().split()] a.sort() top = [a[0], a[-1]] right = [a[n - 1], a[n]] print(abs((top[0] - right[0])*(top[1] - right[1]))) ```
instruction
0
20,279
23
40,558
No
output
1
20,279
23
40,559
Provide tags and a correct Python 3 solution for this coding contest problem. Like any unknown mathematician, Yuri has favourite numbers: A, B, C, and D, where A ≀ B ≀ C ≀ D. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides x, y, and z exist, such that A ≀ x ≀ B ≀ y ≀ C ≀ z ≀ D holds? Yuri is preparing problems for a new contest now, so he is very busy. That's why he asked you to calculate the number of triangles with described property. The triangle is called non-degenerate if and only if its vertices are not collinear. Input The first line contains four integers: A, B, C and D (1 ≀ A ≀ B ≀ C ≀ D ≀ 5 β‹… 10^5) β€” Yuri's favourite numbers. Output Print the number of non-degenerate triangles with integer sides x, y, and z such that the inequality A ≀ x ≀ B ≀ y ≀ C ≀ z ≀ D holds. Examples Input 1 2 3 4 Output 4 Input 1 2 2 5 Output 3 Input 500000 500000 500000 500000 Output 1 Note In the first example Yuri can make up triangles with sides (1, 3, 3), (2, 2, 3), (2, 3, 3) and (2, 3, 4). In the second example Yuri can make up triangles with sides (1, 2, 2), (2, 2, 2) and (2, 2, 3). In the third example Yuri can make up only one equilateral triangle with sides equal to 5 β‹… 10^5.
instruction
0
20,420
23
40,840
Tags: binary search, implementation, math, two pointers Correct Solution: ``` import sys input = sys.stdin.readline def sum1(x): k = min(d, c + x - 1, b + x - 1) if k < c: return 0 else: return (c - b + 1) * (k - c + 1) def sum2(x): k = min(d, c + x - 1) l = max(b + x, c) if k < l: return(0) else: return (c + x) * (k - l + 1) - (k + l) * (k - l + 1) // 2 a, b, c, d = map(int, input().split()) res = 0 for x in range(a, b + 1): res += sum1(x) + sum2(x) print(res) ```
output
1
20,420
23
40,841