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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 Γ 5 garden may look as follows (empty cells denote grass):
<image>
You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction β either left or right. And initially, you face right.
In one move you can do either one of these:
1) Move one cell in the direction that you are facing.
* if you are facing right: move from cell (r, c) to cell (r, c + 1)
<image>
* if you are facing left: move from cell (r, c) to cell (r, c - 1)
<image>
2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.
* if you were facing right previously, you will face left
<image>
* if you were facing left previously, you will face right
<image>
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.
What is the minimum number of moves required to mow all the weeds?
Input
The first line contains two integers n and m (1 β€ n, m β€ 150) β the number of rows and columns respectively. Then follow n lines containing m characters each β the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left corner of the grid will contain grass.
Output
Print a single number β the minimum number of moves required to mow all the weeds.
Examples
Input
4 5
GWGGW
GGWGG
GWGGG
WGGGG
Output
11
Input
3 3
GWW
WWW
WWG
Output
7
Input
1 1
G
Output
0
Note
For the first example, this is the picture of the initial state of the grid:
<image>
A possible solution is by mowing the weeds as illustrated below:
<image>
Submitted Solution:
```
"""
Brandt Smith, Lemuel Gorion and Peter Haddad
codeforces.com
Problem 115B
"""
n, m = input().split(' ')
n = int(n)
m = int(m)
count = 0
prev_ind = 0
weed_row = 0
for i in range(n):
temp = input()
start = temp.find('W')
end = temp.rfind('W')
if end != -1:
if i % 2 == 0:
count += end - prev_ind
if start < prev_ind:
count += 2 * (prev_ind - start)
prev_ind = end
else:
count += prev_ind - start
if end > prev_ind:
count += 2 * (end - prev_ind)
prev_ind = start
weed_row = i
print(count + weed_row)
``` | instruction | 0 | 43,887 | 15 | 87,774 |
Yes | output | 1 | 43,887 | 15 | 87,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 Γ 5 garden may look as follows (empty cells denote grass):
<image>
You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction β either left or right. And initially, you face right.
In one move you can do either one of these:
1) Move one cell in the direction that you are facing.
* if you are facing right: move from cell (r, c) to cell (r, c + 1)
<image>
* if you are facing left: move from cell (r, c) to cell (r, c - 1)
<image>
2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.
* if you were facing right previously, you will face left
<image>
* if you were facing left previously, you will face right
<image>
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.
What is the minimum number of moves required to mow all the weeds?
Input
The first line contains two integers n and m (1 β€ n, m β€ 150) β the number of rows and columns respectively. Then follow n lines containing m characters each β the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left corner of the grid will contain grass.
Output
Print a single number β the minimum number of moves required to mow all the weeds.
Examples
Input
4 5
GWGGW
GGWGG
GWGGG
WGGGG
Output
11
Input
3 3
GWW
WWW
WWG
Output
7
Input
1 1
G
Output
0
Note
For the first example, this is the picture of the initial state of the grid:
<image>
A possible solution is by mowing the weeds as illustrated below:
<image>
Submitted Solution:
```
n,m = list(map(int,input().split()))
mat = []
for i in range(n):
x = input()
x = list(x)
a,b = -1,-1
for j in range(m):
if x[j]=='W' and a==-1:
a = j
b = j
elif x[j]=='W' and a!=-1:
b = j
mat.append([a,b])
last = n-1
r = 1
ans = 0
prev = 0
while last>0 and mat[last][0]==-1:
last-=1
ans = last
for i in mat[:last+1]:
if i[0]!=-1:
if r==1:
ans+=abs(i[0]-prev)+i[1]-i[0]
prev = i[1]
else:
ans+=abs(i[1]-prev)+i[1]-i[0]
prev = i[0]
r = r^1
print(ans)
``` | instruction | 0 | 43,888 | 15 | 87,776 |
Yes | output | 1 | 43,888 | 15 | 87,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 Γ 5 garden may look as follows (empty cells denote grass):
<image>
You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction β either left or right. And initially, you face right.
In one move you can do either one of these:
1) Move one cell in the direction that you are facing.
* if you are facing right: move from cell (r, c) to cell (r, c + 1)
<image>
* if you are facing left: move from cell (r, c) to cell (r, c - 1)
<image>
2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.
* if you were facing right previously, you will face left
<image>
* if you were facing left previously, you will face right
<image>
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.
What is the minimum number of moves required to mow all the weeds?
Input
The first line contains two integers n and m (1 β€ n, m β€ 150) β the number of rows and columns respectively. Then follow n lines containing m characters each β the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left corner of the grid will contain grass.
Output
Print a single number β the minimum number of moves required to mow all the weeds.
Examples
Input
4 5
GWGGW
GGWGG
GWGGG
WGGGG
Output
11
Input
3 3
GWW
WWW
WWG
Output
7
Input
1 1
G
Output
0
Note
For the first example, this is the picture of the initial state of the grid:
<image>
A possible solution is by mowing the weeds as illustrated below:
<image>
Submitted Solution:
```
n, m = [int(i) for i in input().split()]
if n == 1 and m == 1: # nothing to mow
print(0)
elif n == 1: # 1 row --> move right until last weed
lawn = input()
print(lawn.rfind('W'))
elif m == 1: # 1 column --> move down until last weed
weeds = 0
for i in range(n):
lawn = input()
if lawn == 'W':
weeds = i
print(weeds)
else: # generic solution for n-by-m lawn
# Get lawn as a list of strings, where each string is a row
lawn = []
for i in range(n):
lawn.append(input())
# Determine the first and last weed in each row
first_weed = [row.find('W') for row in lawn]
last_weed = [row.rfind('W') for row in lawn]
if all([i == -1 for i in first_weed]): # there are not weeds!
print(0)
else: # there must be some weeds to mow
# Determine the last row that needs to be mowed
last_row = max(i for i, v in enumerate(first_weed) if v >= 0)
lawn = lawn[:last_row+1]
first_weed = first_weed[:last_row+1]
last_weed = last_weed[:last_row+1]
n = len(lawn)
# Add down movement
moves = n-1
# Add left/right movement
even = True
col = 0
for i in range(n):
if first_weed[i] != -1:
if even:
moves += abs(first_weed[i] - col)
col = last_weed[i]
else:
moves += abs(last_weed[i] - col)
col = first_weed[i]
moves += last_weed[i] - first_weed[i]
even = not even
print(moves)
``` | instruction | 0 | 43,889 | 15 | 87,778 |
Yes | output | 1 | 43,889 | 15 | 87,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 Γ 5 garden may look as follows (empty cells denote grass):
<image>
You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction β either left or right. And initially, you face right.
In one move you can do either one of these:
1) Move one cell in the direction that you are facing.
* if you are facing right: move from cell (r, c) to cell (r, c + 1)
<image>
* if you are facing left: move from cell (r, c) to cell (r, c - 1)
<image>
2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.
* if you were facing right previously, you will face left
<image>
* if you were facing left previously, you will face right
<image>
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.
What is the minimum number of moves required to mow all the weeds?
Input
The first line contains two integers n and m (1 β€ n, m β€ 150) β the number of rows and columns respectively. Then follow n lines containing m characters each β the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left corner of the grid will contain grass.
Output
Print a single number β the minimum number of moves required to mow all the weeds.
Examples
Input
4 5
GWGGW
GGWGG
GWGGG
WGGGG
Output
11
Input
3 3
GWW
WWW
WWG
Output
7
Input
1 1
G
Output
0
Note
For the first example, this is the picture of the initial state of the grid:
<image>
A possible solution is by mowing the weeds as illustrated below:
<image>
Submitted Solution:
```
n, m = map(int, input().split())
t = [(p.find('W'), p.rfind('W')) for p in [input() for i in range(n)]]
c, s, k = 0, n - 1, True
while s > 0 and t[s][0] == -1: s -= 1
for a, b in t[: s + 1]:
if a != -1:
if k:
s += abs(a - c) + b - a
c = b
else:
s += abs(b - c) + b - a
c = a
k = not k
print(s)
# Made By Mostafa_Khaled
``` | instruction | 0 | 43,890 | 15 | 87,780 |
Yes | output | 1 | 43,890 | 15 | 87,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 Γ 5 garden may look as follows (empty cells denote grass):
<image>
You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction β either left or right. And initially, you face right.
In one move you can do either one of these:
1) Move one cell in the direction that you are facing.
* if you are facing right: move from cell (r, c) to cell (r, c + 1)
<image>
* if you are facing left: move from cell (r, c) to cell (r, c - 1)
<image>
2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.
* if you were facing right previously, you will face left
<image>
* if you were facing left previously, you will face right
<image>
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.
What is the minimum number of moves required to mow all the weeds?
Input
The first line contains two integers n and m (1 β€ n, m β€ 150) β the number of rows and columns respectively. Then follow n lines containing m characters each β the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left corner of the grid will contain grass.
Output
Print a single number β the minimum number of moves required to mow all the weeds.
Examples
Input
4 5
GWGGW
GGWGG
GWGGG
WGGGG
Output
11
Input
3 3
GWW
WWW
WWG
Output
7
Input
1 1
G
Output
0
Note
For the first example, this is the picture of the initial state of the grid:
<image>
A possible solution is by mowing the weeds as illustrated below:
<image>
Submitted Solution:
```
m,n=map(int,input().split())
arr=[]
move=0
row=0
q=0
for i in range(m):
a=input()
arr.append(a)
for i in range(m-1):
if 'W' in arr[i]:
if i%2==0:
p=max(arr[i].rfind('W'),arr[i+1].rfind('W'))
move+=p-q
else:
q=min(arr[i].find('W'),arr[i+1].find('W'))
move+=p-q
row=i
if 'W' in arr[m-1]:
if (m-1)%2==0:
p=arr[m-1].rfind('W')
move+=p-q
else:
q=arr[m-1].rfind('W')
move+=p-q
row=m-1
print(move+row)
``` | instruction | 0 | 43,891 | 15 | 87,782 |
No | output | 1 | 43,891 | 15 | 87,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 Γ 5 garden may look as follows (empty cells denote grass):
<image>
You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction β either left or right. And initially, you face right.
In one move you can do either one of these:
1) Move one cell in the direction that you are facing.
* if you are facing right: move from cell (r, c) to cell (r, c + 1)
<image>
* if you are facing left: move from cell (r, c) to cell (r, c - 1)
<image>
2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.
* if you were facing right previously, you will face left
<image>
* if you were facing left previously, you will face right
<image>
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.
What is the minimum number of moves required to mow all the weeds?
Input
The first line contains two integers n and m (1 β€ n, m β€ 150) β the number of rows and columns respectively. Then follow n lines containing m characters each β the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left corner of the grid will contain grass.
Output
Print a single number β the minimum number of moves required to mow all the weeds.
Examples
Input
4 5
GWGGW
GGWGG
GWGGG
WGGGG
Output
11
Input
3 3
GWW
WWW
WWG
Output
7
Input
1 1
G
Output
0
Note
For the first example, this is the picture of the initial state of the grid:
<image>
A possible solution is by mowing the weeds as illustrated below:
<image>
Submitted Solution:
```
n,m = map(int, input().split());
cri = 0
lr = [[0,0]];
gl = [];
for i in range(n):
s = input();
l,r = s.find('W'),s.rfind('W');
if -1<l<=r:
cri=i+1
else:
l,r = lr[i][0],lr[i][1];
lr+=[[l,r]];
# print(lr)
dlr = True;
ps = 0
ct = 0
for j in range(1,cri+1):
if lr[j][dlr]==-1:
dlr=not dlr;
continue;
ct+=abs(lr[j][not dlr]-lr[j][dlr])+abs(lr[j][not dlr]-ps);
# print(ct, ps,j, dlr)
ps = lr[j][dlr];
# if dlr:
# max(lr[j][dlr],lr[j+1][dlr])-ps;
# else:
# ps-min(lr[j][dlr],lr[j+1][dlr]);
dlr=not dlr;
print(ct+(cri-1 if cri>0 else 0));
``` | instruction | 0 | 43,892 | 15 | 87,784 |
No | output | 1 | 43,892 | 15 | 87,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 Γ 5 garden may look as follows (empty cells denote grass):
<image>
You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction β either left or right. And initially, you face right.
In one move you can do either one of these:
1) Move one cell in the direction that you are facing.
* if you are facing right: move from cell (r, c) to cell (r, c + 1)
<image>
* if you are facing left: move from cell (r, c) to cell (r, c - 1)
<image>
2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.
* if you were facing right previously, you will face left
<image>
* if you were facing left previously, you will face right
<image>
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.
What is the minimum number of moves required to mow all the weeds?
Input
The first line contains two integers n and m (1 β€ n, m β€ 150) β the number of rows and columns respectively. Then follow n lines containing m characters each β the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left corner of the grid will contain grass.
Output
Print a single number β the minimum number of moves required to mow all the weeds.
Examples
Input
4 5
GWGGW
GGWGG
GWGGG
WGGGG
Output
11
Input
3 3
GWW
WWW
WWG
Output
7
Input
1 1
G
Output
0
Note
For the first example, this is the picture of the initial state of the grid:
<image>
A possible solution is by mowing the weeds as illustrated below:
<image>
Submitted Solution:
```
import sys
try:
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
input = sys.stdin.readline
n, m = map(int, input().split())
grid = []
first, last = [], []
# nonweed = set([])
for j in range(n):
grid.append(input().strip())
st, end = -1, -1
for i in range(m):
if grid[-1][i] == "W":
if st == -1: st = i
end = i
first.append(st)
last.append(end)
while last and last[-1] == -1:
first.pop()
last.pop()
grid.pop()
if grid:
grid.append(grid[-1])
first.append(first[-1])
last.append(last[-1])
# print(grid, first)
ans = 0
curr = 1
left = True
for row in range(0, len(grid)-1):
if left:
la = max(last[row], last[row+1])
if la == -1:
pass
else:
ans += la-curr
curr = la
else:
ra = min(first[row], first[row+1])
if ra == -1:
pass
else:
ans += curr-ra
curr = ra
left = not left
ans += 1
print(ans)
``` | instruction | 0 | 43,893 | 15 | 87,786 |
No | output | 1 | 43,893 | 15 | 87,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 Γ 5 garden may look as follows (empty cells denote grass):
<image>
You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction β either left or right. And initially, you face right.
In one move you can do either one of these:
1) Move one cell in the direction that you are facing.
* if you are facing right: move from cell (r, c) to cell (r, c + 1)
<image>
* if you are facing left: move from cell (r, c) to cell (r, c - 1)
<image>
2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.
* if you were facing right previously, you will face left
<image>
* if you were facing left previously, you will face right
<image>
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.
What is the minimum number of moves required to mow all the weeds?
Input
The first line contains two integers n and m (1 β€ n, m β€ 150) β the number of rows and columns respectively. Then follow n lines containing m characters each β the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.
It is guaranteed that the top-left corner of the grid will contain grass.
Output
Print a single number β the minimum number of moves required to mow all the weeds.
Examples
Input
4 5
GWGGW
GGWGG
GWGGG
WGGGG
Output
11
Input
3 3
GWW
WWW
WWG
Output
7
Input
1 1
G
Output
0
Note
For the first example, this is the picture of the initial state of the grid:
<image>
A possible solution is by mowing the weeds as illustrated below:
<image>
Submitted Solution:
```
"""
Brandt Smith, Lemuel Gorion and Peter Haddad
codeforces.com
Problem 115B
"""
n, m = input().split(' ')
n = int(n)
m = int(m)
garden = [[] for i in range(n)]
for i in range(n):
for j in list(input()):
garden[i].append(j)
count = 0
curr_index = 0
for i in range(n - 1):
if i % 2 == 0 or i == 0:
temp1 = garden[i]
temp1 = temp1[::-1]
temp2 = garden[i + 1]
temp2 = temp2[::-1]
ind1 = len(temp1) - 1 - temp1.index('W')
ind2 = len(temp2) - 1 - temp2.index('W')
temp = curr_index
curr_index = max(ind1,ind2)
count += abs(curr_index - temp) + 1
else:
ind1 = garden[i].index('W')
ind2 = garden[i + 1].index('W')
temp = curr_index
curr_index = min(ind1,ind2)
count += abs(curr_index - temp) + 1
if garden[n - 1].count('W') > 1:
count += garden[n - 1].count('W')
print(count)
``` | instruction | 0 | 43,894 | 15 | 87,788 |
No | output | 1 | 43,894 | 15 | 87,789 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 β€ x β€ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0 | instruction | 0 | 43,912 | 15 | 87,824 |
Tags: math
Correct Solution:
```
"""
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x (β-β109ββ€βxββ€β109).
Output
Output the minimal number of jumps that Jack requires to reach x.
"""
from math import *
def is_even(a):
return False if a%2 else True
def calc_sum(n):
return n * (n + 1)/2
def check(a, x):
return (not is_even(a) and not is_even(x)) or (is_even(a) and is_even(x))
x = abs(int(input()))
if x == 0:
print(0)
else:
n = (-1+pow(1+4*2*x, 0.5))/2
ceil_n = ceil(n)
if check(calc_sum(ceil_n), x):
print(ceil_n)
else:
if check(calc_sum(ceil_n + 1), x):
print(ceil_n + 1)
else:
print(ceil_n + 2)
``` | output | 1 | 43,912 | 15 | 87,825 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 β€ x β€ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0 | instruction | 0 | 43,913 | 15 | 87,826 |
Tags: math
Correct Solution:
```
x, s, v = abs(int(input())), 0, 0
while s < x or (x ^ s) & 1:
v += 1
s += v
print(v)
``` | output | 1 | 43,913 | 15 | 87,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 β€ x β€ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0 | instruction | 0 | 43,915 | 15 | 87,830 |
Tags: math
Correct Solution:
```
x=abs(int(input()));lis=[];sq=0;i=1
while sq<x or (sq-x)%2==1:
sq=sq+i
lis.append(i)
i+=1
print(len(lis))
``` | output | 1 | 43,915 | 15 | 87,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 β€ x β€ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0 | instruction | 0 | 43,916 | 15 | 87,832 |
Tags: math
Correct Solution:
```
def getsum(x):
return int((x * (x + 1)) / 2)
def countJumps(n):
n = abs(n)
ans = 0
while (getsum(ans) < n or
(getsum(ans) - n) & 1):
ans += 1
return ans
if __name__ == '__main__':
n = int(input())
print(countJumps(n))
``` | output | 1 | 43,916 | 15 | 87,833 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 β€ x β€ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0 | instruction | 0 | 43,917 | 15 | 87,834 |
Tags: math
Correct Solution:
```
__author__ = 'Darren'
def solve():
from math import ceil
x = abs(int(input()))
k = ceil(((8 * x + 1) ** 0.5 - 1) / 2)
location = k * (k + 1) // 2
if location == x or (location - x) % 2 == 0:
print(k)
elif ((location - x) + (k + 1)) % 2 == 0:
print(k+1)
else:
print(k+2)
if __name__ == '__main__':
solve()
``` | output | 1 | 43,917 | 15 | 87,835 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 β€ x β€ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0 | instruction | 0 | 43,918 | 15 | 87,836 |
Tags: math
Correct Solution:
```
def main():
x = int(input())
print(jumps(x))
def jumps(n):
n = abs(n)
i = 0
while True:
product = i * (i + 1) // 2
if product >= n and product % 2 == n % 2:
return i
i += 1
#print(jumps(6))
main()
``` | output | 1 | 43,918 | 15 | 87,837 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 β€ x β€ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0
Submitted Solution:
```
import math
x = int(input())
if x<0:
x = -x
k = math.floor((math.sqrt(8*x+1)-1)/2)
S = (k*k+k)//2
if S == x:
print(k)
elif (S+k+1-x)%2 == 0:
print(k+1)
elif (k+2)%2 == 1:
print(k+2)
else:
print(k+3)
``` | instruction | 0 | 43,920 | 15 | 87,840 |
Yes | output | 1 | 43,920 | 15 | 87,841 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 β€ n β€ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 β€ xi β€ 105, xi β 0, 1 β€ ai β€ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | instruction | 0 | 44,239 | 15 | 88,478 |
Tags: brute force, implementation, sortings
Correct Solution:
```
n=int(input())
a=dict()
b=dict()
c=0
for i in range(n):
x,y=map(int,input().split())
if(x<0):
a.update({x:y})
else:
b.update({x:y})
if(len(a)>len(b)):
for i in range(len(b)+1):
c+=a[max(a.keys())]
del a[max(a.keys())]
print(c+sum(b.values()))
elif(len(a)==len(b)):
print(sum(a.values())+sum(b.values()))
else:
for i in range(len(a)+1):
c+=b[min(b.keys())]
del b[min(b.keys())]
print(c+sum(a.values()))
``` | output | 1 | 44,239 | 15 | 88,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 β€ n β€ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 β€ xi β€ 105, xi β 0, 1 β€ ai β€ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | instruction | 0 | 44,240 | 15 | 88,480 |
Tags: brute force, implementation, sortings
Correct Solution:
```
n = int(input())
trees = list()
for i in range(n):
x, a = map(int, input().split())
trees.append((x, a))
trees.sort()
from bisect import bisect
i = bisect(trees, (0, 0))
cnt = min(i, n - i)
l1, r1 = max(0, i - cnt - 1), min(n, i + cnt)
l2, r2 = max(0, i - cnt), min(n, i + cnt + 1)
print(max(sum([a for x, a in trees[l1:r1]]), sum([a for x, a in trees[l2:r2]])))
``` | output | 1 | 44,240 | 15 | 88,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 β€ n β€ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 β€ xi β€ 105, xi β 0, 1 β€ ai β€ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | instruction | 0 | 44,241 | 15 | 88,482 |
Tags: brute force, implementation, sortings
Correct Solution:
```
def main():
n = int(input())
l = list(tuple(map(int, input().split())) for _ in range(n))
l.append((0, 0))
l.sort()
start = l.index((0, 0)) * 2
lo, hi = 0, n + 1
if start > n:
lo = start - n - 1
elif start < n - 1:
hi = start + 2
print(sum(a for _, a in l[lo:hi]))
if __name__ == "__main__":
main()
``` | output | 1 | 44,241 | 15 | 88,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 β€ n β€ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 β€ xi β€ 105, xi β 0, 1 β€ ai β€ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | instruction | 0 | 44,242 | 15 | 88,484 |
Tags: brute force, implementation, sortings
Correct Solution:
```
def nsum(a):
res = 0
for i in range(len(a)):
res += a[i][1]
return res
n = int(input())
l, r = [], []
for i in range(n):
x, t = [int(x) for x in input().split()]
if x < 0:
l.append([-x, t])
else:
r.append([x, t])
l.sort()
r.sort()
if len(l) == len(r):
print(nsum(l) + nsum(r))
elif len(l) < len(r):
print(nsum(r[:len(l)+1]) + nsum(l))
else:
print(nsum(r) + nsum(l[:len(r)+1]))
``` | output | 1 | 44,242 | 15 | 88,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 β€ n β€ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 β€ xi β€ 105, xi β 0, 1 β€ ai β€ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | instruction | 0 | 44,243 | 15 | 88,486 |
Tags: brute force, implementation, sortings
Correct Solution:
```
n = int(input())
lefts = {}
rights = {}
for i in range(n):
xi, ai = map(int, input().split())
if xi < 0:
lefts[xi] = ai
else:
rights[xi] = ai
lefts = [v[1] for v in sorted(lefts.items(), reverse=True)]
rights = [v[1] for v in sorted(rights.items())]
ll = len(lefts)
lr = len(rights)
if ll == lr:
print(sum(lefts) + sum(rights))
elif ll > lr:
print(sum(lefts[:lr+1]) + sum(rights))
elif ll < lr:
print(sum(lefts) + sum(rights[:ll+1]))
``` | output | 1 | 44,243 | 15 | 88,487 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 β€ n β€ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 β€ xi β€ 105, xi β 0, 1 β€ ai β€ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | instruction | 0 | 44,244 | 15 | 88,488 |
Tags: brute force, implementation, sortings
Correct Solution:
```
def show_direction(num:int) -> str:
if num>= 0:
return 'right'
else:
return 'left'
def reverse(_str:str) -> str:
if _str == 'right':
return 'left'
else:
return 'right'
number = int(input())
coord = []
for i in range(number):
coord.append(list(map(int, input().split())))
coord_left, coord_right, dup_coord_left, dup_coord_right = [], [], [], []
for i in range(number):
if show_direction(coord[i][0]) == 'right':
coord_right.append(coord[i])
dup_coord_right.append(coord[i])
else:
coord_left.append(coord[i])
dup_coord_left.append(coord[i])
if len(coord) == 1 and coord_left == []:
print(coord_right[0][1])
elif len(coord) == 1 and coord_right== []:
print(coord_left[0][1])
else:
current_direction = 'left'
apple_left = 0
while 1:
if current_direction == 'left':
if coord_left == []:
break
apple_left += max(coord_left)[1]
del coord_left[coord_left.index(max(coord_left))]
current_direction = reverse(current_direction)
elif current_direction == 'right':
if coord_right == []:
break
apple_left += min(coord_right)[1]
del coord_right[coord_right.index(min(coord_right))]
current_direction = reverse(current_direction)
current_direction = 'right'
apple_right = 0
while 1:
if current_direction == 'left':
if dup_coord_left == []:
break
apple_right += max(dup_coord_left)[1]
del dup_coord_left[dup_coord_left.index(max(dup_coord_left))]
current_direction = reverse(current_direction)
elif current_direction == 'right':
if dup_coord_right == []:
break
apple_right += min(dup_coord_right)[1]
del dup_coord_right[dup_coord_right.index(min(dup_coord_right))]
current_direction = reverse(current_direction)
print(max(apple_left, apple_right))
``` | output | 1 | 44,244 | 15 | 88,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 β€ n β€ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 β€ xi β€ 105, xi β 0, 1 β€ ai β€ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | instruction | 0 | 44,245 | 15 | 88,490 |
Tags: brute force, implementation, sortings
Correct Solution:
```
n = int(input())
l = []
r = []
u = []
for i in range(n):
x, a = map(int,input().split())
u += [(x, a)]
u.sort()
for e in u:
if e[0] < 0:
l += [e[1]]
else:
r += [e[1]]
l.reverse()
if len(l) == len(r):
print(sum(l) + sum(r))
else:
if len(l) > len(r):
print(sum(r) + sum(l[0:len(r) + 1]))
else:
print(sum(l) + sum(r[0:len(l) + 1]))
``` | output | 1 | 44,245 | 15 | 88,491 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 β€ n β€ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 β€ xi β€ 105, xi β 0, 1 β€ ai β€ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | instruction | 0 | 44,246 | 15 | 88,492 |
Tags: brute force, implementation, sortings
Correct Solution:
```
n = int(input())
a = []
for i in range(n):
a.append(tuple(map(int, input().split())))
a.sort()
ans = 0
ind = 0
while (ind < n and a[ind][0] < 0):
ind += 1
k = 1
sign = -1
while (0 <= ind < n):
ans += a[ind][1]
ind += sign * k
k += 1
sign = -sign
second_ans = 0
ind = n - 1
while (ind >= 0 and a[ind][0] > 0):
ind -= 1
k = 1
sign = 1
while (0 <= ind < n):
second_ans += a[ind][1]
ind += sign * k
k += 1
sign = -sign
print(max(ans, second_ans))
``` | output | 1 | 44,246 | 15 | 88,493 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archerβs fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k β the archer's shot range (1 β€ k β€ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19 | instruction | 0 | 44,323 | 15 | 88,646 |
Tags: binary search, geometry, math, two pointers
Correct Solution:
```
from math import sqrt
# t = int(input())
t = 1
rList = [int(i) for i in input().split(' ')]
for i in range(t):
r = rList[i]
r2 = r * r
sums = 0
b = 1
sig = True
while(b <= r):
a = b - 0.5
n1 = sqrt((r2 - a * a) * 4 / 3)
n2 = sqrt((r2 - b * b) * 4 / 3)
if sig:
n1 -= 1
else:
n2 += 1
n1 //= 2
n2 //= 2
num = int(min(n1, n2))
# print('num :', num)3
if b == 1:
sums = num * 2 + 1
elif sig:
sums += num * 4 + 2
else:
sums += num * 4
sig = not sig
b += 1.5
print(sums)
``` | output | 1 | 44,323 | 15 | 88,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archerβs fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k β the archer's shot range (1 β€ k β€ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19 | instruction | 0 | 44,324 | 15 | 88,648 |
Tags: binary search, geometry, math, two pointers
Correct Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
k = int(input())
R = 4 * k**2
def judge(x, y, c):
if x & 1:
return (
c >= 12 * y**2 + 24 * y + 12
and c >= 6 * x + 12 * y**2 + 12 * y + 3
)
else:
return (
c >= 12 * y**2 + 12 * y + 3
and c >= 6 * x + 12 * y**2
)
def solve(x):
c = R - (9 * x**2 + 6 * x + 1)
ok, ng = -1, 10**6
while abs(ok - ng) > 1:
y = (ok + ng) >> 1
if judge(x, y, c):
ok = y
else:
ng = y
return ok
y = solve(0)
if y == -1:
print(0)
exit()
ans = 1 + y * 2
for x in range(1, k):
y += 1
c = R - (9 * x**2 + 6 * x + 1)
if x & 1:
while y >= 0 and not judge(x, y, c):
y -= 1
else:
while y >= 0 and not judge(x, y, c):
y -= 1
if y < 0:
break
ans += ((y + 1) * 2 if x & 1 else 1 + y * 2) * 2
print(ans)
``` | output | 1 | 44,324 | 15 | 88,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archerβs fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k β the archer's shot range (1 β€ k β€ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19 | instruction | 0 | 44,325 | 15 | 88,650 |
Tags: binary search, geometry, math, two pointers
Correct Solution:
```
n = int(input())
if n < 3:
print(1)
else:
fail = []
x = 0
y = (n // 3 + 1) * 2
while y >= x:
while 4*n*n >= (3*y+2)*(3*y+2)+3*x*x:
x += 2
fail.append((x, y))
if x:
x -= 1
else:
x = 1
y -= 1
total = 0
for x, y in fail:
if x >= y + 2:
total += y
elif x > 1:
total += x - 1
while y > 1:
y -= 1
total += y
print(total * 6 + 1)
# updated
``` | output | 1 | 44,325 | 15 | 88,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archerβs fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k β the archer's shot range (1 β€ k β€ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19 | instruction | 0 | 44,326 | 15 | 88,652 |
Tags: binary search, geometry, math, two pointers
Correct Solution:
```
import math
k = int(input())
n = int(k/3)*2 + 1
# print('n', n)
ans = 0
last = 0
while True:
point_to_check = (n+2)//2
# print('p', point_to_check)
x = 0.0
y = n# *math.sqrt(3)
# print('r', math.sqrt((x**2+y**2)))
# p1
x -= 0.5
y += 0.5 #* math.sqrt(3)
# print('r', math.sqrt((x**2+y**2)))
x -= 1.5*(point_to_check-1)
y -= 0.5*(point_to_check-1)
count = point_to_check
x += 1.5*last
y += 0.5*last
for i in range(last, point_to_check):
if ((x**2+3*(y**2))>k**2):
count = i
last = i
break
x += 1.5
y += 0.5 # * math.sqrt(3)
# print(count)
# input()
extra = 0
if count != 0:
extra = count
if (n+1)%2==0:
extra *= 2
else:
extra = extra*2 -1
if extra == n+1:
ans += (extra-1)*6
break
else:
ans += extra*6
# print('n', n, 'ans', ans, 'point_to_check', point_to_check)
n = n-1
# print('extra', extra)
ans += 1
ans += 3*n*(n-1)
if k<=2:
print(1)
else:
print(ans)
# R = 1
# r = sqrt(3)*0.5*R
# full_cycle_count = k / (math.sqrt(3)) - 0.5
# print(full_cycle_count)
# full_cycle_count = int(full_cycle_count)
# print(full_cycle_count)
#
# half_cycle_count = int((k - 1) / 3) * 2
# print(half_cycle_count)
#
# ans = 1
# last_add = 0
# for i in range(1, full_cycle_count+1):
# last_add +=6
# ans += last_add
#
# print(last_add)
#
# if half_cycle_count>full_cycle_count:
# ans += (last_add+6) / 2
#
# print(int(ans))
# Made By Mostafa_Khaled
``` | output | 1 | 44,326 | 15 | 88,653 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archerβs fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k β the archer's shot range (1 β€ k β€ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19 | instruction | 0 | 44,327 | 15 | 88,654 |
Tags: binary search, geometry, math, two pointers
Correct Solution:
```
import math
k = int(input())
n = int(k/3)*2 + 1
# print('n', n)
ans = 0
last = 0
while True:
point_to_check = (n+2)//2
# print('p', point_to_check)
x = 0.0
y = n# *math.sqrt(3)
# print('r', math.sqrt((x**2+y**2)))
# p1
x -= 0.5
y += 0.5 #* math.sqrt(3)
# print('r', math.sqrt((x**2+y**2)))
x -= 1.5*(point_to_check-1)
y -= 0.5*(point_to_check-1)
count = point_to_check
x += 1.5*last
y += 0.5*last
for i in range(last, point_to_check):
if ((x**2+3*(y**2))>k**2):
count = i
last = i
break
x += 1.5
y += 0.5 # * math.sqrt(3)
# print(count)
# input()
extra = 0
if count != 0:
extra = count
if (n+1)%2==0:
extra *= 2
else:
extra = extra*2 -1
if extra == n+1:
ans += (extra-1)*6
break
else:
ans += extra*6
# print('n', n, 'ans', ans, 'point_to_check', point_to_check)
n = n-1
# print('extra', extra)
ans += 1
ans += 3*n*(n-1)
if k<=2:
print(1)
else:
print(ans)
# R = 1
# r = sqrt(3)*0.5*R
# full_cycle_count = k / (math.sqrt(3)) - 0.5
# print(full_cycle_count)
# full_cycle_count = int(full_cycle_count)
# print(full_cycle_count)
#
# half_cycle_count = int((k - 1) / 3) * 2
# print(half_cycle_count)
#
# ans = 1
# last_add = 0
# for i in range(1, full_cycle_count+1):
# last_add +=6
# ans += last_add
#
# print(last_add)
#
# if half_cycle_count>full_cycle_count:
# ans += (last_add+6) / 2
#
# print(int(ans))
``` | output | 1 | 44,327 | 15 | 88,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archerβs fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k β the archer's shot range (1 β€ k β€ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19
Submitted Solution:
```
#!/usr/bin/env python3
k = int(input())
answer = 1
full_rings = ((k-1) // 2)
answer += full_rings*(full_rings+1)*3
if (k > 1) and (k % 3 == 1):
answer += 6
print(answer)
``` | instruction | 0 | 44,328 | 15 | 88,656 |
No | output | 1 | 44,328 | 15 | 88,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archerβs fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k β the archer's shot range (1 β€ k β€ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19
Submitted Solution:
```
from sys import stdin, stdout
from decimal import Decimal
n = int(stdin.readline())
k = (n - ((3) ** (0.5)) / (2)) / ((3) ** (0.5))
ans = 1 + int(k) * 6
cnt = 6
for i in range(int(k) - 1):
ans += cnt
cnt += 6
y = int(k + 1) * (3 ** 0.5)
x1, x2 = 0.5, 1.5
cnt = 1
label = 0
while cnt:
cnt = 0
y = int(k + 1 + label) * (3 ** 0.5)
x1, x2 = 0.5, 1.5
for i in range(int(k)):
if y ** 2 + x2 ** 2 <= n ** 2:
cnt += 1
x1 += 1
x2 += 1
y -= (3 ** 0.5) / 2
label += 1
ans += cnt * 6
stdout.write(str(ans))
``` | instruction | 0 | 44,330 | 15 | 88,660 |
No | output | 1 | 44,330 | 15 | 88,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archerβs fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k β the archer's shot range (1 β€ k β€ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19
Submitted Solution:
```
def f(n):
if n&1:
k=(n+1)//2
return 3*(k-1)*k+1
else:
n+=1
k=(n+1)//2
k=(k-1)*3
return f(n)-k
print(f(int(input())))
``` | instruction | 0 | 44,331 | 15 | 88,662 |
No | output | 1 | 44,331 | 15 | 88,663 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1). | instruction | 0 | 44,693 | 15 | 89,386 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n = int(input())
t = ['WB', 'BW']
for i in range(n):
print(t[i & 1] * (n // 2) + t[i & 1][:n % 2])
``` | output | 1 | 44,693 | 15 | 89,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1). | instruction | 0 | 44,694 | 15 | 89,388 |
Tags: constructive algorithms, greedy
Correct Solution:
```
import math
n=int(input())
a=[[0 for i in range (n)]for j in range(n)]
for i in range(n):
if i%2:
ch='B'
else:
ch='W'
for j in range(n):
print(ch,end="")
if ch=="W":
ch='B'
else:
ch="W"
print()
``` | output | 1 | 44,694 | 15 | 89,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1). | instruction | 0 | 44,695 | 15 | 89,390 |
Tags: constructive algorithms, greedy
Correct Solution:
```
a=int(input())
t=''
r=''
for i in range(a):
if(i%2==0):
t=t+'W'
r=r+'B'
else:
t=t+'B'
r=r+'W'
for i in range(a):
if(i%2==0):
print(r)
else:
print(t)
``` | output | 1 | 44,695 | 15 | 89,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1). | instruction | 0 | 44,696 | 15 | 89,392 |
Tags: constructive algorithms, greedy
Correct Solution:
```
t = int(input())
s = 'WB' * ((t + 3) // 2)
for i in range (t):
if i % 2 == 0:
print(s[:t])
else:
print(s[1:t + 1])
``` | output | 1 | 44,696 | 15 | 89,393 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1). | instruction | 0 | 44,697 | 15 | 89,394 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n= int(input())
for i in range(n):
for j in range(n):
if (i+j)%2==1:
print('W',end='')
else:
print('B',end='')
print()
``` | output | 1 | 44,697 | 15 | 89,395 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1). | instruction | 0 | 44,698 | 15 | 89,396 |
Tags: constructive algorithms, greedy
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
def main():
n = int(input())
if n % 2 != 0:
for i in range(n * n):
if i % 2 == 0:
print("W", end = "")
else:
print("B", end = "")
if (i + 1) % n == 0:
print()
else:
for i in range(n):
if i % 2 == 0:
print("WB" * (n // 2))
else:
print("BW" * (n // 2))
# 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()
``` | output | 1 | 44,698 | 15 | 89,397 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1). | instruction | 0 | 44,699 | 15 | 89,398 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n=int(input())
for i in range(n):print(('WB'*n)[i:][:n])
``` | output | 1 | 44,699 | 15 | 89,399 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1). | instruction | 0 | 44,700 | 15 | 89,400 |
Tags: constructive algorithms, greedy
Correct Solution:
```
num = int(input())
even = "WB" * (num//2) + "W" * (num%2)
odd = "BW" * (num//2) + "B" * (num%2)
for i in range(num):
if(i%2==0): print(even)
else: print(odd)
``` | output | 1 | 44,700 | 15 | 89,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1).
Submitted Solution:
```
from sys import stdin
n=int(stdin.readline().strip())
if n%2!=0:
t=True
for i in range(n):
ans=""
for j in range(n):
if t:
ans+="W"
else:
ans+="B"
t=not t
print(ans)
else:
t=False
for i in range(n):
ans=""
t=not t
for j in range(n):
if t:
ans+="W"
else:
ans+="B"
t=not t
print(ans)
``` | instruction | 0 | 44,701 | 15 | 89,402 |
Yes | output | 1 | 44,701 | 15 | 89,403 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1).
Submitted Solution:
```
def main():
n = int(input())
for i in range(n):
for j in range(n):
if (i+j) % 2:
print('B', end='')
else:
print('W', end='')
print()
if __name__ == "__main__":
main()
``` | instruction | 0 | 44,702 | 15 | 89,404 |
Yes | output | 1 | 44,702 | 15 | 89,405 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1).
Submitted Solution:
```
n=int(input())
mat=list(list())
for j in range(n):
s=str()
t=str()
for i in range(n):
if j%2==0:
if i%2==0:
s=s+'W'
else:
s=s+'B'
else:
if i%2==0:
t=t+'B'
else:
t=t+'W'
if s!='':
print(s)
if t!='':
print(t)
``` | instruction | 0 | 44,703 | 15 | 89,406 |
Yes | output | 1 | 44,703 | 15 | 89,407 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1).
Submitted Solution:
```
n=int(input())
l=[]
for i in range(n):
l.append([0 for j in range(n)])
for j in range(n):
for k in range(n):
if((j+k)%2==0):
l[j][k]='W'
else:
l[j][k]='B'
for i in range(len(l)):
print("".join(l[i]))
``` | instruction | 0 | 44,704 | 15 | 89,408 |
Yes | output | 1 | 44,704 | 15 | 89,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1).
Submitted Solution:
```
n=int(input())
if n==3 :
print ('WBW')
print('BBB')
print ('WBW')
elif (n % 2)==0 :
ch= (n//2)*'WB'
ch2=(n//2)*'BW'
else :
ch= (n//2)*'WB'+'W'
ch2=(n//2)*'BW'+'B'
l=''
for j in range (n):
if((j==(n//2))):
if ((n//2)%2 == 0):
l=l+'B'
else :
l=l+'B'
elif (j%2)==1:
l=l +'W'
else :
l=l + 'B'
if n!=3 :
for i in range (n) :
if ((i==(n//2))) and (((n//2)%2)==1):
print (l)
elif (i%2)==0 :
print (ch)
else:
print (ch2)
``` | instruction | 0 | 44,705 | 15 | 89,410 |
No | output | 1 | 44,705 | 15 | 89,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1).
Submitted Solution:
```
a = int(input())
t=[]
for k in range(a):
t.append([0]*a)
p=0
for u in range(a):
for h in range(a):
if t[u][h]==0:
t[u][h]='B'
if u+2<=a-1 and h+1<=a-1:
if t[u+2][h+1]==0:
t[u+2][h+1]='w'
if u-2>=0 and h-1>=0:
if t[u-2][h-1]==0:
t[u-2][h-1]='w'
if u-2>=0 and h+1<=a-1:
if t[u-2][h+1]==0:
t[u-2][h+1]='w'
if u+2<=a-1 and h-1>=0:
if t[u+2][h-1]==0:
t[u+2][h-1]='w'
for s in t:
print(''.join(s))
``` | instruction | 0 | 44,706 | 15 | 89,412 |
No | output | 1 | 44,706 | 15 | 89,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1).
Submitted Solution:
```
n= int(input())
arr =[[0 for i in range(n)] for i in range(n)]
w = 'W'
b = 'B'
l = n*n
stack = []
row =[-2,-2,2,2,1,1,-1,-1]
col = [-1,1,1,-1,-2,2,2,-2]
stack.append((0,0,w))
l-=1
while(l>0 and len(stack)!=0):
curr = stack.pop()
r1 = curr[0]
c1 = curr[1]
colo = curr[2]
for i in range(8):
r = r1+row[i]
c = c1+col[i]
if r>=0 and r<n and c>=0 and c<n and arr[r][c]==0:
if colo==w:
stack.append((r,c,b))
arr[r][c]=b
else:
stack.append((r,c,w))
arr[r][c]=w
l-=1
def solve(i,j):
count1= 0
for i in range(8):
r = i+row[i]
c = j+col[i]
if r>=0 and r<n and c>=0 and c<n and arr[r][c]==b:
count1+=1
count2=0
for i in range(8):
r = i+row[i]
c = j+col[i]
if r>=0 and r<n and c>=0 and c<n and arr[r][c]==w:
count2+=1
if count1>=count2:
return 'W'
return 'B'
for i in range(n):
for j in range(n):
if arr[i][j]==0:
k = solve(i,j)
print(k,end='')
else:
print(arr[i][j],end='')
print()
``` | instruction | 0 | 44,707 | 15 | 89,414 |
No | output | 1 | 44,707 | 15 | 89,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_1 - x_2| = 2 and |y_1 - y_2| = 1, or
* |x_1 - x_2| = 1 and |y_1 - y_2| = 2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).
<image>
A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.
Input
The first line contains one integer n (3 β€ n β€ 100) β the number of rows (and columns) in the board.
Output
Print n lines with n characters in each line. The j-th character in the i-th line should be W, if the cell (i, j) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.
Example
Input
3
Output
WBW
BBB
WBW
Note
In the first example, there are 8 duels:
1. the white knight in (1, 1) attacks the black knight in (3, 2);
2. the white knight in (1, 1) attacks the black knight in (2, 3);
3. the white knight in (1, 3) attacks the black knight in (3, 2);
4. the white knight in (1, 3) attacks the black knight in (2, 1);
5. the white knight in (3, 1) attacks the black knight in (1, 2);
6. the white knight in (3, 1) attacks the black knight in (2, 3);
7. the white knight in (3, 3) attacks the black knight in (1, 2);
8. the white knight in (3, 3) attacks the black knight in (2, 1).
Submitted Solution:
```
n= int(input())
arr =[[0 for i in range(n)] for i in range(n)]
w = 'W'
b = 'B'
l = n*n
stack = []
row =[-2,-2,2,2,1,1,-1,-1]
col = [-1,1,1,-1,-2,2,2,-2]
stack.append((0,0,w))
l-=1
while(l>0 and len(stack)!=0):
curr = stack.pop()
r1 = curr[0]
c1 = curr[1]
colo = curr[2]
for i in range(8):
r = r1+row[i]
c = c1+col[i]
if r>=0 and r<n and c>=0 and c<n and arr[r][c]==0:
if colo==w:
stack.append((r,c,b))
arr[r][c]=b
else:
stack.append((r,c,w))
arr[r][c]=w
l-=1
for i in range(n):
for j in range(n):
if arr[i][j]==0:
print('W',end='')
else:
print(arr[i][j],end='')
print()
``` | instruction | 0 | 44,708 | 15 | 89,416 |
No | output | 1 | 44,708 | 15 | 89,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that this process is finite. One can also prove that position in the end does not depend on the order in which new knights are placed.
Ivan asked you to find initial placement of exactly n knights such that in the end there will be at least β \frac{n^{2}}{10} β knights.
Input
The only line of input contains one integer n (1 β€ n β€ 10^{3}) β number of knights in the initial placement.
Output
Print n lines. Each line should contain 2 numbers x_{i} and y_{i} (-10^{9} β€ x_{i}, y_{i} β€ 10^{9}) β coordinates of i-th knight. For all i β j, (x_{i}, y_{i}) β (x_{j}, y_{j}) should hold. In other words, all knights should be in different cells.
It is guaranteed that the solution exists.
Examples
Input
4
Output
1 1
3 1
1 5
4 4
Input
7
Output
2 1
1 2
4 1
5 2
2 6
5 7
6 6
Note
Let's look at second example:
<image>
Green zeroes are initial knights. Cell (3, 3) is under attack of 4 knights in cells (1, 2), (2, 1), (4, 1) and (5, 2), therefore Ivan will place a knight in this cell. Cell (4, 5) is initially attacked by only 3 knights in cells (2, 6), (5, 7) and (6, 6). But new knight in cell (3, 3) also attacks cell (4, 5), now it is attacked by 4 knights and Ivan will place another knight in this cell. There are no more free cells which are attacked by 4 or more knights, so the process stops. There are 9 knights in the end, which is not less than β \frac{7^{2}}{10} β = 4. | instruction | 0 | 45,406 | 15 | 90,812 |
Tags: constructive algorithms
Correct Solution:
```
gcd = lambda a, b: gcd(b, a % b) if b else a
def main():
n = int(input())
if n == 1:
print(0, 0)
return
x = 2 * n // 3
if 2 * n % 2:
x += 1
s = 0
for i in range(x):
print(i, 0)
s += 1
for j in range(1, x, 2):
print(j, 3)
s += 1
while n - s:
s += 1
i += 1
print(i, 0)
main()
``` | output | 1 | 45,406 | 15 | 90,813 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that this process is finite. One can also prove that position in the end does not depend on the order in which new knights are placed.
Ivan asked you to find initial placement of exactly n knights such that in the end there will be at least β \frac{n^{2}}{10} β knights.
Input
The only line of input contains one integer n (1 β€ n β€ 10^{3}) β number of knights in the initial placement.
Output
Print n lines. Each line should contain 2 numbers x_{i} and y_{i} (-10^{9} β€ x_{i}, y_{i} β€ 10^{9}) β coordinates of i-th knight. For all i β j, (x_{i}, y_{i}) β (x_{j}, y_{j}) should hold. In other words, all knights should be in different cells.
It is guaranteed that the solution exists.
Examples
Input
4
Output
1 1
3 1
1 5
4 4
Input
7
Output
2 1
1 2
4 1
5 2
2 6
5 7
6 6
Note
Let's look at second example:
<image>
Green zeroes are initial knights. Cell (3, 3) is under attack of 4 knights in cells (1, 2), (2, 1), (4, 1) and (5, 2), therefore Ivan will place a knight in this cell. Cell (4, 5) is initially attacked by only 3 knights in cells (2, 6), (5, 7) and (6, 6). But new knight in cell (3, 3) also attacks cell (4, 5), now it is attacked by 4 knights and Ivan will place another knight in this cell. There are no more free cells which are attacked by 4 or more knights, so the process stops. There are 9 knights in the end, which is not less than β \frac{7^{2}}{10} β = 4. | instruction | 0 | 45,407 | 15 | 90,814 |
Tags: constructive algorithms
Correct Solution:
```
n = int(input())
ans = [(0, 0)]
for i in range(1, n):
ans.append((0, i))
ans.append((i, 0))
ans.append((0, -i))
ans.append((-i, 0))
for i in range(n):
print(str(ans[i][0]) + ' ' + str(ans[i][1]))
``` | output | 1 | 45,407 | 15 | 90,815 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that this process is finite. One can also prove that position in the end does not depend on the order in which new knights are placed.
Ivan asked you to find initial placement of exactly n knights such that in the end there will be at least β \frac{n^{2}}{10} β knights.
Input
The only line of input contains one integer n (1 β€ n β€ 10^{3}) β number of knights in the initial placement.
Output
Print n lines. Each line should contain 2 numbers x_{i} and y_{i} (-10^{9} β€ x_{i}, y_{i} β€ 10^{9}) β coordinates of i-th knight. For all i β j, (x_{i}, y_{i}) β (x_{j}, y_{j}) should hold. In other words, all knights should be in different cells.
It is guaranteed that the solution exists.
Examples
Input
4
Output
1 1
3 1
1 5
4 4
Input
7
Output
2 1
1 2
4 1
5 2
2 6
5 7
6 6
Note
Let's look at second example:
<image>
Green zeroes are initial knights. Cell (3, 3) is under attack of 4 knights in cells (1, 2), (2, 1), (4, 1) and (5, 2), therefore Ivan will place a knight in this cell. Cell (4, 5) is initially attacked by only 3 knights in cells (2, 6), (5, 7) and (6, 6). But new knight in cell (3, 3) also attacks cell (4, 5), now it is attacked by 4 knights and Ivan will place another knight in this cell. There are no more free cells which are attacked by 4 or more knights, so the process stops. There are 9 knights in the end, which is not less than β \frac{7^{2}}{10} β = 4. | instruction | 0 | 45,408 | 15 | 90,816 |
Tags: constructive algorithms
Correct Solution:
```
n = int(input())
top = n // 3
for i in range(top):
x = 1 + 2 * i
print(str(x) + ' 3')
bot = n - top
for i in range(bot):
print(str(i) + ' 0')
``` | output | 1 | 45,408 | 15 | 90,817 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.