message stringlengths 2 67k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 463 109k | cluster float64 19 19 | __index_level_0__ int64 926 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snakes, so there are only ladders left now.
The game is played on a 10 × 10 board as follows:
* At the beginning of the game, the player is at the bottom left square.
* The objective of the game is for the player to reach the Goal (the top left square) by following the path and climbing vertical ladders. Once the player reaches the Goal, the game ends.
* The path is as follows: if a square is not the end of its row, it leads to the square next to it along the direction of its row; if a square is the end of its row, it leads to the square above it. The direction of a row is determined as follows: the direction of the bottom row is to the right; the direction of any other row is opposite the direction of the row below it. See Notes section for visualization of path.
* During each turn, the player rolls a standard six-sided dice. Suppose that the number shown on the dice is r. If the Goal is less than r squares away on the path, the player doesn't move (but the turn is performed). Otherwise, the player advances exactly r squares along the path and then stops. If the player stops on a square with the bottom of a ladder, the player chooses whether or not to climb up that ladder. If she chooses not to climb, then she stays in that square for the beginning of the next turn.
* Some squares have a ladder in them. Ladders are only placed vertically — each one leads to the same square of some of the upper rows. In order for the player to climb up a ladder, after rolling the dice, she must stop at the square containing the bottom of the ladder. After using the ladder, the player will end up in the square containing the top of the ladder. She cannot leave the ladder in the middle of climbing. And if the square containing the top of the ladder also contains the bottom of another ladder, she is not allowed to use that second ladder.
* The numbers on the faces of the dice are 1, 2, 3, 4, 5, and 6, with each number having the same probability of being shown.
Please note that:
* it is possible for ladders to overlap, but the player cannot switch to the other ladder while in the middle of climbing the first one;
* it is possible for ladders to go straight to the top row, but not any higher;
* it is possible for two ladders to lead to the same tile;
* it is possible for a ladder to lead to a tile that also has a ladder, but the player will not be able to use that second ladder if she uses the first one;
* the player can only climb up ladders, not climb down.
Hyakugoku wants to finish the game as soon as possible. Thus, on each turn she chooses whether to climb the ladder or not optimally. Help her to determine the minimum expected number of turns the game will take.
Input
Input will consist of ten lines. The i-th line will contain 10 non-negative integers h_{i1}, h_{i2}, ..., h_{i10}. If h_{ij} is 0, then the tile at the i-th row and j-th column has no ladder. Otherwise, the ladder at that tile will have a height of h_{ij}, i.e. climbing it will lead to the tile h_{ij} rows directly above. It is guaranteed that 0 ≤ h_{ij} < i. Also, the first number of the first line and the first number of the last line always contain 0, i.e. the Goal and the starting tile never have ladders.
Output
Print only one line containing a single floating-point number — the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.
Examples
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
33.0476190476
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 4 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9
Output
20.2591405923
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 6 6 6 6 6 6 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
15.9047592939
Note
A visualization of the path and the board from example 2 is as follows: <image>
The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal.
For the first example, there are no ladders.
For the second example, the board looks like the one in the right part of the image (the ladders have been colored for clarity).
It is possible for ladders to overlap, as is the case with the red and yellow ladders and green and blue ladders. It is also possible for ladders to go straight to the top, as is the case with the black and blue ladders. However, it is not possible for ladders to go any higher (outside of the board). It is also possible that two ladders lead to the same tile, as is the case with the red and yellow ladders. Also, notice that the red and yellow ladders lead to the tile with the orange ladder. So if the player chooses to climb either of the red and yellow ladders, they will not be able to climb the orange ladder. Finally, notice that the green ladder passes through the starting tile of the blue ladder. The player cannot transfer from the green ladder to the blue ladder while in the middle of climbing the green ladder. | instruction | 0 | 11,732 | 19 | 23,464 |
Tags: dp, probabilities, shortest paths
Correct Solution:
```
def pos(x, y):
if y & 1:
return y * w + w - 1 - x
return y * w + x
CUBE = 6
h, w = 10, 10
n = h * w
grid = []
for y in range(h):
line = list(map(int, input().split()))
grid.append(line)
grid.reverse()
# print(*grid, sep='\n')
to = [0] * n
for y in range(h):
for x in range(w):
y1 = y + grid[y][x]
if y1 != y:
# print(f"({x}, {y}) --> ({x}, {y1})", pos(x, y), pos(x, y1))
to[pos(x, y)] = pos(x, y + grid[y][x])
# print(to)
exp = [0] * (n + CUBE)
for i in range(n - 2, -1, -1):
exp[i] = 1
for j in range(1, CUBE + 1):
exp_to = exp[i + j] / CUBE
if i + j < n and to[i + j]:
exp_to = min(exp_to, exp[to[i + j]] / CUBE)
exp[i] += exp_to
if i + CUBE >= n:
exp[i] = CUBE * exp[i] / (n - 1 - i)
# print(*[f"{x:.1f}" for x in exp[:n]])
print(f"{exp[0]:.16f}")
``` | output | 1 | 11,732 | 19 | 23,465 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snakes, so there are only ladders left now.
The game is played on a 10 × 10 board as follows:
* At the beginning of the game, the player is at the bottom left square.
* The objective of the game is for the player to reach the Goal (the top left square) by following the path and climbing vertical ladders. Once the player reaches the Goal, the game ends.
* The path is as follows: if a square is not the end of its row, it leads to the square next to it along the direction of its row; if a square is the end of its row, it leads to the square above it. The direction of a row is determined as follows: the direction of the bottom row is to the right; the direction of any other row is opposite the direction of the row below it. See Notes section for visualization of path.
* During each turn, the player rolls a standard six-sided dice. Suppose that the number shown on the dice is r. If the Goal is less than r squares away on the path, the player doesn't move (but the turn is performed). Otherwise, the player advances exactly r squares along the path and then stops. If the player stops on a square with the bottom of a ladder, the player chooses whether or not to climb up that ladder. If she chooses not to climb, then she stays in that square for the beginning of the next turn.
* Some squares have a ladder in them. Ladders are only placed vertically — each one leads to the same square of some of the upper rows. In order for the player to climb up a ladder, after rolling the dice, she must stop at the square containing the bottom of the ladder. After using the ladder, the player will end up in the square containing the top of the ladder. She cannot leave the ladder in the middle of climbing. And if the square containing the top of the ladder also contains the bottom of another ladder, she is not allowed to use that second ladder.
* The numbers on the faces of the dice are 1, 2, 3, 4, 5, and 6, with each number having the same probability of being shown.
Please note that:
* it is possible for ladders to overlap, but the player cannot switch to the other ladder while in the middle of climbing the first one;
* it is possible for ladders to go straight to the top row, but not any higher;
* it is possible for two ladders to lead to the same tile;
* it is possible for a ladder to lead to a tile that also has a ladder, but the player will not be able to use that second ladder if she uses the first one;
* the player can only climb up ladders, not climb down.
Hyakugoku wants to finish the game as soon as possible. Thus, on each turn she chooses whether to climb the ladder or not optimally. Help her to determine the minimum expected number of turns the game will take.
Input
Input will consist of ten lines. The i-th line will contain 10 non-negative integers h_{i1}, h_{i2}, ..., h_{i10}. If h_{ij} is 0, then the tile at the i-th row and j-th column has no ladder. Otherwise, the ladder at that tile will have a height of h_{ij}, i.e. climbing it will lead to the tile h_{ij} rows directly above. It is guaranteed that 0 ≤ h_{ij} < i. Also, the first number of the first line and the first number of the last line always contain 0, i.e. the Goal and the starting tile never have ladders.
Output
Print only one line containing a single floating-point number — the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.
Examples
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
33.0476190476
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 4 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9
Output
20.2591405923
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 6 6 6 6 6 6 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
15.9047592939
Note
A visualization of the path and the board from example 2 is as follows: <image>
The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal.
For the first example, there are no ladders.
For the second example, the board looks like the one in the right part of the image (the ladders have been colored for clarity).
It is possible for ladders to overlap, as is the case with the red and yellow ladders and green and blue ladders. It is also possible for ladders to go straight to the top, as is the case with the black and blue ladders. However, it is not possible for ladders to go any higher (outside of the board). It is also possible that two ladders lead to the same tile, as is the case with the red and yellow ladders. Also, notice that the red and yellow ladders lead to the tile with the orange ladder. So if the player chooses to climb either of the red and yellow ladders, they will not be able to climb the orange ladder. Finally, notice that the green ladder passes through the starting tile of the blue ladder. The player cannot transfer from the green ladder to the blue ladder while in the middle of climbing the green ladder. | instruction | 0 | 11,733 | 19 | 23,466 |
Tags: dp, probabilities, shortest paths
Correct Solution:
```
from math import *
c=10
av=[]
for i in range(c):
l=[int(s) for s in input().split()]
if i%2==0:
l.reverse()
for j in range(c):
if l[j]%2==0:
l[j]=c*l[j]
else:
l[j]=c*l[j]+c-1-2*j
av=l+av
d=[0]*c**2
for i in range(c**2-2,-1,-1):
rep=max(0,6-c**2+1+i)
t=0
for j in range(1,6-rep+1):
t+=min(d[i+j],d[i+j+av[i+j]])+1
d[i]=(rep+t)/(6-rep)
print(d[0])
``` | output | 1 | 11,733 | 19 | 23,467 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snakes, so there are only ladders left now.
The game is played on a 10 × 10 board as follows:
* At the beginning of the game, the player is at the bottom left square.
* The objective of the game is for the player to reach the Goal (the top left square) by following the path and climbing vertical ladders. Once the player reaches the Goal, the game ends.
* The path is as follows: if a square is not the end of its row, it leads to the square next to it along the direction of its row; if a square is the end of its row, it leads to the square above it. The direction of a row is determined as follows: the direction of the bottom row is to the right; the direction of any other row is opposite the direction of the row below it. See Notes section for visualization of path.
* During each turn, the player rolls a standard six-sided dice. Suppose that the number shown on the dice is r. If the Goal is less than r squares away on the path, the player doesn't move (but the turn is performed). Otherwise, the player advances exactly r squares along the path and then stops. If the player stops on a square with the bottom of a ladder, the player chooses whether or not to climb up that ladder. If she chooses not to climb, then she stays in that square for the beginning of the next turn.
* Some squares have a ladder in them. Ladders are only placed vertically — each one leads to the same square of some of the upper rows. In order for the player to climb up a ladder, after rolling the dice, she must stop at the square containing the bottom of the ladder. After using the ladder, the player will end up in the square containing the top of the ladder. She cannot leave the ladder in the middle of climbing. And if the square containing the top of the ladder also contains the bottom of another ladder, she is not allowed to use that second ladder.
* The numbers on the faces of the dice are 1, 2, 3, 4, 5, and 6, with each number having the same probability of being shown.
Please note that:
* it is possible for ladders to overlap, but the player cannot switch to the other ladder while in the middle of climbing the first one;
* it is possible for ladders to go straight to the top row, but not any higher;
* it is possible for two ladders to lead to the same tile;
* it is possible for a ladder to lead to a tile that also has a ladder, but the player will not be able to use that second ladder if she uses the first one;
* the player can only climb up ladders, not climb down.
Hyakugoku wants to finish the game as soon as possible. Thus, on each turn she chooses whether to climb the ladder or not optimally. Help her to determine the minimum expected number of turns the game will take.
Input
Input will consist of ten lines. The i-th line will contain 10 non-negative integers h_{i1}, h_{i2}, ..., h_{i10}. If h_{ij} is 0, then the tile at the i-th row and j-th column has no ladder. Otherwise, the ladder at that tile will have a height of h_{ij}, i.e. climbing it will lead to the tile h_{ij} rows directly above. It is guaranteed that 0 ≤ h_{ij} < i. Also, the first number of the first line and the first number of the last line always contain 0, i.e. the Goal and the starting tile never have ladders.
Output
Print only one line containing a single floating-point number — the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.
Examples
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
33.0476190476
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 4 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9
Output
20.2591405923
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 6 6 6 6 6 6 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
15.9047592939
Note
A visualization of the path and the board from example 2 is as follows: <image>
The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal.
For the first example, there are no ladders.
For the second example, the board looks like the one in the right part of the image (the ladders have been colored for clarity).
It is possible for ladders to overlap, as is the case with the red and yellow ladders and green and blue ladders. It is also possible for ladders to go straight to the top, as is the case with the black and blue ladders. However, it is not possible for ladders to go any higher (outside of the board). It is also possible that two ladders lead to the same tile, as is the case with the red and yellow ladders. Also, notice that the red and yellow ladders lead to the tile with the orange ladder. So if the player chooses to climb either of the red and yellow ladders, they will not be able to climb the orange ladder. Finally, notice that the green ladder passes through the starting tile of the blue ladder. The player cannot transfer from the green ladder to the blue ladder while in the middle of climbing the green ladder. | instruction | 0 | 11,734 | 19 | 23,468 |
Tags: dp, probabilities, shortest paths
Correct Solution:
```
#!/usr/bin/python3
import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys
def main():
H = [read_ints() for _ in range(10)]
print(solve(H))
def pos_idx(x, y):
i = y * 10
if y % 2 == 0:
i += x
else:
i += 9 - x
return i
def idx_pos(i):
y = i // 10
if y % 2 == 0:
x = i % 10
else:
x = 9 - i % 10
return x, y
def solve(H):
dp = [0] * 100
for i in range(1, 100):
e = 0
for d in range(1, 7):
j = i - d
if j < 0:
rem = 7 - d
e += rem / 6
e *= 6 / (6 - rem)
break
x, y = idx_pos(j)
if H[y][x] != 0:
dy = y - H[y][x]
k = pos_idx(x, dy)
assert idx_pos(k) == (x, dy)
e += (min(dp[j], dp[k]) + 1) / 6
else:
e += (dp[j] + 1) / 6
dp[i] = e
return dp[99]
###############################################################################
# AUXILIARY FUNCTIONS
DEBUG = 'DEBUG' in os.environ
def inp():
return sys.stdin.readline().rstrip()
def read_int():
return int(inp())
def read_ints():
return [int(e) for e in inp().split()]
def dprint(*value, sep=' ', end='\n'):
if DEBUG:
print(*value, sep=sep, end=end)
if __name__ == '__main__':
main()
``` | output | 1 | 11,734 | 19 | 23,469 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snakes, so there are only ladders left now.
The game is played on a 10 × 10 board as follows:
* At the beginning of the game, the player is at the bottom left square.
* The objective of the game is for the player to reach the Goal (the top left square) by following the path and climbing vertical ladders. Once the player reaches the Goal, the game ends.
* The path is as follows: if a square is not the end of its row, it leads to the square next to it along the direction of its row; if a square is the end of its row, it leads to the square above it. The direction of a row is determined as follows: the direction of the bottom row is to the right; the direction of any other row is opposite the direction of the row below it. See Notes section for visualization of path.
* During each turn, the player rolls a standard six-sided dice. Suppose that the number shown on the dice is r. If the Goal is less than r squares away on the path, the player doesn't move (but the turn is performed). Otherwise, the player advances exactly r squares along the path and then stops. If the player stops on a square with the bottom of a ladder, the player chooses whether or not to climb up that ladder. If she chooses not to climb, then she stays in that square for the beginning of the next turn.
* Some squares have a ladder in them. Ladders are only placed vertically — each one leads to the same square of some of the upper rows. In order for the player to climb up a ladder, after rolling the dice, she must stop at the square containing the bottom of the ladder. After using the ladder, the player will end up in the square containing the top of the ladder. She cannot leave the ladder in the middle of climbing. And if the square containing the top of the ladder also contains the bottom of another ladder, she is not allowed to use that second ladder.
* The numbers on the faces of the dice are 1, 2, 3, 4, 5, and 6, with each number having the same probability of being shown.
Please note that:
* it is possible for ladders to overlap, but the player cannot switch to the other ladder while in the middle of climbing the first one;
* it is possible for ladders to go straight to the top row, but not any higher;
* it is possible for two ladders to lead to the same tile;
* it is possible for a ladder to lead to a tile that also has a ladder, but the player will not be able to use that second ladder if she uses the first one;
* the player can only climb up ladders, not climb down.
Hyakugoku wants to finish the game as soon as possible. Thus, on each turn she chooses whether to climb the ladder or not optimally. Help her to determine the minimum expected number of turns the game will take.
Input
Input will consist of ten lines. The i-th line will contain 10 non-negative integers h_{i1}, h_{i2}, ..., h_{i10}. If h_{ij} is 0, then the tile at the i-th row and j-th column has no ladder. Otherwise, the ladder at that tile will have a height of h_{ij}, i.e. climbing it will lead to the tile h_{ij} rows directly above. It is guaranteed that 0 ≤ h_{ij} < i. Also, the first number of the first line and the first number of the last line always contain 0, i.e. the Goal and the starting tile never have ladders.
Output
Print only one line containing a single floating-point number — the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.
Examples
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
33.0476190476
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 4 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9
Output
20.2591405923
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 6 6 6 6 6 6 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
15.9047592939
Note
A visualization of the path and the board from example 2 is as follows: <image>
The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal.
For the first example, there are no ladders.
For the second example, the board looks like the one in the right part of the image (the ladders have been colored for clarity).
It is possible for ladders to overlap, as is the case with the red and yellow ladders and green and blue ladders. It is also possible for ladders to go straight to the top, as is the case with the black and blue ladders. However, it is not possible for ladders to go any higher (outside of the board). It is also possible that two ladders lead to the same tile, as is the case with the red and yellow ladders. Also, notice that the red and yellow ladders lead to the tile with the orange ladder. So if the player chooses to climb either of the red and yellow ladders, they will not be able to climb the orange ladder. Finally, notice that the green ladder passes through the starting tile of the blue ladder. The player cannot transfer from the green ladder to the blue ladder while in the middle of climbing the green ladder. | instruction | 0 | 11,735 | 19 | 23,470 |
Tags: dp, probabilities, shortest paths
Correct Solution:
```
board = []
for i in range(10):
board.append([int(i) for i in input().split()])
def next_squares(x, y):
current_dir = 1 if x%2 else -1
# print(x, y, current_dir)
res = []
for _ in range(6):
nx, ny = x, y + current_dir
if ny < 0 or ny == 10:
nx, ny = x - 1, y
current_dir *= -1
if nx == -1: break
x, y = nx, ny
res.append([x, y])
# print(x, y, res)
return res
from functools import lru_cache
@lru_cache(None)
def dp(i, j, can_climb):
if i == j == 0: return 0
expected = []
for x, y in next_squares(i, j):
expected.append(dp(x, y, True))
score = sum(expected) / len(expected) + (6 / len(expected))
# print(i, j)
if can_climb and board[i][j]: return min(score, dp(i - board[i][j], j, False))
return score
print(dp(9, 0, True))
``` | output | 1 | 11,735 | 19 | 23,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snakes, so there are only ladders left now.
The game is played on a 10 × 10 board as follows:
* At the beginning of the game, the player is at the bottom left square.
* The objective of the game is for the player to reach the Goal (the top left square) by following the path and climbing vertical ladders. Once the player reaches the Goal, the game ends.
* The path is as follows: if a square is not the end of its row, it leads to the square next to it along the direction of its row; if a square is the end of its row, it leads to the square above it. The direction of a row is determined as follows: the direction of the bottom row is to the right; the direction of any other row is opposite the direction of the row below it. See Notes section for visualization of path.
* During each turn, the player rolls a standard six-sided dice. Suppose that the number shown on the dice is r. If the Goal is less than r squares away on the path, the player doesn't move (but the turn is performed). Otherwise, the player advances exactly r squares along the path and then stops. If the player stops on a square with the bottom of a ladder, the player chooses whether or not to climb up that ladder. If she chooses not to climb, then she stays in that square for the beginning of the next turn.
* Some squares have a ladder in them. Ladders are only placed vertically — each one leads to the same square of some of the upper rows. In order for the player to climb up a ladder, after rolling the dice, she must stop at the square containing the bottom of the ladder. After using the ladder, the player will end up in the square containing the top of the ladder. She cannot leave the ladder in the middle of climbing. And if the square containing the top of the ladder also contains the bottom of another ladder, she is not allowed to use that second ladder.
* The numbers on the faces of the dice are 1, 2, 3, 4, 5, and 6, with each number having the same probability of being shown.
Please note that:
* it is possible for ladders to overlap, but the player cannot switch to the other ladder while in the middle of climbing the first one;
* it is possible for ladders to go straight to the top row, but not any higher;
* it is possible for two ladders to lead to the same tile;
* it is possible for a ladder to lead to a tile that also has a ladder, but the player will not be able to use that second ladder if she uses the first one;
* the player can only climb up ladders, not climb down.
Hyakugoku wants to finish the game as soon as possible. Thus, on each turn she chooses whether to climb the ladder or not optimally. Help her to determine the minimum expected number of turns the game will take.
Input
Input will consist of ten lines. The i-th line will contain 10 non-negative integers h_{i1}, h_{i2}, ..., h_{i10}. If h_{ij} is 0, then the tile at the i-th row and j-th column has no ladder. Otherwise, the ladder at that tile will have a height of h_{ij}, i.e. climbing it will lead to the tile h_{ij} rows directly above. It is guaranteed that 0 ≤ h_{ij} < i. Also, the first number of the first line and the first number of the last line always contain 0, i.e. the Goal and the starting tile never have ladders.
Output
Print only one line containing a single floating-point number — the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.
Examples
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
33.0476190476
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 4 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9
Output
20.2591405923
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 6 6 6 6 6 6 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
15.9047592939
Note
A visualization of the path and the board from example 2 is as follows: <image>
The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal.
For the first example, there are no ladders.
For the second example, the board looks like the one in the right part of the image (the ladders have been colored for clarity).
It is possible for ladders to overlap, as is the case with the red and yellow ladders and green and blue ladders. It is also possible for ladders to go straight to the top, as is the case with the black and blue ladders. However, it is not possible for ladders to go any higher (outside of the board). It is also possible that two ladders lead to the same tile, as is the case with the red and yellow ladders. Also, notice that the red and yellow ladders lead to the tile with the orange ladder. So if the player chooses to climb either of the red and yellow ladders, they will not be able to climb the orange ladder. Finally, notice that the green ladder passes through the starting tile of the blue ladder. The player cannot transfer from the green ladder to the blue ladder while in the middle of climbing the green ladder. | instruction | 0 | 11,736 | 19 | 23,472 |
Tags: dp, probabilities, shortest paths
Correct Solution:
```
links = list(range(100))
# 0 0 = left up
# 10*y+x
# i = height
# j = pos
for i in range(10):
l = list(map(int, input().split()))
for j, h in enumerate(l):
coo = i*10+(j if i%2==0 else 9-j)
target = (i-h)*10+(j if (i-h)%2==0 else 9-j)
links[coo] = target
exp = [0]
for i in range(1, 6):
exp.append((1 + sum(exp)*1/6)*6/i)
for i in range(6, 100):
new = 0
for j in range(1, 7):
new += min(exp[i-j], exp[links[i-j]])
exp.append(1 + new/6)
print(exp[-1])
``` | output | 1 | 11,736 | 19 | 23,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snakes, so there are only ladders left now.
The game is played on a 10 × 10 board as follows:
* At the beginning of the game, the player is at the bottom left square.
* The objective of the game is for the player to reach the Goal (the top left square) by following the path and climbing vertical ladders. Once the player reaches the Goal, the game ends.
* The path is as follows: if a square is not the end of its row, it leads to the square next to it along the direction of its row; if a square is the end of its row, it leads to the square above it. The direction of a row is determined as follows: the direction of the bottom row is to the right; the direction of any other row is opposite the direction of the row below it. See Notes section for visualization of path.
* During each turn, the player rolls a standard six-sided dice. Suppose that the number shown on the dice is r. If the Goal is less than r squares away on the path, the player doesn't move (but the turn is performed). Otherwise, the player advances exactly r squares along the path and then stops. If the player stops on a square with the bottom of a ladder, the player chooses whether or not to climb up that ladder. If she chooses not to climb, then she stays in that square for the beginning of the next turn.
* Some squares have a ladder in them. Ladders are only placed vertically — each one leads to the same square of some of the upper rows. In order for the player to climb up a ladder, after rolling the dice, she must stop at the square containing the bottom of the ladder. After using the ladder, the player will end up in the square containing the top of the ladder. She cannot leave the ladder in the middle of climbing. And if the square containing the top of the ladder also contains the bottom of another ladder, she is not allowed to use that second ladder.
* The numbers on the faces of the dice are 1, 2, 3, 4, 5, and 6, with each number having the same probability of being shown.
Please note that:
* it is possible for ladders to overlap, but the player cannot switch to the other ladder while in the middle of climbing the first one;
* it is possible for ladders to go straight to the top row, but not any higher;
* it is possible for two ladders to lead to the same tile;
* it is possible for a ladder to lead to a tile that also has a ladder, but the player will not be able to use that second ladder if she uses the first one;
* the player can only climb up ladders, not climb down.
Hyakugoku wants to finish the game as soon as possible. Thus, on each turn she chooses whether to climb the ladder or not optimally. Help her to determine the minimum expected number of turns the game will take.
Input
Input will consist of ten lines. The i-th line will contain 10 non-negative integers h_{i1}, h_{i2}, ..., h_{i10}. If h_{ij} is 0, then the tile at the i-th row and j-th column has no ladder. Otherwise, the ladder at that tile will have a height of h_{ij}, i.e. climbing it will lead to the tile h_{ij} rows directly above. It is guaranteed that 0 ≤ h_{ij} < i. Also, the first number of the first line and the first number of the last line always contain 0, i.e. the Goal and the starting tile never have ladders.
Output
Print only one line containing a single floating-point number — the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.
Examples
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
33.0476190476
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 4 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9
Output
20.2591405923
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 6 6 6 6 6 6 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
15.9047592939
Note
A visualization of the path and the board from example 2 is as follows: <image>
The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal.
For the first example, there are no ladders.
For the second example, the board looks like the one in the right part of the image (the ladders have been colored for clarity).
It is possible for ladders to overlap, as is the case with the red and yellow ladders and green and blue ladders. It is also possible for ladders to go straight to the top, as is the case with the black and blue ladders. However, it is not possible for ladders to go any higher (outside of the board). It is also possible that two ladders lead to the same tile, as is the case with the red and yellow ladders. Also, notice that the red and yellow ladders lead to the tile with the orange ladder. So if the player chooses to climb either of the red and yellow ladders, they will not be able to climb the orange ladder. Finally, notice that the green ladder passes through the starting tile of the blue ladder. The player cannot transfer from the green ladder to the blue ladder while in the middle of climbing the green ladder. | instruction | 0 | 11,737 | 19 | 23,474 |
Tags: dp, probabilities, shortest paths
Correct Solution:
```
t=[]
def corresp(i,j):
return 100 - (i*10 + (j if not i%2 else (9-j)))
paths=[[i] for i in range(101)]
for i in range(10):
z=[int(k) for k in input().split(" ")]
if i%2:
t+=z[::-1]
else:
t+=z
for j in range(10):
if z[j]:
paths[corresp(i,j)]=[corresp(i,j),corresp(i-z[j],j)]
res=[0 for i in range(101)]
for i in range(99,94,-1):
ri=max(1,6/(100-i))
#print(i,ri,)
for j in range(i+1,101):
ri+=res[j]/(min(6,100-i))
# print(j,ri,)
#print("")
res[i]=ri
for i in range(94,-1,-1):
ri=1
for j in range(i+1,i+7):
ri+= min([res[k] for k in paths[j]])/6
res[i]=ri
#print(res)
#print(corresp(9,0))
print(res[1])
``` | output | 1 | 11,737 | 19 | 23,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snakes, so there are only ladders left now.
The game is played on a 10 × 10 board as follows:
* At the beginning of the game, the player is at the bottom left square.
* The objective of the game is for the player to reach the Goal (the top left square) by following the path and climbing vertical ladders. Once the player reaches the Goal, the game ends.
* The path is as follows: if a square is not the end of its row, it leads to the square next to it along the direction of its row; if a square is the end of its row, it leads to the square above it. The direction of a row is determined as follows: the direction of the bottom row is to the right; the direction of any other row is opposite the direction of the row below it. See Notes section for visualization of path.
* During each turn, the player rolls a standard six-sided dice. Suppose that the number shown on the dice is r. If the Goal is less than r squares away on the path, the player doesn't move (but the turn is performed). Otherwise, the player advances exactly r squares along the path and then stops. If the player stops on a square with the bottom of a ladder, the player chooses whether or not to climb up that ladder. If she chooses not to climb, then she stays in that square for the beginning of the next turn.
* Some squares have a ladder in them. Ladders are only placed vertically — each one leads to the same square of some of the upper rows. In order for the player to climb up a ladder, after rolling the dice, she must stop at the square containing the bottom of the ladder. After using the ladder, the player will end up in the square containing the top of the ladder. She cannot leave the ladder in the middle of climbing. And if the square containing the top of the ladder also contains the bottom of another ladder, she is not allowed to use that second ladder.
* The numbers on the faces of the dice are 1, 2, 3, 4, 5, and 6, with each number having the same probability of being shown.
Please note that:
* it is possible for ladders to overlap, but the player cannot switch to the other ladder while in the middle of climbing the first one;
* it is possible for ladders to go straight to the top row, but not any higher;
* it is possible for two ladders to lead to the same tile;
* it is possible for a ladder to lead to a tile that also has a ladder, but the player will not be able to use that second ladder if she uses the first one;
* the player can only climb up ladders, not climb down.
Hyakugoku wants to finish the game as soon as possible. Thus, on each turn she chooses whether to climb the ladder or not optimally. Help her to determine the minimum expected number of turns the game will take.
Input
Input will consist of ten lines. The i-th line will contain 10 non-negative integers h_{i1}, h_{i2}, ..., h_{i10}. If h_{ij} is 0, then the tile at the i-th row and j-th column has no ladder. Otherwise, the ladder at that tile will have a height of h_{ij}, i.e. climbing it will lead to the tile h_{ij} rows directly above. It is guaranteed that 0 ≤ h_{ij} < i. Also, the first number of the first line and the first number of the last line always contain 0, i.e. the Goal and the starting tile never have ladders.
Output
Print only one line containing a single floating-point number — the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.
Examples
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
33.0476190476
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 4 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9
Output
20.2591405923
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 6 6 6 6 6 6 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
15.9047592939
Note
A visualization of the path and the board from example 2 is as follows: <image>
The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal.
For the first example, there are no ladders.
For the second example, the board looks like the one in the right part of the image (the ladders have been colored for clarity).
It is possible for ladders to overlap, as is the case with the red and yellow ladders and green and blue ladders. It is also possible for ladders to go straight to the top, as is the case with the black and blue ladders. However, it is not possible for ladders to go any higher (outside of the board). It is also possible that two ladders lead to the same tile, as is the case with the red and yellow ladders. Also, notice that the red and yellow ladders lead to the tile with the orange ladder. So if the player chooses to climb either of the red and yellow ladders, they will not be able to climb the orange ladder. Finally, notice that the green ladder passes through the starting tile of the blue ladder. The player cannot transfer from the green ladder to the blue ladder while in the middle of climbing the green ladder.
Submitted Solution:
```
import sys
def read_ints():
return [int(x) for x in sys.stdin.readline().split()]
def ind(i, j):
return 10 * i + (j if i % 2 == 0 else 9 - j)
def read_field():
field = [0] * 100
for i in range(10):
for j, h in enumerate(read_ints()[:10]):
if h != 0:
h = ind(i - h, j)
else:
h = ind(i, j)
field[ind(i, j)] = h
return field
def solve(field):
dp = [1.0] * 100
dp[0] = 0.0
for _ in range(100):
for i in range(1, 100):
sum = 1.0
for j in range(1, 7):
if (i - j) >= 0:
sum += min(dp[i - j], dp[field[i - j]]) / 6
else:
sum += dp[i] / 6
dp[i] = sum
return dp[99]
def main():
field = read_field()
result = solve(field)
sys.stdout.write("{:.6f}\n".format(result))
if __name__ == "__main__":
main()
``` | instruction | 0 | 11,738 | 19 | 23,476 |
Yes | output | 1 | 11,738 | 19 | 23,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snakes, so there are only ladders left now.
The game is played on a 10 × 10 board as follows:
* At the beginning of the game, the player is at the bottom left square.
* The objective of the game is for the player to reach the Goal (the top left square) by following the path and climbing vertical ladders. Once the player reaches the Goal, the game ends.
* The path is as follows: if a square is not the end of its row, it leads to the square next to it along the direction of its row; if a square is the end of its row, it leads to the square above it. The direction of a row is determined as follows: the direction of the bottom row is to the right; the direction of any other row is opposite the direction of the row below it. See Notes section for visualization of path.
* During each turn, the player rolls a standard six-sided dice. Suppose that the number shown on the dice is r. If the Goal is less than r squares away on the path, the player doesn't move (but the turn is performed). Otherwise, the player advances exactly r squares along the path and then stops. If the player stops on a square with the bottom of a ladder, the player chooses whether or not to climb up that ladder. If she chooses not to climb, then she stays in that square for the beginning of the next turn.
* Some squares have a ladder in them. Ladders are only placed vertically — each one leads to the same square of some of the upper rows. In order for the player to climb up a ladder, after rolling the dice, she must stop at the square containing the bottom of the ladder. After using the ladder, the player will end up in the square containing the top of the ladder. She cannot leave the ladder in the middle of climbing. And if the square containing the top of the ladder also contains the bottom of another ladder, she is not allowed to use that second ladder.
* The numbers on the faces of the dice are 1, 2, 3, 4, 5, and 6, with each number having the same probability of being shown.
Please note that:
* it is possible for ladders to overlap, but the player cannot switch to the other ladder while in the middle of climbing the first one;
* it is possible for ladders to go straight to the top row, but not any higher;
* it is possible for two ladders to lead to the same tile;
* it is possible for a ladder to lead to a tile that also has a ladder, but the player will not be able to use that second ladder if she uses the first one;
* the player can only climb up ladders, not climb down.
Hyakugoku wants to finish the game as soon as possible. Thus, on each turn she chooses whether to climb the ladder or not optimally. Help her to determine the minimum expected number of turns the game will take.
Input
Input will consist of ten lines. The i-th line will contain 10 non-negative integers h_{i1}, h_{i2}, ..., h_{i10}. If h_{ij} is 0, then the tile at the i-th row and j-th column has no ladder. Otherwise, the ladder at that tile will have a height of h_{ij}, i.e. climbing it will lead to the tile h_{ij} rows directly above. It is guaranteed that 0 ≤ h_{ij} < i. Also, the first number of the first line and the first number of the last line always contain 0, i.e. the Goal and the starting tile never have ladders.
Output
Print only one line containing a single floating-point number — the minimum expected number of turns Hyakugoku can take to finish the game. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.
Examples
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
33.0476190476
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 4 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 9
Output
20.2591405923
Input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 6 6 6 6 6 6 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output
15.9047592939
Note
A visualization of the path and the board from example 2 is as follows: <image>
The tile with an 'S' is the starting tile and the tile with an 'E' is the Goal.
For the first example, there are no ladders.
For the second example, the board looks like the one in the right part of the image (the ladders have been colored for clarity).
It is possible for ladders to overlap, as is the case with the red and yellow ladders and green and blue ladders. It is also possible for ladders to go straight to the top, as is the case with the black and blue ladders. However, it is not possible for ladders to go any higher (outside of the board). It is also possible that two ladders lead to the same tile, as is the case with the red and yellow ladders. Also, notice that the red and yellow ladders lead to the tile with the orange ladder. So if the player chooses to climb either of the red and yellow ladders, they will not be able to climb the orange ladder. Finally, notice that the green ladder passes through the starting tile of the blue ladder. The player cannot transfer from the green ladder to the blue ladder while in the middle of climbing the green ladder.
Submitted Solution:
```
#work out expected all the way back
#1/6th sum of expected of next few moves
#99 98 97 ...
#80 81 82 ...
#
#
#19 18
#0 1
def toLadderIndex(row,col):
if row%2==0:
return (10-row)*10-col-1
return (10-row-1)*10+col
def getLadders(p):
ladders = [0 for i in range(100)]
p = [[int(cell) for cell in row.split()] for row in p.split("\n")]
for row in range(10):
for col in range(10):
#print(p)
if p[row][col] != 0:
source = toLadderIndex(row,col)
dest = toLadderIndex(row-p[row][col],col)
if (source < dest):
ladders[source] = dest
return ladders
cache = []
def redoCache():
global cache
cache = [None for i in range(100)]
cache[99] = 0
cache[98] = 6
cache[97] = 6
cache[96] = 6
cache[95] = 6
cache[94] = 6
cache[93] = 6
def exp(n): #expected no. turns to finish from position, 99 = finish, 0 = start
if cache[n]:
return cache[n]
ret = 0
for i in range(1,7):
if (ladder[n+i]):
ret += exp(ladder[n+i])
else:
ret += exp(n+i)
cache[n] = 1 + ret/6
return cache[n]
def boom(p):
redoCache()
global ladder
ladder = getLadders(p)
return exp(0)
p = ""
for j in range(10):
p += input() + "\n"
print(boom(p))
``` | instruction | 0 | 11,739 | 19 | 23,478 |
No | output | 1 | 11,739 | 19 | 23,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win. | instruction | 0 | 11,828 | 19 | 23,656 |
Tags: math, probabilities
Correct Solution:
```
def main():
t = int(input())
for ti in range(t):
sz = int(input())
rs = input()
rsz = len(rs)//sz
r = 0
bs = input()
bsz = len(bs)//sz
b = 0
for ni in range(sz):
ri = ni * rsz
bi = ni * bsz
diff = int(rs[ri:ri+rsz]) - int(bs[bi:bi+bsz])
if diff > 0:
r += 1
elif diff < 0:
b += 1
print('RED' if r > b else 'BLUE' if r < b else 'EQUAL')
if __name__ == "__main__":
main()
``` | output | 1 | 11,828 | 19 | 23,657 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win. | instruction | 0 | 11,829 | 19 | 23,658 |
Tags: math, probabilities
Correct Solution:
```
import sys
try:sys.stdin,sys.stdout=open('in.txt','r'),open('out.txt','w')
except:pass
ii1=lambda:int(sys.stdin.readline().strip()) # for interger
is1=lambda:sys.stdin.readline().strip() # for str
iia=lambda:list(map(int,sys.stdin.readline().strip().split())) # for List[int]
isa=lambda:sys.stdin.readline().strip().split() # for List[str]
mod=int(1e9 + 7);from collections import *;from math import *
# abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
###################### Start Here ######################
for _ in range(ii1()):
n = ii1()
arr = is1()
ar = is1()
r = 0
b = 0
for i in range(n):
if arr[i]>ar[i]:
r+=1
elif arr[i]<ar[i]:
b+=1
else:
b+=1;r+=1
if r==b:print('EQUAL')
else:
if r>b:
print('RED')
else:
print('BLUE')
``` | output | 1 | 11,829 | 19 | 23,659 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win. | instruction | 0 | 11,830 | 19 | 23,660 |
Tags: math, probabilities
Correct Solution:
```
T = int(input())
for _ in range(T):
n = int(input())
r = [int(c) for c in input()]
b = [int(c) for c in input()]
A = sum([r[i]>b[i] for i in range(n)])
B = sum([b[i]>r[i] for i in range(n)])
C = n - A - B
if A>B:
print ('RED')
elif B >A:
print ('BLUE')
else:
print ('EQUAL')
``` | output | 1 | 11,830 | 19 | 23,661 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win. | instruction | 0 | 11,831 | 19 | 23,662 |
Tags: math, probabilities
Correct Solution:
```
test1=int(input())
for _ in range(test1):
n=int(input())
a=input()
b=input()
s1=s2=0
for i in range(n):
if(int(a[i])>int(b[i])):
s1+=1
elif(int(b[i])>int(a[i])):
s2+=1
if(s1==s2):
print("EQUAL")
elif(s1>s2):
print("RED")
else:
print("BLUE")
``` | output | 1 | 11,831 | 19 | 23,663 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win. | instruction | 0 | 11,832 | 19 | 23,664 |
Tags: math, probabilities
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
s=input()
s1=input()
a=0
b=0
for i in range(n):
if s[i]>s1[i]:
a=a+1
elif s[i]<s1[i]:
b=b+1
if a>b:
print("RED")
elif b>a:
print("BLUE")
else:
print("EQUAL")
``` | output | 1 | 11,832 | 19 | 23,665 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win. | instruction | 0 | 11,833 | 19 | 23,666 |
Tags: math, probabilities
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
r=list(map(int,input()))
b=list(map(int,input()))
red=0
blue=0
for i in range(n):
if r[i]>b[i]:
red+=1
elif b[i]>r[i]:
blue+=1
if red>blue:
print("RED")
elif blue>red:
print("BLUE")
else:
print("EQUAL")
``` | output | 1 | 11,833 | 19 | 23,667 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win. | instruction | 0 | 11,834 | 19 | 23,668 |
Tags: math, probabilities
Correct Solution:
```
#import sys
#import math
#sys.stdout=open("python/output.txt","w")
#sys.stdin=open("python/input.txt","r")
t=int(input())
for i in range(t):
n=int(input())
r=input()
b=input()
rl=list(r)
red=0
blue=0
bl=list(b)
for i in range(n):
if rl[i]>bl[i]:
red+=1
if bl[i]>rl[i]:
blue+=1
if red>blue:
print("RED")
elif blue>red:
print("BLUE")
else:
print("EQUAL")
``` | output | 1 | 11,834 | 19 | 23,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win. | instruction | 0 | 11,835 | 19 | 23,670 |
Tags: math, probabilities
Correct Solution:
```
t = int(input())
res = []
for i in range(t):
n = int(input())
reds = input()
reds = list(map(int,[char for char in reds]))
blues = input()
blues = list(map(int,[char for char in blues]))
bluepoints,redpoints =0,0
for card in range(n):
blue = blues[card]
red = reds[card]
if blue>red:
bluepoints+=1
elif red>blue:
redpoints+=1
if redpoints>bluepoints:
res.append('RED')
elif redpoints<bluepoints:
res.append('BLUE')
elif redpoints==bluepoints:
res.append('EQUAL')
for r in res:
print(r)
``` | output | 1 | 11,835 | 19 | 23,671 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.
Submitted Solution:
```
t=int(input())
for _ in range(t):
n=int(input())
s1=[i for i in input()]
s2=[i for i in input()]
a1=0
a2=0
for i in range(n):
if(s1[i]>s2[i]):a1+=1
elif(s1[i]<s2[i]):a2+=1
if(a1>a2):print("RED")
elif(a2>a1):print("BLUE")
else:print("EQUAL")
``` | instruction | 0 | 11,836 | 19 | 23,672 |
Yes | output | 1 | 11,836 | 19 | 23,673 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
R,B=0,0
A=input()
C=input()
if A==C:
print("EQUAL")
else:
for i in range(len(A)):
if int(A[i])>int(C[i]):
R+=1
elif int(C[i])>int(A[i]):
B+=1
else:
continue
if R>B:
print("RED")
elif B>R:
print("BLUE")
else:
print("EQUAL")
``` | instruction | 0 | 11,837 | 19 | 23,674 |
Yes | output | 1 | 11,837 | 19 | 23,675 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
r=input()
b=input()
rs,bs=0,0
for i in range(n):
if r[i]>b[i]:
rs+=1
elif b[i]>r[i]:
bs+=1
if rs>bs:
print("RED")
elif bs>rs:
print("BLUE")
else:
print("EQUAL")
``` | instruction | 0 | 11,838 | 19 | 23,676 |
Yes | output | 1 | 11,838 | 19 | 23,677 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.
Submitted Solution:
```
t = int(input())
for i in range(t):
n = input()
red = input()
blue = input()
#red = ''.join(sorted(red))[::-1]
#blue = ''.join(sorted(blue))[::-1]
p,j=0,0
for char in red:
if char > blue[j]:
p+=1
elif char < blue[j]:
p-=1
else:
pass
j+=1
if p>0:
print("RED")
elif p<0:
print("BLUE")
else:
print("EQUAL")
``` | instruction | 0 | 11,839 | 19 | 23,678 |
Yes | output | 1 | 11,839 | 19 | 23,679 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
a=input()
b=input()
l1=[]
l2=[]
for i in a:
l1.append(int(i))
for i in b:
l2.append(int(i))
l1.sort()
l2.sort()
cou1=0
cou2=0
for i in range(n):
if l1[i]>l2[i]:
cou1+=1
elif l1[i]<l2[i]:
cou2+=1
else:
cou1+=1
cou2+=1
if cou1>cou2:
print("RED")
elif cou1<cou2:
print("BLUE")
else:
print("EQUAL")
``` | instruction | 0 | 11,840 | 19 | 23,680 |
No | output | 1 | 11,840 | 19 | 23,681 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.
Submitted Solution:
```
"""
Code of Ayush Tiwari
Codeforces: servermonk
Codechef: ayush572000
"""
#import sys
#input = sys.stdin.buffer.readline
#Fast IO
import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill(): pass
return super(FastIO,self).read()
def readline(self):
while self.newlines == 0:
s = self._fill(); self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s:self.buffer.write(s.encode('ascii'))
self.read = lambda:self.buffer.read().decode('ascii')
self.readline = lambda:self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# Cout implemented in Python
import sys
class ostream:
def __lshift__(self,a):
sys.stdout.write(str(a))
return self
cout = ostream()
endl = '\n'
def solution():
# This is the main code
n=int(input())
a=input()
b=input()
num1=[]
num2=[]
for i in range(n):
num1.append(int(a[i]))
num2.append(int(b[i]))
x=0
y=0
num1.sort()
num2.sort()
for i in range(n):
if num1[i]>num2[i]:
x+=1
elif num2[i]>num1[i]:
y+=1
if y==x:
print('EQUAL')
else:
if x>y:
print('RED')
else:
print('BLUE')
t=int(input())
for _ in range(t):
solution()
``` | instruction | 0 | 11,841 | 19 | 23,682 |
No | output | 1 | 11,841 | 19 | 23,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
r=list(map(int,list(input())))
b=list(map(int,list(input())))
s1=0
s2=0
for i in range(n):
for j in range(n):
if(r[i]>b[j]):
s1+=1
elif(r[i]<b[j]):
s2+=1
if(s1>s2):
print('RED')
elif(s1<s2):
print('BLUE')
else:
print('EQUAL')
``` | instruction | 0 | 11,842 | 19 | 23,684 |
No | output | 1 | 11,842 | 19 | 23,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it.
We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.
<image>
Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R > B, and Blue bets that R < B. If in the end R = B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
Input
The first line contains a single integer T (1 ≤ T ≤ 100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1 ≤ n ≤ 1000) — the number of cards.
The following line contains a string of n digits r_1, …, r_n — red digits on cards 1, …, n respectively.
The following line contains a string of n digits b_1, …, b_n — blue digits on cards 1, …, n respectively.
Note that digits in the same line are not separated with any delimiters.
Output
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
Example
Input
3
3
777
111
3
314
159
5
09281
09281
Output
RED
BLUE
EQUAL
Note
Formally, let n_R be the number of permutations of cards 1, …, n such that the resulting numbers R and B satisfy R > B. Similarly, let n_B be the number of permutations such that R < B. If n_R > n_B, you should print "RED". If n_R < n_B, you should print "BLUE". If n_R = n_B, print "EQUAL".
In the first sample case, R = 777 and B = 111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
* order 1, 2, 3: 314 > 159;
* order 1, 3, 2: 341 > 195;
* order 2, 1, 3: 134 < 519;
* order 2, 3, 1: 143 < 591;
* order 3, 1, 2: 431 < 915;
* order 3, 2, 1: 413 < 951.
Since R < B is more frequent, the answer is "BLUE".
In the third sample case, R = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.
Submitted Solution:
```
t=int(input())
for i in range(t):
n=int(input())
a=input()
b=input()
c1=0
c2=0
c3=0
for i in range(n):
if a[i]>b[i]:
c1=c1+1
if a[i]<b[i]:
c2=c2+1
elif a[i]==b[i]:
c3=c3+1
if c1>c2 and c1>c3:
print("RED")
elif c1<c2 and c2>c3:
print("BLUE")
else:
print("EQUAL")
``` | instruction | 0 | 11,843 | 19 | 23,686 |
No | output | 1 | 11,843 | 19 | 23,687 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).
Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card.
The numbers in the lines are separated by single spaces.
Output
On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.
Examples
Input
3
4 7
4 7
7 4
Output
0
Input
5
4 7
7 4
2 11
9 7
1 1
Output
2
Note
In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | instruction | 0 | 11,908 | 19 | 23,816 |
Tags: binary search, data structures
Correct Solution:
```
def solve():
n = int(input())
cards = []
cnt = {}
for i in range(n):
card = tuple(map(int, input().split(' ')))
cards.append(card)
cnt[card[0]] = [0, 0]
cnt[card[1]] = [0, 0]
for card in cards:
if card[0] != card[1]:
cnt[card[0]][0] += 1
cnt[card[1]][1] += 1
else:
cnt[card[0]][0] += 1
border = (len(cards) + 1) // 2
best = float('inf')
for num in cnt.keys():
count = cnt[num]
if sum(count) >= border:
# try to flip down -> top or vice versa
needTop = max(0, border - count[0])
best = min(best, needTop)
if best == float('inf'):
print(-1)
else:
print(best)
solve()
``` | output | 1 | 11,908 | 19 | 23,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).
Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card.
The numbers in the lines are separated by single spaces.
Output
On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.
Examples
Input
3
4 7
4 7
7 4
Output
0
Input
5
4 7
7 4
2 11
9 7
1 1
Output
2
Note
In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | instruction | 0 | 11,909 | 19 | 23,818 |
Tags: binary search, data structures
Correct Solution:
```
def main():
n = int(input())
d = {}
for i in range(n):
a, b = [int(i) for i in input().split()]
if a == b:
if a not in d:
d[a] = [0, 0]
d[a][0] += 1
else:
if a not in d:
d[a] = [0, 0]
d[a][0] += 1
if b not in d:
d[b] = [0, 0]
d[b][1] += 1
result = float("inf")
half = (n + 1) // 2
for a, b in d.values():
if a + b >= half:
result = min(max(0, half - a), result)
if result == float("inf"):
print(-1)
else:
print(result)
main()
``` | output | 1 | 11,909 | 19 | 23,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).
Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card.
The numbers in the lines are separated by single spaces.
Output
On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.
Examples
Input
3
4 7
4 7
7 4
Output
0
Input
5
4 7
7 4
2 11
9 7
1 1
Output
2
Note
In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | instruction | 0 | 11,910 | 19 | 23,820 |
Tags: binary search, data structures
Correct Solution:
```
from collections import Counter
import sys
n=int(input())
ans=10**20
fr={}
ba={}
for _ in range(n):
x,y=map(int,input().split())
if x in fr:
fr[x]+=1
else:
fr[x]=1
if x!=y:
if y in ba:
ba[y]+=1
else:
ba[y]=1
for i in fr:
if i in ba:
x=fr[i]+ba[i]
if x*2>=n:
ans=min(ans,max(0,(n+1)//2-fr[i]))
else:
x=fr[i]
if x*2>=n:
ans=min(ans,max(0,(n+1)//2-fr[i]))
for j in ba:
y=ba[j]
if y*2>=n:
ans=min(ans,max(0,(n+1)//2))
if ans==10**20:
ans=-1
print(ans)
``` | output | 1 | 11,910 | 19 | 23,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).
Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card.
The numbers in the lines are separated by single spaces.
Output
On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.
Examples
Input
3
4 7
4 7
7 4
Output
0
Input
5
4 7
7 4
2 11
9 7
1 1
Output
2
Note
In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
Submitted Solution:
```
from collections import Counter
import sys
n=int(input())
ans=10**20
a=[]
b=[]
same=[]
for _ in range(n):
x,y=map(int,input().split())
a.append(x)
b.append(y)
if x==y:
same.append(_)
ac=Counter(a)
bc=Counter(b)
for i in ac:
if ac[i]>=(n+1)//2:
print(0)
sys.exit()
for j in bc:
if bc[i]>=(n+1)//2:
ans=(n+1)//2
break
for i in range(n):
if a[i]==b[i]:
continue
else:
y=bc[b[i]]
ya=ac[b[i]]
sm=0
for j in same:
if b[i]==b[j]:
sm+=1
rem=y-sm
if rem+ya>=(n+1)//2:
ans=min(ans,(n+1)//2-ya)
if ans==10**20:
print(0)
else:
print(ans)
``` | instruction | 0 | 11,911 | 19 | 23,822 |
No | output | 1 | 11,911 | 19 | 23,823 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees. | instruction | 0 | 11,997 | 19 | 23,994 |
Tags: constructive algorithms, greedy
Correct Solution:
```
a,b=map(int,input().split())
c=list()
x00=0
x01=0
x11=0
for i in range(a):
c.append(list(input().split()))
x11+=c[-1].count('11')
x01+=c[-1].count('01')+c[-1].count('10')
x00=a*b-x11-x01
new=[[]for i in range(b)]
i=0
while x11>0:
x11-=1
new[i].append('11')
i+=1
i%=b
step=1
reverse=False
while x01>0:
x01-=1
if reverse:
new[i].append('01')
else:
new[i].append('10')
i+=step
if i==-1 or i==b:
step=-step
i+=step
reverse=1-reverse
for r in new:
r+=['00']*(a-len(r))
for i in range(a):
print(' '.join([new[k][i]for k in range(b)]))
``` | output | 1 | 11,997 | 19 | 23,995 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees. | instruction | 0 | 11,998 | 19 | 23,996 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
k, d = n * m, 2 * m
c = {'11': 0, '01': 0, '10': 0}
for i in range(n):
t = input()
for i in ('11', '01', '10'): c[i] += t.count(i)
a, b = c['11'], c['10'] + c['01']
t = ['11'] * a + (b // 2) * ['10', '01'] + ['10'] * (b & 1) + ['00'] * (k - a - b)
for i in range(0, k, d):
print(' '.join(t[i: i + m]))
print(' '.join(t[i + d - 1: i + m - 1: -1]))
# Made By Mostafa_Khaled
``` | output | 1 | 11,998 | 19 | 23,997 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees. | instruction | 0 | 11,999 | 19 | 23,998 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
cnt0 = 0
cnt2 = 0
for i in range(n):
line = input()
cnt0 += line.count("00")
cnt2 += line.count("11")
mat = [ [-1]*(m) for i in range(n) ]
col = [0]*(2*m)
strB = [ "00", "01", "10", "11" ]
i = j = 0
while cnt2 > 0:
cnt2 -= 1
mat[i][j] = 3
col[2*j] += 1
col[2*j+1] += 1
j += 1
if j == m:
i += 1
j = 0
i = n-1
j = 0
while cnt0 > 0:
if mat[i][j] == -1:
cnt0 -= 1
mat[i][j] = 0
j += 1
if j == m:
i -= 1
j = 0
for i in range(n):
for j in range(0,m):
if mat[i][j] == -1:
if col[2*j] > col[2*j+1]:
mat[i][j] = 1
col[2*j+1] += 1
else:
mat[i][j] = 2
col[2*j] += 1
for i in range(n):
print(" ".join(strB[x] for x in mat[i]))
``` | output | 1 | 11,999 | 19 | 23,999 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees. | instruction | 0 | 12,000 | 19 | 24,000 |
Tags: constructive algorithms, greedy
Correct Solution:
```
def find_matrix_col_sum(mat):
max_sum = -1
for cols in range(len(mat[0])):
s = 0
for i in range(2):
for rows in range(len(mat)):
s+=int(mat[rows][cols][i])
if s > max_sum:
max_sum = s
return max_sum
n,m=input().split()
n,m=int(n), int(m)
dominos_count = [0, 0, 0]
for i in range(n):
dominos = input().split()
for dominohaya in dominos:
if dominohaya == "11":
dominos_count[0] += 1
elif dominohaya == "01" or dominohaya == "10":
dominos_count[1] += 1
else:
dominos_count[2] += 1
dominios_list = [0]*n
total_sum = [0]*n
prev_sum_row = [0]*(2*m)
new_sum_row=[0]*(2*m)
for i in range(n):
new_row = [""]*(m)
for j in range(m):
if dominos_count[0] > 0:
new_sum_row[2*j]=prev_sum_row[2 * j] + 1
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1] + 1
new_row[j]="11"
dominos_count[0] -= 1
elif dominos_count[1] > 0:
min_val = min(prev_sum_row)
if prev_sum_row[2 * j] == min_val:
new_row[j]="10"
dominos_count[1] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j] + 1
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1]
elif prev_sum_row[2 * j + 1] == min_val:
new_row[j]="01"
dominos_count[1] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j]
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1] + 1
else:
if dominos_count[2]>0:
new_row[j]="00"
dominos_count[2] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j]
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1]
else:
new_row[j]="01"
dominos_count[1] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j] + 1
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1] + 1
else:
new_row[j]="00"
dominos_count[2] -= 1
new_sum_row[2*j]=prev_sum_row[2 * j]
new_sum_row[2*j+1]=prev_sum_row[2 * j + 1]
total_sum[i] = new_sum_row
# dominios_list[i] = new_row
prev_sum_row = new_sum_row
s = " ".join(new_row)
print(s)
# for i in range(n):
# for j in range(m):
# print(dominios_list[i][j], end="")
# if j < m-1:
# print(" ", end="")
# print("")
#
``` | output | 1 | 12,000 | 19 | 24,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees. | instruction | 0 | 12,001 | 19 | 24,002 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
doubles, singles = 0, 0
for r in range(n):
for s in input().split():
if s == '11':
doubles += 1
elif s != '00':
singles += 1
lines = {
'zero': ' '.join(m * [ '00' ]),
'double': ' '.join(m * [ '11' ]),
'single_0': ' '.join(m * [ '01' ]),
'single_1': ' '.join(m * [ '10' ])
}
zeros = n * m - doubles - singles
while doubles >= m:
print(lines['double'])
doubles -= m
while singles >= 2 * m:
print(lines['single_0'])
print(lines['single_1'])
singles -= 2 * m
while zeros >= m:
print(lines['zero'])
zeros -= m
x = doubles + singles + zeros
tail = [ m * [ '00' ] for r in range(x // m) ]
height = len(tail)
r, c = 0, 0
while singles + doubles > 0:
if tail[r][c] == '00':
if doubles > 0:
tail[r][c] = '11'
doubles -= 1
else:
tail[r][c] = '01'
singles -= 1
if singles > 0 and r + 1 < height:
tail[r + 1][c] = '10'
singles -= 1
c += 1
if c == m:
c = 0
r += 1
for row in tail:
print(' '.join(row))
``` | output | 1 | 12,001 | 19 | 24,003 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees. | instruction | 0 | 12,002 | 19 | 24,004 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
cnt1 = 0
cnt2 = 0
for i in range(n):
for x in input().split():
if x == "11": cnt2 += 1
elif x == "01": cnt1 += 1
elif x == "10": cnt1 += 1
cnt0 = n*m - cnt1 - cnt2
mat = [ [-1]*(m) for i in range(n) ]
col = [0]*(2*m)
strB = [ "00", "01", "10", "11" ]
i = j = 0
while cnt2 > 0:
cnt2 -= 1
mat[i][j] = 3
col[2*j] += 1
col[2*j+1] += 1
j += 1
if j == m:
i += 1
j = 0
i = n-1
j = 0
while cnt0 > 0:
if mat[i][j] == -1:
cnt0 -= 1
mat[i][j] = 0
j += 1
if j == m:
i -= 1
j = 0
for i in range(n):
for j in range(0,m):
if mat[i][j] == -1:
if col[2*j] > col[2*j+1]:
mat[i][j] = 1
col[2*j+1] += 1
else:
mat[i][j] = 2
col[2*j] += 1
for i in range(n):
print(" ".join(strB[x] for x in mat[i]))
``` | output | 1 | 12,002 | 19 | 24,005 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees. | instruction | 0 | 12,003 | 19 | 24,006 |
Tags: constructive algorithms, greedy
Correct Solution:
```
line = input().split()
n = int(line[0])
m = int(line[1])
one = 0
double = 0
switch = -1
switchm = -1
dom = [["00" for i in range(m)] for j in range(n)]
for i in range(n):
line = input().split()
for j in range(m):
num = int(line[j][0])+int(line[j][1])
if num == 1:
one+=1
elif num == 2:
double+=1
for i in range(n):
for j in range(m):
if double>0:
dom[i][j]="11"
double-=1;
elif one>0:
if switch==-1:
switch=i+1
switchm=j
dom[i][j]=str(i%2)+str((i+1)%2)
one-=1
if switch!=-1:
break
for i in [k+switch for k in range(n-switch)]:
for j in range(m):
if one==0:
break
else:
dom[i][(j+switchm)%m]=str(i%2)+str((i+1)%2)
one-=1
for i in range(n):
print(" ".join(dom[i]))
``` | output | 1 | 12,003 | 19 | 24,007 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees. | instruction | 0 | 12,004 | 19 | 24,008 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n, m = map(int, input().split())
k, d = n * m, 2 * m
c = {'11': 0, '01': 0, '10': 0}
for i in range(n):
t = input()
for i in ('11', '01', '10'): c[i] += t.count(i)
a, b = c['11'], c['10'] + c['01']
t = ['11'] * a + (b // 2) * ['10', '01'] + ['10'] * (b & 1) + ['00'] * (k - a - b)
for i in range(0, k, d):
print(' '.join(t[i: i + m]))
print(' '.join(t[i + d - 1: i + m - 1: -1]))
``` | output | 1 | 12,004 | 19 | 24,009 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Submitted Solution:
```
n, m = map(int, input().split())
k, d = n * m, 2 * m
c = {'11': 0, '01': 0, '10': 0}
for i in range(n):
t = input()
for i in ('11', '01', '10'): c[i] += t.count(i)
a, b = c['11'], c['10'] + c['01']
t = '11 ' * a + '10 01 ' * (b // 2) + '10 ' * (b & 1) + '00 ' * (k - a - b)
k *= 3; d *= 3; m *= 3
for i in range(0, k, d):
print(t[i: i + m])
print(t[i + m: i + d])
if n & 1: print(t[k - m: m])
``` | instruction | 0 | 12,005 | 19 | 24,010 |
No | output | 1 | 12,005 | 19 | 24,011 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Submitted Solution:
```
a,b=map(int,input().split())
c=list()
cn=list()
x00=0
x01=0
x11=0
for i in range(a):
c.append(list(input().split()))
x11+=c[-1].count('11')
x01+=c[-1].count('01')+c[-1].count('10')
d=x11//b
for i in range(d):
print((b-1)*'11 '+'11')
d=x11%b
e=x01//2
f=(d+e)//b
for i in range(f):
print((d//f)*'11 '+(e//f-1)*'01 '+'01')
print((d//f)*'00 '+(e//f-1)*'10 '+'10')
for i in range(a-d-2*f):
print((b-1)*'00 '+'00')
``` | instruction | 0 | 12,006 | 19 | 24,012 |
No | output | 1 | 12,006 | 19 | 24,013 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Submitted Solution:
```
n, m = map(int, input().split())
doubles, singles = 0, 0
for r in range(n):
for s in input().split():
if s == '11':
doubles += 1
elif s != '00':
singles += 1
lines = {
'zero': ' '.join(m * [ '00' ]),
'double': ' '.join(m * [ '11' ]),
'single_0': ' '.join(m * [ '01' ]),
'single_1': ' '.join(m * [ '10' ])
}
zeros = n * m - doubles - singles
while doubles >= m:
print(lines['double'])
doubles -= m
while singles >= 2 * m:
print(lines['single_0'])
print(lines['single_1'])
singles -= 2 * m
while zeros >= m:
print(lines['zero'])
zeros -= m
tail = [ m * [ '00' ] for r in range((doubles + singles + zeros) // m) ]
if len(tail) >= 1:
for c in range(0, m, 2):
if doubles == 0:
break
tail[0][c] = '11'
doubles -= 1
if len(tail) >= 2 and singles >= 2:
tail[0][c + 1] = '01'
tail[1][c + 1] = '10'
singles -= 2
if len(tail) == 3:
for c in range(1, m, 2):
if doubles == 0:
break
tail[2][c] = '11'
doubles -= 1
for r in range(len(tail)):
if singles == 0:
break
s = '01' if r % 2 == 0 else '10'
for c in range(m):
if singles == 0:
break
if tail[r][c] == '00':
tail[r][c] = s
singles -= 1
for row in tail:
print(' '.join(row))
``` | instruction | 0 | 12,007 | 19 | 24,014 |
No | output | 1 | 12,007 | 19 | 24,015 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.
The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).
We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".
We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.
Input
The first line contains integers n, m (1 ≤ n, m ≤ 103).
In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.
Output
Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.
If there are multiple optimal solutions, print any of them.
Examples
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00
Note
Consider the answer for the first sample. There, the maximum sum among all columns equals 1 (the number of columns is 6, and not 3). Obviously, this maximum can't be less than 1, then such matrix is optimal.
Note that the dominoes can be rotated by 180 degrees.
Submitted Solution:
```
n, m = map(int, input().split())
doubles, singles = 0, 0
for r in range(n):
for s in input().split():
if s == '11':
doubles += 1
elif s != '00':
singles += 1
lines = {
'zero': ' '.join(m * [ '00' ]),
'double': ' '.join(m * [ '11' ]),
'single_0': ' '.join(m * [ '01' ]),
'single_1': ' '.join(m * [ '10' ])
}
zeros = n * m - doubles - singles
print(zeros, singles, doubles)
while doubles >= m:
print(lines['double'])
doubles -= m
while singles >= 2 * m:
print(lines['single_0'])
print(lines['single_1'])
singles -= 2 * m
while zeros >= m:
print(lines['zero'])
zeros -= m
tail = [ m * [ '00' ] for r in range((doubles + singles + zeros) // m) ]
if len(tail) >= 1:
for c in range(0, m, 2):
if doubles == 0:
break
tail[0][c] = '11'
doubles -= 1
if len(tail) >= 2 and singles >= 2:
tail[0][c + 1] = '01'
tail[1][c + 1] = '10'
singles -= 2
if len(tail) == 3:
for c in range(1, m, 2):
if doubles == 0:
break
tail[2][c] = '11'
doubles -= 1
for r in range(len(tail)):
if singles == 0:
break
s = '01' if r % 2 == 0 else '10'
for c in range(m):
if singles == 0:
break
if tail[r][c] == '00':
tail[r][c] = s
singles -= 1
for row in tail:
print(' '.join(row))
``` | instruction | 0 | 12,008 | 19 | 24,016 |
No | output | 1 | 12,008 | 19 | 24,017 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
? | instruction | 0 | 12,025 | 19 | 24,050 |
Tags: implementation, schedules
Correct Solution:
```
import sys
a, b, c = input().strip(), input().strip(), input().strip()
def beats(x, y):
if x == 'rock' and y == 'scissors':
return True
if x == 'scissors' and y == 'paper':
return True
if x == 'paper' and y == 'rock':
return True
return False
if beats(a, b) and beats(a, c):
print('F')
elif beats(b, a) and beats(b, c):
print('M')
elif beats(c, a) and beats(c, b):
print('S')
else:
print('?')
``` | output | 1 | 12,025 | 19 | 24,051 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
? | instruction | 0 | 12,026 | 19 | 24,052 |
Tags: implementation, schedules
Correct Solution:
```
F=input()
M=input()
S=input()
Beater={"rock":"paper","paper":"scissors","scissors":"rock"}
if(F==M and S==Beater[F]):
print("S")
elif(F==S and M==Beater[F]):
print("M")
elif(S==M and F==Beater[S]):
print("F")
else:
print("?")
``` | output | 1 | 12,026 | 19 | 24,053 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
? | instruction | 0 | 12,027 | 19 | 24,054 |
Tags: implementation, schedules
Correct Solution:
```
a=input()
b=input()
c=input()
if (a==b and b==c) or (a!=b and b!=c and a!=c):
print('?')
elif (a=='rock' and b=='scissors' and b==c) or (a=='paper' and b=='rock' and b==c) or (a=='scissors' and b=='paper' and b==c):
print('F')
elif (b=='rock' and a=='scissors' and a==c) or (b=='paper' and a=='rock' and a==c) or (b=='scissors' and a=='paper' and a==c):
print('M')
elif (a=='rock' and ((b=='rock' and c=='scissors') or (c=='rock' and b=='scissors'))) or (b=='rock' and ((a=='rock' and c=='scissors') or (c=='rock' and a=='scissors'))) or (c=='rock' and ((b=='rock' and a=='scissors') or (a=='rock' and b=='scissors'))):
print('?')
elif (a=='paper' and ((b=='paper' and c=='rock') or (c=='paper' and b=='rock'))) or (b=='paper' and ((a=='rock' and c=='paper') or (c=='rock' and a=='paper'))) or (c=='paper' and ((b=='rock' and a=='paper') or (a=='rock' and b=='paper'))):
print('?')
elif (a=='scissors' and ((b=='paper' and c=='scissors') or (c=='paper' and b=='scissors'))) or (b=='scissors' and ((a=='scissors' and c=='paper') or (c=='scissors' and a=='paper'))) or (c=='scissors' and ((b=='scissors' and a=='paper') or (a=='scissors' and b=='paper'))):
print('?')
else:
print('S')
``` | output | 1 | 12,027 | 19 | 24,055 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
? | instruction | 0 | 12,028 | 19 | 24,056 |
Tags: implementation, schedules
Correct Solution:
```
F=str(input())
M=str(input())
W=str(input())
if F=="rock" and M=="scissors" and W=="scissors":
print("F")
elif F=="rock" and M=="paper" and W=="rock":
print("M")
elif F=="rock" and M=="rock" and W=="paper":
print("S")
elif F=="paper" and M=="rock" and W=="rock":
print("F")
elif F=="scissors" and M=="paper" and W=="paper":
print("F")
elif F=="scissors" and M=="scissors" and W=="rock":
print("S")
elif F=="paper" and M=="scissors" and W=="paper":
print("M")
elif F=="scissors" and M=="rock" and W=="scissors":
print("M")
elif F=="paper" and M=="paper" and W=="scissors":
print("S")
else:
print("?")
``` | output | 1 | 12,028 | 19 | 24,057 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
? | instruction | 0 | 12,029 | 19 | 24,058 |
Tags: implementation, schedules
Correct Solution:
```
F = input()
M = input()
S = input()
ans = ["F", "M","S"]
#print(set([F,M,S]))
if len(set([F,M,S]))!=2:
print("?")
else:
if [F,M,S].count("rock")==2:
if "paper" in [F,M,S]:print(ans[[F,M,S].index("paper")])
else:print("?")
elif [F,M,S].count("paper")==2:
if "scissors" in [F,M,S]:print(ans[[F,M,S].index("scissors")])
else:print("?")
else:
if "rock" in [F,M,S]:
print(ans[[F,M,S].index("rock")])
else:
print("?")
``` | output | 1 | 12,029 | 19 | 24,059 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
? | instruction | 0 | 12,030 | 19 | 24,060 |
Tags: implementation, schedules
Correct Solution:
```
f = ""
m = ""
s = ""
paper = "paper"
rock = "rock"
scissors = "scissors"
def compare(f, s, m):
if f == s and s == m:
return "?"
# F wins
if f == paper:
if s == rock and m == rock:
return "F"
if f == rock:
if s == scissors and m == scissors:
return "F"
if f == scissors:
if s == paper and m == paper:
return "F"
# M wins
if m == paper:
if s == rock and f == rock:
return "M"
if m == rock:
if s == scissors and f == scissors:
return "M"
if m == scissors:
if s == paper and f == paper:
return "M"
# S wins
if s == paper:
if m == rock and f == rock:
return "S"
if s == rock:
if m == scissors and f == scissors:
return "S"
if s == scissors:
if m == paper and f == paper:
return "S"
# Nobody wins
return "?"
def main(inputs):
f = inputs[0]
m = inputs[1]
s = inputs[2]
print(compare(f, s, m))
import sys
inputs = sys.stdin.read().split()
main(inputs)
``` | output | 1 | 12,030 | 19 | 24,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
? | instruction | 0 | 12,031 | 19 | 24,062 |
Tags: implementation, schedules
Correct Solution:
```
f = input()
m = input()
s = input()
t = [f, m, s]
if t.count('rock') == 3 or t.count('paper') == 3 or t.count('scissors') == 3:
print('?')
exit()
if t.count('rock') == 1 and t.count('paper') == 1 and t.count('scissors') == 1:
print('?')
exit()
if t.count('rock') == 2:
if t.count('paper') == 1:
d = t.index('paper')
if d == 0:
print('F')
exit()
if d == 1:
print('M')
exit()
if d == 2:
print('S')
exit()
if t.count('scissors'):
print('?')
exit()
if t.count('paper') == 2:
if t.count('scissors') == 1:
d = t.index('scissors')
if d == 0:
print('F')
exit()
if d == 1:
print('M')
exit()
if d == 2:
print('S')
exit()
if t.count('rock'):
print('?')
exit()
if t.count('scissors') == 2:
if t.count('rock') == 1:
d = t.index('rock')
if d == 0:
print('F')
exit()
if d == 1:
print('M')
exit()
if d == 2:
print('S')
exit()
if t.count('paper'):
print('?')
exit()
``` | output | 1 | 12,031 | 19 | 24,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
? | instruction | 0 | 12,032 | 19 | 24,064 |
Tags: implementation, schedules
Correct Solution:
```
def winner(f,s):
if f == "r":
if s == "r":
return 0
elif s == "s":
return 1
return -1
elif f == "s":
if s == "s":
return 0
elif s == "p":
return 1
return -1
else:
if s == "p":
return 0
elif s == "r":
return 1
return -1
f = input()[0]
m = input()[0]
s = input()[0]
###rpsr
if (f != m and f != s and m != s) or (f == m and m == s):
print("?")
elif (winner(f,m) == 0 and winner(f,s) == 1) or (winner(f,s) == 0 and winner(f,m) == 1) or (winner(s,m) == 0 and winner(s,f) == 1):
print("?")
else:
print("F" *winner(f,m) + "M" * winner(m,f )+ "S" * winner(s,m))
``` | output | 1 | 12,032 | 19 | 24,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
F=input()
M=input()
S=input()
d=dict()
d['rock']='paper'
d['paper']='scissors'
d['scissors']='rock'
if(F==M):
if(d[F]==S):
print('S')
else:
print('?')
elif(M==S):
if(d[M]==F):
print('F')
else:
print('?')
elif(F==S):
if(d[F]==M):
print('M')
else:
print('?')
else:
print('?')
``` | instruction | 0 | 12,033 | 19 | 24,066 |
Yes | output | 1 | 12,033 | 19 | 24,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
Input
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Output
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Examples
Input
rock
rock
rock
Output
?
Input
paper
rock
rock
Output
F
Input
scissors
rock
rock
Output
?
Input
scissors
paper
rock
Output
?
Submitted Solution:
```
manos = [input(),input(),input()]
indice_ganador = None
jugadores = ['F','M','S']
#manos = ['rock','paper','scissors']
reglas = ['paper','rock','scissors','paper']
for i in range(3):
for j in range(4):
if manos[i] == reglas[j]:
if reglas[j+1] == manos[(i+1)%3] and reglas[j+1] == manos[(i+2)%3]:
indice_ganador = i
break
if indice_ganador != None:
print(jugadores[indice_ganador])
else:
print('?')
``` | instruction | 0 | 12,034 | 19 | 24,068 |
Yes | output | 1 | 12,034 | 19 | 24,069 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.