Dataset Viewer
Auto-converted to Parquet Duplicate
message
stringlengths
2
19.9k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
322
108k
cluster
float64
15
15
__index_level_0__
int64
644
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1
instruction
0
322
15
644
Tags: graphs, math, shortest paths Correct Solution: ``` def nrook(r1, c1, r2, c2): if r1 == r2 or c1 == c2: return 1 return 2 def nking(r1, c1, r2, c2): dr = abs(r1 - r2) dc = abs(c1 - c2) return dr + dc - min(dr, dc) def iswhite(r, c): return c % 2 != 0 if r % 2 else c % 2 == 0 def nbishop(r1, c1, r2, c2): if iswhite(r1, c1) != iswhite(r2, c2): return 0 if r1 + c1 == r2 + c2 or r1 - c1 == r2 - c2: return 1 return 2 def main(): r1, c1, r2, c2 = [int(x) - 1 for x in input().split()] rook = nrook(r1, c1, r2, c2) bishop = nbishop(r1, c1, r2, c2) king = nking(r1, c1, r2, c2) print(rook, bishop, king) if __name__ == '__main__': main() ```
output
1
322
15
645
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1
instruction
0
323
15
646
Tags: graphs, math, shortest paths Correct Solution: ``` x1,y1,x2,y2 = list(map(int,input().split())) arr = [min(abs(x1-x2),1) + min(abs(y1-y2),1),(1 if abs(x1-x2) == abs(y1-y2) else 2) if (x1&1^y1&1)==(x2&1^y2&1) else 0,max(abs(y2-y1),abs(x2-x1))] print(*arr) ```
output
1
323
15
647
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1
instruction
0
324
15
648
Tags: graphs, math, shortest paths Correct Solution: ``` a = list(map(int, input().split())) y1 = a[0] d1 = a[1] y2 = a[2] d2 = a[3] yatay = abs(y1 - y2)#0 dikey = abs(d1 - d2)#1 a = [0, 0 , 0] # kale fil şah if yatay == 0 or dikey == 0: a[0] = 1 else: a[0] = 2 if ((y1+d1) % 2) == ((y2+d2) % 2): if yatay == dikey: a[1] = 1 else: a[1] = 2 else: a[1] = 0 if yatay == dikey: a[2] = yatay else: a[2] = abs(yatay - dikey) + min(yatay, dikey) print(*a) ```
output
1
324
15
649
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1
instruction
0
325
15
650
Tags: graphs, math, shortest paths Correct Solution: ``` __author__ = 'Esfandiar and HajLorenzo' a=list(map(int,input().split())) res = 2 res-= a[0]==a[2] res-= a[1]==a[3] print(res,end=" ") res=2 black1 = (a[0]+a[1]) % 2 != 0 black2 = (a[2]+a[3]) % 2 != 0 if black1 != black2 or (a[0] == a[2] and a[1] == a[3]): print(0,end=" ") else: print(1 if abs(a[0]-a[2]) == abs(a[1]-a[3]) else 2,end=" ") print(abs(a[0] - a[2]) + max(abs(a[1] - a[3]) - (abs(a[0] - a[2])),0)) ```
output
1
325
15
651
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1
instruction
0
326
15
652
Tags: graphs, math, shortest paths Correct Solution: ``` sx,sy,ex,ey=map(int,input().split()) rook=1 if sx==ex or sy==ey else 2 bishop=0 if abs(sx-ex)==abs(sy-ey): bishop=1 elif (sx+sy)%2==(ex+ey)%2: bishop=2 king=max(abs(sx-ex),abs(sy-ey)) print(rook,bishop,king) ```
output
1
326
15
653
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1
instruction
0
327
15
654
Tags: graphs, math, shortest paths Correct Solution: ``` pos = input() c1 = int(pos.split()[0]) r1 = int(pos.split()[1]) c2 = int(pos.split()[2]) r2 = int(pos.split()[3]) def rook(): if c1 == c2 or r1==r2: return 1 else : return 2 def bishop(): if (c1+r1)%2 == (c2+r2)%2: if (c1-r1) == (c2-r2) or (c1+r1) == (c2+r2): return 1 else : return 2 else: return 0 def king(): if r1==r2: return abs(c2-c1) elif c1==c2: return abs(r2-r1) else: if abs(c2-c1)>=abs(r2-r1): return abs(c2-c1) else: return abs(r2-r1) print (rook(), bishop(), king()) ```
output
1
327
15
655
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1
instruction
0
328
15
656
Tags: graphs, math, shortest paths Correct Solution: ``` from math import ceil d = {"r":0,"b":0,"k":0} r1,c1,r2,c2 = map(int,input().split()) if r1 != r2: d["r"] = d["r"] + 1 if c1 != c2: d["r"] = d["r"] + 1 if (abs(r1-r2)+abs(c1-c2))%2 == 1: d["b"] = 0 elif c1-c2 != 0 and (r1-r2)/(c1-c2) == -1 or c1-c2 != 0 and (r1-r2)/(c1-c2) == 1: d["b"] = 1 elif(abs(r1-r2)+abs(c1-c2))%2 == 0: d["b"] = 2 y1 = -(r1-c1-r2) y2 = (r1+c1-r2) x1 = (r1-c1+c2) x2 = (r1+c1-c2) d1 = pow(pow((x1-r1),2)+pow(c2-c1,2),1/2)/pow(2,1/2)+abs(x1-r2) d2 = pow(pow((x2-r1),2)+pow(c2-c1,2),1/2)/pow(2,1/2)+abs(x2-r2) d3 = pow(pow((r2-r1),2)+pow(c1-y2,2),1/2)/pow(2,1/2)+abs(c2-y2) d4 = pow(pow((r2-r1),2)+pow(c1-y1,2),1/2)/pow(2,1/2)+abs(c2-y1) d5 = (abs(r2-r1)+abs(c2-c1)) d["k"] = min(d1,d2,d3,d4,d5) for i in d: print(int(ceil(d[i])),end=" ") ```
output
1
328
15
657
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1
instruction
0
329
15
658
Tags: graphs, math, shortest paths Correct Solution: ``` r1,c1,r2,c2=map(int,input().split()) def f(): if abs(r1-r2)==abs(c1-c2): return 1 elif (r1+c1)%2==(c2+r2)%2: return 2 else: return 0 def k(): dx=abs(r1-r2) dy=abs(c1-c2) return max(dx,dy) def r(): if r1==r2 or c1==c2: return 1 else: return 2 print(r(),f(),k()) ```
output
1
329
15
659
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1 Submitted Solution: ``` #Program Rook,Bishop,and King def rook(sx,sy,lx,ly): if sx != lx or sy != ly: if sx == lx: move = 1 elif sy == ly: move = 1 else: move = 2 else: move = 0 return move def bishop(sx,sy,lx,ly): if sx != lx or sy != ly: if (sx+sy)%2 != (lx+ly)%2: move = 0 else: if (sx+sy) == (lx+ly) or abs(sx-lx) == abs(sy-ly): move = 1 else: move = 2 else: move = 0 return move def king(sx,sy,lx,ly): move = 0 if sx == lx: move = abs(sy-ly) elif sy == ly: move = abs(sx-lx) else: while sx != lx or sy != ly: if sx > lx: sx-=1 elif sx < lx: sx+=1 if sy > ly: sy-=1 elif sy < ly: sy+=1 move+=1 return move def main(): p1,p2,p3,p4 = map(int,input().split()) move = [] move.append(rook(p1,p2,p3,p4)) move.append(bishop(p1,p2,p3,p4)) move.append(king(p1,p2,p3,p4)) for x in move: print(x,end=" ") main() ```
instruction
0
330
15
660
Yes
output
1
330
15
661
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1 Submitted Solution: ``` a = [int(i) for i in input().split()] x1 = a[0] y1 = a[1] x2 = a[2] y2 = a[3] # for rook if(x1 == x2) or (y2 == y1): print(1, end = ' ') elif(x1 != x2 and y2 != y1): print(2, end = ' ') #for bishop if(x1 + y1 == x2 + y2 or x1-y1 == x2 - y2): print(1, end = ' ') elif (x1 + y1) % 2 != (x2 + y2)%2 : print(0, end = ' ') else: print(2) #for king print(max(abs(x1 - x2), abs(y1-y2)) , end = ' ') ```
instruction
0
331
15
662
Yes
output
1
331
15
663
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1 Submitted Solution: ``` read = lambda: map(int, input().split()) r1, c1, r2, c2 = read() L = 1 if r1 == r2 or c1 == c2 else 2 K = max(abs(r1 - r2), abs(c1 - c2)) if abs(r1 - r2) == abs(c1 - c2): S = 1 elif (r1 + c1) % 2 == (r2 + c2) % 2: S = 2 else: S = 0 print(L, S, K) ```
instruction
0
332
15
664
Yes
output
1
332
15
665
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1 Submitted Solution: ``` r1,c1,r2,c2=map(int,input().split()) if r1==r2 or c1==c2:r=1 else:r=2 if abs((r1+c1)-(r2+c2))%2==1:b=0 elif abs(c2-c1)==abs(r2-r1):b=1 else:b=2 k=max(abs(c2-c1),abs(r2-r1)) print(r,b,k) ```
instruction
0
333
15
666
Yes
output
1
333
15
667
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1 Submitted Solution: ``` r1,c1,r2,c2=map(int,input().split()) ans=[] if r1==r2 or c1==c2: ans.append(1) else: ans.append(2) if r1%2==c1%2: if r2%2==c2%2: if (r1+c1)==(r2+c2) or (r1-c1)==(r2-c2): ans.append(1) else: ans.append(2) else: ans.append(0) elif r1%2!=c1%2: if r2%2!=c2%2: if (r1+c1)==(r2+c2) or abs(r1-c1)==abs(r2-c2): ans.append(1) else: ans.append(2) else: ans.append(0) ans.append(max(abs(r1-r2),abs(c1-c2))) #diff print(*ans) ```
instruction
0
334
15
668
No
output
1
334
15
669
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1 Submitted Solution: ``` from math import ceil d = {"r":0,"b":0,"k":0} r1,c1,r2,c2 = map(int,input().split()) if r1 != r2: d["r"] = d["r"] + 1 if c1 != c2: d["r"] = d["r"] + 1 if (abs(r1-r2)+abs(c1-c2))%2 == 1: d["b"] = 0 elif (r1-r2)/(c1-c2) == -1 or (r1-r2)/(c1-c2) == 1: d["b"] = 1 elif(abs(r1-r2)+abs(c1-c2))%2 == 0: d["b"] = 2 y1 = r1-c1-r2 y2 = r1+c1-r2 x1 = r1-c1-c2 x2 = r1+c1-c2 d1 = pow(pow((x1-r1),2)+pow(c2-c1,2),1/2)/pow(2,1/2)+abs(y1-c2) d2 = pow(pow((x2-r1),2)+pow(c2-c1,2),1/2)/pow(2,1/2)+abs(y2-c2) d3 = pow(pow((r2-r1),2)+pow(c1-y2,2),1/2)/pow(2,1/2)+abs(x2-r2) d4 = pow(pow((r2-r1),2)+pow(c1-y1,2),1/2)/pow(2,1/2)+abs(x1-r2) d5 = (abs(r2-r1)+abs(c2-c1)) # print(d1,d2,d3,d4,d5) d["k"] = min(d1,d2,d3,d4,d5) for i in d: print(int(ceil(d[i])),end=" ") ```
instruction
0
335
15
670
No
output
1
335
15
671
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1 Submitted Solution: ``` r1,c1,r2,c2 = input().split(" ") r1,c1,r2,c2 = int(r1),int(c1),int(r2),int(c2) analyze = r2-r1==c2-c1 or r2-r1==c1-c2 or r1-r2==c2-c1 or r1-r2==c1-c2 if (r1==r2) and (c1==c2): r = 0 elif (r1==r2) or (c1==c2): r = 1 else: r = 2 if (r1%2==c1%2)!=(r2%2==c2%2) or (r1==r2 and c1==c2): b = 0 elif analyze: b = 1 else: b = 2 if analyze: k = r2-r1 elif r2==r1 and c2!=c1: k = c2-c1 elif c2==c1 and r2!=r1: k = r2-r1 elif r2-r1==c2-c1-1 or r2-r1==c1-c2-1 or r1-r2==c2-c1-1 or r1-r2==c1-c2-1 or r2-r1==c2-c1+1 or r2-r1==c1-c2+1 or r1-r2==c2-c1+1 or r1-r2==c1-c2+1: k = r2-r1 if k<0: 0-k k += 1 elif r2<r1: k = r1-r2 if c2<c1: k += c1-c2 else: k += c2-c1 elif r2>r1: k = r2-r1 if c2<c1: k += c1-c2 else: k += c2-c1 if k<0: k = 0-k print(r,b,k) ```
instruction
0
336
15
672
No
output
1
336
15
673
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 Γ— 8 table. A field is represented by a pair of integers (r, c) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: * A rook moves any number of fields horizontally or vertically. * A bishop moves any number of fields diagonally. * A king moves one field in any direction β€” horizontally, vertically or diagonally. <image> The pieces move like that Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input The input contains four integers r1, c1, r2, c2 (1 ≀ r1, c1, r2, c2 ≀ 8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Examples Input 4 3 1 6 Output 2 1 3 Input 5 5 5 6 Output 1 0 1 Submitted Solution: ``` def fn(r1,c1,r2,c2): if r1==r2 and c1==c2: rook = bishop = king = 0 print(rook, bishop, king) return if r1==r2 or c1==c2: rook=1 else: rook=2 if (r1-r2 == c1-c2) or (r1-r2 ==c2-c1): bishop=1 elif (r1-r2) % 2== 1 or (c1-c2) % 2 == 1: bishop=0 else: bishop=2 if r1==r2: king=abs(c1-c2) elif c1==c2: king=abs(r1-r2) elif (r1-r2 == c1-c2) or (r1-r2 == c2-c1): king = abs(r1-r2) else: king = abs(r1-r2) + abs(c2-c1+abs(r1-r2)) print(rook, bishop, king) return ```
instruction
0
337
15
674
No
output
1
337
15
675
Provide tags and a correct Python 3 solution for this coding contest problem. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2
instruction
0
359
15
718
Tags: greedy, hashing, implementation Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): n = int(input()) a = [list(map(int,input().split())) for _ in range(n)] lst = [0]*(2*n-1) for i in range(n): for j in range(n): lst[i+j] += a[i][j] odd,eve = -1,-1 ls = [[-1,-1],[-1,-1]] for j in range(n): ans,aa = 0,-1 for i in range(n-j): ans += a[i][j+i] if lst[2*i+j]-a[i][j+i] > aa: aa = lst[2*i+j]-a[i][j+i] v = [i+1,j+i+1] if j&1: if odd < ans+aa: odd = ans+aa ls[1] = v else: if eve < ans+aa: eve = ans+aa ls[0] = v for i in range(n): ans,aa = 0,-1 for j in range(n-i): ans += a[i+j][j] if lst[i+2*j]-a[i+j][j] > aa: aa = lst[i+2*j]-a[i+j][j] v = [i+j+1,j+1] if i&1: if odd < ans+aa: odd = ans+aa ls[1] = v else: if eve < ans+aa: eve = ans+aa ls[0] = v print(odd+eve) print(ls[0][0],ls[0][1],ls[1][0],ls[1][1]) # Fast IO Region 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") if __name__ == "__main__": main() ```
output
1
359
15
719
Provide tags and a correct Python 3 solution for this coding contest problem. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2
instruction
0
360
15
720
Tags: greedy, hashing, implementation Correct Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ####################################### a=int(input()) ans=[] for i in range(a): z=list(map(int,input().split())) ans.append(z) pri1=pow(10,9)+7 from collections import * obt=defaultdict(int) act=defaultdict(int) for i in range(a): for j in range(a): p,q=i,j p,q=p-min(p,q),q-min(p,q) obt[p-q]+=ans[i][j] p,q=i,j act[p+q]+=ans[i][j] maxa1=0 maxa2=0 p1=0 p2=0 p3=0 p4=0 for i in range(a): for j in range(a): if(i%2==j%2): if(min(i,j)==0 or min(i,j)==a-1): value=ans[i][j] else: p,q=i,j p,q=p-min(p,q),q-min(p,q) value=0 value+=obt[p-q] value+=act[i+j] value-=ans[i][j] maxa1=max(maxa1,value) if(maxa1==value): p1,p2=i,j else: if(min(i,j)==0 or min(i,j)==a-1): value=ans[i][j] else: p,q=i,j value=0 p,q=p-min(p,q),q-min(p,q) value+=obt[p-q] value+=act[i+j] value-=ans[i][j] maxa2=max(maxa2,value) if(maxa2==value): p3,p4=i,j print(maxa1+maxa2) print(p1+1,p2+1,p3+1,p4+1) ```
output
1
360
15
721
Provide tags and a correct Python 3 solution for this coding contest problem. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2
instruction
0
361
15
722
Tags: greedy, hashing, implementation Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) 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") #------------------------------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=-10**6, func=lambda a, b: max(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) class SegmentTree1: def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- prime = [True for i in range(50001)] pp=[] def SieveOfEratosthenes(n=50000): # Create a boolean array "prime[0..n]" and initialize # all entries it as true. A value in prime[i] will # finally be false if i is Not a prime, else true. p = 2 while (p * p <= n): # If prime[p] is not changed, then it is a prime if (prime[p] == True): # Update all multiples of p for i in range(p * p, n+1, p): prime[i] = False p += 1 for i in range(50001): if prime[i]: pp.append(i) #---------------------------------running code------------------------------------------ n=int(input()) a=[] d1=defaultdict(int) d2=defaultdict(int) for i in range (n): b=list(map(int,input().split())) a.append(b) for j in range (n): d1[i+j]+=b[j] d2[i-j]+=b[j] m1,m2=-1,-1 res1,res2=[0,0],[0,0] #print(d1) #print(d2) for i in range (n): for j in range (n): if (i+j)%2==0: if d1[i+j]+d2[i-j]-a[i][j]>m1: m1=d1[i+j]+d2[i-j]-a[i][j] res1=[i+1,j+1] else: if d1[i+j]+d2[i-j]-a[i][j]>m2: m2=d1[i+j]+d2[i-j]-a[i][j] res2=[i+1,j+1] #print(m1,m2,d1[i+j]+d2[i-j]-a[i][j]) print(m1+m2) print(*res1,*res2) ```
output
1
361
15
723
Provide tags and a correct Python 3 solution for this coding contest problem. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2
instruction
0
362
15
724
Tags: greedy, hashing, implementation Correct Solution: ``` import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush # from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect from time import perf_counter from fractions import Fraction import copy import time # import numpy as np starttime = time.time() # import numpy as np mod = int(pow(10, 9) + 7) mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end) def L(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] try: # sys.setrecursionlimit(int(pow(10,6))) sys.stdin = open("input.txt", "r") # sys.stdout = open("../output.txt", "w") except: pass from sys import stdin input = stdin.buffer.readline I = lambda : list(map(int,input().split())) n,=I() l=[] for i in range(n): l.append(I()) d={};su={};s=0;an=[1,1,2,1] for i in range(n): for j in range(n): d[i-j]=d.get(i-j,0)+l[i][j] su[i+j]=su.get(i+j,0)+l[i][j] x=0;y=0 for i in range(n): for j in range(n): p=d[i-j]+su[i+j]-l[i][j] if (i+j)%2: if p>x: an[0],an[1]=i+1,j+1 x=p else: if p>y: an[2],an[3]=i+1,j+1 y=p s=x+y print(s) print(*an) endtime = time.time() # print(f"Runtime of the program is {endtime - starttime}") ```
output
1
362
15
725
Provide tags and a correct Python 3 solution for this coding contest problem. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2
instruction
0
363
15
726
Tags: greedy, hashing, implementation Correct Solution: ``` from sys import stdin input = stdin.buffer.readline from collections import defaultdict as dd I = lambda : list(map(int,input().split())) n,=I() l=[];d=dd(int);su=dd(int);s=0;an=[1,1,2,1] for i in range(n): l.append(I()) for j in range(n): d[i-j]+=l[i][j] su[i+j]+=l[i][j] x=0;y=0 for i in range(n): for j in range(n): l[i][j]=d[i-j]+su[i+j]-l[i][j] if (i+j)%2: if l[i][j]>x: an[0],an[1]=i+1,j+1 x=l[i][j] else: if l[i][j]>y: an[2],an[3]=i+1,j+1 y=l[i][j] s=x+y print(s) print(*an) ```
output
1
363
15
727
Provide tags and a correct Python 3 solution for this coding contest problem. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2
instruction
0
364
15
728
Tags: greedy, hashing, implementation Correct Solution: ``` import sys input=sys.stdin.buffer.readline t=1 for __ in range(t): a=[] n=int(input()) for i in range(n): b=list(map(int,input().split())) a.append(b) dr={} di={} for i in range(n): for j in range(n): dr[i+j]=dr.get(i+j,0)+a[i][j] di[i+n-j+1]=di.get(i+n-j+1,0)+a[i][j] ind1=[0]*2 ind2=[0]*2 maxi1=0 maxi2=0 for i in range(n): for j in range(n): #if maxi<(dr[i+j]+di[i+n-j+1]-a[i][j]): if ((i+j)&1)==1: if maxi1<=(dr[i+j]+di[i+n-j+1]-a[i][j]): maxi1=(dr[i+j]+di[i+n-j+1]-a[i][j]) ind1[0]=i+1 ind1[1]=j+1 else: if maxi2<=(dr[i+j]+di[i+n-j+1]-a[i][j]): maxi2=(dr[i+j]+di[i+n-j+1]-a[i][j]) ind2[0]=i+1 ind2[1]=j+1 print(maxi1+maxi2) print(ind1[0],ind1[1],ind2[0],ind2[1]) ```
output
1
364
15
729
Provide tags and a correct Python 3 solution for this coding contest problem. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2
instruction
0
365
15
730
Tags: greedy, hashing, implementation Correct Solution: ``` import os import sys from io import BytesIO, IOBase def main(): pass # 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() n=int(input()) arr=[] for i in range(n): li=[int(x) for x in input().split()] arr.append(li) d1,d2={},{} for i in range(n): for j in range(n): if((i-j) in d1): d1[i-j]+=arr[i][j] else: d1[i-j]=arr[i][j] if((i+j) in d2): d2[i+j]+=arr[i][j] else: d2[i+j]=arr[i][j] m1,m2=-1,-1 ans1,ans2=(),() for i in range(n): for j in range(n): if((i+j)%2==0): if(d1[i-j]+d2[i+j]-arr[i][j]>m1): ans1=(i,j) m1=d1[i-j]+d2[i+j]-arr[i][j] else: if(d1[i-j]+d2[i+j]-arr[i][j]>m2): ans2=(i,j) m2=d1[i-j]+d2[i+j]-arr[i][j] print(m1+m2,ans1[0]+1,ans1[1]+1,ans2[0]+1,ans2[1]+1) ```
output
1
365
15
731
Provide tags and a correct Python 3 solution for this coding contest problem. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2
instruction
0
366
15
732
Tags: greedy, hashing, implementation Correct Solution: ``` from __future__ import division, print_function import os import sys from io import BytesIO, IOBase from math import inf def main(): # a bishop has to be on a cell intercepted by even diagonals, # and another on a cell intercepted by odd diagonals # i + j is even -> white # i + j is odd -> gray # diagonal 1 -> i - j (top-left to bottom-right) (this difference is constant) # diagonal 2 -> i + j (top-right to bottom-left) (this sum is constant) # calculate the sum of each diagonal (n2) # find the best cell (with max total) intercepted by even diagonals and the # best cell (with max total) intercepted by odd diagonals n = int(input()) chessboard = [ [ int(x) for x in input().split() ] for row in range(n) ] mainDiagonalSums = {} secondaryDiagonalSums = {} for i in range(n): for j in range(n): mainDiagonal = i - j if mainDiagonal in mainDiagonalSums: mainDiagonalSums[mainDiagonal] += chessboard[i][j] else: mainDiagonalSums[mainDiagonal] = chessboard[i][j] secondaryDiagonal = i + j if secondaryDiagonal in secondaryDiagonalSums: secondaryDiagonalSums[secondaryDiagonal] += chessboard[i][j] else: secondaryDiagonalSums[secondaryDiagonal] = chessboard[i][j] maxPoints = [-inf, -inf] bestPosition = [None, None] for i in range(n): for j in range(n): points = ( mainDiagonalSums[i-j] + secondaryDiagonalSums[i+j] - chessboard[i][j] ) if (i + j) & 1: if points > maxPoints[1]: bestPosition[1] = (i, j) maxPoints[1] = points else: if points > maxPoints[0]: bestPosition[0] = (i, j) maxPoints[0] = points print(sum(maxPoints)) print(' '.join([ f'{i+1} {j+1}' for i, j in bestPosition ])) 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") input = lambda: sys.stdin.readline().rstrip("\r\n") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep = kwargs.pop("sep", " ") file = kwargs.pop("file", sys.stdout) atStart = True for x in args: if not atStart: file.write(sep) file.write(str(x)) atStart = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) main() ```
output
1
366
15
733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2 Submitted Solution: ``` from sys import stdin input = stdin.buffer.readline n=int(input()) l=[[*map(int,input().split())] for _ in range(n)] d={};su={};s=0;an=[1,1,2,1] for i in range(n): for j in range(n): d[i-j]=d.get(i-j,0)+l[i][j] su[i+j]=su.get(i+j,0)+l[i][j] position=[2,1,1,1] x,y=0,0 for i in range(n): for j in range(n): p=d[i-j]+su[i+j]-l[i][j] if (i+j)%2: if p>x: x=p position[:2]=[i+1,j+1] else: if p>y: y=p position[2:]=[i+1,j+1] print(x+y) print(*position) ```
instruction
0
367
15
734
Yes
output
1
367
15
735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2 Submitted Solution: ``` from sys import stdin input = stdin.buffer.readline I = lambda : list(map(int,input().split())) n = int(input()) ans = [] for _ in range(n): arr = I() ans.append(arr) topLeft, bottomLeft = {}, {} for i in range(n): for j in range(n): topLeft[i-j] = topLeft.get(i-j, 0) + ans[i][j] bottomLeft[i+j] = bottomLeft.get(i+j, 0) + ans[i][j] mx1, mx2, pos1, pos2 = -1, -1, [-1,-1], [-1,-1] for i in range(n): for j in range(n): if (i+j) & 1: if mx1 < topLeft[i-j] + bottomLeft[i+j] - ans[i][j]: mx1, pos1 = topLeft[i-j] + bottomLeft[i+j] - ans[i][j], [i+1,j+1] else: if mx2 < topLeft[i - j] + bottomLeft[i + j] - ans[i][j]: mx2, pos2 = topLeft[i - j] + bottomLeft[i + j] - ans[i][j], [i+1, j+1] print(mx1+mx2) print(pos1[0], pos1[1], pos2[0], pos2[1]) ```
instruction
0
368
15
736
Yes
output
1
368
15
737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2 Submitted Solution: ``` import os import sys from io import BytesIO, IOBase nmbr = lambda: int(input()) lst = lambda: list(map(int, input().split())) def main(): # n, k = map(int, input().split()) # s = input() n = int(input()) a = [list(map(int, input().split())) for _ in range(n)] ss = {} # / sd = {} # \ mx = 0; x = y = x1 = y1 = -1 for i in range(n): for j in range(n): ss[i + j] = ss.get(i + j, 0) + a[i][j] sd[i - j] = sd.get(i - j, 0) + a[i][j] for i in range(n): for j in range(n): val = ss[i + j] + sd[i - j] - a[i][j] if val >= mx: mx = val x, y = i, j mx1 = 0 for i in range(n): for j in range(n): if (i + j) & 1 == (x + y) & 1: continue val = ss[i + j] + sd[i - j] - a[i][j] if val >= mx1: mx1 = val x1, y1 = i, j print(mx + mx1) print(x + 1, y + 1, x1 + 1, y1 + 1) # sys.stdout.write(str(ans)) 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") if __name__ == "__main__": for t in range(1):main()#int(input())): ```
instruction
0
369
15
738
Yes
output
1
369
15
739
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2 Submitted Solution: ``` from sys import stdin input = stdin.buffer.readline I = lambda : list(map(int,input().split())) n,=I() l=[] for i in range(n): l.append(I()) d={};su={};s=0;an=[1,1,2,1] for i in range(n): for j in range(n): d[i-j]=d.get(i-j,0)+l[i][j] su[i+j]=su.get(i+j,0)+l[i][j] x=0;y=0 for i in range(n): for j in range(n): p=d[i-j]+su[i+j]-l[i][j] if (i+j)%2: if p>x: an[0],an[1]=i+1,j+1 x=p else: if p>y: an[2],an[3]=i+1,j+1 y=p s=x+y print(s) print(*an) ```
instruction
0
370
15
740
Yes
output
1
370
15
741
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2 Submitted Solution: ``` def max_num(a): maxm=a[0][0] ind=[0,0] for i in range(n): for j in range(n): if a[i][j]>maxm: maxm=a[i][j] ind=[i,j] return ind n = int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) b=[[0 for i in range(n)] for j in range(n)] c=[[0 for i in range(n)] for j in range(n)] for i in range(n): for j in range(n-i): b[0][i]+=a[j][i+j] for i in range(1,n): for j in range(n-i): b[i][0]+=a[i+j][j] for i in range(1,n): for j in range(1,n): z=min(i,j) b[i][j]+=b[i-z][j-z] for i in range(n): for j in range(i+1): c[0][i]+=a[i-j][j] for i in range(1,n): for j in range(n-i): c[i][-1]+=a[i+j][n-j-1] for i in range(1,n): for j in range(n-1): c[i][j]+=c[i-1][j+1] d = [[0 for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): d[i][j]=b[i][j]+c[i][j]-a[i][j] ans1=max_num(d) ans3=d[ans1[0]][ans1[1]] d[ans1[0]][ans1[1]]=0 ans2=max_num(d) ans3+=d[ans2[0]][ans2[1]] print(ans3) print(ans1[0]+1,ans1[1]+1,ans2[0]+1,ans2[1]+1) ```
instruction
0
371
15
742
No
output
1
371
15
743
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2 Submitted Solution: ``` a, b, c, d = 0, 0, 0, 0 m1 = 0 m2 = 0 n = int(input()) board = [] for _ in range(n): board.append(list(map(int, input().split()))) pos = {} neg = {} for i in range(-n+1, n): pos[i] = 0 for i in range(2*n): neg[i] = 0 for i in range(n): for j in range(n): pos[j-i]+=board[i][j] neg[j+i]+=board[i][j] for i in range(n): for j in range(n): if (i+j)%2==0: temp = pos[j-i] + neg[j+i] - board[i][j] if temp>=m1: m1 = temp a = i b = j else: temp = pos[j - i] + neg[j + i] - board[i][j] if temp >= m2: m2 = temp c = i d = j print(m1 + m2) print(str(a)+' '+str(b)+' '+str(c)+' '+str(d)) ```
instruction
0
372
15
744
No
output
1
372
15
745
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2 Submitted Solution: ``` import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) n,=I() l=[] for i in range(n): l.append(I()) d={};su={};s=0;an=[1,1,2,1] for i in range(n): for j in range(n): d[i-j]=d.get(i-j,0)+l[i][j] su[i+j]=su.get(i+j,0)+l[i][j] x=0;y=0 for i in range(n): for j in range(n): l[i][j]=d[i-j]+su[i+j]-l[i][j] if l[i][j]>x: k=x;x=l[i][j];p=list(an) an[0],an[1]=i+1,j+1 if k>y: y=k;an[2]=p[0] an[3]=p[1] elif l[i][j]>y: y=l[i][j] an[2]=i+1;an[3]=j+1 s=x+y print(s) print(*an) ```
instruction
0
373
15
746
No
output
1
373
15
747
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n Γ— n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). Input The first line contains a single integer n (2 ≀ n ≀ 2000). Each of the next n lines contains n integers aij (0 ≀ aij ≀ 109) β€” description of the chessboard. Output On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≀ x1, y1, x2, y2 ≀ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. Examples Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Output 12 2 2 3 2 Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Sun Jun 16 21:28:32 2019 @author: sj """ n=int(input()) a=[] for i in range(0,n): s=input().split(" ") for j in range(0,n): s[j]=int(s[j]) a.append(s) b=[] c=[] d=[] for i in range(0,n): cc=[] for j in range(0,n): cc.append(0) b.append(cc) d.append(cc) c.append(cc) for i in range(0,n): j=0 x=i ans=0 while(x<n): ans+=a[j][x] x+=1 j+=1 x=i j=0 while(x<n): b[j][x]=ans x+=1 j+=1 for i in range(1,n): j=0 x=i ans=0 while(x<n): ans+=a[x][j] x+=1 j+=1 x=i j=0 while(x<n): b[x][j]=ans x+=1 j+=1 for i in range(0,n): j=0 x=n-i-1 ans=0 while(x>=0): ans+=a[j][x] x-=1 j+=1 x=n-i-1 j=0 while(x>=0): b[j][x]=ans x-=1 j+=1 for i in range(1,n): j=n-1 x=i ans=0 while(x<n): ans+=a[x][j] x+=1 j-=1 x=i j=n-1 while(x<n): c[x][j]=ans x+=1 j-=1 for i in range(0,n): for j in range(0,n): d[i][j]=b[i][j]+c[i][j]-a[i][j] max=0 x=i y=j for i in range(0,n): for j in range(0,n): if max<d[i][j]: max=d[i][j] x=i y=j max1=0 x1=0 y1=0 for i in range(0,n): for j in range(0,n): if max1<d[i][j] and (i!=x or j!=y) and ((x+y+i+j)%2==1): max1=d[i][j] x1=i y1=j print(max+max1) print(x,y,x1,y1) ```
instruction
0
374
15
748
No
output
1
374
15
749
Provide tags and a correct Python 3 solution for this coding contest problem. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO
instruction
0
412
15
824
Tags: games Correct Solution: ``` n, m, k = [int(i) for i in input().split()] flag = False for j in range(k): x, y = [int(z) for z in input().split()] flag |= x < 6 or n - x < 5 flag |= y < 6 or m - y < 5 if flag: print("YES") else: print("NO") ```
output
1
412
15
825
Provide tags and a correct Python 3 solution for this coding contest problem. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO
instruction
0
413
15
826
Tags: games Correct Solution: ``` n, m, k = [int(x) for x in input().split()] canwin = False for i in range(k): x, y = [int(x) for x in input().split()] canwin |= x < 6 or n - x < 5 canwin |= y < 6 or m - y < 5 print("YES" if canwin else "NO") ```
output
1
413
15
827
Provide tags and a correct Python 3 solution for this coding contest problem. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO
instruction
0
414
15
828
Tags: games Correct Solution: ``` n, m, k = map(int, input().split()) win = False for i in range(k): r, c = map(int, input().split()) dr = min(r - 1, n - r) dc = min(c - 1, m - c) if dr <= 4 or dc <= 4: win = True print("YES" if win else "NO") ```
output
1
414
15
829
Provide tags and a correct Python 3 solution for this coding contest problem. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO
instruction
0
415
15
830
Tags: games Correct Solution: ``` [n,m,k]=[int(i) for i in input().split()] isDone=False for i in range(0,k): [x,y]=[int(i) for i in input().split()] if x<=5 or x>n-5 or y<=5 or y>m-5: isDone=True if isDone: print("YES") else: print("NO") ```
output
1
415
15
831
Provide tags and a correct Python 3 solution for this coding contest problem. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO
instruction
0
416
15
832
Tags: games Correct Solution: ``` n, m, k = map(int, input().split()) win = False for i in range(k): x, y = map(int, input().split()) if abs(x - 1) <= 4 or abs(y - 1) <= 4 or \ abs(n - x) <= 4 or abs(m - y) <= 4: win = True print('YES' if win else 'NO') ```
output
1
416
15
833
Provide tags and a correct Python 3 solution for this coding contest problem. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO
instruction
0
417
15
834
Tags: games Correct Solution: ``` n,m,k=list(map(int,input().split())) for i in range(k): x,y=list(map(int,input().split())) if min(x,n-x+1,y,m-y+1)<6: print('YES') break else: print('NO') ```
output
1
417
15
835
Provide tags and a correct Python 3 solution for this coding contest problem. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO
instruction
0
418
15
836
Tags: games Correct Solution: ``` n, m, k = map( int , input().split() ) flag = False while k > 0: k -= 1 x, y = map( int , input().split() ) d = min( x , n - x + 1 , y , m - y + 1 ) if d <= 5: flag = True print( "YES" if flag else "NO" ) ```
output
1
418
15
837
Provide tags and a correct Python 3 solution for this coding contest problem. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO
instruction
0
419
15
838
Tags: games Correct Solution: ``` n, m, k = [int(x) for x in input().split()] canwin = False for i in range(k): x, y = [int(x) for x in input().split()] canwin |= x < 6 or n - x < 5 canwin |= y < 6 or m - y < 5 print("YES" if canwin else "NO") # Made By Mostafa_Khaled ```
output
1
419
15
839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO Submitted Solution: ``` n, m, k = map(int, input().split()) win = False for i in range(k): row, col = map(int, input().split()) d = min(row - 1, n - row, col - 1, m - col) if d <= 4: win = True if win: print("YES") else: print("NO") ```
instruction
0
420
15
840
Yes
output
1
420
15
841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO Submitted Solution: ``` n, m, k = map(int, input().split()) win = False for i in range(k): row, col = map(int, input().split()) d = max(row - 1, n - row, col - 1, m - col) if d <= 4: win = True if win: print("YES") else: print("NO") ```
instruction
0
421
15
842
No
output
1
421
15
843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO Submitted Solution: ``` n, m, k = [int(x) for x in input().split()] canwin = False for i in range(k): x, y = [int(x) for x in input().split()] canwin |= x <= 9 or n - x <= 8 canwin |= y <= 9 or m - y <= 8 print("YES" if canwin else "NO") ```
instruction
0
422
15
844
No
output
1
422
15
845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO Submitted Solution: ``` n, m, k = map(int, input().split()) win = False for i in range(k): row, col = map(int, input().split()) if row == 1 or col == 1 or row == n or col == m: win = True if win: print("YES") else: print("NO") ```
instruction
0
423
15
846
No
output
1
423
15
847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Volodya and Vlad play the following game. There are k pies at the cells of n Γ— m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy. <image> Input First line contains 3 integers, separated by space: 1 ≀ n, m ≀ 100 β€” dimensions of the board and 0 ≀ k ≀ 100 β€” the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≀ x ≀ n, 1 ≀ y ≀ m β€” coordinates of the corresponding pie. There could be more than one pie at a cell. Output Output only one word: "YES" β€” if Volodya wins, "NO" β€” otherwise. Examples Input 2 2 1 1 2 Output YES Input 3 4 0 Output NO Input 100 50 2 50 25 50 25 Output NO Submitted Solution: ``` n, m, k = [int(x) for x in input().split()] canwin = False for i in range(k): x, y = [int(x) for x in input().split()] canwin |= x <= 3 or n - x <= 2 canwin |= y <= 3 or m - y <= 2 print("YES" if canwin else "NO") ```
instruction
0
424
15
848
No
output
1
424
15
849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let us consider a grid of squares with N rows and N columns. Arbok has cut out some part of the grid so that, for each i = 1, 2, \ldots, N, the bottommost h_i squares are remaining in the i-th column from the left. Now, he wants to place rooks into some of the remaining squares. A rook is a chess piece that occupies one square and can move horizontally or vertically, through any number of unoccupied squares. A rook can not move through squares that have been cut out by Arbok. Let's say that a square is covered if it either contains a rook, or a rook can be moved to this square in one move. Find the number of ways to place rooks into some of the remaining squares so that every remaining square is covered, modulo 998244353. Constraints * 1 \leq N \leq 400 * 1 \leq h_i \leq N * All input values are integers. Input Input is given from Standard Input in the following format: N h_1 h_2 ... h_N Output Print the number of ways to place rooks into some of the remaining squares so that every remaining square is covered, modulo 998244353. Examples Input 2 2 2 Output 11 Input 3 2 1 2 Output 17 Input 4 1 2 4 1 Output 201 Input 10 4 7 4 8 4 6 8 2 3 6 Output 263244071 Submitted Solution: ``` n = map(int, raw_input().split()) if (n==2): a1, a2 = map(int, raw_input().split()) elif (n==3): a1, a2, a3 = map(int, raw_input().split()) elif (n==4): a1, a2, a3, a4 = map(int, raw_input().split()) elif (n==10): a1, a2, a3, a4,a5,a6,a7,a8,a9,a10 = map(int, raw_input().split()) if (n == 2): print(11) if (n == 3): print(17) if (n == 4): print(201) if (n == 10): print(263244071) ```
instruction
0
574
15
1,148
No
output
1
574
15
1,149
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are AΓ—B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020
instruction
0
671
15
1,342
"Correct Solution: ``` H, W, A, B = map(int, input().split()) P = 10**9+7 fa = [1] for i in range(1, 202020): fa.append(fa[-1] * i % P) fainv = [pow(fa[-1], P-2, P)] for i in range(1, 202020)[::-1]: fainv.append(fainv[-1] * i % P) fainv = fainv[::-1] calc = lambda a, b: fa[a+b] * fainv[a] * fainv[b] % P ans = 0 for i in range(H-A): ans = (ans + calc(B-1, i) * calc(H-1-i, W-B-1) )% P print(ans) ```
output
1
671
15
1,343
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are AΓ—B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020
instruction
0
672
15
1,344
"Correct Solution: ``` def solve(): h,w,a,b = map(int, input().split()) mx = max(h,w) mod = 10**9+7 fac = [1]*(h+w+1) for i in range(1,h+w+1): fac[i] = fac[i-1]*i%mod inv = [1]*(mx+1) inv[-1] = pow(fac[mx], mod-2, mod) for i in range(mx-1, -1, -1): inv[i] = inv[i+1]*(i+1)%mod const = inv[h-a-1]*inv[a-1]%mod ans = sum(fac[h-a+i-1]*inv[i]*fac[a+w-2-i]*inv[w-i-1]%mod for i in range(b,w)) print(ans*const%mod) if __name__=="__main__":solve() ```
output
1
672
15
1,345
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are AΓ—B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020
instruction
0
673
15
1,346
"Correct Solution: ``` from sys import exit from itertools import count def read(): return [int(x) for x in input().split()] P = 10**9 + 7 def inv(x): return pow(x, P-2, P) def comb(n, r): res = 1 for i in range(r): res = (res * (n-i) * inv(i+1)) % P return res (H, W, A, B) = read() result = 0 c1 = comb(H-A-1+B, B) c2 = comb(W-B-1+A, A) for i in range(1, min(H-A+1, W-B+1)): # print(c1, c2) result = (result + c1 * c2) % P c1 = (c1 * (H-A-i) * inv(B+i)) % P c2 = (c2 * (W-B-i) * inv(A+i)) % P print(result) ```
output
1
673
15
1,347
Provide a correct Python 3 solution for this coding contest problem. We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are AΓ—B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7. Constraints * 1 ≦ H, W ≦ 100,000 * 1 ≦ A < H * 1 ≦ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7. Examples Input 2 3 1 1 Output 2 Input 10 7 3 4 Output 3570 Input 100000 100000 99999 99999 Output 1 Input 100000 100000 44444 55555 Output 738162020
instruction
0
674
15
1,348
"Correct Solution: ``` def inpl(): return [int(i) for i in input().split()] mod = 10**9+7 H, W, A, B = inpl() fac = [1 for _ in range(H+W-1)] for i in range(H+W-2): fac[i+1] = (i+1)*fac[i]%mod inv = [1 for _ in range(H+W-1)] for i in range(2,H+W-2): inv[i] = (-(mod//i) * inv[mod%i]) %mod facinv = [1 for _ in range(H+W-1)] for i in range(H+W-2): facinv[i+1] = inv[i+1]*facinv[i]%mod ans = 0 for i in range(W-B): ans += (fac[H+B-A-1+i] * fac[W+A-B-2-i] * facinv[H-A-1] * facinv[B+i]\ * facinv[A-1] * facinv[W-B-1-i] )%mod print(ans%mod) ```
output
1
674
15
1,349
End of preview. Expand in Data Studio

Dataset Card for "python3-standardized_cluster_15_std"

More Information needed

Downloads last month
7