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.
There are n emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The i-th emote increases the opponent's happiness by a_i units (we all know that emotes in this game are used to make opponents happy).
You have time to use some emotes only m times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than k times in a row (otherwise the opponent will think that you're trolling him).
Note that two emotes i and j (i ≠ j) such that a_i = a_j are considered different.
You have to make your opponent as happy as possible. Find the maximum possible opponent's happiness.
Input
The first line of the input contains three integers n, m and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ m ≤ 2 ⋅ 10^9) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is value of the happiness of the i-th emote.
Output
Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement.
Examples
Input
6 9 2
1 3 3 7 4 2
Output
54
Input
3 1000000000 1
1000000000 987654321 1000000000
Output
1000000000000000000
Note
In the first example you may use emotes in the following sequence: 4, 4, 5, 4, 4, 5, 4, 4, 5.
Submitted Solution:
```
n,m,k = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
x = m//(k+1)
a = x*(l[-1]*k+l[-2])
y = m%(k+1)
a+=y*l[-1]
print(a)
``` | instruction | 0 | 71,689 | 19 | 143,378 |
Yes | output | 1 | 71,689 | 19 | 143,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The i-th emote increases the opponent's happiness by a_i units (we all know that emotes in this game are used to make opponents happy).
You have time to use some emotes only m times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than k times in a row (otherwise the opponent will think that you're trolling him).
Note that two emotes i and j (i ≠ j) such that a_i = a_j are considered different.
You have to make your opponent as happy as possible. Find the maximum possible opponent's happiness.
Input
The first line of the input contains three integers n, m and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ m ≤ 2 ⋅ 10^9) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is value of the happiness of the i-th emote.
Output
Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement.
Examples
Input
6 9 2
1 3 3 7 4 2
Output
54
Input
3 1000000000 1
1000000000 987654321 1000000000
Output
1000000000000000000
Note
In the first example you may use emotes in the following sequence: 4, 4, 5, 4, 4, 5, 4, 4, 5.
Submitted Solution:
```
n, m, k=map(int, input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
mx = a[n-1]
mx2 = a[n-2]
ans = (m//(k+1)) * mx2 + (m - m // (k+1)) *mx
print(ans)
``` | instruction | 0 | 71,690 | 19 | 143,380 |
Yes | output | 1 | 71,690 | 19 | 143,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The i-th emote increases the opponent's happiness by a_i units (we all know that emotes in this game are used to make opponents happy).
You have time to use some emotes only m times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than k times in a row (otherwise the opponent will think that you're trolling him).
Note that two emotes i and j (i ≠ j) such that a_i = a_j are considered different.
You have to make your opponent as happy as possible. Find the maximum possible opponent's happiness.
Input
The first line of the input contains three integers n, m and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ m ≤ 2 ⋅ 10^9) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is value of the happiness of the i-th emote.
Output
Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement.
Examples
Input
6 9 2
1 3 3 7 4 2
Output
54
Input
3 1000000000 1
1000000000 987654321 1000000000
Output
1000000000000000000
Note
In the first example you may use emotes in the following sequence: 4, 4, 5, 4, 4, 5, 4, 4, 5.
Submitted Solution:
```
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
max = A[-1]
min = A[-2]
if m % (k + 1) == 0:
t = m // (k + 1)
an = t * k * max + t * min
print(an)
else:
t = m // (k + 1)
an = t * k * max + t * min
an += (m % (k + 1)) * max
print(an)
``` | instruction | 0 | 71,691 | 19 | 143,382 |
Yes | output | 1 | 71,691 | 19 | 143,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The i-th emote increases the opponent's happiness by a_i units (we all know that emotes in this game are used to make opponents happy).
You have time to use some emotes only m times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than k times in a row (otherwise the opponent will think that you're trolling him).
Note that two emotes i and j (i ≠ j) such that a_i = a_j are considered different.
You have to make your opponent as happy as possible. Find the maximum possible opponent's happiness.
Input
The first line of the input contains three integers n, m and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ m ≤ 2 ⋅ 10^9) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is value of the happiness of the i-th emote.
Output
Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement.
Examples
Input
6 9 2
1 3 3 7 4 2
Output
54
Input
3 1000000000 1
1000000000 987654321 1000000000
Output
1000000000000000000
Note
In the first example you may use emotes in the following sequence: 4, 4, 5, 4, 4, 5, 4, 4, 5.
Submitted Solution:
```
def bin_pow(a, n):
if n == 0:
return 1
else:
if n % 2 == 0:
return bin_pow(a, n//2)**2
else:
return bin_pow(a, n-1)*a
def main():
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tmp = 1
ans = 0
#print(b)
m1 = max(b)
#print(m1)
b.remove(m1)
m2 = max(b)
b.append(m1)
#print(m2)
#print(b)
ans = (a[1] / (a[2] + 1)) * (a[2] * m2 + m1) + a[1] % (a[2] + 1) * m2
#print()
print(int(ans))
if __name__ == "__main__":
main()
``` | instruction | 0 | 71,692 | 19 | 143,384 |
No | output | 1 | 71,692 | 19 | 143,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The i-th emote increases the opponent's happiness by a_i units (we all know that emotes in this game are used to make opponents happy).
You have time to use some emotes only m times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than k times in a row (otherwise the opponent will think that you're trolling him).
Note that two emotes i and j (i ≠ j) such that a_i = a_j are considered different.
You have to make your opponent as happy as possible. Find the maximum possible opponent's happiness.
Input
The first line of the input contains three integers n, m and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ m ≤ 2 ⋅ 10^9) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is value of the happiness of the i-th emote.
Output
Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement.
Examples
Input
6 9 2
1 3 3 7 4 2
Output
54
Input
3 1000000000 1
1000000000 987654321 1000000000
Output
1000000000000000000
Note
In the first example you may use emotes in the following sequence: 4, 4, 5, 4, 4, 5, 4, 4, 5.
Submitted Solution:
```
n,k,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
if m==0:
print(0)
else:
x=k//(m+1)
c=0
if k>m:
c+=a[0]*m*x+a[1]*(n%(m))
c+=a[1]*x
elif k<=m:
c+=k*a[0]
print(c)
``` | instruction | 0 | 71,693 | 19 | 143,386 |
No | output | 1 | 71,693 | 19 | 143,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The i-th emote increases the opponent's happiness by a_i units (we all know that emotes in this game are used to make opponents happy).
You have time to use some emotes only m times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than k times in a row (otherwise the opponent will think that you're trolling him).
Note that two emotes i and j (i ≠ j) such that a_i = a_j are considered different.
You have to make your opponent as happy as possible. Find the maximum possible opponent's happiness.
Input
The first line of the input contains three integers n, m and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ m ≤ 2 ⋅ 10^9) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is value of the happiness of the i-th emote.
Output
Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement.
Examples
Input
6 9 2
1 3 3 7 4 2
Output
54
Input
3 1000000000 1
1000000000 987654321 1000000000
Output
1000000000000000000
Note
In the first example you may use emotes in the following sequence: 4, 4, 5, 4, 4, 5, 4, 4, 5.
Submitted Solution:
```
h = 0
nmk_in = input()
nmk = list(map(int, nmk_in.split(' ')))
m = nmk[1]
k = nmk[2]
emotes_in = input()
emotes = list(map(int, emotes_in.split(' ')))
emotes.sort()
emotes.reverse()
##i = 0
##while m > 0:
## if (i%2==0):
## h += k*emotes[0]
## m -= k
## else:
## h += emotes[1]
## m -= 1
## i += 1
n1 = m//(k+1)
##print(n1)
##h += (n1-1)*k*emotes[0]+(m-(n1-1)*k)*emotes[1]
h += n1*k*emotes[0]+(m-n1*k)*emotes[1]
print(h)
``` | instruction | 0 | 71,694 | 19 | 143,388 |
No | output | 1 | 71,694 | 19 | 143,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The i-th emote increases the opponent's happiness by a_i units (we all know that emotes in this game are used to make opponents happy).
You have time to use some emotes only m times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than k times in a row (otherwise the opponent will think that you're trolling him).
Note that two emotes i and j (i ≠ j) such that a_i = a_j are considered different.
You have to make your opponent as happy as possible. Find the maximum possible opponent's happiness.
Input
The first line of the input contains three integers n, m and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ m ≤ 2 ⋅ 10^9) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is value of the happiness of the i-th emote.
Output
Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement.
Examples
Input
6 9 2
1 3 3 7 4 2
Output
54
Input
3 1000000000 1
1000000000 987654321 1000000000
Output
1000000000000000000
Note
In the first example you may use emotes in the following sequence: 4, 4, 5, 4, 4, 5, 4, 4, 5.
Submitted Solution:
```
t,m,k=map(int,input().split())
l=list(map(int,input().split()))
max1=max(l)
l.remove(max1)
max2=max(l)
ans = 0
a =m//(k+1)
ans = a*( k*max1 + max2)
print(ans)
b = m%(k+1)
ans += b*max1
print(ans)
``` | instruction | 0 | 71,695 | 19 | 143,390 |
No | output | 1 | 71,695 | 19 | 143,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely. | instruction | 0 | 72,237 | 19 | 144,474 |
Tags: implementation, probabilities, strings
Correct Solution:
```
s=input()
n=len(s)
pos=[[] for i in range(26)]
for i in range(len(s)):
pos[ord(s[i])-97].append(s[i:] + s[:i])
ans=0
for i in range(26):
max1=0
for j in range(n):
b=[0 for i in range(26)]
for k in pos[i]:
b[ord(k[j])-97]+=1
temp1=0
for k in range(26):
if(b[k]==1):
temp1+=1
max1=max(temp1,max1)
ans+=max1
print(ans/n)
``` | output | 1 | 72,237 | 19 | 144,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely. | instruction | 0 | 72,238 | 19 | 144,476 |
Tags: implementation, probabilities, strings
Correct Solution:
```
str = input()
l = len(str)
a = [0] * (2 * l)
pos = [[] for i in range(26)]
for i, c in enumerate(str):
t = ord(c) - ord('a')
a[i] = t
a[i + l] = t
pos[t].append(i)
ans = 0
for c in range(26):
cur = 0
for k in range(1, l):
cnt = [0] * 26
for i in pos[c]:
cnt[a[i + k]] += 1
cur = max(cur, len(list(filter(lambda x : x == 1, cnt))))
ans += cur
print(ans / l)
``` | output | 1 | 72,238 | 19 | 144,477 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely. | instruction | 0 | 72,239 | 19 | 144,478 |
Tags: implementation, probabilities, strings
Correct Solution:
```
str = input()
l = len(str)
a = [0] * (2 * l)
pos = [[] for i in range(26)]
for i, c in enumerate(str):
t = ord(c) - ord('a')
a[i] = t
a[i + l] = t
pos[t].append(i)
ans = 0
for c in range(26):
cur = 0
for k in range(1, l):
cnt = [0] * 26
for i in pos[c]:
cnt[a[i + k]] += 1
cur = max(cur, len([1 for x in cnt if x == 1]))
ans += cur
print(ans / l)
``` | output | 1 | 72,239 | 19 | 144,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely. | instruction | 0 | 72,240 | 19 | 144,480 |
Tags: implementation, probabilities, strings
Correct Solution:
```
import sys
from collections import defaultdict
s = sys.stdin.readline().strip()
n = len(s)
s_mp = defaultdict(list)
for i in range(n):
s_mp[s[i]].append(i)
result = 0
for let, starts in s_mp.items():
max_p = 0.0
for j in range(1, n):
cnter = defaultdict(int)
for start in starts:
cnter[s[(start + j) % n]] += 1
uniq = 0
for i, v in cnter.items():
if v == 1:
uniq += 1
max_p = max(max_p, uniq/len(starts))
total = len(starts)
result += max_p * len(starts)/n
print('{:.8f}'.format(result))
``` | output | 1 | 72,240 | 19 | 144,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely. | instruction | 0 | 72,241 | 19 | 144,482 |
Tags: implementation, probabilities, strings
Correct Solution:
```
str = input()
l = len(str)
a = []
for c in str:
a.append(ord(c) - ord('a'))
a *= 2
tot = [[0] * l for i in range(26)]
for i in range(1, l):
cnt = [[0] * 26 for i in range(26)]
for j in range(l):
cnt[a[j]][a[j + i]] += 1
for j in range(l):
if cnt[a[j]][a[j + i]] == 1:
tot[a[j]][i] += 1
ans = 0
for sub in tot:
ans += max(sub)
print(ans / l)
``` | output | 1 | 72,241 | 19 | 144,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely. | instruction | 0 | 72,242 | 19 | 144,484 |
Tags: implementation, probabilities, strings
Correct Solution:
```
s = str(input())
n = len(s)
t = s+s
P = [[[0]*26 for i in range(26)] for j in range(n)]
for i in range(n):
c1 = ord(t[i])-ord('a')
for j in range(1, n):
c2 = ord(t[i+j])-ord('a')
P[j][c1][c2] += 1
s = set(s)
ans = 0
for c1 in s:
c1 = ord(c1)-ord('a')
M = 0
for j in range(1, n):
temp = 0
for c2 in range(26):
if P[j][c1][c2] == 1:
temp += 1
M = max(M, temp)
ans += M
print(ans/n)
``` | output | 1 | 72,242 | 19 | 144,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely. | instruction | 0 | 72,243 | 19 | 144,486 |
Tags: implementation, probabilities, strings
Correct Solution:
```
def func(a):
b=[0]*26
for i in range(len(a)):
b[ord(a[i])-ord("a")]+=1
c=0
for i in b:
if i==1:
c=c+1
return c
s=input()
n=len(s)
a={}
for i in range(n):
a[s[i]]=[]
for i in range(n):
a[s[i]].append(i)
c=0
for i in a:
if len(a[i])==1:
c=c+1
else:
e=[]
for j in range(n):
b=[]
d=0
for k in a[i]:
b.append((s[(k+j)%n]))
d=d+func(b)
e.append(d)
c=c+max(e)
print(c/n)
``` | output | 1 | 72,243 | 19 | 144,487 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely. | instruction | 0 | 72,244 | 19 | 144,488 |
Tags: implementation, probabilities, strings
Correct Solution:
```
s=input()
d=dict()
mod=[]
mx=[]
for k in s:
d[k]=[]
for i in range(len(s)):
d[s[i]].append(i)
index=0
for k in d.keys():
mod.append(d[k])
for k in mod:
mxct=0
ct=0
x=[]
for i in range(len(s)):
ct=0
dic=dict()
for j in k:
elt = s[(j+i)%(len(s))]
if elt in dic.keys():
dic[elt]+=1
else:
dic[elt]=1
for r in dic.keys():
if dic[r]==1:
ct+=1
mxct=max(ct,mxct)
mx.append(mxct)
sm=0
for k in mx:
sm+=k
print(sm/len(s))
``` | output | 1 | 72,244 | 19 | 144,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely.
Submitted Solution:
```
str = input()
l = len(str)
a = [0] * (2 * l)
pos = [[] for i in range(26)]
for i, c in enumerate(str):
t = ord(c) - ord('a')
a[i] = t
a[i + l] = t
pos[t].append(i)
ans = 0
for c in range(26):
cur = 0
for k in range(1, l):
cnt = [0] * 26
for i in pos[c]:
cnt[a[i + k]] += 1
tot = 0
for i in cnt:
if i == 1:
tot += 1
cur = max(cur, tot)
ans += cur
print(ans / l)
``` | instruction | 0 | 72,245 | 19 | 144,490 |
Yes | output | 1 | 72,245 | 19 | 144,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely.
Submitted Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
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")
#-------------------game starts now-----------------------------------------------------
s = input()
l = len(s)
instances = [[] for x in range(26)]
s_i = [ord(c) - 97 for c in s]
for i in range(l):
instances[s_i[i]].append(i)
#sum_probability += len * probability
#probability = sum_probabilty
sum_probability = 0
for c in range(0,26):
if not instances[c]:
continue
if len(instances[c]) == 0:
sum_probability += 1
continue
max_probability = 0
for guess in range(1, l):
num_seen = [0]*26
probability = 0
for index in instances[c]:
num_seen[s_i[(index+guess)%l]] += 1
for x in num_seen:
if x == 1:
probability += 1
max_probability = max(max_probability, probability)
sum_probability += max_probability
print(sum_probability/l)
``` | instruction | 0 | 72,246 | 19 | 144,492 |
Yes | output | 1 | 72,246 | 19 | 144,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely.
Submitted Solution:
```
s = input()
l = len(s)
instances = [[] for x in range(26)]
s_i = [ord(c) - 97 for c in s]
for i in range(l):
instances[s_i[i]].append(i)
#sum_probability += len * probability
#probability = sum_probabilty
sum_probability = 0
for c in range(0,26):
if not instances[c]:
continue
if len(instances[c]) == 0:
sum_probability += 1
continue
max_probability = 0
for guess in range(1, l):
num_seen = [0]*26
probability = 0
for index in instances[c]:
num_seen[s_i[(index+guess)%l]] += 1
for x in num_seen:
if x == 1:
probability += 1
max_probability = max(max_probability, probability)
sum_probability += max_probability
print(sum_probability/l)
``` | instruction | 0 | 72,247 | 19 | 144,494 |
Yes | output | 1 | 72,247 | 19 | 144,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely.
Submitted Solution:
```
s = input()
n = len(s)
sett = {}
for i in range(n):
if s[i] not in sett:
sett[s[i]] = []
sett[s[i]].append(s[i + 1:] + s[:i])
ans = 0
# ao fazer sett.items(), é realizado unpack da chave,valor para k,l, respectivamente
for k, l in sett.items():
tmp = 0
for j in range(n - 1):
seen, sett1 = set(), set()
for i in range(len(l)):
if l[i][j] in sett1:
sett1.remove(l[i][j])
elif l[i][j] not in seen:
sett1.add(l[i][j])
seen.add(l[i][j])
tmp = max(tmp, len(sett1))
tmp /= n
ans += tmp
# precisao 10^6
print('{:.7}'.format(ans))
``` | instruction | 0 | 72,248 | 19 | 144,496 |
Yes | output | 1 | 72,248 | 19 | 144,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely.
Submitted Solution:
```
# https://codeforces.com/problemset/problem/930/B
S = input()
d = {}
is_ok = {}
n = len(S)
for i, c in enumerate(S):
if c not in d:
d[c] = []
d[c].append(i)
for k in d:
is_ok[k] = False
for k in range(1, n):
for c in d:
next_c = [S[(i+k)%n] for i in d[c]]
next_c = set(next_c)
if len(next_c) == len(d[c]):
is_ok[c] = True
count = 0
for k in is_ok:
if is_ok[k] == True:
count += len(d[k])
if count > 0 :
print(count / n)
else:
print(1 / n)
``` | instruction | 0 | 72,249 | 19 | 144,498 |
No | output | 1 | 72,249 | 19 | 144,499 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely.
Submitted Solution:
```
from collections import defaultdict, Counter
k_cnt = defaultdict(int)
s = input()
digs = set(s)
n = len(s)
for i in range(n):
for k in range(1, n-1):
k_cnt[(s[i], s[(i+k)%n], k)] += 1
meet_props = Counter(s)
# print(meet_props)
prop = 0
for b in digs:
# print('possible pairs for ', [(b,a,k,' ', k_cnt[(b,a,k)]) for a in digs for k in range(1, n-1) if k_cnt[(b,a,k)]])
min_pairs = min([k_cnt[(b,a,k)] for a in digs for k in range(1, n-1) if k_cnt[(b,a,k)]>0])
# print(b, 'min_pairs = ', min_pairs)
if min_pairs == 1:
prop += meet_props[b]
print(prop/n)
``` | instruction | 0 | 72,250 | 19 | 144,500 |
No | output | 1 | 72,250 | 19 | 144,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.
Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.
Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win.
Input
The only string contains the string s of length l (3 ≤ l ≤ 5000), consisting of small English letters only.
Output
Print the only number — the answer for the problem. You 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 considered correct if <image>
Examples
Input
technocup
Output
1.000000000000000
Input
tictictactac
Output
0.333333333333333
Input
bbaabaabbb
Output
0.100000000000000
Note
In the first example Vasya can always open the second letter after opening the first letter, and the cyclic shift is always determined uniquely.
In the second example if the first opened letter of t is "t" or "c", then Vasya can't guess the shift by opening only one other letter. On the other hand, if the first letter is "i" or "a", then he can open the fourth letter and determine the shift uniquely.
Submitted Solution:
```
s=input()
def uniq(iii):
for jj in range(1,len(s)):
se=set(s[ii-jj] for ii in iii)
if len(se)==len(iii):
return 1
aa={}
for ii,ss in enumerate(s):
aa.setdefault(ss,[]).append(ii)
ans=0
for iii in aa.values():
if uniq(iii):
ans+=len(iii)
print(ans/len(s))
``` | instruction | 0 | 72,251 | 19 | 144,502 |
No | output | 1 | 72,251 | 19 | 144,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:
* Replace b with b - ak. Number k can be chosen by the player, considering the limitations that k > 0 and b - ak ≥ 0. Number k is chosen independently each time an active player casts a spell.
* Replace b with b mod a.
If a > b, similar moves are possible.
If at least one of the numbers equals zero, a player can't make a move, because taking a remainder modulo zero is considered somewhat uncivilized, and it is far too boring to subtract a zero. The player who cannot make a move, loses.
To perform well in the magic totalizator, you need to learn to quickly determine which player wins, if both wizards play optimally: the one that moves first or the one that moves second.
Input
The first line contains a single integer t — the number of input data sets (1 ≤ t ≤ 104). Each of the next t lines contains two integers a, b (0 ≤ a, b ≤ 1018). The numbers are separated by a space.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output
For any of the t input sets print "First" (without the quotes) if the player who moves first wins. Print "Second" (without the quotes) if the player who moves second wins. Print the answers to different data sets on different lines in the order in which they are given in the input.
Examples
Input
4
10 21
31 10
0 1
10 30
Output
First
Second
Second
First
Note
In the first sample, the first player should go to (11,10). Then, after a single move of the second player to (1,10), he will take 10 modulo 1 and win.
In the second sample the first player has two moves to (1,10) and (21,10). After both moves the second player can win.
In the third sample, the first player has no moves.
In the fourth sample, the first player wins in one move, taking 30 modulo 10. | instruction | 0 | 72,777 | 19 | 145,554 |
Tags: games, math
Correct Solution:
```
def solve(a, b):
if a == 0:
return False
if solve(b % a, a):
b //= a
return not (b % (a + 1) & 1)
return True
n = int(input())
for _ in range(n):
a, b = [int(x) for x in input().split()]
if a > b:
a, b = b, a
if solve(a, b):
print("First")
else:
print("Second")
``` | output | 1 | 72,777 | 19 | 145,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:
* Replace b with b - ak. Number k can be chosen by the player, considering the limitations that k > 0 and b - ak ≥ 0. Number k is chosen independently each time an active player casts a spell.
* Replace b with b mod a.
If a > b, similar moves are possible.
If at least one of the numbers equals zero, a player can't make a move, because taking a remainder modulo zero is considered somewhat uncivilized, and it is far too boring to subtract a zero. The player who cannot make a move, loses.
To perform well in the magic totalizator, you need to learn to quickly determine which player wins, if both wizards play optimally: the one that moves first or the one that moves second.
Input
The first line contains a single integer t — the number of input data sets (1 ≤ t ≤ 104). Each of the next t lines contains two integers a, b (0 ≤ a, b ≤ 1018). The numbers are separated by a space.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output
For any of the t input sets print "First" (without the quotes) if the player who moves first wins. Print "Second" (without the quotes) if the player who moves second wins. Print the answers to different data sets on different lines in the order in which they are given in the input.
Examples
Input
4
10 21
31 10
0 1
10 30
Output
First
Second
Second
First
Note
In the first sample, the first player should go to (11,10). Then, after a single move of the second player to (1,10), he will take 10 modulo 1 and win.
In the second sample the first player has two moves to (1,10) and (21,10). After both moves the second player can win.
In the third sample, the first player has no moves.
In the fourth sample, the first player wins in one move, taking 30 modulo 10.
Submitted Solution:
```
def gcd(a, b):
a, b = min(a, b), max(a, b)
if a == 0:
return False
if not gcd(b % a, a):
return True
if a % 2 == 1:
return 1 - (b // a) % 2
ans1 = True
ans2 = False
j = a
while j <= b:
ans1 ^= (b // j) % 2
j *= a
j = a
while j <= b - a:
ans2 ^= ((b - a) // j) % 2
j *= a
return ans1 | ans2
t = int(input())
for i in range(t):
a, b = map(int, input().split())
if gcd(a, b):
print("First")
else:
print("Second")
``` | instruction | 0 | 72,778 | 19 | 145,556 |
No | output | 1 | 72,778 | 19 | 145,557 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items.
Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.
Who loses if both players play optimally and Stas's turn is first?
Input
The only input line has three integers a, b, n (1 ≤ a ≤ 10000, 1 ≤ b ≤ 30, 2 ≤ n ≤ 109) — the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.
Output
Output "Stas" if Masha wins. Output "Masha" if Stas wins. In case of a draw, output "Missing".
Examples
Input
2 2 10
Output
Masha
Input
5 5 16808
Output
Masha
Input
3 1 4
Output
Stas
Input
1 4 10
Output
Missing
Note
In the second example the initial number of ways is equal to 3125.
* If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat.
* But if Stas increases the number of items, then any Masha's move will be losing. | instruction | 0 | 72,847 | 19 | 145,694 |
Tags: dp, games
Correct Solution:
```
a, b, L = list(map(int, input().split()))
import sys
import math
if a == 1 and 2 ** b >= L:
print("Missing")
sys.exit()
memo = {}
memo[(32001, 1)] = 0
memo[(1, 30)] = 0
for i in range(min(int(L ** (1 / b)) + 1, 32000), a - 1, -1):
for j in range(29, b - 1, -1):
# If it's not a terminal state, we need to compute the mex
if i ** j >= L:
continue
s = set()
if (i + 1) ** j < L:
s.add(memo[(i + 1, j)])
if i ** (j + 1) < L:
s.add(memo[(i, j + 1)])
mex = 0
while mex in s:
mex += 1
memo[(i, j)] = mex
if memo[(a, b)] > 0:
print("Masha")
else:
print("Stas")
``` | output | 1 | 72,847 | 19 | 145,695 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items.
Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.
Who loses if both players play optimally and Stas's turn is first?
Input
The only input line has three integers a, b, n (1 ≤ a ≤ 10000, 1 ≤ b ≤ 30, 2 ≤ n ≤ 109) — the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.
Output
Output "Stas" if Masha wins. Output "Masha" if Stas wins. In case of a draw, output "Missing".
Examples
Input
2 2 10
Output
Masha
Input
5 5 16808
Output
Masha
Input
3 1 4
Output
Stas
Input
1 4 10
Output
Missing
Note
In the second example the initial number of ways is equal to 3125.
* If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat.
* But if Stas increases the number of items, then any Masha's move will be losing. | instruction | 0 | 72,848 | 19 | 145,696 |
Tags: dp, games
Correct Solution:
```
a, b, L = list(map(int, input().split()))
memo = {}
#10^9 rougly equals 31700 * 31700
memo[(31701, 1)] = ((L - 31701) + 1)% 2
#2**30 > 10^9
memo[(1, 30)] = -1
for i in range(31700, a - 1, -1):
for j in range(29, b - 1, -1):
if i**j>=L:
continue
s = set()
if (i + 1) ** j < L:
s.add(memo[(i + 1, j)])
if i ** (j + 1) < L:
s.add(memo[(i, j + 1)])
if 0 not in s and -1 in s:
memo[(i, j)] = -1
else:
mex = 0
while mex in s:
mex += 1
memo[(i, j)] = mex
if memo[(a, b)] > 0:
print("Masha")
elif memo[(a, b)] == -1:
print("Missing")
else:
print("Stas")
``` | output | 1 | 72,848 | 19 | 145,697 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items.
Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.
Who loses if both players play optimally and Stas's turn is first?
Input
The only input line has three integers a, b, n (1 ≤ a ≤ 10000, 1 ≤ b ≤ 30, 2 ≤ n ≤ 109) — the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.
Output
Output "Stas" if Masha wins. Output "Masha" if Stas wins. In case of a draw, output "Missing".
Examples
Input
2 2 10
Output
Masha
Input
5 5 16808
Output
Masha
Input
3 1 4
Output
Stas
Input
1 4 10
Output
Missing
Note
In the second example the initial number of ways is equal to 3125.
* If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat.
* But if Stas increases the number of items, then any Masha's move will be losing. | instruction | 0 | 72,849 | 19 | 145,698 |
Tags: dp, games
Correct Solution:
```
a, b, L = list(map(int, input().split()))
import sys
import math
memo = {}
memo[(31701, 1)] = ((L - 31701) + 1)% 2
memo[(1, 30)] = -1
# memo[(a, b)] = 0 if a ** b >= L else 1
# max_a = min(int(L ** (1 / b)) + 1, int(L ** (1 / 2)) + 1)
for i in range(31700, a - 1, -1):
for j in range(29, b - 1, -1):
if i ** j >= L:
continue
s = set()
if (i + 1) ** j < L:
s.add(memo[(i + 1, j)])
if i ** (j + 1) < L:
s.add(memo[(i, j + 1)])
if 0 not in s and -1 in s:
memo[(i, j)] = -1
else:
mex = 0
while mex in s:
mex += 1
memo[(i, j)] = mex
if memo[(a, b)] > 0:
print("Masha")
elif memo[(a, b)] == -1:
print("Missing")
else:
print("Stas")
``` | output | 1 | 72,849 | 19 | 145,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items.
Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.
Who loses if both players play optimally and Stas's turn is first?
Input
The only input line has three integers a, b, n (1 ≤ a ≤ 10000, 1 ≤ b ≤ 30, 2 ≤ n ≤ 109) — the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.
Output
Output "Stas" if Masha wins. Output "Masha" if Stas wins. In case of a draw, output "Missing".
Examples
Input
2 2 10
Output
Masha
Input
5 5 16808
Output
Masha
Input
3 1 4
Output
Stas
Input
1 4 10
Output
Missing
Note
In the second example the initial number of ways is equal to 3125.
* If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat.
* But if Stas increases the number of items, then any Masha's move will be losing.
Submitted Solution:
```
from math import log
def first_wins(a, b, n):
if pow(a + 1, b) >= n and pow(a, b + 1) >= n:
return False
if pow(a, b + 1) >= n:
x = int(log(n, a)) - 1
while pow(a, x) < n:
x += 1
return not ((n - pow(a, x - 1)) % 2)
return (not first_wins(a + 1, b, n) or not first_wins(a, b + 1, n))
a, b, n = map(int, input().split())
if a == 1 and pow(2, b) >= n:
print('Missing')
elif first_wins(a, b, n):
print('Masha')
else:
print('Stas')
``` | instruction | 0 | 72,850 | 19 | 145,700 |
No | output | 1 | 72,850 | 19 | 145,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items.
Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.
Who loses if both players play optimally and Stas's turn is first?
Input
The only input line has three integers a, b, n (1 ≤ a ≤ 10000, 1 ≤ b ≤ 30, 2 ≤ n ≤ 109) — the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.
Output
Output "Stas" if Masha wins. Output "Masha" if Stas wins. In case of a draw, output "Missing".
Examples
Input
2 2 10
Output
Masha
Input
5 5 16808
Output
Masha
Input
3 1 4
Output
Stas
Input
1 4 10
Output
Missing
Note
In the second example the initial number of ways is equal to 3125.
* If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat.
* But if Stas increases the number of items, then any Masha's move will be losing.
Submitted Solution:
```
a, b, L = list(map(int, input().split()))
import sys
import math
# a**b <= L
# b <= log(L,a)
# if a==1 then b<30
def solve(a, b):
memo = {}
max_exponent = int(math.log(L, a)) + 1 if a != 1 else int(math.log(L, 2)) + 1
for i in range(int(L ** (1 / b)) + 1, a - 1, -1):
for j in range(max_exponent, b - 1, -1):
# If it's not a terminal state, we need to compute the mex
if i ** j >= L:
continue
s = set()
if (i + 1) ** j < L:
s.add(memo[(i + 1, j)])
if i ** (j + 1) < L:
s.add(memo[(i, j + 1)])
mex = 0
while mex in s:
mex += 1
memo[(i, j)] = mex
if memo[(a, b)] > 0:
return "Masha"
else:
return "Stas"
if a == 1 and 2 ** b >= L:
print("Missing")
sys.exit()
if a == 1:
if solve(2, b) == "Stas":
print("Masha")
else:
print("Stas")
else:
print(solve(a, b))
``` | instruction | 0 | 72,851 | 19 | 145,702 |
No | output | 1 | 72,851 | 19 | 145,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items.
Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.
Who loses if both players play optimally and Stas's turn is first?
Input
The only input line has three integers a, b, n (1 ≤ a ≤ 10000, 1 ≤ b ≤ 30, 2 ≤ n ≤ 109) — the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.
Output
Output "Stas" if Masha wins. Output "Masha" if Stas wins. In case of a draw, output "Missing".
Examples
Input
2 2 10
Output
Masha
Input
5 5 16808
Output
Masha
Input
3 1 4
Output
Stas
Input
1 4 10
Output
Missing
Note
In the second example the initial number of ways is equal to 3125.
* If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat.
* But if Stas increases the number of items, then any Masha's move will be losing.
Submitted Solution:
```
a, b, L = list(map(int, input().split()))
import sys
import math
# a**b <= L
# b <= log(L,a)
# if a==1 then b<30
def solve(a, b):
memo = {}
max_exponent = int(math.log(L, a)) + 1 if a != 1 else int(math.log(L, 2)) + 1
for i in range(int(L ** (1 / b)) + 1, a - 1, -1):
for j in range(max_exponent, b - 1, -1):
# If it's not a terminal state, we need to compute the mex
if i ** j >= L:
continue
s = set()
if (i + 1) ** j < L:
s.add(memo[(i + 1, j)])
if i ** (j + 1) < L:
s.add(memo[(i, j + 1)])
mex = 0
while mex in s:
mex += 1
memo[(i, j)] = mex
if memo[(a, b)] > 0:
return "Masha"
else:
return "Stas"
if a == 1 and 2 ** b >= L:
print("Missing")
sys.exit()
if a == 1:
if solve(2, b) == "Stas":
print("Mash")
else:
print("Stas")
else:
solve(a, b)
``` | instruction | 0 | 72,852 | 19 | 145,704 |
No | output | 1 | 72,852 | 19 | 145,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items.
Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.
Who loses if both players play optimally and Stas's turn is first?
Input
The only input line has three integers a, b, n (1 ≤ a ≤ 10000, 1 ≤ b ≤ 30, 2 ≤ n ≤ 109) — the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.
Output
Output "Stas" if Masha wins. Output "Masha" if Stas wins. In case of a draw, output "Missing".
Examples
Input
2 2 10
Output
Masha
Input
5 5 16808
Output
Masha
Input
3 1 4
Output
Stas
Input
1 4 10
Output
Missing
Note
In the second example the initial number of ways is equal to 3125.
* If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat.
* But if Stas increases the number of items, then any Masha's move will be losing.
Submitted Solution:
```
from math import log
def first_wins(a, b, n):
if pow(a, b) >= n:
return True
if pow(a, b + 1) >= n:
x = log(n, a) - 1
while pow(a, x) < n:
x += 1
return not ((n - pow(a, x - 1)) % 2)
if not first_wins(a + 1, b, n) or not first_wins(a, b + 1, n):
return True
return False
a, b, n = map(int, input().split())
if a == 1 and pow(2, b) >= n:
print('Missing')
elif first_wins(a, b, n):
print('Masha')
else:
print('Stas')
``` | instruction | 0 | 72,853 | 19 | 145,706 |
No | output | 1 | 72,853 | 19 | 145,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | instruction | 0 | 72,966 | 19 | 145,932 |
Tags: brute force, implementation
Correct Solution:
```
import sys
def finder(arr):
if any(map(lambda x: x.find('.xx') > -1 or
x.find('xx.') > -1 or
x.find('x.x') > -1, arr)):
print('YES')
sys.exit()
field = [input() for _ in range(4)]
finder(field)
transposed = list(map(lambda x: ''.join(x), zip(*field[::-1])))
finder(transposed)
def diags(arr):
for y_of in range(2):
for x_of in range(2):
yield ''.join([arr[y_of + i][x_of + i] for i in range(3)])
yield ''.join([arr[3-(y_of + i)][x_of + i] for i in range(3)])
finder(list(diags(field)))
print('NO')
``` | output | 1 | 72,966 | 19 | 145,933 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | instruction | 0 | 72,967 | 19 | 145,934 |
Tags: brute force, implementation
Correct Solution:
```
def check(AL):
for i in AL:
if (i[:3].count('x')==2 and '.' in i[:3]) or (i[1:].count('x')==2 and '.' in i[1:]):
return True
B=[[0,0],[0,1],[1,0],[1,1]]
C=[]
for a,b in B:
l=[]
for i in range(3):l.append(AL[a+i][b+i])
C.append(l)
for i in C:
if i.count('x')==2 and '.'in i:return True
return False
A=[]
for i in range(4):A.append(input())
D=[]
for i in range(4):
l=[]
for j in range(4):
l.append(A[j][3-i])
D.append(l)
print('YES' if check(A) or check(D) else 'NO')
``` | output | 1 | 72,967 | 19 | 145,935 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | instruction | 0 | 72,968 | 19 | 145,936 |
Tags: brute force, implementation
Correct Solution:
```
a = []
for i in range(4):
s = input()
for elem in s:
a.append(elem)
def c(q, w, e):
q -= 1
w -= 1
e -= 1
q = a[q]
w = a[w]
e = a[e]
kr = 0
ps = 0
if (q == 'o') or (w == 'o') or (e == 'o'):
return False
if (q == 'x'):
kr += 1
if (w == 'x'):
kr += 1
if (e == 'x'):
kr += 1
if (kr == 2):
print("YES")
exit()
return True
else:
return False
c(1, 2, 3)
c(2, 3, 4)
c(5, 6, 7)
c(6, 7, 8)
c(9, 10, 11)
c(10, 11, 12)
c(13, 14, 15)
c(14, 15, 16)
c(1, 5, 9)
c(5, 9, 13)
c(2, 6, 10)
c(6, 10, 14)
c(3, 7, 11)
c(7, 11, 15)
c(4, 8, 12)
c(8, 12, 16)
c(1, 6, 11)
c(5, 10, 15)
c(2, 7, 12)
c(6, 11, 16)
c(3, 6, 9)
c(7, 10, 13)
c(4, 7, 10)
c(8, 11, 14)
print("NO")
``` | output | 1 | 72,968 | 19 | 145,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | instruction | 0 | 72,969 | 19 | 145,938 |
Tags: brute force, implementation
Correct Solution:
```
x=[]
for i in range(4):
x.append(list(input()))
def check(a,b):
x[a][b]='x'
for i in range(4):
for j in range(2):
if x[i][j]+x[i][j+1]+x[i][j+2]=='xxx':
return('YES')
for i in range(2):
for j in range(4):
if x[i][j]+x[i+1][j]+x[i+2][j]=='xxx':
return('YES')
if x[2][0]+x[1][1]+x[0][2]=='xxx':return('YES')
if x[3][0]+x[2][1]+x[1][2]=='xxx':return('YES')
if x[2][1]+x[1][2]+x[0][3]=='xxx':return('YES')
if x[3][1]+x[2][2]+x[1][3]=='xxx':return('YES')
if x[0][0]+x[1][1]+x[2][2]=='xxx':return('YES')
if x[1][0]+x[2][1]+x[3][2]=='xxx':return('YES')
if x[0][1]+x[1][2]+x[2][3]=='xxx':return('YES')
if x[1][1]+x[2][2]+x[3][3]=='xxx':return('YES')
return('NO')
for i in range(4):
for j in range(4):
if x[i][j]=='.':
if check(i,j)=='YES':
print('YES')
quit()
x[i][j]='.'
else:
print('NO')
``` | output | 1 | 72,969 | 19 | 145,939 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | instruction | 0 | 72,970 | 19 | 145,940 |
Tags: brute force, implementation
Correct Solution:
```
def verify(x):
won = 0
for row in x:
won += 'xxx' in row
xt = ["".join([line[i] for line in x]) for i in range(4)]
for col in xt:
won += 'xxx' in col
for mat in [x, [line[::-1] for line in x]]:
won += 'xxx' in mat[0][0] + mat[1][1] + mat[2][2] + mat[3][3]
won += 'xxx' in mat[0][1] + mat[1][2] + mat[2][3]
won += 'xxx' in mat[1][0] + mat[2][1] + mat[3][2]
return won
def split_in_rows(x):
return [x[i:i+4] for i in range(0, len(x), 4)]
if __name__ == '__main__':
nlines = 4
lines = list()
for _ in range(nlines):
lines.append(input())
lines = "".join(lines)
won = 0
i = 0
while won == 0 and i < len(lines):
if lines[i] == '.':
won += verify(split_in_rows(lines[:i]+'x'+lines[i+1:]))
i += 1
if won > 0:
print("YES")
else:
print("NO")
``` | output | 1 | 72,970 | 19 | 145,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | instruction | 0 | 72,971 | 19 | 145,942 |
Tags: brute force, implementation
Correct Solution:
```
t = [input() for _ in range(4)]
w = ["xx.", ".xx", "x.x"]
if any(i in j for i in w for j in t):
print("YES")
else:
for p in range(4):
c = "".join([r[p] for r in t])
if any(i in c for i in w):
print("YES")
break
else:
d = [t[0][0]+t[1][1]+t[2][2]+t[3][3], t[1][0]+t[2][1]+t[3][2], t[0][1]+t[1][2]+t[2][3], t[3][0]+t[2][1]+t[1][2]+t[0][3], t[2][0]+t[1][1]+t[0][2], t[3][1]+t[2][2]+t[1][3]]
if any(i in j for i in w for j in d):
print("YES")
else:
print("NO")
``` | output | 1 | 72,971 | 19 | 145,943 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | instruction | 0 | 72,972 | 19 | 145,944 |
Tags: brute force, implementation
Correct Solution:
```
A = []
for i in range(4):
A.append(input())
answer = False
answer_platform = ['xx.', 'x.x', '.xx']
for i in range(4):
if A[i][0:3] in answer_platform or A[i][1:] in answer_platform:
answer = True
if A[0][i] + A[1][i] + A[2][i] in answer_platform or A[1][i] + A[2][i] + A[3][i] in answer_platform :
answer = True
if A[1][0] + A[2][1] + A[3][2] in answer_platform or A[0][1] + A[1][2] + A[2][3] in answer_platform or A[0][0] + A[1][1] + A[2][2] in answer_platform or A[1][1] + A[2][2]+A[3][3] in answer_platform:
answer = True
if A[0][2] + A[1][1] + A[2][0] in answer_platform or A[1][3] + A[2][2] + A[3][1] in answer_platform or A[0][3] + A[1][2] + A[2][1] in answer_platform or A[1][2] + A[2][1] + A[3][0] in answer_platform:
answer = True
if answer:
print("YES")
else:
print("NO")
``` | output | 1 | 72,972 | 19 | 145,945 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | instruction | 0 | 72,973 | 19 | 145,946 |
Tags: brute force, implementation
Correct Solution:
```
from sys import stdin ,stdout
from os import path
rd = lambda:stdin.readline().strip()
wr = stdout.write
if(path.exists('input.txt')):
stdin = open("input.txt","r")
import time ,math
#------------------------------------=
mylist= []
for i in range(4):
mylist.append(rd())
def validUpOrDown(x,y):
if x+2 < 4 :
counterX = counterD = 0
for i in range(x,x+3):
if mylist[i][y] == 'x':
counterX+=1
elif mylist[i][y] == '.':
counterD +=1
if counterD == 1 and counterX == 2:
return True
if x-2 >= 0 :
counterX = counterD = 0
for i in range(x,x-3,-1):
if mylist[i][y] == 'x':
counterX+=1
elif mylist[i][y] == '.':
counterD +=1
if counterD == 1 and counterX == 2:
return True
def validLeftOrRight(x,y):
if y+2 < 4 :
counterX = counterD = 0
for i in range(y,y+3):
if mylist[x][i] == 'x':
counterX+=1
elif mylist[x][i] == '.':
counterD +=1
if counterD == 1 and counterX == 2:
return True
if y-2 >= 0 :
counterX = counterD = 0
for i in range(y,y-3,-1):
if mylist[x][i] == 'x':
counterX+=1
elif mylist[x][i] == '.':
counterD +=1
if counterD == 1 and counterX == 2:
return True
def validDiagonal(x,y):
if x+2 < 4 and y+2 < 4:
counter = counterX = counterD =0
x1,y1 = x,y
while counter < 3:
if mylist[x1][y1] == 'x':
counterX +=1
elif mylist[x1][y1] =='.':
counterD+=1
counter+=1
x1+=1
y1+=1
if counterX == 2 and counterD ==1 :
return True
if x+2 < 4 and y-2 >= 0:
counter = counterX = counterD =0
x1,y1 = x,y
while counter < 3:
if mylist[x1][y1] == 'x':
counterX +=1
elif mylist[x1][y1] =='.':
counterD+=1
counter+=1
x1+=1
y1-=1
if counterX == 2 and counterD ==1 :
return True
if x-2 >= 0 and y+2 < 4:
counter = counterX = counterD =0
x1,y1 = x,y
while counter < 3:
if mylist[x1][y1] == 'x':
counterX +=1
elif mylist[x1][y1] =='.':
counterD+=1
counter+=1
x1-=1
y1+=1
if counterX == 2 and counterD ==1 :
return True
if x-2 >= 0 and y-2>=0:
counter = counterX = counterD =0
x1,y1 = x,y
while counter < 3:
if mylist[x1][y1] == 'x':
counterX +=1
elif mylist[x1][y1] =='.':
counterD+=1
counter+=1
x1-=1
y1-=1
if counterX == 2 and counterD ==1 :
return True
wrong = True
for i in range(len(mylist)):
for j in range(len(mylist[i])):
if mylist[i][j] == 'x':
if validLeftOrRight(i,j) == True or validUpOrDown(i,j) == True or validDiagonal(i,j) == True:
wrong = False
break
print("YES" if wrong == False else "NO")
``` | output | 1 | 72,973 | 19 | 145,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
Submitted Solution:
```
ttt = []
xs = []
mA = [-2, -2, -2, 0, 0, 2, 2, 2]
mB = [-2, 0, 2, -2, 2, -2, 0, 2]
mA2 = [-1, -1, -1, 0, 0, 1, 1, 1]
mB2 = [-1, 0, 1, -1, 1, -1, 0, 1]
for a in range(4):
red = input()
ttt.append(red)
for b in range(4):
if red[b] == "x":
xs.append([a, b])
def isFree(a, b):
if a>= 0 and b>= 0 and a <=3 and b<=3:
return 1
else:
return 0
sol = "NO"
for pos in xs:
pa = pos[0]
pb = pos[1]
for mo in range(8):
pa1 = pa+mA[mo]
pb1 = pb+mB[mo]
if isFree(pa1, pb1):
pa2 = pa+mA2[mo]
pb2 = pb+mB2[mo]
if ttt[pa2][pb2] == "." and ttt[pa1][pb1] == "x" or ttt[pa2][pb2] == "x" and ttt[pa1][pb1] == ".":
sol = "YES"
break
if sol == "YES":
break
print(sol)
``` | instruction | 0 | 72,974 | 19 | 145,948 |
Yes | output | 1 | 72,974 | 19 | 145,949 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
Submitted Solution:
```
import sys, copy
A = []
def isAllX(a1, a2, b1, b2, c1, c2):
global A
if A[a1][a2] == "x" and A[b1][b2] == "x" and A[c1][c2] == "x":
return True
return False
for i in range(4):
s = input()
B = []
for i in s:
B.append(i)
A.append(B)
for i in range(4):
for j in range(4):
if A[i][j] == ".":
C = copy.deepcopy(A)
A[i][j] = "x"
if isAllX(0, 0, 0, 1, 0, 2) or isAllX(0, 1, 0, 2, 0, 3)\
or isAllX(1, 0, 1, 1, 1, 2)\
or isAllX(1, 1, 1, 2, 1, 3)\
or isAllX(2, 0, 2, 1, 2, 2)\
or isAllX(2, 1, 2, 2, 2, 3)\
or isAllX(3, 0, 3, 1, 3, 2)\
or isAllX(3, 1, 3, 2, 3, 3)\
or isAllX(0, 0, 1, 0, 2, 0)\
or isAllX(1, 0, 2, 0, 3, 0)\
or isAllX(0, 1, 1, 1, 2, 1)\
or isAllX(1, 1, 2, 1, 3, 1)\
or isAllX(0, 2, 1, 2, 2, 2)\
or isAllX(1, 2, 2, 2, 3, 2)\
or isAllX(0, 3, 1, 3, 2, 3)\
or isAllX(1, 3, 2, 3, 3, 3)\
or isAllX(0, 0, 1, 1, 2, 2)\
or isAllX(1, 1, 2, 2, 3, 3)\
or isAllX(1, 0, 2, 1, 3, 2)\
or isAllX(0, 1, 1, 2, 2, 3)\
or isAllX(0, 3, 1, 2, 2, 1)\
or isAllX(1, 2, 2, 1, 3, 0)\
or isAllX(0, 2, 1, 1, 2, 0)\
or isAllX(1, 3, 2, 2, 3, 1):
print("YES")
sys.exit()
A = copy.deepcopy(C)
print("NO")
``` | instruction | 0 | 72,975 | 19 | 145,950 |
Yes | output | 1 | 72,975 | 19 | 145,951 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
Submitted Solution:
```
def checkwinning(a):
for j in range(4):
for i in range(2):
xc = sum([a[u][j] == "x" for u in range(i,i+3)])
dotc = sum([a[u][j] =="." for u in range(i,i+3)])
if (xc == 2 and dotc ==1):
return True
for i in range(4):
for j in range(2):
xc = sum([a[i][u] == "x" for u in range(j,j+3)])
dotc = sum([a[i][u] =="." for u in range(j,j+3)])
if (xc == 2 and dotc ==1):
return True
for i in range(2):
for j in range(2):
xc = sum([a[i+k][j+k] == "x" for k in range(3)])
dotc =sum([a[i+k][j+k] == "." for k in range(3)])
if (xc == 2 and dotc ==1):
return True
for i in range(2):
for j in range(2,4):
xc = sum([a[i+k][j-k] == "x" for k in range(3)])
dotc =sum([a[i+k][j-k] == "." for k in range(3)])
if (xc == 2 and dotc ==1):
return True
if __name__ == "__main__":
a=[]
for i in range(4):
a.append((list(input().strip())))
if(checkwinning(a)):
print("YES")
else:
print("NO")
``` | instruction | 0 | 72,976 | 19 | 145,952 |
Yes | output | 1 | 72,976 | 19 | 145,953 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
Submitted Solution:
```
import sys
rows = [input() for i in range(4)]
cols = []
for j in range(4):
col = [rows[i][j] for i in range(4)]
cols.append("".join(col))
diags = []
diags.append("".join([rows[i][i] for i in range(4)]))
diags.append("".join([rows[0][1], rows[1][2], rows[2][3]]))
diags.append("".join([rows[1][0], rows[2][1], rows[3][2]]))
diags.append("".join([rows[i][3-i] for i in range(4)]))
diags.append("".join([rows[0][2], rows[1][1], rows[2][0]]))
diags.append("".join([rows[1][3], rows[2][2], rows[3][1]]))
strs = rows + cols + diags
winstrs = ["xx.", "x.x", ".xx"]
for winstr in winstrs:
for s in strs:
if winstr in s:
print("YES")
sys.exit(0)
print("NO")
``` | instruction | 0 | 72,977 | 19 | 145,954 |
Yes | output | 1 | 72,977 | 19 | 145,955 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
Submitted Solution:
```
def horizontal():
# xStreak = 0
# pointCounter = 0
for i in range(len(field)):
xStreak = 0
pointCounter = 0
borderPointCounter = 0
for j in range(len(field[i])):
if (j == 0 and field[i][j] == 'o') or (j == 3 and field[i][j] == 'o'):
continue
elif (field[i][j] == 'o'):
break
elif (field[i][j] == 'x'):
xStreak += 1
elif (field[i][j] == '.'):
pointCounter += 1
if (field[i][j] == '.' and (j == 0 or j == 3)):
borderPointCounter += 1
if(pointCounter == 1 and xStreak >= 2):
print("YES")
return True
if (pointCounter == 2 and xStreak == 2 and borderPointCounter == 2 and field[i][0] == '.' and field[i][3] == '.'):
print("YES")
return True
if (pointCounter == 2 and xStreak == 2 and borderPointCounter > 0):
print("YES")
return True
return False
def vertical():
# xStreak = 0
# pointCounter = 0
for j in range(len(field)):
xStreak = 0
pointCounter = 0
borderPointCounter = 0
for i in range(len(field[j])):
if (j == 0 and field[i][j] == 'o') or (j == 3 and field[i][j] == 'o'):
continue
elif (field[i][j] == 'o'):
break
elif (field[i][j] == 'x'):
xStreak += 1
elif (field[i][j] == '.'):
pointCounter += 1
if (field[i][j] == '.' and (i == 0 or i == 3)):
borderPointCounter += 1
if (pointCounter == 1 and xStreak >= 2):
print("YES")
return True
if (pointCounter == 2 and xStreak == 2 and borderPointCounter == 2 and field[0][j] == '.' and field[3][j] == '.'):
print("YES")
return True
if (pointCounter == 2 and xStreak == 2 and borderPointCounter > 0):
print("YES")
return True
return False
def diagonal1():
if (field[0][1] == 'x' and field[1][2] == 'x' and field[2][3] == '.'):
print("YES")
return True
if (field[0][1] == 'x' and field[1][2] == '.' and field[2][3] == 'x'):
print("YES")
return True
if (field[0][1] == '.' and field[1][2] == 'x' and field[2][3] == 'x'):
print("YES")
return True
if (field[1][0] == 'x' and field[2][1] == 'x' and field[3][2] == '.'):
print("YES")
return True
if (field[1][0] == 'x' and field[2][1] == '.' and field[3][2] == 'x'):
print("YES")
return True
if (field[1][0] == '.' and field[2][1] == 'x' and field[3][2] == 'x'):
print("YES")
return True
if (field[2][0] == 'x' and field[1][1] == 'x' and field[0][2] == '.'):
print("YES")
return True
if (field[2][0] == 'x' and field[1][1] == '.' and field[0][2] == 'x'):
print("YES")
return True
if (field[2][0] == '.' and field[1][1] == 'x' and field[0][2] == 'x'):
print("YES")
return True
if (field[3][1] == 'x' and field[2][2] == 'x' and field[1][3] == '.'):
print("YES")
return True
if (field[3][1] == 'x' and field[2][2] == '.' and field[1][3] == 'x'):
print("YES")
return True
if (field[3][1] == '.' and field[2][2] == 'x' and field[1][3] == 'x'):
print("YES")
return True
return False
def diagonal2():
xStreak = 0
pointCounter = 0
borderPointCounter = 0
for i in range(len(field)):
if ((i == 0 and field[i][i] == 'o') or (i == 3 and field[i][i] == 'o')):
continue
elif (field[i][i] == 'o'):
return False
elif (field[i][i] == 'x'):
xStreak += 1
elif (field[i][i] == '.'):
pointCounter += 1
if ((i == 0 and field[i][i] == '.') or (i == 3 and field[i][i] == '.')):
borderPointCounter += 1
if(pointCounter == 1 and xStreak >= 2):
print("YES")
return True
if (pointCounter == 2 and xStreak == 2 and borderPointCounter == 2 and field[0][0] == '.' and field[3][3] == '.'):
print("YES")
return True
if (pointCounter == 2 and xStreak == 2 and borderPointCounter > 0):
print("YES")
return True
return False
def diagonal3():
xStreak = 0
pointCounter = 0
borderPointCounter = 0
for i in range(len(field)):
if (field[0][3] == 'o') or (field[3][0] == 'o'):
continue
elif (field[i][3 - i] == 'o'):
return False
elif (field[i][3 - i] == 'x'):
xStreak += 1
elif (field[i][3 - i] == '.'):
pointCounter += 1
if ((i == 0 and field[i][3 - i] == '.') or (i == 3 and field[i][3 - i] == '.')):
borderPointCounter += 1
if(pointCounter == 1 and xStreak >= 2):
print("YES")
return True
if (pointCounter == 2 and xStreak == 2 and borderPointCounter == 2 and field[0][3] == '.' and field[3][0] == '.'):
print("YES")
return True
if (pointCounter == 2 and xStreak == 2 and borderPointCounter > 0):
print("YES")
return True
return False
field = []
horiz = False
vertic = False
diag1 = False
diag2 = False
diag3 = False
i = 0
while (i < 4):
a = list(input())
field.append(a)
i += 1
horiz = horizontal()
if (horiz == False):
vertic = vertical()
if (horiz == False and vertic == False):
diag1 = diagonal1()
if (horiz == False and vertic == False and diag1 == False):
diag2 = diagonal2()
if (horiz == False and vertic == False and diag1 == False and diag2 == False):
diag3 = diagonal3()
if (horiz == False and vertic == False and diag1 == False and diag2 == False and diag3 == False):
print("NO")
#print(field)
``` | instruction | 0 | 72,978 | 19 | 145,956 |
No | output | 1 | 72,978 | 19 | 145,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
Submitted Solution:
```
field = []
triggered = False
for i in range(4):
field.append(input())
for i in field:
if ('.xx' in i) or ('x.x' in i) or ('xx.' in i):
print('YES')
triggered = True
if not triggered:
new_field = [[],[],[],[]]
for i in range(4):
for j in range(4):
new_field[j].append(field[i][j])
for i in range(4):
new_field[i] = "".join(new_field[i])
for i in new_field:
if ('.xx' in i) or ('x.x' in i) or ('xx.' in i):
print('YES')
break
else:
print('NO')
``` | instruction | 0 | 72,979 | 19 | 145,958 |
No | output | 1 | 72,979 | 19 | 145,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
Submitted Solution:
```
board = []
for i in range(4):
arr = [str(x) for x in input()]
board.append(arr)
def check(board):
for n in range(4):
for nums, item in enumerate(board[n]):
if item == '.':
board[n][nums] = 'x'
if (board[0][0]==board[0][1]==board[0][2]=='x' or
board[0][1]==board[0][2]==board[0][3]=='x' or
board[1][0]==board[1][1]==board[1][2]=='x' or
board[1][1]==board[1][2]==board[1][3]=='x' or
board[2][0]==board[2][1]==board[2][2]=='x' or
board[2][1]==board[2][2]==board[2][3]=='x' or
board[3][0]==board[3][1]==board[3][2]=='x' or
board[3][1]==board[3][2]==board[3][3]=='x' or
### Vertical
board[0][0]==board[1][0]==board[2][0]=='x' or
board[1][0]==board[2][0]==board[3][0]=='x' or
board[0][1]==board[1][1]==board[2][1]=='x' or
board[1][1]==board[2][1]==board[3][1]=='x' or
board[0][2]==board[1][2]==board[2][2]=='x' or
board[1][2]==board[2][2]==board[3][2]=='x' or
board[0][3]==board[1][3]==board[2][3]=='x' or
board[1][3]==board[2][3]==board[3][3]=='x' or
### Dioganal
board[0][2]==board[1][1]==board[2][0]=='x' or
board[0][3]==board[1][2]==board[2][1]=='x' or
board[1][2]==board[2][1]==board[3][0]=='x' or
board[1][3]==board[2][2]==board[3][1]=='x' or
board[0][1]==board[1][2]==board[2][3]=='x' or
board[0][0]==board[1][1]==board[2][2]=='x' or
board[1][1]==board[2][2]==board[3][3]=='x' or
board[1][0]==board[2][1]==board[3][2]=='x'):
return 'YES'
board[n][nums] = 'o'
return 'NO'
check(board)
``` | instruction | 0 | 72,980 | 19 | 145,960 |
No | output | 1 | 72,980 | 19 | 145,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
Input
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
Output
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
Examples
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
Note
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
Submitted Solution:
```
def myc(a,b,c,d,e,f):
return str(iph[a][b]+iph[c][d]+iph[e][f])
iph=[]
for i in range(4):
iph.append(str(input()))
ipv=[]
b=0
for i in range(4):
ipv.append(str(iph[0][i]+iph[1][i]+iph[2][i]+iph[3][i]))
for i in iph:
if 'x.x' in i or 'xx.' in i or '.xx' in i:
b=1
if 'ooo' in i:
b=2
break
if b!=2:
for i in ipv:
if 'x.x' in i or 'xx.' in i or '.xx' in i:
b=1
if 'ooo' in i:
b=2
break
if b!=2:
ipd=[myc(0,0,1,1,2,2),myc(1,1,2,2,3,3),myc(1,0,2,1,3,2),myc(0,1,1,2,2,3),
myc(0,2,1,1,2,0),myc(0,3,1,2,2,1),myc(1,2,2,1,3,0),myc(1,3,2,2,3,1)]
for i in ipv:
if 'x.x' in i or 'xx.' in i or '.xx' in i and b==0:
b=1
if 'ooo' in i:
b=2
break
if b==0 or b==2:
print('NO')
else:
print('YES')
``` | instruction | 0 | 72,981 | 19 | 145,962 |
No | output | 1 | 72,981 | 19 | 145,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who can't move the chip loses. If the game lasts for 106 turns the draw is announced.
Vasya was performing big laboratory work in "Spelling and parts of speech" at night before the game, so he fell asleep at the very beginning of the game. Petya decided to take the advantage of this situation and make both Petya's and Vasya's moves.
Your task is to help Petya find out if he can win the game or at least draw a tie.
Input
The first line of input contain two integers n and m — the number of vertices and the number of edges in the graph (2 ≤ n ≤ 105, 0 ≤ m ≤ 2·105).
The next n lines contain the information about edges of the graph. i-th line (1 ≤ i ≤ n) contains nonnegative integer ci — number of vertices such that there is an edge from i to these vertices and ci distinct integers ai, j — indices of these vertices (1 ≤ ai, j ≤ n, ai, j ≠ i).
It is guaranteed that the total sum of ci equals to m.
The next line contains index of vertex s — the initial position of the chip (1 ≤ s ≤ n).
Output
If Petya can win print «Win» in the first line. In the next line print numbers v1, v2, ..., vk (1 ≤ k ≤ 106) — the sequence of vertices Petya should visit for the winning. Vertex v1 should coincide with s. For i = 1... k - 1 there should be an edge from vi to vi + 1 in the graph. There must be no possible move from vertex vk. The sequence should be such that Petya wins the game.
If Petya can't win but can draw a tie, print «Draw» in the only line. Otherwise print «Lose».
Examples
Input
5 6
2 2 3
2 4 5
1 4
1 5
0
1
Output
Win
1 2 4 5
Input
3 2
1 3
1 1
0
2
Output
Lose
Input
2 2
1 2
1 1
1
Output
Draw
Note
In the first example the graph is the following:
<image>
Initially the chip is located at vertex 1. In the first move Petya moves the chip to vertex 2, after that he moves it to vertex 4 for Vasya. After that he moves to vertex 5. Now it is Vasya's turn and there is no possible move, so Petya wins.
In the second example the graph is the following:
<image>
Initially the chip is located at vertex 2. The only possible Petya's move is to go to vertex 1. After that he has to go to 3 for Vasya. Now it's Petya's turn but he has no possible move, so Petya loses.
In the third example the graph is the following:
<image>
Petya can't win, but he can move along the cycle, so the players will draw a tie. | instruction | 0 | 73,047 | 19 | 146,094 |
Tags: dfs and similar, dp, games, graphs
Correct Solution:
```
n,m = map(int, input().split())
g = [[] for i in range(n)]
fs = set()
for i in range(n):
a = list(map(int , input().split()))
c = a[0]
if c == 0:
fs.add(i)
continue
for j in range(1,c+1):
g[i].append(a[j]-1)
s = int(input())-1
prev0 = [None for i in range(n)]
prev1=[None for i in range(n)]
vis0 = [0 for i in range(n)]
vis0[s]=1
vis1 = [0 for i in range(n)]
q = [(s, 0)]
ans = None
draw = False
while len(q) > 0:
v, c = q[0]
del q[0]
for u in g[v]:
if c == 0:
if vis1[u] == 0:
vis1[u] =1
q.append((u, 1))
prev1[u] =v
if u in fs:
ans = u
break
elif c == 1:
if vis0[u] == 0:
vis0[u] =1
q.append((u, 0))
prev0[u] =v
if ans is not None:
break
if ans is None:
q = [s]
vis=[0 for i in range(n)]
vis[s]=1
nxt = [0 for i in range(n)]
while len(q) > 0:
v = q[-1]
if nxt[v] < len(g[v]):
u = g[v][nxt[v]]
if vis[u] == 1:
print('Draw')
exit()
elif vis[u] == 0:
vis[u]=1
q.append(u)
nxt[v] +=1
else:
vis[v] = 2
del q[-1]
print('Lose')
exit()
arn = []
nxt = ans
while nxt is not None:
arn.append(nxt)
if len(arn) % 2 == 1:
nxt = prev1[nxt]
else:
nxt = prev0[nxt]
print('Win')
arn = list(reversed(arn))
print(' '.join([str(i+1) for i in arn]))
``` | output | 1 | 73,047 | 19 | 146,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who can't move the chip loses. If the game lasts for 106 turns the draw is announced.
Vasya was performing big laboratory work in "Spelling and parts of speech" at night before the game, so he fell asleep at the very beginning of the game. Petya decided to take the advantage of this situation and make both Petya's and Vasya's moves.
Your task is to help Petya find out if he can win the game or at least draw a tie.
Input
The first line of input contain two integers n and m — the number of vertices and the number of edges in the graph (2 ≤ n ≤ 105, 0 ≤ m ≤ 2·105).
The next n lines contain the information about edges of the graph. i-th line (1 ≤ i ≤ n) contains nonnegative integer ci — number of vertices such that there is an edge from i to these vertices and ci distinct integers ai, j — indices of these vertices (1 ≤ ai, j ≤ n, ai, j ≠ i).
It is guaranteed that the total sum of ci equals to m.
The next line contains index of vertex s — the initial position of the chip (1 ≤ s ≤ n).
Output
If Petya can win print «Win» in the first line. In the next line print numbers v1, v2, ..., vk (1 ≤ k ≤ 106) — the sequence of vertices Petya should visit for the winning. Vertex v1 should coincide with s. For i = 1... k - 1 there should be an edge from vi to vi + 1 in the graph. There must be no possible move from vertex vk. The sequence should be such that Petya wins the game.
If Petya can't win but can draw a tie, print «Draw» in the only line. Otherwise print «Lose».
Examples
Input
5 6
2 2 3
2 4 5
1 4
1 5
0
1
Output
Win
1 2 4 5
Input
3 2
1 3
1 1
0
2
Output
Lose
Input
2 2
1 2
1 1
1
Output
Draw
Note
In the first example the graph is the following:
<image>
Initially the chip is located at vertex 1. In the first move Petya moves the chip to vertex 2, after that he moves it to vertex 4 for Vasya. After that he moves to vertex 5. Now it is Vasya's turn and there is no possible move, so Petya wins.
In the second example the graph is the following:
<image>
Initially the chip is located at vertex 2. The only possible Petya's move is to go to vertex 1. After that he has to go to 3 for Vasya. Now it's Petya's turn but he has no possible move, so Petya loses.
In the third example the graph is the following:
<image>
Petya can't win, but he can move along the cycle, so the players will draw a tie. | instruction | 0 | 73,048 | 19 | 146,096 |
Tags: dfs and similar, dp, games, graphs
Correct Solution:
```
import sys
data = sys.stdin.readlines()
n, m = map(int, data[0].split())
g = {}
for i, line in enumerate(data[1:-1], 1):
g[i] = list(map(int, line.split()[1:]))
mk = {}
start = int(data[-1])
queue = [(start, 0, -1, 1)]
cycle = False
while len(queue) > 0:
v, player, prev, color = queue.pop()
if color == 2:
mk[(v, player)] = (prev, 2)
continue
if mk.get((v, player), None):
if mk[(v, player)][1] == 1:
cycle = True
continue
mk[(v, player)] = (prev, 1)
queue.append((v, player, prev, 2))
for w in g[v]:
queue.append((w, 1-player, v, 1))
sol = None
for v in range(1, n+1):
if len(g[v]) == 0 and mk.get((v, 1), None):
sol = v
break
if sol:
path = [sol]
cur = (sol, 1)
while cur != (start, 0):
cur = (mk.get(cur)[0], 1-cur[1])
path.append(cur[0])
print('Win')
print(*path[::-1])
elif cycle:
print('Draw')
else:
print('Lose')
``` | output | 1 | 73,048 | 19 | 146,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who can't move the chip loses. If the game lasts for 106 turns the draw is announced.
Vasya was performing big laboratory work in "Spelling and parts of speech" at night before the game, so he fell asleep at the very beginning of the game. Petya decided to take the advantage of this situation and make both Petya's and Vasya's moves.
Your task is to help Petya find out if he can win the game or at least draw a tie.
Input
The first line of input contain two integers n and m — the number of vertices and the number of edges in the graph (2 ≤ n ≤ 105, 0 ≤ m ≤ 2·105).
The next n lines contain the information about edges of the graph. i-th line (1 ≤ i ≤ n) contains nonnegative integer ci — number of vertices such that there is an edge from i to these vertices and ci distinct integers ai, j — indices of these vertices (1 ≤ ai, j ≤ n, ai, j ≠ i).
It is guaranteed that the total sum of ci equals to m.
The next line contains index of vertex s — the initial position of the chip (1 ≤ s ≤ n).
Output
If Petya can win print «Win» in the first line. In the next line print numbers v1, v2, ..., vk (1 ≤ k ≤ 106) — the sequence of vertices Petya should visit for the winning. Vertex v1 should coincide with s. For i = 1... k - 1 there should be an edge from vi to vi + 1 in the graph. There must be no possible move from vertex vk. The sequence should be such that Petya wins the game.
If Petya can't win but can draw a tie, print «Draw» in the only line. Otherwise print «Lose».
Examples
Input
5 6
2 2 3
2 4 5
1 4
1 5
0
1
Output
Win
1 2 4 5
Input
3 2
1 3
1 1
0
2
Output
Lose
Input
2 2
1 2
1 1
1
Output
Draw
Note
In the first example the graph is the following:
<image>
Initially the chip is located at vertex 1. In the first move Petya moves the chip to vertex 2, after that he moves it to vertex 4 for Vasya. After that he moves to vertex 5. Now it is Vasya's turn and there is no possible move, so Petya wins.
In the second example the graph is the following:
<image>
Initially the chip is located at vertex 2. The only possible Petya's move is to go to vertex 1. After that he has to go to 3 for Vasya. Now it's Petya's turn but he has no possible move, so Petya loses.
In the third example the graph is the following:
<image>
Petya can't win, but he can move along the cycle, so the players will draw a tie.
Submitted Solution:
```
import sys
from collections import deque
g = {}
data = sys.stdin.readlines()
n, m = map(int, data[0].split())
for i, line in enumerate(data[1:-1], 1):
g[i] = list(map(int, line.split()[1:]))
cycle = False
mk = {}
start = int(data[-1])
queue = deque()
queue.append((start, 0, -1))
while len(queue) > 0:
v, player, prev = queue.popleft()
if mk.get((v, player), 0):
cycle = True
continue
mk[(v, player)] = prev
for w in g[v]:
queue.append((w, 1-player, v))
sol = 0
for v in range(1, n+1):
if len(g[v]) == 0 and mk.get((v, 1), 0):
sol = v
break
if sol:
path = [sol]
cur = (sol, 1)
while cur != (start, 0):
cur = (mk.get(cur), 1-cur[1])
path.append(cur[0])
print('Win')
print(*path[::-1])
elif cycle:
print('Draw')
else:
print('Lose')
``` | instruction | 0 | 73,049 | 19 | 146,098 |
No | output | 1 | 73,049 | 19 | 146,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.