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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
n distinct integers x_1,x_2,β¦,x_n are written on the board. Nezzar can perform the following operation multiple times.
* Select two integers x,y (not necessarily distinct) on the board, and write down 2x-y. Note that you don't remove selected numbers.
Now, Nezzar wonders if it is possible to have his favorite number k on the board after applying above operation multiple times.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
The first line of each test case contains two integers n,k (2 β€ n β€ 2 β
10^5, -10^{18} β€ k β€ 10^{18}).
The second line of each test case contains n distinct integers x_1,x_2,β¦,x_n (-10^{18} β€ x_i β€ 10^{18}).
It is guaranteed that the sum of n for all test cases does not exceed 2 β
10^5.
Output
For each test case, print "YES" on a single line if it is possible to have k on the board. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
6
2 1
1 2
3 0
2 3 7
2 -1
31415926 27182818
2 1000000000000000000
1 1000000000000000000
2 -1000000000000000000
-1000000000000000000 123
6 80
-5 -20 13 -14 -2 -11
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, the number 1 is already on the board.
In the second test case, Nezzar could perform the following operations to write down k=0 on the board:
* Select x=3 and y=2 and write down 4 on the board.
* Select x=4 and y=7 and write down 1 on the board.
* Select x=1 and y=2 and write down 0 on the board.
In the third test case, it is impossible to have the number k = -1 on the board.
Submitted Solution:
```
def lcd(x, y):
if y == 0:
return x
return lcd(y, x % y)
t = int(input())
for i in range(t):
n, k = map(int, input().split())
xlist = list(map(int, input().split()))
# print("~~~~~~~~~",n,k,xlist)
mi = min(min(xlist), k-1)
k -= mi
if k == 0:
print("YES")
continue
xlist = [x - mi for x in xlist if x - mi != 0]
if len(xlist) == 0:
print("NO")
continue
lm = xlist[0]
for i in xlist:
lm = lcd(lm, i)
if k % lm == 0:
print("YES")
else:
print("NO")
``` | instruction | 0 | 99,677 | 19 | 199,354 |
No | output | 1 | 99,677 | 19 | 199,355 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win. | instruction | 0 | 100,400 | 19 | 200,800 |
Tags: games
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
d=set()
t={}
rep=set()
if a.count(0)>=2:
print("cslnb")
exit()
for i in a:
if i in d:
if t[i]+1==3:
print("cslnb")
exit()
else:
t[i]+=1
rep.add(i)
if len(rep)>=2:
print("cslnb")
exit()
else:
t[i]=1
d.add(i)
if rep:
for c in rep:
if c-1 in d:
print("cslnb")
exit()
s=0
a.sort()
for i in range(n):
s+=a[i]-i
if s%2==1:print("sjfnb")
else:print("cslnb")
``` | output | 1 | 100,400 | 19 | 200,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win. | instruction | 0 | 100,401 | 19 | 200,802 |
Tags: games
Correct Solution:
```
n = int(input())
u = list(map(int, input().split()))
u.sort()
ans = 0
k = 1
ok = False
for i in range(1, n):
if u[i] == u[i - 1]:
k += 1
if k == 3:
print('cslnb')
exit()
if k == 2:
if ok or u[i] == 0 or u[i] - u[i - 2] == 1:
print('cslnb')
exit()
ok = True
else:
k = 1
for i in range(n):
ans += u[i] - i
if ans % 2 == 0:
print('cslnb')
else:
print('sjfnb')
``` | output | 1 | 100,401 | 19 | 200,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win. | instruction | 0 | 100,402 | 19 | 200,804 |
Tags: games
Correct Solution:
```
from sys import stdin, stdout, exit
n = int(input())
a = list(map(int, stdin.readline().split()))
def z(winner):
return 'sjfnb' if winner == 0 else 'cslnb'
a.sort()
dups = set(a)
if len(dups) < len(a) - 1:
print(z(1))
exit()
winner = 0
for i in range(n-1):
if a[i] == a[i+1]:
if a[i] == 0 or a[i]-1 in a:
print(z(1))
exit()
winner = 1
a[i] = a[i] - 1
s = sum(a)
final = n*(n-1) // 2
winner += (s - final) + 1
winner %= 2
print(z(winner))
``` | output | 1 | 100,402 | 19 | 200,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win. | instruction | 0 | 100,403 | 19 | 200,806 |
Tags: games
Correct Solution:
```
n = int(input())
lst = [int(i) for i in input().split()]
st = set()
flag = False
count = 0
for i in lst:
if i not in st:
st.add(i)
else:
flag = True
count+=1
lol = i
sum1 = n*(n-1)//2
if count>1:
print('cslnb')
quit()
if not flag:
if (sum(lst)- sum1)% 2 == 0:
print('cslnb')
else:
print('sjfnb')
else:
if (lol-1) in lst or lol == 0:
print('cslnb')
else:
if (sum(lst)- sum1)% 2 == 0:
print('cslnb')
else:
print('sjfnb')
``` | output | 1 | 100,403 | 19 | 200,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win. | instruction | 0 | 100,404 | 19 | 200,808 |
Tags: games
Correct Solution:
```
from sys import stdin, stdout
import math
N = int(input())
#N,M,K = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
if sum(arr)==0:
print('cslnb')
quit()
arr.sort()
zeros = 0
freq = {}
dup = 0
res = 0
for i in range(N):
num = arr[i]
if num==0:
zeros += 1
if zeros==2:
print('cslnb')
quit()
if num not in freq:
freq[num] = 1
else:
dup += 1
freq[num] += 1
if dup==2:
print('cslnb')
quit()
for i in range(N):
num = arr[i]
if freq[num]==2:
if (num-1) not in freq:
freq[num-1] = 1
freq[num] = 1
arr[i] = arr[i] - 1
res += 1
break
else:
print('cslnb')
quit()
#print(arr)
minus = [0]*N
level = 0
for i in range(N):
minus[i] = min(arr[i],level)
if arr[i]>=level:
level += 1
for i in range(N):
res += arr[i] - minus[i]
if res%2==0:
print('cslnb')
else:
print('sjfnb')
``` | output | 1 | 100,404 | 19 | 200,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win. | instruction | 0 | 100,405 | 19 | 200,810 |
Tags: games
Correct Solution:
```
n = int(input())
a = sorted(list(map(int, input().split())))
cnt = 0
pair = 0
for i in range(n):
if i < n - 1 and a[i] == a[i + 1]:
pair += 1
if i > 0 and a[i - 1] == a[i] - 1:
pair += 1
if a[i] == 0:
pair = 2
cnt += a[i] - i
if pair > 1:
print("cslnb")
exit()
if cnt & 1:
print("sjfnb")
else:
print("cslnb")
``` | output | 1 | 100,405 | 19 | 200,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win. | instruction | 0 | 100,406 | 19 | 200,812 |
Tags: games
Correct Solution:
```
import sys
import math
import bisect
from collections import deque
sys.setrecursionlimit(1000000000)
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def finput():
return float(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
def modst(a, s):
res = 1
while s:
if s % 2:
res *= a
a *= a
s //= 2
return res
def main():
w = ["cslnb", "sjfnb"]
n = iinput()
q = sorted(rlinput())
t = 0
for i in range(1, n):
t += q[i] == q[i - 1]
if t >= 2:
return w[0]
if t:
for i in range(n):
if q[i] == q[i + 1]:
if q[i] and q[i] != q[i - 1] + 1:
q[i] -= 1
break
else:
return w[0]
return w[(sum(q) - t - n * (n - 1) // 2) & 1]
for i in range(1):
print(main())
``` | output | 1 | 100,406 | 19 | 200,813 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win. | instruction | 0 | 100,407 | 19 | 200,814 |
Tags: games
Correct Solution:
```
n = int(input())
a = sorted(list(map(int, input().split())))
win = None
first = True
if n == 1:
win = a[0] % 2 == 1
elif a[1] == 0:
win = False
if n > 2:
for i in range(n-1):
if a[i] == a[i+1]:
if i > 0:
if a[i-1] == a[i]-1:
win = False
break
if not first:
win = False
break
first = False
if win is None:
win = (sum(a) - (n*(n-1)//2)) % 2 == 1
if win:
print('sjfnb')
else:
print('cslnb')
``` | output | 1 | 100,407 | 19 | 200,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.
Submitted Solution:
```
n = int(input())
import sys
l = ["cslnb", "sjfnb"]
data = [int(i) for i in input().split()]
data.sort()
dup = -1
for i in range(n-1):
if data[i] == data[i+1]:
if dup == -1:
dup = i
else:
print("cslnb")
sys.exit()
if dup != -1:
if dup == 0:
if data[0] == 0:
print("cslnb")
sys.exit()
else:
data[0] -= 1
l.reverse()
elif data[dup - 1] + 1 == data[dup]:
print("cslnb")
sys.exit()
else:
data[dup] -= 1
l.reverse()
cnt = 0
for i in range(n):
if data[i] < i:
break
else:
cnt += data[i] - i
print(l[cnt%2])
``` | instruction | 0 | 100,408 | 19 | 200,816 |
Yes | output | 1 | 100,408 | 19 | 200,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.
Submitted Solution:
```
n = int(input())
a = sorted(list(map(int,input().split())))
bal = 0
if a.count(0)>1:
print('cslnb')
exit()
if n-len(set(a))>1:
print('cslnb')
exit()
if n-len(set(a))==1:
for i in range(1,n):
if a[i]==a[i-1]:
if a[i]-1 in a:
print('cslnb')
exit()
break
if n==1:
print('cslnb' if not a[0] % 2 else 'sjfnb')
exit()
for i in range(n):
bal+=a[i]-i
print('sjfnb'if bal%2 else 'cslnb')
``` | instruction | 0 | 100,409 | 19 | 200,818 |
Yes | output | 1 | 100,409 | 19 | 200,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.
Submitted Solution:
```
numStones=int(input())
ints=[int(x) for x in input().split()]
ints.sort()
if numStones==1:
if ints[0] % 2 == 0:
print("cslnb")
else:
print("sjfnb")
elif numStones==2:
if ints[0]==0 and ints[1]==0:
print("cslnb")
elif ints[0] % 2 == ints[1] % 2:
print("sjfnb")
else:
print("cslnb")
else:
impos=False
onePair=False
firstWins=False
if ints[0]==ints[1]:
onePair=True
if ints[0]==0:
print("cslnb")
impos=True
if ints[0] % 2 == 1:
firstWins=True
if impos==False:
for i in range(numStones-2):
if ints[i+1]==ints[i+2]:
if onePair==True or ints[i]+1==ints[i+1]:
print("cslnb")
impos=True
break
else:
onePair=True
if (ints[i+1]-i) % 2 == 0:
firstWins=not firstWins
if (ints[numStones-1]-numStones) % 2 == 0:
firstWins=not firstWins
if impos==False:
if firstWins:
print("sjfnb")
else:
print("cslnb")
``` | instruction | 0 | 100,410 | 19 | 200,820 |
Yes | output | 1 | 100,410 | 19 | 200,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
d = {}
t=0
s = sum(a)
for i in a:
d[i] = d.get(i, 0) + 1
# print(d)
if a.count(0)>1:
exit(print("cslnb"))
for i in a:
if i and d[i] >= 2:
d[i] -= 1
d[i - 1] = d.get(i-1,0) + 1
i -= 1
t=1
break
# print(t,d)
if t==1:
for i in a:
if d[i] >= 2:
print("cslnb")
exit()
ss=((n-1)*(n))//2
# print(s)
if (s - ss) % 2==0:
print("cslnb")
else:
print("sjfnb")
``` | instruction | 0 | 100,411 | 19 | 200,822 |
Yes | output | 1 | 100,411 | 19 | 200,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.
Submitted Solution:
```
n = int(input())
l = list(map(int, input().split()))
ansl = ['sjfnb', 'cslnb']
ans = -1
flag = False
d = dict()
val = 0
if n == 1:
ans = (l[0] + 1) % 2
else:
l.sort()
for elem in l:
d[elem] = d.get(elem, 0) + 1
hm = 0
which = -1
i = 0
for elem in d.values():
if elem >= 2:
hm += 1
which = i
i += 1
if max(d.values()) >= 3 or d.get(0, 0) >= 2 or hm > 1:
ans = 1
elif hm == 1:
if d.get(which - 1, 0) > 0:
ans = 1
else:
for i in range(n):
val += l[i] - i
ans = (val + 1) % 2
print(ansl[ans])
``` | instruction | 0 | 100,412 | 19 | 200,824 |
No | output | 1 | 100,412 | 19 | 200,825 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.
Submitted Solution:
```
from sys import stdin
n = int(stdin.readline())
stones = sorted([int(x) for x in stdin.readline().split()])
if n == 1:
if stones[0]%2 == 0:
print('cslnb')
else:
print('sjfnb')
else:
s = sum(stones)
if s%2 == 1:
print('cslnb')
else:
print('sjfnb')
``` | instruction | 0 | 100,413 | 19 | 200,826 |
No | output | 1 | 100,413 | 19 | 200,827 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.
Submitted Solution:
```
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
ans=0
for i in range(len(arr)-1):
if(arr[i]!=arr[i+1]):
ans+=(arr[i+1]-arr[i])
ans-=1
arr[i+1]=arr[i]+1
#print(ans)
#print(arr)
mark=0
for i in range(len(arr)):
if(arr[i]>=mark):
ans+=(arr[i]-mark)
mark+=1
#print(ans)
if(ans%2==0):
print('cslnb')
else:
print('sjfnb')
``` | instruction | 0 | 100,414 | 19 | 200,828 |
No | output | 1 | 100,414 | 19 | 200,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?
Consider an example: n=3 and sizes of piles are a_1=2, a_2=3, a_3=0. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be [1, 3, 0] and it is a good move. But if she chooses the second pile then the state will be [2, 2, 0] and she immediately loses. So the only good move for her is to choose the first pile.
Supposing that both players always take their best moves and never make mistakes, who will win the game?
Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.
Input
The first line contains a single integer n (1 β€ n β€ 10^5) β the number of piles.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_1, a_2, β¦, a_n β€ 10^9), which mean the i-th pile has a_i stones.
Output
Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.
Examples
Input
1
0
Output
cslnb
Input
2
1 0
Output
cslnb
Input
2
2 2
Output
sjfnb
Input
3
2 3 1
Output
sjfnb
Note
In the first example, Tokitsukaze cannot take any stone, so CSL will win.
In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.
In the third example, Tokitsukaze will win. Here is one of the optimal ways:
* Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.
* Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.
* Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose.
In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.
Submitted Solution:
```
def find(A):
from collections import defaultdict
A=sorted(A)
N=len(A)
dic=defaultdict(int)
for i in range(N):
dic[A[i]]+=1
checked=[]
count=set([])
for x in A:
if dic[x]>2:
return "cslnb"
if dic[x]==2:
count.add(x)
y=x-1
if y in dic:
return "cslnb"
if len(count)>1:
return "cslnb"
temp=0
for i in range(N):
temp+=A[i]-i
if temp%2==1:
return "sjfnb"
return "cslnb"
input()
A=list(map(int,input().strip().split(' ')))
print(find(A))
``` | instruction | 0 | 100,415 | 19 | 200,830 |
No | output | 1 | 100,415 | 19 | 200,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Gena play a very interesting game "Put a Knight!" on a chessboard n Γ n in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (r, c) can threat squares (r - 1, c + 2), (r - 1, c - 2), (r + 1, c + 2), (r + 1, c - 2), (r - 2, c + 1), (r - 2, c - 1), (r + 2, c + 1) and (r + 2, c - 1) (some of the squares may be located outside the chessboard). The player who can't put a new knight during his move loses. Determine which player wins considering that both players play optimally well and Petya starts.
Input
The first line contains integer T (1 β€ T β€ 100) β the number of boards, for which you should determine the winning player. Next T lines contain T integers ni (1 β€ ni β€ 10000) β the sizes of the chessboards.
Output
For each ni Γ ni board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1".
Examples
Input
2
2
1
Output
1
0
Submitted Solution:
```
import sys
sys.stdin = open("input.txt", "r")
input = sys.stdin.readline
sys.stdout = open("output.txt", "w")
print = sys.stdout.write
T=int(input())
for i in range(T):
n = int(input())
if n & 1 == 1:
print('0')
else:
print('1')
``` | instruction | 0 | 100,416 | 19 | 200,832 |
No | output | 1 | 100,416 | 19 | 200,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Gena play a very interesting game "Put a Knight!" on a chessboard n Γ n in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (r, c) can threat squares (r - 1, c + 2), (r - 1, c - 2), (r + 1, c + 2), (r + 1, c - 2), (r - 2, c + 1), (r - 2, c - 1), (r + 2, c + 1) and (r + 2, c - 1) (some of the squares may be located outside the chessboard). The player who can't put a new knight during his move loses. Determine which player wins considering that both players play optimally well and Petya starts.
Input
The first line contains integer T (1 β€ T β€ 100) β the number of boards, for which you should determine the winning player. Next T lines contain T integers ni (1 β€ ni β€ 10000) β the sizes of the chessboards.
Output
For each ni Γ ni board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1".
Examples
Input
2
2
1
Output
1
0
Submitted Solution:
```
lista_sizes_boards=[]
winner=1
txt_object=open("input.txt","r")
no_boards=int(txt_object.readline())
for i in range(no_boards):
lista_sizes_boards.append(int(txt_object.readline()))
txt_object.close()
def Eliminar_casas(best_option):
x=best_option[0]
y=best_option[1]
casas_proibidas.append((x,y))
try:
tabuleiro[x-2][y+1]
casas_proibidas.append((x-2,y+1))
except:
pass
try:
tabuleiro[x-2][y-1]
casas_proibidas.append((x-2,y+1))
except:
pass
try:
tabuleiro[x-1][y+2]
casas_proibidas.append((x-2,y+1))
except:
pass
try:
tabuleiro[x-1][y-2]
casas_proibidas.append((x-2,y+1))
except:
pass
try:
tabuleiro[x+1][y+2]
casas_proibidas.append((x-2,y+1))
except:
pass
try:
tabuleiro[x+1][y-2]
casas_proibidas.append((x-2,y+1))
except:
pass
try:
tabuleiro[x+2][y+1]
casas_proibidas.append((x-2,y+1))
except:
pass
try:
tabuleiro[x+2][y-1]
casas_proibidas.append((x-2,y+1))
except:
pass
return(Escolha_melhor_casa())
def Escolha_melhor_casa():
global winner
lista_no_casas_eliminadas=[]
for x in range(len(tabuleiro)):
for y in range(len(tabuleiro[0])):
if (x,y) not in casas_proibidas:
casas_eliminadas=0
try:
tabuleiro[x-2][y+1]
if (x-2,y+1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x-2][y-1]
if (x-2,y-1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x-1][y+2]=1
if (x-1,y+2) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x-1][y-2]
if (x-1,y-2) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x+1][y+2]
if (x+1,y+1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x+1][y-2]
if (x+1,y-2) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x+2][y+1]
if (x+2,y+1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x+2][y-1]
if (x+2,y-1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
lista_no_casas_eliminadas.append((x,y,casas_eliminadas))
if len(lista_no_casas_eliminadas)==0:
return winner
elif len(lista_no_casas_eliminadas)==1:
best_option=lista_no_casas_eliminadas[0]
else:
for k in range(len(lista_no_casas_eliminadas)-1):
if lista_no_casas_eliminadas[k][2]>lista_no_casas_eliminadas[k+1][2]:
best_option=lista_no_casas_eliminadas[k]
else:
best_option=lista_no_casas_eliminadas[k+1]
if winner==0:
winner=1
elif winner==1:
winner=0
return(Eliminar_casas(best_option))
lista=[]
for k in lista_sizes_boards:
casas_proibidas=[]
tabuleiro=[[k*0]for b in range(k)]
lista.append(Escolha_melhor_casa())
output=open("output.txt","w")
for i in lista:
output.write(str(i)+"\n")
``` | instruction | 0 | 100,417 | 19 | 200,834 |
No | output | 1 | 100,417 | 19 | 200,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Gena play a very interesting game "Put a Knight!" on a chessboard n Γ n in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (r, c) can threat squares (r - 1, c + 2), (r - 1, c - 2), (r + 1, c + 2), (r + 1, c - 2), (r - 2, c + 1), (r - 2, c - 1), (r + 2, c + 1) and (r + 2, c - 1) (some of the squares may be located outside the chessboard). The player who can't put a new knight during his move loses. Determine which player wins considering that both players play optimally well and Petya starts.
Input
The first line contains integer T (1 β€ T β€ 100) β the number of boards, for which you should determine the winning player. Next T lines contain T integers ni (1 β€ ni β€ 10000) β the sizes of the chessboards.
Output
For each ni Γ ni board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1".
Examples
Input
2
2
1
Output
1
0
Submitted Solution:
```
print(1)
print(0)
``` | instruction | 0 | 100,418 | 19 | 200,836 |
No | output | 1 | 100,418 | 19 | 200,837 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Gena play a very interesting game "Put a Knight!" on a chessboard n Γ n in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (r, c) can threat squares (r - 1, c + 2), (r - 1, c - 2), (r + 1, c + 2), (r + 1, c - 2), (r - 2, c + 1), (r - 2, c - 1), (r + 2, c + 1) and (r + 2, c - 1) (some of the squares may be located outside the chessboard). The player who can't put a new knight during his move loses. Determine which player wins considering that both players play optimally well and Petya starts.
Input
The first line contains integer T (1 β€ T β€ 100) β the number of boards, for which you should determine the winning player. Next T lines contain T integers ni (1 β€ ni β€ 10000) β the sizes of the chessboards.
Output
For each ni Γ ni board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1".
Examples
Input
2
2
1
Output
1
0
Submitted Solution:
```
output=open("output.txt","w")
lista_sizes_boards=[]
txt_object=open("input.txt","r")
no_boards=int(txt_object.readline())
for i in range(no_boards):
lista_sizes_boards.append(int(txt_object.readline()))
txt_object.close()
def Eliminar_casas(best_option):
x=best_option[0]
y=best_option[1]
casas_proibidas.append((x,y))
casas_proibidas.append((x-2,y+1))
casas_proibidas.append((x-2,y+1))
casas_proibidas.append((x-2,y+1))
casas_proibidas.append((x-2,y+1))
casas_proibidas.append((x-2,y+1))
casas_proibidas.append((x-2,y+1))
casas_proibidas.append((x-2,y+1))
casas_proibidas.append((x-2,y+1))
return(Escolha_melhor_casa())
def Escolha_melhor_casa():
global winner
lista_no_casas_eliminadas=[]
for x in range(len(tabuleiro)):
for y in range(len(tabuleiro)):
if (x,y) not in casas_proibidas:
casas_eliminadas=0
try:
tabuleiro[x-2][y+1]
if (x-2,y+1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x-2][y-1]
if (x-2,y-1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x-1][y+2]=1
if (x-1,y+2) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x-1][y-2]
if (x-1,y-2) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x+1][y+2]
if (x+1,y+1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x+1][y-2]
if (x+1,y-2) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x+2][y+1]
if (x+2,y+1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
try:
tabuleiro[x+2][y-1]
if (x+2,y-1) not in casas_proibidas:
casas_eliminadas+=1
except:
pass
lista_no_casas_eliminadas.append((x,y,casas_eliminadas))
if len(lista_no_casas_eliminadas)==0:
return winner
elif len(lista_no_casas_eliminadas)==1:
best_option=lista_no_casas_eliminadas[0]
else:
for k in range(len(lista_no_casas_eliminadas)-1):
if lista_no_casas_eliminadas[k][2]>lista_no_casas_eliminadas[k+1][2]:
best_option=lista_no_casas_eliminadas[k]
else:
best_option=lista_no_casas_eliminadas[k+1]
if winner==0:
winner=1
elif winner==1:
winner=0
return(Eliminar_casas(best_option))
lista=[]
for k in lista_sizes_boards:
winner=1
casas_proibidas=[]
tabuleiro=[[k*0]for b in range(k)]
lista.append(Escolha_melhor_casa())
output.write(str(Escolha_melhor_casa())+"\n")
``` | instruction | 0 | 100,419 | 19 | 200,838 |
No | output | 1 | 100,419 | 19 | 200,839 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86. | instruction | 0 | 100,574 | 19 | 201,148 |
Tags: bitmasks, brute force, dfs and similar, implementation, math, probabilities
Correct Solution:
```
scale = 10 ** 6
def calculate_expectation(c, m, p, v):
expectation = 1
if c != 0:
if c <= v:
if m != 0:
expectation += c/scale * calculate_expectation(0, m + c/2, p + c/2, v)
else:
expectation += c/scale
else:
if m != 0:
expectation += c/scale * calculate_expectation(c - v, m + v/2, p + v/2, v)
else:
expectation += c/scale * calculate_expectation(c - v, 0, p + v, v)
if m != 0:
if m <= v:
if c != 0:
expectation += m/scale * calculate_expectation(c + m/2, 0, p + m/2, v)
else:
expectation += m/scale
else:
if c != 0:
expectation += m/scale * calculate_expectation(c + v/2, m - v, p + v/2, v)
else:
expectation += m/scale * calculate_expectation(0, m - v, p + v, v)
return expectation
t = int(input())
results = []
for i in range(t):
c, m, p, v = map(float, input().split())
c = c * scale
m = m * scale
p = p * scale
v = v * scale
results.append(calculate_expectation(c, m, p, v))
for i in range(t):
print(results[i])
``` | output | 1 | 100,574 | 19 | 201,149 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86. | instruction | 0 | 100,575 | 19 | 201,150 |
Tags: bitmasks, brute force, dfs and similar, implementation, math, probabilities
Correct Solution:
```
from math import *
dic = {}
def brt(lst):
if(tuple(lst) in dic):
return dic[tuple(lst)]
prob1 = lst[0]/(lst[0]+lst[1]+lst[2])
prob2 = lst[1]/(lst[0]+lst[1]+lst[2])
prob3 = lst[2]/(lst[0]+lst[1]+lst[2])
val = prob3
if(lst[0]>0):
nxt1 = list(lst)
dff = min(v,nxt1[0])
nxt1[0]-=v
if(nxt1[0]<0):
nxt1[0]=0
ctt = 1 + (nxt1[1] > 0)
nxt1[2]+=dff/ctt
if(nxt1[1]>0):
nxt1[1]+=dff/ctt
#print(lst,':',nxt1)
if(prob1>0):
val = val + prob1*(1 + brt(nxt1))
if(lst[1] > 0):
nxt2 = list(lst)
dff = min(v,nxt2[1])
nxt2[1]-=v
if(nxt2[1]<0):
nxt2[1]=0
ctt = 1 + (nxt2[0] > 0)
nxt2[2]+=dff/ctt
if(nxt2[0]>0):
nxt2[0]+=dff/ctt
#print(lst,':',nxt2)
if(prob2>0):
val = val + prob2*(1 + brt(nxt2))
dic[tuple(lst)] = val
return val
n = int(input())
for i in range(n):
dic.clear()
sc,sm,sp,sv = input().split(' ')
c = float(sc)*10000
m = float(sm)*10000
p = float(sp)*10000
v = float(sv)*10000
print(brt([c,m,p]))
``` | output | 1 | 100,575 | 19 | 201,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86. | instruction | 0 | 100,576 | 19 | 201,152 |
Tags: bitmasks, brute force, dfs and similar, implementation, math, probabilities
Correct Solution:
```
from collections import deque
import sys
sys.setrecursionlimit(10**6)
scale=10**6
def rec(c,m,p,v):
res=p/scale
if c>0:
if c>v:
if m>0:
res+=c/scale*(1+rec(c-v,m+v/2,p+v/2,v))
else:
res+=c/scale*(1+rec(c-v,0,p+v,v))
else:
if m>0:
res+=c/scale*(1+rec(0,m+c/2,p+c/2,v))
else:
res+=c/scale*(1+rec(0,0,p+c,v))
if m>0:
if m>v:
if c>0:
res+=m/scale*(1+rec(c+v/2,m-v,p+v/2,v))
else:
res+=m/scale*(1+rec(0,m-v,p+v,v))
else:
if c>0:
res+=m/scale*(1+rec(c+m/2,0,p+m/2,v))
else:
res+=m/scale*(1+rec(0,0,p+m,v))
return res
t=int(input())
for i in range(t):
cm,mm,pm,vv=[float(i) for i in input().split()]
print(rec(cm*scale,mm*scale,pm*scale,vv*scale))
``` | output | 1 | 100,576 | 19 | 201,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86. | instruction | 0 | 100,577 | 19 | 201,154 |
Tags: bitmasks, brute force, dfs and similar, implementation, math, probabilities
Correct Solution:
```
def solve():
c, m, p, v = map(float, input().split())
def rec1(a, p, cur, r):
cur += 1
ans = cur * p * r
if (a > 1e-8):
if (a >= v):
ans += rec1(a - v, p + v, cur, r * a)
else:
ans += rec1(0, p + a, cur, r * a)
return ans
def rec(c, m, p, cur, r):
cur += 1
ans = cur * p * r
if (c > 1e-8):
if (c > v + 1e-9):
ans += rec(c - v, m + v/2, p+v/2, cur, r * c)
else:
ans += rec1( m + c/2, p + c/2, cur, r * c)
if (m > 1e-8):
if (m > v + 1e-9):
ans += rec(c + v/2, m - v, p + v/2, cur, r * m)
else:
ans += rec1(c + m/2, p + m/2, cur, r * m)
return ans
print(f'{rec(c, m, p, 0, 1):.{9}f}')
k = int(input())
for i in range(k):
solve()
``` | output | 1 | 100,577 | 19 | 201,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86. | instruction | 0 | 100,578 | 19 | 201,156 |
Tags: bitmasks, brute force, dfs and similar, implementation, math, probabilities
Correct Solution:
```
import sys
from itertools import zip_longest
EPS = 0.00000001
def read_floats():
return [float(i) for i in sys.stdin.readline().strip().split()]
def read_int():
return int(sys.stdin.readline().strip())
def probs(c, m, p, v):
#print(f"calculating p({c, m, p, v})")
if c > m:
return probs(m, c, p, v)
# so c <= m
if c < EPS:
if v >= m:
return [p, 1 - p]
else:
return [p] + [(1 - p) * a for a in probs(0, m - v, p + v, v)]
if c < EPS:
pc = []
elif v > c:
pc = probs(0, m + c / 2, p + c / 2, v)
else:
pc = probs(c - v, m + v / 2, p + v / 2, v)
if m < EPS:
pm = []
elif v > m:
pm = probs(c + m / 2, 0, p + m / 2, v)
else:
pm = probs(c + v / 2, m - v, p + v / 2, v)
return [p] + [m * a + c * b for a, b in zip_longest(pm, pc, fillvalue=0)]
t = read_int()
for i in range(t):
c, m, p, v = read_floats()
pb = probs(c, m, p, v)
print(sum(a * b for a, b in zip(range(1, 20), pb)))
``` | output | 1 | 100,578 | 19 | 201,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86. | instruction | 0 | 100,579 | 19 | 201,158 |
Tags: bitmasks, brute force, dfs and similar, implementation, math, probabilities
Correct Solution:
```
def process(c, m, p, v):
d = {'': [1, (c, m, p), (True, True, True)]}
I = 1
answer = 0
while len(d) > 0:
d2 = {}
for x in d:
prob, t, R = d[x]
c2, m2, p2 = t
c_r, m_r, p_r = R
for i in range(3):
if i==0 and R[0]:
step = 'C'
if c2 > v and (c2-v) > 0.00001:
if R[1]:
t2 = [c2-v, m2+v/2, p2+v/2]
d2[x+step] = [prob*c2, t2, R]
else:
t2 = [c2-v, 0, p2+v]
d2[x+step] = [prob*c2, t2, R]
else:
if R[1]:
t2 = [0, m2+c2/2, p2+c2/2]
d2[x+step] = [prob*c2, t2, (False, m_r, p_r)]
else:
t2 = [0, 0, 1]
d2[x+step] = [prob*c2, t2, (False, m_r, p_r)]
elif i==1 and R[1]:
step = 'M'
if m2 > v and (m2-v) > 0.00001:
if R[0]:
t2 = [c2+v/2, m2-v, p2+v/2]
d2[x+step] = [prob*m2, t2, R]
else:
t2 = [0, m2-v, p2+v]
d2[x+step] = [prob*m2, t2, R]
else:
if R[0]:
t2 = [c2+m2/2, 0, p2+m2/2]
d2[x+step] = [prob*m2, t2, (c_r, False, p_r)]
else:
t2 = [0, 0, 1]
d2[x+step] = [prob*m2, t2, (c_r, False, p_r)]
elif i==2:
answer+=(I*prob*p2)
I+=1
d = d2
return answer
t= int(input())
for i in range(t):
c, m, p, v = [float(x) for x in input().split()]
print(process(c, m, p, v))
``` | output | 1 | 100,579 | 19 | 201,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86. | instruction | 0 | 100,580 | 19 | 201,160 |
Tags: bitmasks, brute force, dfs and similar, implementation, math, probabilities
Correct Solution:
```
import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
stdin, stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
mod = pow(10, 9) + 7
mod2 = 998244353
def inp(): return stdin.readline().strip()
def iinp(): return int(inp())
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
def ceil(a, b): return (a+b-1)//b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def isprime(x):
if x<=1: return False
if x in (2, 3): return True
if x%2 == 0: return False
for i in range(3, int(sqrt(x))+1, 2):
if x%i == 0: return False
return True
mndif = 10**-6
def solve(curr, currp, c, m, p, v):
ans = (curr+1)*currp*p
if c<mndif and m<mndif:
return ans
if c<mndif:
if m > v:
ans += solve(curr+1, currp*m, 0, m-v, p+v, v)
else:
ans += solve(curr+1, currp*m, 0, 0, p+m, v)
return ans
if m<mndif:
if c > v:
ans += solve(curr+1, currp*c, c-v, 0, p+v, v)
else:
ans += solve(curr+1, currp*c, 0, 0, p+c, v)
return ans
if c > v:
ans += solve(curr+1, currp*c, c-v, m+v/2, p+v/2, v)
else:
ans += solve(curr+1, currp*c, 0, m+c/2, p+c/2, v)
if m > v:
ans += solve(curr+1, currp*m, c+v/2, m-v, p+v/2, v)
else:
ans += solve(curr+1, currp*m, c+m/2, 0, p+m/2, v)
return ans
for _ in range(int(inp())):
c, m, p, v = map(float, inp().split())
ans = solve(0, 1, c, m, p, v)
print(ans)
``` | output | 1 | 100,580 | 19 | 201,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86. | instruction | 0 | 100,581 | 19 | 201,162 |
Tags: bitmasks, brute force, dfs and similar, implementation, math, probabilities
Correct Solution:
```
import math;import heapq;import sys;input=sys.stdin.readline;S=lambda:input();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());H=1000000000+7
def solve(c,m,p,v,s,res,a):
if len(s)!=0 and s[-1]=="P":
res[0]+=len(s)*a
return
solve(c,m,p,v,s+"P",res,a*p)
if c>pow(10,-6):
if c>v:
k=1
if m>pow(10,-6):
k+=1
x=v/k
if m>pow(10,-6):
t=m+x
else:
t=m
solve(c-v,t,p+x,v,s+"C",res,a*c)
else:
k=1
if m>pow(10,-6):
k+=1
x=c/k
if m>pow(10,-6):
t=m+x
else:
t=m
solve(0,t,p+x,v,s+"C",res,a*c)
if m>pow(10,-6):
if m>v:
k=1
if c>pow(10,-6):
k+=1
x=v/k
if c>pow(10,-6):
t=c+x
else:
t=c
solve(t,m-v,p+x,v,s+"M",res,a*m)
else:
k=1
if c>pow(10,-6):
k+=1
x=m/k
if c>pow(10,-6):
t=c+x
else:
t=c
solve(t,0,p+x,v,s+"M",res,a*m)
for _ in range(I()):
c,m,p,v=map(float,input().split())
res=[0]
solve(c,m,p,v,"",res,1)
print(res[0])
``` | output | 1 | 100,581 | 19 | 201,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86.
Submitted Solution:
```
def E(c, m, p, v):
ans = 0
if p > 0.000001:
ans += p
if c > 0.000001:
m2 = m
p2 = p
if m > 0.000001 and p > 0.000001:
m2 += min(c, v) / 2
p2 += min(c, v) / 2
elif p > 0.000001:
p2 += min(c, v)
ans += c * (1 + E(max(c - v, 0), m2, p2, v))
if m > 0.000001:
c1 = c
p1 = p
if c > 0.000001 and p > 0.000001:
c1 += min(m, v) / 2
p1 += min(m, v) / 2
elif p > 0.000001:
p1 += min(m, v)
ans += m * (1 + E(c1, max(m - v, 0), p1, v))
return ans
for _ in range(int(input())):
c, m, p, v = list(map(float, input().split()))
print(E(c, m, p, v))
``` | instruction | 0 | 100,582 | 19 | 201,164 |
Yes | output | 1 | 100,582 | 19 | 201,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86.
Submitted Solution:
```
"""
ID: happyn61
LANG: PYTHON3
PROB: loan
"""
from itertools import product
import itertools
#from collections import defaultdict
import sys
import heapq
from collections import deque
MOD=1000000000007
#fin = open ('loan.in', 'r')
#fout = open ('loan.out', 'w')
#print(dic["4734"])
def find(parent,i):
if parent[i] != i:
parent[i]=find(parent,parent[i])
return parent[i]
# A utility function to do union of two subsets
def union(parent,rank,xx,yy):
x=find(parent,xx)
y=find(parent,yy)
if rank[x]>rank[y]:
parent[y]=x
elif rank[y]>rank[x]:
parent[x]=y
else:
parent[y]=x
rank[x]+=1
ans=0
#NK=sys.stdin.readline().strip().split()
K=int(sys.stdin.readline().strip())
#N=int(NK[0])
#K=int(NK[1])
#M=int(NK[2])
#ol=list(map(int,sys.stdin.readline().strip().split()))
#d={0:0,1:0}
x=0
y=0
#d={"N":(0,1),"S":(0,-1),"W":(-1,0),"E":(1,0)}
for _ in range(K):
#a=int(sys.stdin.readline().strip())
c,m,p,v=list(map(float,sys.stdin.readline().strip().split()))
#print(c,m,p,v)
stack=deque([(c,m,p,1,1)])
ans=0
while stack:
c,m,p,kk,w=stack.popleft()
#print(c,m,p,w)
ans+=p*w*kk
if (c-0.0000001)>0:
k=c*kk
if c<=v:
#pp+=(c/2)
#m+=(c/2)
#c=0
if (m-0.0000001)>0:
stack.append((0,m+c/2,p+c/2,k,w+1))
else:
stack.append((0,0,p+c,k,w+1))
else:
if (m-0.0000001)>0:
stack.append((c-v,m+v/2,p+v/2,k,w+1))
else:
stack.append((c-v,m,p+v,k,w+1))
if (m-0.0000001)>0:
k=m*kk
if m<=v:
if (c-0.0000001)>0:
stack.append((c+m/2,0,p+m/2,k,w+1))
else:
stack.append((c,0,p+m,k,w+1))
else:
if (c-0.0000001)>0:
stack.append((c+v/2,m-v,p+v/2,k,w+1))
else:
stack.append((c,m-v,p+v,k,w+1))
#print(stack)
print(ans)
``` | instruction | 0 | 100,583 | 19 | 201,166 |
Yes | output | 1 | 100,583 | 19 | 201,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86.
Submitted Solution:
```
from decimal import *
getcontext().prec = 20
input = __import__('sys').stdin.readline
mis = lambda: map(int, input().split())
ii = lambda: int(input())
dp = {}
v = None
def solve(s) :
if s in dp : return dp[s]
a, b, c = s
ret = (c, c)
if a > 0 :
na = max(Decimal(0), a-v)
x = a-na
nb = b
nc = c
if b > 0 :
nb += x/2
nc += x/2
else : nc += x
nret = solve((na, nb, nc))
ret = (ret[0] + a*(nret[0]+nret[1]), ret[1] + a*nret[1])
if b > 0 :
nb = max(Decimal(0), b-v)
x = b-nb
na = a
nc = c
if a > 0 :
na += x/2
nc += x/2
else : nc += x
nret = solve((na, nb, nc))
ret = (ret[0] + b*(nret[0]+nret[1]), ret[1] + b*nret[1])
dp[s] = ret
return ret
for tc in range(ii()) :
dp = {}
a,b,c,_v = map(Decimal, input().split())
v = _v
print(solve((a,b,c))[0])
``` | instruction | 0 | 100,584 | 19 | 201,168 |
Yes | output | 1 | 100,584 | 19 | 201,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86.
Submitted Solution:
```
def dfs(c,m,p,v,steps,prob):
ans =0
if c!=-1:
if m!=-1:
if c<=v:
ans+=dfs(-1,m+c/2,p+c/2,v,steps+1,prob*c/r)
else:
ans+=dfs(c-v,m+v/2,p+v/2,v,steps+1,prob*c/r)
else:
if c<=v:
ans+=dfs(-1,-1,p+c,v,steps+1,prob*c/r)
else:
ans+=dfs(c-v,-1,p+v,v,steps+1,prob*c/r)
if m!=-1:
if c!=-1:
if m<=v:
ans+=dfs(c+m/2,-1,p+m/2,v,steps+1,prob*m/r)
else:
ans+=dfs(c+v/2,m-v,p+v/2,v,steps+1,prob*m/r)
else:
if m<=v:
ans+=dfs(-1,-1,p+m,v,steps+1,prob*m/r)
else:
ans+=dfs(-1,m-v,p+v,v,steps+1,prob*m/r)
if p:
ans+=steps*prob*p/r
return ans
r = 10**9
T = int(input())
for case in range(T):
c,m,p,v = list(map(float,input().split()))
c*=r
m*=r
p*=r
v*=r
answer = dfs(c,m,p,v,1,1)
print(answer)
``` | instruction | 0 | 100,585 | 19 | 201,170 |
Yes | output | 1 | 100,585 | 19 | 201,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86.
Submitted Solution:
```
#Fast I/O
import sys,os
#User Imports
from math import *
from bisect import *
from heapq import *
from collections import *
# To enable the file I/O i the below 2 lines are uncommented.
# read from in.txt if uncommented
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
# will print on Console if file I/O is not activated
#if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
# inputs template
from io import BytesIO, IOBase
#Main Logic
def main():
for _ in range(int(input())):
scale=10**6
c,m,p,v=map(float,input().split())
c,m,p,v=int(c*scale),int(m*scale),int(p*scale),int(v*scale)
def rec(c,m,p):
out=p/scale
if c:
if c>v:
if m:
out+=(c/scale)*(1+rec(c-v,m+v//2,p+v//2))
else:
out+=(c/scale)*(1+rec(c-v,0,p+v))
else:
if m:
out+=(c/scale)*(1+rec(0,m+c//2,p+c//2))
else:
out+=(c/scale)*(1+rec(0,0,p+c))
if m:
if m>v:
if c:
out+=(m/scale)*(1+rec(c+v//2,m-v,p+v//2))
else:
out+=(m/scale)*(1+rec(c,m-v,p+v))
else:
if c:
out+=(m/scale)*(1+rec(c+m//2,0,p+m//2))
else:
out+=(m/scale)*(1+rec(c,0,p+m))
return out
print(rec(c,m,p))
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#for array of integers
def MI():return (map(int,input().split()))
# endregion
#for fast output, always take string
def outP(var): sys.stdout.write(str(var)+'\n')
# end of any user-defined functions
MOD=10**9+7
mod=998244353
# main functions for execution of the program.
if __name__ == '__main__':
#This doesn't works here but works wonders when submitted on CodeChef or CodeForces
main()
``` | instruction | 0 | 100,586 | 19 | 201,172 |
No | output | 1 | 100,586 | 19 | 201,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86.
Submitted Solution:
```
import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
# mod = 998244353
mod = 1000000007
sys.setrecursionlimit(1000000)
try:
sys.stdin = open("actext.txt", "r")
OPENFILE = 1
except:
pass
def get_ints():
return map(int,input().split())
def palindrome(s):
mid = len(s)//2
for i in range(mid):
if(s[i]!=s[len(s)-i-1]):
return False
return True
def check(i,n):
if(0<=i<n):
return True
else:
return False
# --------------------------------------------------------------------------
def dpsolve(i,c,m,p,v):
if(c==0 and m==0):
return p*(i)
if(c==0):
if(m>v):
newm = m-v
newp = p+v
else:
newm = 0
newp = 1
return m*dpsolve(i+1,0,newm,newp,v) + p*i
if(m==0):
if(c>v):
newc = c-v
newp = p+v
else:
newc = 0
newp = 1
return c*dpsolve(i+1,newc,0,newp,v) + p*i
first = 0
if(c>v):
newc = c-v
newm = m+v/2
newp = p+v/2
else:
newc = 0
newm = m+c/2
newp = p+c/2
first = c*dpsolve(i+1,newc,newm,newp,v)
second = 0
if(m>v):
newm = m-v
newc = c+v/2
newp = p+v/2
else:
newm = 0
newc = c+m/2
newp = p+m/2
second = m*dpsolve(i+1,newc,newm,newp,v)
return (first+second)+p*i
def solve(c,m,p,v):
ans = dpsolve(1,c,m,p,v)
print(ans)
t = int(input())
for tt in range(t):
c,m,p,v = map(float,input().split())
solve(c,m,p,v)
``` | instruction | 0 | 100,587 | 19 | 201,174 |
No | output | 1 | 100,587 | 19 | 201,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86.
Submitted Solution:
```
import math
scale = 1e+6
def eq(a, b):
return abs(a - b) < 1e-17
def recur(c, m, p, v, d):
ca, cb, cc = 0, 0, 0
# print(c, m, p, v, d)
if c != None and c > v and not eq(c, v):
if m == None and p:
ca = recur(c - v, m, p + v, v, d + 1)
elif p and m:
ca = recur(c - v, m + v / 2, p + v / 2, v, d + 1)
else:
ca = 0
if c != None and c <= v:
if m == None and p:
ca = recur(None, m, p + c, v, d + 1)
elif p and m:
ca = recur(None, m + c / 2, p + c / 2, v, d + 1)
else:
ca = 0
if m != None and m > v and not eq(m, v):
if c == None and p != None:
cb = recur(c, m - v, p + v, v, d + 1)
elif p != None and c != None:
cb = recur(c + v / 2, m - v, p + v / 2, v, d + 1)
else:
cb = 0
if m != None and m <= v:
if c == None and p != None:
cb = recur(c, None, p + m, v, d + 1)
elif p != None and c != None:
cb = recur(c + m / 2, None, p + m / 2, v, d + 1)
else:
cb = 0
if p:
cc = p
c1, c2, c3 = c if c else 0, m if m else 0, p if p else 0
c1 /= scale
c2 /= scale
# print(c1, c2, c3, ca, cb, cc)
return (c1 * ca + c2 * cb) + p / scale * float(d)
def solve():
c, m, p, v = tuple(float(x) * scale for x in input().split())
# print(c, m, p, v)
print(recur(int(c), int(m), int(p), int(v), 1))
return
for _ in range(int(input())):
solve()
``` | instruction | 0 | 100,588 | 19 | 201,176 |
No | output | 1 | 100,588 | 19 | 201,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After defeating a Blacklist Rival, you get a chance to draw 1 reward slip out of x hidden valid slips. Initially, x=3 and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are c, m, and p, respectively. There is also a volatility factor v. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the x valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was a. Then,
* If the item was a Pink Slip, the quest is over, and you will not play any more races.
* Otherwise,
1. If aβ€ v, the probability of the item drawn becomes 0 and the item is no longer a valid item for all the further draws, reducing x by 1. Moreover, the reduced probability a is distributed equally among the other remaining valid items.
2. If a > v, the probability of the item drawn reduces by v and the reduced probability is distributed equally among the other valid items.
For example,
* If (c,m,p)=(0.2,0.1,0.7) and v=0.1, after drawing Cash, the new probabilities will be (0.1,0.15,0.75).
* If (c,m,p)=(0.1,0.2,0.7) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,0.25,0.75).
* If (c,m,p)=(0.2,Invalid,0.8) and v=0.1, after drawing Cash, the new probabilities will be (0.1,Invalid,0.9).
* If (c,m,p)=(0.1,Invalid,0.9) and v=0.2, after drawing Cash, the new probabilities will be (Invalid,Invalid,1.0).
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
Input
The first line of input contains a single integer t (1β€ tβ€ 10) β the number of test cases.
The first and the only line of each test case contains four real numbers c, m, p and v (0 < c,m,p < 1, c+m+p=1, 0.1β€ vβ€ 0.9).
Additionally, it is guaranteed that each of c, m, p and v have at most 4 decimal places.
Output
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed 10^{-6}.
Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} β€ 10^{-6}.
Example
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
Note
For the first test case, the possible drawing sequences are:
* P with a probability of 0.6;
* CP with a probability of 0.2β
0.7 = 0.14;
* CMP with a probability of 0.2β
0.3β
0.9 = 0.054;
* CMMP with a probability of 0.2β
0.3β
0.1β
1 = 0.006;
* MP with a probability of 0.2β
0.7 = 0.14;
* MCP with a probability of 0.2β
0.3β
0.9 = 0.054;
* MCCP with a probability of 0.2β
0.3β
0.1β
1 = 0.006.
So, the expected number of races is equal to 1β
0.6 + 2β
0.14 + 3β
0.054 + 4β
0.006 + 2β
0.14 + 3β
0.054 + 4β
0.006 = 1.532.
For the second test case, the possible drawing sequences are:
* P with a probability of 0.4;
* CP with a probability of 0.4β
0.6 = 0.24;
* CMP with a probability of 0.4β
0.4β
1 = 0.16;
* MP with a probability of 0.2β
0.5 = 0.1;
* MCP with a probability of 0.2β
0.5β
1 = 0.1.
So, the expected number of races is equal to 1β
0.4 + 2β
0.24 + 3β
0.16 + 2β
0.1 + 3β
0.1 = 1.86.
Submitted Solution:
```
blanck=[]
from decimal import *
def rec(a,b,c,v,p,card):
# c=round(c,6)
if (a==float("inf") and b==float("inf")) or c>=1 :
blanck.append(p*(card+1))
return
# print(a,b,c)
l=[a,b,c]
for i in range(3):
if i!=2 and i!=float("inf") and l[i]!=1:
if i==0:
ta=l[i]
if ta<=v:
ta=float("inf")
else:
ta-=v
cnt=2
# if b!=float("inf"):
# cnt+=1
dd=min(l[i],v)
if b!=float("inf"):
rec(ta,b+(dd/cnt),c+(dd/cnt),v,p*l[i],card+1)
else:
rec(ta,b,c+(dd/cnt),v,p*l[i],card+1)
if i==1:
tb=l[i]
if tb<=v:
tb=float("inf")
else:
tb-=v
cnt=1
# if a!=float("inf"):
# cnt+=1
cnt=2
dd=min(l[i],v)
if a!=float("inf"):
rec(a+(dd/cnt),tb,c+(dd/cnt),v,p*l[i],card+1)
else:
rec(a,tb,min(c+(dd/cnt),1.0),v,p*l[i],card+1)
if i==2:
blanck.append(p*c*(card+1))
for t in range(int(input())):
blanck=[]
a,b,c,d=map(float,input().strip().split())
rec(a,b,c,d,1.0,0.0)
ans=0
# blanck=[]
# print(blanck)
# cnt=Counter(blanck)
# print(cnt)
for i in blanck:
if i!=float("inf"):
ans+=i
# print(ans)
print(ans)
``` | instruction | 0 | 100,589 | 19 | 201,178 |
No | output | 1 | 100,589 | 19 | 201,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja loves integer sequences very much. He especially likes stairs.
Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 β€ i β€ |a|), that the following condition is met:
a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.
For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.
Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?
Input
The first line contains integer m (1 β€ m β€ 105) β the number of Sereja's cards. The second line contains m integers bi (1 β€ bi β€ 5000) β the numbers on the Sereja's cards.
Output
In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.
Examples
Input
5
1 2 3 4 5
Output
5
5 4 3 2 1
Input
6
1 1 2 2 3 3
Output
5
1 2 3 2 1
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
a.sort()
i=0
rev=[]
temp='0'
hd=0
while(i<len(a)):
if(a[i]==temp):
temp=a.pop(i)
if(hd>0 and not(rev[hd-1]==temp)):
rev.append(temp)
hd=hd+1
elif(hd==0):
rev.append(temp)
hd=hd+1
else:
temp=a[i]
i=i+1
if(len(rev)>0 and a[len(a)-1]==rev[len(rev)-1]):
rev.pop()
if(len(rev)>0):
rev=[str(i) for i in rev]
a=[str(i) for i in a]
ans=a+rev[::-1]
print(str(len(a)+len(rev)))
print(' '.join(ans))
``` | instruction | 0 | 100,660 | 19 | 201,320 |
Yes | output | 1 | 100,660 | 19 | 201,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja loves integer sequences very much. He especially likes stairs.
Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 β€ i β€ |a|), that the following condition is met:
a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.
For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.
Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?
Input
The first line contains integer m (1 β€ m β€ 105) β the number of Sereja's cards. The second line contains m integers bi (1 β€ bi β€ 5000) β the numbers on the Sereja's cards.
Output
In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.
Examples
Input
5
1 2 3 4 5
Output
5
5 4 3 2 1
Input
6
1 1 2 2 3 3
Output
5
1 2 3 2 1
Submitted Solution:
```
m = int(input())
arr = list(map(int,input().split()))
freq = {}
for ele in arr:
freq[ele] = freq.get(ele,0)+1
s=0
first = []
last = []
mx = max(arr)
for key in freq.keys():
if key!=mx:
s+= min(freq[key],2)
if freq[key]>=2:
first+=[key]
last+=[key]
else:
first+=[key]
print(s+1)
op = sorted(first)+[mx]+ sorted(last,reverse=True)
print(' '.join(map(str,op)))
``` | instruction | 0 | 100,661 | 19 | 201,322 |
Yes | output | 1 | 100,661 | 19 | 201,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja loves integer sequences very much. He especially likes stairs.
Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 β€ i β€ |a|), that the following condition is met:
a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.
For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.
Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?
Input
The first line contains integer m (1 β€ m β€ 105) β the number of Sereja's cards. The second line contains m integers bi (1 β€ bi β€ 5000) β the numbers on the Sereja's cards.
Output
In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.
Examples
Input
5
1 2 3 4 5
Output
5
5 4 3 2 1
Input
6
1 1 2 2 3 3
Output
5
1 2 3 2 1
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
col = [0]*5001
ans = []
do_max=[]
posle_max = []
max = 0
for i in range(n):
col[a[i]]+=1
if a[i]>max:
max=a[i]
for i in range(5001):
if i==max:
do_max.append(i)
elif col[i]>=2:
do_max.append(i)
posle_max.append(i)
elif col[i]==1:
do_max.append(i)
print(len(do_max)+len(posle_max))
for i in range(len(do_max)):
print(do_max[i],end=' ')
for i in range(len(posle_max)-1,-1,-1):
print(posle_max[i],end=' ')
``` | instruction | 0 | 100,662 | 19 | 201,324 |
Yes | output | 1 | 100,662 | 19 | 201,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja loves integer sequences very much. He especially likes stairs.
Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 β€ i β€ |a|), that the following condition is met:
a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.
For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.
Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?
Input
The first line contains integer m (1 β€ m β€ 105) β the number of Sereja's cards. The second line contains m integers bi (1 β€ bi β€ 5000) β the numbers on the Sereja's cards.
Output
In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.
Examples
Input
5
1 2 3 4 5
Output
5
5 4 3 2 1
Input
6
1 1 2 2 3 3
Output
5
1 2 3 2 1
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
a.sort()
otv = []
otv_1 = []
l = max(a)
kol = 0
pr = -1
for i in range(len(a)):
if a[i] == l:
otv.append(l)
break
if a[i] == pr:
if kol == 1:
otv_1.append(a[i])
kol += 1
else:
pr = a[i]
kol = 1
otv.append(a[i])
otv_1 = otv_1[::-1]
for i in range(len(otv_1)):
otv.append(otv_1[i])
print(len(otv))
print(*otv)
``` | instruction | 0 | 100,663 | 19 | 201,326 |
Yes | output | 1 | 100,663 | 19 | 201,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja loves integer sequences very much. He especially likes stairs.
Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 β€ i β€ |a|), that the following condition is met:
a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.
For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.
Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?
Input
The first line contains integer m (1 β€ m β€ 105) β the number of Sereja's cards. The second line contains m integers bi (1 β€ bi β€ 5000) β the numbers on the Sereja's cards.
Output
In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.
Examples
Input
5
1 2 3 4 5
Output
5
5 4 3 2 1
Input
6
1 1 2 2 3 3
Output
5
1 2 3 2 1
Submitted Solution:
```
n = int(input())
ip = input().split(' ')
ip2 = list(map(int, ip))
ip2 = sorted(ip2)
leader = max(ip2)
lower = set()
upper = set()
for x in ip2:
if x < leader and x not in lower:
lower.add(x)
elif x < leader and x not in upper:
upper.add(x)
lower.add(leader)
res = list(lower) + (sorted(upper, reverse = True))
print(len(res))
for y in range(len(res)):
if y < len(res) - 1:
print(res[y],end=' ')
else:
print(res[y])
``` | instruction | 0 | 100,664 | 19 | 201,328 |
No | output | 1 | 100,664 | 19 | 201,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja loves integer sequences very much. He especially likes stairs.
Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 β€ i β€ |a|), that the following condition is met:
a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.
For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.
Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?
Input
The first line contains integer m (1 β€ m β€ 105) β the number of Sereja's cards. The second line contains m integers bi (1 β€ bi β€ 5000) β the numbers on the Sereja's cards.
Output
In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.
Examples
Input
5
1 2 3 4 5
Output
5
5 4 3 2 1
Input
6
1 1 2 2 3 3
Output
5
1 2 3 2 1
Submitted Solution:
```
from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *
####################################---fast-input-output----#########################################
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = read(self._fd, max(fstat(self._fd).st_size, 8192))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = read(self._fd, max(fstat(self._fd).st_size, 8192))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
stdin, stdout = IOWrapper(stdin), IOWrapper(stdout)
graph, mod, szzz = {}, 10**9 + 7, lambda: sorted(zzz())
def getStr(): return input()
def getInt(): return int(input())
def listStr(): return list(input())
def getStrs(): return input().split()
def isInt(s): return '0' <= s[0] <= '9'
def input(): return stdin.readline().strip()
def zzz(): return [int(i) for i in input().split()]
def output(answer, end='\n'): stdout.write(str(answer) + end)
def lcd(xnum1, xnum2): return (xnum1 * xnum2 // gcd(xnum1, xnum2))
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
#################################################---Some Rule For Me To Follow---#################################
"""
--instants of Reading problem continuously try to understand them.
--If you Know some-one , Then you probably don't know him !
--Try & again try, maybe you're just one statement away!
"""
##################################################---START-CODING---###############################################
# s = input().strip()
# n = len(s)
# class segTree:
# def __init__(self):
# self.a = [0]*(2*n)
# self.b = [0]*(2*n)
# self.c = [0]*(2*n)
# def build(self, arr):
# for i in range(n):
# self.a[i+n] = 0
# self.b[i+n] = 1 if arr[i] == '(' else 0
# self.c[i+n] = 1 if arr[i] == ')' else 0
# for i in range(n-1,0,-1):
# to_match = min(self.b[i << 1],self.c[i << 1 | 1])
# self.a[i] = self.a[i << 1] + self.a[i << 1 | 1] + 2*to_match
# self.b[i] = self.b[i << 1] + self.b[i << 1 | 1] - to_match
# self.c[i] = self.c[i << 1] + self.c[i << 1 | 1] - to_match
# def query(self, l, r):
# left = []
# right = []
# l += n
# r += n
# while l <= r:
# if (l & 1):
# left.append((self.a[l],self.b[l],self.c[l]))
# l += 1
# if not (r & 1):
# right.append((self.a[r],self.b[r],self.c[r]))
# r -= 1
# l >>= 1
# r >>= 1
# a1 = b1 = c1 = 0
# for a2, b2, c2 in left + right[::-1]:
# to_match = min(b1,c2)
# a1 += a2 + 2*to_match
# b1 += b2 - to_match
# c1 += c2 - to_match
# return a1
# tree = segTree()
# tree.build(s)
# for m in range(getInt()):
# l, r = zzz()
# l -= 1
# r -= 1
# print(tree.query(l,r))
n=getInt()
arr = szzz()
cnt = Counter(arr)
set1=set()
set2=set()
for i in arr:
if i not in set1:
set1.add(i)
elif i not in set2:
set2.add(i)
a=sorted(set1)
b=sorted(set2,reverse=True)
try:
if a[-1]==b[0]:
print(len(set1)+len(set2)-1)
print(*a+b[1:])
except:
print(len(set1)+len(set2))
print(*a+b)
``` | instruction | 0 | 100,665 | 19 | 201,330 |
No | output | 1 | 100,665 | 19 | 201,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja loves integer sequences very much. He especially likes stairs.
Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 β€ i β€ |a|), that the following condition is met:
a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.
For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.
Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?
Input
The first line contains integer m (1 β€ m β€ 105) β the number of Sereja's cards. The second line contains m integers bi (1 β€ bi β€ 5000) β the numbers on the Sereja's cards.
Output
In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.
Examples
Input
5
1 2 3 4 5
Output
5
5 4 3 2 1
Input
6
1 1 2 2 3 3
Output
5
1 2 3 2 1
Submitted Solution:
```
from sys import stdin,stdout
from math import factorial as f
inp=stdin.readline
op=stdout.write
n=int(inp())
a=list(map(int,inp().split()))
a.sort()
# op(str(a))
# if(len(set(a))==n):
# op(str(len(a))+"\n")
# a=[str(i) for i in a]
# op(' '.join(a[::-1])+"\n")
# else:
temp=float('inf')
i=0
rev=[]
while(i<len(a)):
if(a[i]==temp):
temp=a.pop(i)
rev.append(str(temp))
else:
temp=a[i]
a[i]=str(a[i])
i=i+1
rev=list(set(rev))
rev.sort()
if(len(rev)>0 and a[len(a)-1]<=rev[len(rev)-1]):
rev.pop()
op(str(len(a)+len(rev))+"\n")
op(' '.join(a)+' '+' '.join(rev[::-1]))
# dp=[]
# a=set(a)
# op(str(len(a)))
# for i in range
``` | instruction | 0 | 100,666 | 19 | 201,332 |
No | output | 1 | 100,666 | 19 | 201,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja loves integer sequences very much. He especially likes stairs.
Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 β€ i β€ |a|), that the following condition is met:
a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.
For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.
Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?
Input
The first line contains integer m (1 β€ m β€ 105) β the number of Sereja's cards. The second line contains m integers bi (1 β€ bi β€ 5000) β the numbers on the Sereja's cards.
Output
In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.
Examples
Input
5
1 2 3 4 5
Output
5
5 4 3 2 1
Input
6
1 1 2 2 3 3
Output
5
1 2 3 2 1
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
m = int(sys.stdin.readline())
b = [int(x) for x in sys.stdin.readline().split(' ')]
b.sort()
l1 = []
l2 = []
last = b[0]
rep = 1
l1.append(last)
for i in range(1, len(b)):
if b[i] == last:
rep += 1
else:
last = b[i]
rep = 1
if rep == 1:
l1.append(last)
elif rep == 2:
l2.append(last)
#ε¦εδΈ’εΌ
if l2 and l2[-1] == l1[-1]:
l2.pop()
print(len(l1)+len(l2))
print(' '.join([str(x) for x in l1]), end='')
if l2:
print(' ', end='')
print(' '.join([str(x) for x in l2]))
else:
print()
``` | instruction | 0 | 100,667 | 19 | 201,334 |
No | output | 1 | 100,667 | 19 | 201,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n), and a probability 1 - pi to lose and move to the casino on the left (i - 1) or also exit the row (if i = 1).
We say that Memory dominates on the interval i... j if he completes a walk such that,
* He starts on casino i.
* He never looses in casino i.
* He finishes his walk by winning in casino j.
Note that Memory can still walk left of the 1-st casino and right of the casino n and that always finishes the process.
Now Memory has some requests, in one of the following forms:
* 1 i a b: Set <image>.
* 2 l r: Print the probability that Memory will dominate on the interval l... r, i.e. compute the probability that Memory will first leave the segment l... r after winning at casino r, if she starts in casino l.
It is guaranteed that at any moment of time p is a non-decreasing sequence, i.e. pi β€ pi + 1 for all i from 1 to n - 1.
Please help Memory by answering all his requests!
Input
The first line of the input contains two integers n and q(1 β€ n, q β€ 100 000), β number of casinos and number of requests respectively.
The next n lines each contain integers ai and bi (1 β€ ai < bi β€ 109) β <image> is the probability pi of winning in casino i.
The next q lines each contain queries of one of the types specified above (1 β€ a < b β€ 109, 1 β€ i β€ n, 1 β€ l β€ r β€ n).
It's guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that p forms a non-decreasing sequence at all times.
Output
Print a real number for every request of type 2 β the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10 - 4.
Namely: let's assume that one of your answers is a, and the corresponding answer of the jury is b. The checker program will consider your answer correct if |a - b| β€ 10 - 4.
Example
Input
3 13
1 3
1 2
2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
1 2 2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
Output
0.3333333333
0.2000000000
0.1666666667
0.5000000000
0.4000000000
0.6666666667
0.3333333333
0.2500000000
0.2222222222
0.6666666667
0.5714285714
0.6666666667
Submitted Solution:
```
import math
import sys
n,q = input().split()
n = int(n)
q = int(q)
p = [0]*n
for i in range(n):
a = input().split()
p[i] = int(a[0])/int(a[1])
r = [0]*n
for i in range(n):
r[i] = [0]*n
def P(i,j):
if (i == j):
return p[i]
return P(i,int(j/2))*P(int(j/2)+1,j)/(1-(1-P(int(j/2)+1,j))*P(i,int(j/2)))
for i in range(q):
a = input().split()
if (int(a[0]) == 1):
p[int(a[1])-1] = int(a[2])/int(a[3])
if (int(a[0]) == 2):
print(P(int(a[1])-1,int(a[2])-1))
``` | instruction | 0 | 100,796 | 19 | 201,592 |
No | output | 1 | 100,796 | 19 | 201,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n), and a probability 1 - pi to lose and move to the casino on the left (i - 1) or also exit the row (if i = 1).
We say that Memory dominates on the interval i... j if he completes a walk such that,
* He starts on casino i.
* He never looses in casino i.
* He finishes his walk by winning in casino j.
Note that Memory can still walk left of the 1-st casino and right of the casino n and that always finishes the process.
Now Memory has some requests, in one of the following forms:
* 1 i a b: Set <image>.
* 2 l r: Print the probability that Memory will dominate on the interval l... r, i.e. compute the probability that Memory will first leave the segment l... r after winning at casino r, if she starts in casino l.
It is guaranteed that at any moment of time p is a non-decreasing sequence, i.e. pi β€ pi + 1 for all i from 1 to n - 1.
Please help Memory by answering all his requests!
Input
The first line of the input contains two integers n and q(1 β€ n, q β€ 100 000), β number of casinos and number of requests respectively.
The next n lines each contain integers ai and bi (1 β€ ai < bi β€ 109) β <image> is the probability pi of winning in casino i.
The next q lines each contain queries of one of the types specified above (1 β€ a < b β€ 109, 1 β€ i β€ n, 1 β€ l β€ r β€ n).
It's guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that p forms a non-decreasing sequence at all times.
Output
Print a real number for every request of type 2 β the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10 - 4.
Namely: let's assume that one of your answers is a, and the corresponding answer of the jury is b. The checker program will consider your answer correct if |a - b| β€ 10 - 4.
Example
Input
3 13
1 3
1 2
2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
1 2 2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
Output
0.3333333333
0.2000000000
0.1666666667
0.5000000000
0.4000000000
0.6666666667
0.3333333333
0.2500000000
0.2222222222
0.6666666667
0.5714285714
0.6666666667
Submitted Solution:
```
import math
import sys
n,q = input().split()
n = int(n)
q = int(q)
p = [0]*n
for i in range(n):
a = input().split()
p[i] = int(a[0])/int(a[1])
r = [0]*n
for i in range(n):
r[i] = [0]*n
def P(i,j):
if (r[i][j] == 0):
if (i == j):
r[i][j] = p[i]
return p[i]
r[i][j] = p[i]*P(i+1,j)/(1-(1-P(i+1,j))*p[i])
return p[i]*P(i+1,j)/(1-(1-P(i+1,j))*p[i])
else:
return r[i][j]
for i in range(q):
a = input().split()
if (int(a[0]) == 1):
for j in range (n):
r[int(a[1])-1][j] = 0
p[int(a[1])-1] = int(a[2])/int(a[3])
if (int(a[0]) == 2):
print(P(int(a[1])-1,int(a[2])-1))
``` | instruction | 0 | 100,797 | 19 | 201,594 |
No | output | 1 | 100,797 | 19 | 201,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n), and a probability 1 - pi to lose and move to the casino on the left (i - 1) or also exit the row (if i = 1).
We say that Memory dominates on the interval i... j if he completes a walk such that,
* He starts on casino i.
* He never looses in casino i.
* He finishes his walk by winning in casino j.
Note that Memory can still walk left of the 1-st casino and right of the casino n and that always finishes the process.
Now Memory has some requests, in one of the following forms:
* 1 i a b: Set <image>.
* 2 l r: Print the probability that Memory will dominate on the interval l... r, i.e. compute the probability that Memory will first leave the segment l... r after winning at casino r, if she starts in casino l.
It is guaranteed that at any moment of time p is a non-decreasing sequence, i.e. pi β€ pi + 1 for all i from 1 to n - 1.
Please help Memory by answering all his requests!
Input
The first line of the input contains two integers n and q(1 β€ n, q β€ 100 000), β number of casinos and number of requests respectively.
The next n lines each contain integers ai and bi (1 β€ ai < bi β€ 109) β <image> is the probability pi of winning in casino i.
The next q lines each contain queries of one of the types specified above (1 β€ a < b β€ 109, 1 β€ i β€ n, 1 β€ l β€ r β€ n).
It's guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that p forms a non-decreasing sequence at all times.
Output
Print a real number for every request of type 2 β the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10 - 4.
Namely: let's assume that one of your answers is a, and the corresponding answer of the jury is b. The checker program will consider your answer correct if |a - b| β€ 10 - 4.
Example
Input
3 13
1 3
1 2
2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
1 2 2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
Output
0.3333333333
0.2000000000
0.1666666667
0.5000000000
0.4000000000
0.6666666667
0.3333333333
0.2500000000
0.2222222222
0.6666666667
0.5714285714
0.6666666667
Submitted Solution:
```
import math
import sys
n,q = input().split()
n = int(n)
q = int(q)
p = [0]*n
for i in range(n):
a = input().split()
p[i] = int(a[0])/int(a[1])
r = [0]*n
for i in range(n):
r[i] = [0]*n
def P(i,j):
if (i == j):
return p[i]
bord = i + 1
if (j == i + 1):
bord = i
return P(i,bord)*P(bord+1,j)/(1 - P(i,bord)*(1 - P(bord+1,j)) )
for i in range(q):
a = input().split()
if (int(a[0]) == 1):
p[int(a[1])-1] = int(a[2])/int(a[3])
if (int(a[0]) == 2):
print(P(int(a[1])-1,int(a[2])-1))
``` | instruction | 0 | 100,798 | 19 | 201,596 |
No | output | 1 | 100,798 | 19 | 201,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n), and a probability 1 - pi to lose and move to the casino on the left (i - 1) or also exit the row (if i = 1).
We say that Memory dominates on the interval i... j if he completes a walk such that,
* He starts on casino i.
* He never looses in casino i.
* He finishes his walk by winning in casino j.
Note that Memory can still walk left of the 1-st casino and right of the casino n and that always finishes the process.
Now Memory has some requests, in one of the following forms:
* 1 i a b: Set <image>.
* 2 l r: Print the probability that Memory will dominate on the interval l... r, i.e. compute the probability that Memory will first leave the segment l... r after winning at casino r, if she starts in casino l.
It is guaranteed that at any moment of time p is a non-decreasing sequence, i.e. pi β€ pi + 1 for all i from 1 to n - 1.
Please help Memory by answering all his requests!
Input
The first line of the input contains two integers n and q(1 β€ n, q β€ 100 000), β number of casinos and number of requests respectively.
The next n lines each contain integers ai and bi (1 β€ ai < bi β€ 109) β <image> is the probability pi of winning in casino i.
The next q lines each contain queries of one of the types specified above (1 β€ a < b β€ 109, 1 β€ i β€ n, 1 β€ l β€ r β€ n).
It's guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that p forms a non-decreasing sequence at all times.
Output
Print a real number for every request of type 2 β the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10 - 4.
Namely: let's assume that one of your answers is a, and the corresponding answer of the jury is b. The checker program will consider your answer correct if |a - b| β€ 10 - 4.
Example
Input
3 13
1 3
1 2
2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
1 2 2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
Output
0.3333333333
0.2000000000
0.1666666667
0.5000000000
0.4000000000
0.6666666667
0.3333333333
0.2500000000
0.2222222222
0.6666666667
0.5714285714
0.6666666667
Submitted Solution:
```
import math
import sys
n,q = input().split()
n = int(n)
q = int(q)
p = [0]*n
for i in range(n):
a = input().split()
p[i] = int(a[0])/int(a[1])
r = [0]*n
for i in range(n):
r[i] = [0]*n
def P(i,j):
if (i == j):
return p[i]
bord = int((j+i - 1)/2)
if (j == i + 1):
bord = i
return P(i,bord)*P(bord+1,j)/(1 - P(i,bord)*(1 - P(bord+1,j)) )
for i in range(q):
a = input().split()
if (int(a[0]) == 1):
p[int(a[1])-1] = int(a[2])/int(a[3])
if (int(a[0]) == 2):
print(P(int(a[1])-1,int(a[2])-1))
``` | instruction | 0 | 100,799 | 19 | 201,598 |
No | output | 1 | 100,799 | 19 | 201,599 |
Provide a correct Python 3 solution for this coding contest problem.
Your friend gave you a dequeue D as a birthday present.
D is a horizontal cylinder that contains a row of N jewels.
The values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.
In the beginning, you have no jewel in your hands.
You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):
* Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.
* Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.
* Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.
* Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.
Find the maximum possible sum of the values of jewels in your hands after the operations.
Constraints
* All values in input are integers.
* 1 \leq N \leq 50
* 1 \leq K \leq 100
* -10^7 \leq V_i \leq 10^7
Input
Input is given from Standard Input in the following format:
N K
V_1 V_2 ... V_N
Output
Print the maximum possible sum of the values of jewels in your hands after the operations.
Examples
Input
6 4
-10 8 2 1 2 6
Output
14
Input
6 4
-6 -100 50 -2 -5 -3
Output
44
Input
6 3
-6 -100 50 -2 -5 -3
Output
0 | instruction | 0 | 100,968 | 19 | 201,936 |
"Correct Solution:
```
n,k=map(int,input().split())
v=list(map(int,input().split()))
ans=0
for i in range(min(n+1,k+1)):
for j in range(min(n-i+1,k-i+1)):
a=v[:i]+v[n-j:]
a.sort(reverse=True)
for _ in range(k-i-j):
if a and a[-1]<0:
a.pop()
ans=max(ans,sum(a))
print(ans)
``` | output | 1 | 100,968 | 19 | 201,937 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.