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.
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them.
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty.
Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
<image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10.
Tokitsukaze wants to know the number of operations she would do in total.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 10^{18}, 1 ≤ m ≤ 10^5, 1 ≤ m, k ≤ n) — the number of items, the number of special items to be discarded and the number of positions in each page.
The second line contains m distinct integers p_1, p_2, …, p_m (1 ≤ p_1 < p_2 < … < p_m ≤ n) — the indices of special items which should be discarded.
Output
Print a single integer — the number of operations that Tokitsukaze would do in total.
Examples
Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1
Note
For the first example:
* In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5;
* In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7;
* In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10.
For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
Submitted Solution:
```
n,m,k = list(map(int,input().split()))
l = list(map(int,input().split()))
out = 0
d = 0
while m > d:
nex = l[d]
page = (nex - d - 1)//k
add = 1
while d + add < m and (page * k) < l[d + add] - d <= (page + 1) * k:
add += 1
d += add
out += 1
print(out)
``` | instruction | 0 | 22,922 | 19 | 45,844 |
Yes | output | 1 | 22,922 | 19 | 45,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them.
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty.
Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
<image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10.
Tokitsukaze wants to know the number of operations she would do in total.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 10^{18}, 1 ≤ m ≤ 10^5, 1 ≤ m, k ≤ n) — the number of items, the number of special items to be discarded and the number of positions in each page.
The second line contains m distinct integers p_1, p_2, …, p_m (1 ≤ p_1 < p_2 < … < p_m ≤ n) — the indices of special items which should be discarded.
Output
Print a single integer — the number of operations that Tokitsukaze would do in total.
Examples
Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1
Note
For the first example:
* In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5;
* In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7;
* In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10.
For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
Submitted Solution:
```
n,m,k = list(map(int,input().split()))
l = list(map(int,input().split()))
o = 0
d = 0
while m > d:
g = l[d]
page = (g - d - 1)//k
add = 1
while d + add < m and (page * k) < l[d + add] - d <= (page + 1) * k:
add += 1
d += add
o += 1
print(o)
``` | instruction | 0 | 22,923 | 19 | 45,846 |
Yes | output | 1 | 22,923 | 19 | 45,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them.
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty.
Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
<image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10.
Tokitsukaze wants to know the number of operations she would do in total.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 10^{18}, 1 ≤ m ≤ 10^5, 1 ≤ m, k ≤ n) — the number of items, the number of special items to be discarded and the number of positions in each page.
The second line contains m distinct integers p_1, p_2, …, p_m (1 ≤ p_1 < p_2 < … < p_m ≤ n) — the indices of special items which should be discarded.
Output
Print a single integer — the number of operations that Tokitsukaze would do in total.
Examples
Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1
Note
For the first example:
* In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5;
* In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7;
* In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10.
For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
Submitted Solution:
```
n,m,k=list(map(int,input().split()))
p=list(map(int,input().split()))
ok=k
ip=0
s=1
cnt=0
for i in p:
if ip<=i<=k:
cnt+=1
print(i)
elif ip<=i<=k+cnt:
s+=1
k+=cnt
else:
if ip==0 and k+cnt==ok:
s=1
else:
s+=1
ip=k
k+=ok
print(s)
``` | instruction | 0 | 22,924 | 19 | 45,848 |
No | output | 1 | 22,924 | 19 | 45,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them.
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty.
Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
<image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10.
Tokitsukaze wants to know the number of operations she would do in total.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 10^{18}, 1 ≤ m ≤ 10^5, 1 ≤ m, k ≤ n) — the number of items, the number of special items to be discarded and the number of positions in each page.
The second line contains m distinct integers p_1, p_2, …, p_m (1 ≤ p_1 < p_2 < … < p_m ≤ n) — the indices of special items which should be discarded.
Output
Print a single integer — the number of operations that Tokitsukaze would do in total.
Examples
Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1
Note
For the first example:
* In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5;
* In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7;
* In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10.
For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
Submitted Solution:
```
n,m,k = map(int, input().split())
discard = list(map(int, input().split()))
startK = (int(discard[0]/k)+1) * k
step = 0
id = 0
while True:
#print("startK", startK)
disnum = 0
while (id < m and startK >= discard[id]):
disnum+=1
#print(discard[id], end = ' ')
id+=1
startK += disnum
if disnum == 0:
if id == m: break;
startK += int((discard[id] - startK)/k + 1) * k
else:
step+=1
print(step)
``` | instruction | 0 | 22,925 | 19 | 45,850 |
No | output | 1 | 22,925 | 19 | 45,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them.
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty.
Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
<image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10.
Tokitsukaze wants to know the number of operations she would do in total.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 10^{18}, 1 ≤ m ≤ 10^5, 1 ≤ m, k ≤ n) — the number of items, the number of special items to be discarded and the number of positions in each page.
The second line contains m distinct integers p_1, p_2, …, p_m (1 ≤ p_1 < p_2 < … < p_m ≤ n) — the indices of special items which should be discarded.
Output
Print a single integer — the number of operations that Tokitsukaze would do in total.
Examples
Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1
Note
For the first example:
* In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5;
* In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7;
* In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10.
For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
Submitted Solution:
```
import math
import collections
n, m, k = input().split()
list = input().split()
k = int(k)
c = 0
check = 'false'
answer = 0
k = math.floor(int(list[0]) / k) * k + k
for i in range(len(list)):
list[i] = int(list[i])
if(list[i] <= k):
c += 1
check = 'true'
if(list[i] >= k):
if(check is 'true'):
answer += 1
check = 'false'
k += c
else:
k = math.floor(list[i] / k) * k + k
print(answer if check is 'false' else answer + 1)
``` | instruction | 0 | 22,926 | 19 | 45,852 |
No | output | 1 | 22,926 | 19 | 45,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them.
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty.
Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
<image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10.
Tokitsukaze wants to know the number of operations she would do in total.
Input
The first line contains three integers n, m and k (1 ≤ n ≤ 10^{18}, 1 ≤ m ≤ 10^5, 1 ≤ m, k ≤ n) — the number of items, the number of special items to be discarded and the number of positions in each page.
The second line contains m distinct integers p_1, p_2, …, p_m (1 ≤ p_1 < p_2 < … < p_m ≤ n) — the indices of special items which should be discarded.
Output
Print a single integer — the number of operations that Tokitsukaze would do in total.
Examples
Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1
Note
For the first example:
* In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5;
* In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7;
* In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10.
For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
Submitted Solution:
```
import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
n,m,k=(int(i) for i in input().split())
l=[int(i) for i in input().split()]
i=0
c=0
c1=0
while(i<m):
c2=0
c3=0
p=math.ceil((l[i]-c1)/k)
for j in range(i,m):
p1=math.ceil((l[j]-c1)/k)
if(p1==p):
c2+=1
else:
break
i+=c2
c1+=c2
c+=1
print(c)
``` | instruction | 0 | 22,927 | 19 | 45,854 |
No | output | 1 | 22,927 | 19 | 45,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
[3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo)
Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"!
The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that JOE never answers a question wrong!).
For each question JOE answers, if there are s (s > 0) opponents remaining and t (0 ≤ t ≤ s) of them make a mistake on it, JOE receives \displaystylet/s dollars, and consequently there will be s - t opponents left for the next question.
JOE wonders what is the maximum possible reward he can receive in the best possible scenario. Yet he has little time before show starts, so can you help him answering it instead?
Input
The first and single line contains a single integer n (1 ≤ n ≤ 10^5), denoting the number of JOE's opponents in the show.
Output
Print a number denoting the maximum prize (in dollars) JOE could have.
Your answer will be considered correct if it's absolute or relative error won't exceed 10^{-4}. In other words, if your answer is a and the jury answer is b, then it must hold that (|a - b|)/(max(1, b)) ≤ 10^{-4}.
Examples
Input
1
Output
1.000000000000
Input
2
Output
1.500000000000
Note
In the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be \displaystyle 1/2 + 1/1 = 1.5 dollars. | instruction | 0 | 22,977 | 19 | 45,954 |
Tags: combinatorics, greedy, math
Correct Solution:
```
from math import factorial as f
n=int(input())
ans=0
while(n>0):
ans+= 1/n
n-=1
print(ans)
``` | output | 1 | 22,977 | 19 | 45,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
[3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo)
Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"!
The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that JOE never answers a question wrong!).
For each question JOE answers, if there are s (s > 0) opponents remaining and t (0 ≤ t ≤ s) of them make a mistake on it, JOE receives \displaystylet/s dollars, and consequently there will be s - t opponents left for the next question.
JOE wonders what is the maximum possible reward he can receive in the best possible scenario. Yet he has little time before show starts, so can you help him answering it instead?
Input
The first and single line contains a single integer n (1 ≤ n ≤ 10^5), denoting the number of JOE's opponents in the show.
Output
Print a number denoting the maximum prize (in dollars) JOE could have.
Your answer will be considered correct if it's absolute or relative error won't exceed 10^{-4}. In other words, if your answer is a and the jury answer is b, then it must hold that (|a - b|)/(max(1, b)) ≤ 10^{-4}.
Examples
Input
1
Output
1.000000000000
Input
2
Output
1.500000000000
Note
In the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be \displaystyle 1/2 + 1/1 = 1.5 dollars. | instruction | 0 | 22,978 | 19 | 45,956 |
Tags: combinatorics, greedy, math
Correct Solution:
```
# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
# If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
# If the element is already present in the list,
# the right most position where element has to be inserted is returned
# ==============================================================================================
# fast I/O region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
# ===============================================================================================
# some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def zerolist(n): return [0] * n
def nextline(): out("\n") # as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def printlist(a):
for p in range(0, len(a)):
out(str(a[p]) + ' ')
def lcm(a, b): return (a * b) // gcd(a, b)
def power(x, y, p):
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1): # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n, r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n):
if (n <= 1): return False
if (n <= 3): return True
if (n % 2 == 0 or n % 3 == 0): return False
i = 5
while (i * i <= n):
if (n % i == 0 or n % (i + 2) == 0):
return False
i = i + 6
return True
def solve():
n=int(input())
ans=0
for i in range(1,n+1):
ans+=(1/i)
print(ans)
solve()
``` | output | 1 | 22,978 | 19 | 45,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
[3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo)
Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"!
The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that JOE never answers a question wrong!).
For each question JOE answers, if there are s (s > 0) opponents remaining and t (0 ≤ t ≤ s) of them make a mistake on it, JOE receives \displaystylet/s dollars, and consequently there will be s - t opponents left for the next question.
JOE wonders what is the maximum possible reward he can receive in the best possible scenario. Yet he has little time before show starts, so can you help him answering it instead?
Input
The first and single line contains a single integer n (1 ≤ n ≤ 10^5), denoting the number of JOE's opponents in the show.
Output
Print a number denoting the maximum prize (in dollars) JOE could have.
Your answer will be considered correct if it's absolute or relative error won't exceed 10^{-4}. In other words, if your answer is a and the jury answer is b, then it must hold that (|a - b|)/(max(1, b)) ≤ 10^{-4}.
Examples
Input
1
Output
1.000000000000
Input
2
Output
1.500000000000
Note
In the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be \displaystyle 1/2 + 1/1 = 1.5 dollars. | instruction | 0 | 22,980 | 19 | 45,960 |
Tags: combinatorics, greedy, math
Correct Solution:
```
n=int(input())
rslt=0.0
for i in range(1,n+1):
rslt+=1/i
print(rslt)
``` | output | 1 | 22,980 | 19 | 45,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
[3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo)
Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"!
The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that JOE never answers a question wrong!).
For each question JOE answers, if there are s (s > 0) opponents remaining and t (0 ≤ t ≤ s) of them make a mistake on it, JOE receives \displaystylet/s dollars, and consequently there will be s - t opponents left for the next question.
JOE wonders what is the maximum possible reward he can receive in the best possible scenario. Yet he has little time before show starts, so can you help him answering it instead?
Input
The first and single line contains a single integer n (1 ≤ n ≤ 10^5), denoting the number of JOE's opponents in the show.
Output
Print a number denoting the maximum prize (in dollars) JOE could have.
Your answer will be considered correct if it's absolute or relative error won't exceed 10^{-4}. In other words, if your answer is a and the jury answer is b, then it must hold that (|a - b|)/(max(1, b)) ≤ 10^{-4}.
Examples
Input
1
Output
1.000000000000
Input
2
Output
1.500000000000
Note
In the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be \displaystyle 1/2 + 1/1 = 1.5 dollars. | instruction | 0 | 22,981 | 19 | 45,962 |
Tags: combinatorics, greedy, math
Correct Solution:
```
n = int(input())
t = n
ans = 0
for i in range(n, 0, -1):
ans += 1/t
t-=1
print(ans)
``` | output | 1 | 22,981 | 19 | 45,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
[3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo)
Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"!
The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that JOE never answers a question wrong!).
For each question JOE answers, if there are s (s > 0) opponents remaining and t (0 ≤ t ≤ s) of them make a mistake on it, JOE receives \displaystylet/s dollars, and consequently there will be s - t opponents left for the next question.
JOE wonders what is the maximum possible reward he can receive in the best possible scenario. Yet he has little time before show starts, so can you help him answering it instead?
Input
The first and single line contains a single integer n (1 ≤ n ≤ 10^5), denoting the number of JOE's opponents in the show.
Output
Print a number denoting the maximum prize (in dollars) JOE could have.
Your answer will be considered correct if it's absolute or relative error won't exceed 10^{-4}. In other words, if your answer is a and the jury answer is b, then it must hold that (|a - b|)/(max(1, b)) ≤ 10^{-4}.
Examples
Input
1
Output
1.000000000000
Input
2
Output
1.500000000000
Note
In the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be \displaystyle 1/2 + 1/1 = 1.5 dollars. | instruction | 0 | 22,983 | 19 | 45,966 |
Tags: combinatorics, greedy, math
Correct Solution:
```
number = int(input())
money = 0
for i in range(number):
money += 1/(number - i)
print('%.12f' % money)
``` | output | 1 | 22,983 | 19 | 45,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won. | instruction | 0 | 24,314 | 19 | 48,628 |
Tags: math
Correct Solution:
```
def main():
n, k = map(int, input().split())
aa = []
for i in range(n + 1):
s = input()
aa.append(None if s == '?' else int(s))
qm_cnt = aa.count(None)
if k:
if qm_cnt:
print('Yes' if n & 1 else 'No')
else:
x = 0
for a in reversed(aa):
x = (x * k + a) % 999999937
print('No' if x else 'Yes')
else:
print('Yes' if aa[0] is None and not (n - qm_cnt) & 1 or aa[0] == 0 else 'No')
if __name__ == '__main__':
main()
``` | output | 1 | 24,314 | 19 | 48,629 |
Provide tags and a correct Python 3 solution for this coding contest problem.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won. | instruction | 0 | 24,315 | 19 | 48,630 |
Tags: math
Correct Solution:
```
def solve():
modx = 179426080107
n,m = map(int,input().split())
cnt = 0
a = []
for i in range(n + 1):
s = input()
if(s == '?'): cnt += 1
a.append(s)
#print(cnt)
if (m == 0):
if (a[0] == '0') : return 1
if (a[0] == '?' and (n + 1 - cnt)% 2 == 1):
return 1
return 0
if(cnt):
if (n % 2 == 1):return 1
return 0
for i in range(n+1):
a[i] = int(a[i])
now = a[n]
tmp = 1
ans = 0
for i in range(n + 1):
ans = ans + (tmp * a[i]) % modx
ans %= modx
tmp = (tmp * m) % modx
if (ans == 0) : return 1
else : return 0
if (solve() == 1) : print("Yes")
else : print("No")
``` | output | 1 | 24,315 | 19 | 48,631 |
Provide tags and a correct Python 3 solution for this coding contest problem.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won. | instruction | 0 | 24,316 | 19 | 48,632 |
Tags: math
Correct Solution:
```
n,k = map(int,input().split())
s = 0
a = 0
l = []
f = False
for i in range(n+1):
v = input()
if v == '?':
a += 1
if k == 0 and i == 0:
f = True
elif a==0:
l.append(int(v))
l.reverse()
if a == 0 and k != 0:
for i in l:
s = k*s + i
if s > 10**18 or s < -10**18:
break
if k == 0 and ((not f and l[-1] == 0) or (f and (n-a)%2==0)):
print("Yes")
elif k == 0:
print("No")
elif (a == 0 and s == 0) or (n%2 == 1 and a > 0):
print("Yes")
else:
print("No")
``` | output | 1 | 24,316 | 19 | 48,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won. | instruction | 0 | 24,317 | 19 | 48,634 |
Tags: math
Correct Solution:
```
n, k = map(int, input().split())
a = [input() for i in range(n + 1)]
z = 0
for i in a:
if i == '?':
z += 1
if k == 0:
if a[0] == '0':
print('Yes')
elif a[0] == '?' and (n - z + 1) % 2 == 1:
print('Yes')
else:
print('No')
else:
if z == 0:
d = 0
for i in a[::-1]:
d = (d * k + int(i)) % 7272763523821
#print(d)
if d == 0:
print('Yes')
else:
print('No')
else:
if n % 2 == 0:
print('No')
else:
print('Yes')
``` | output | 1 | 24,317 | 19 | 48,635 |
Provide tags and a correct Python 3 solution for this coding contest problem.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won. | instruction | 0 | 24,318 | 19 | 48,636 |
Tags: math
Correct Solution:
```
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n,k=map(int,input().split())
coeff=[str(input().strip()) for _ in range(n+1)]
if coeff.count('?')==0:
# check game state
total=0
for s in range(n+1)[::-1]:
total=total*k+int(coeff[s])
if abs(total)>1000000000000: break
if total==0: print("Yes")
else: print("No")
elif k==0:
if coeff[0]=='?':
# check if human's turn
if (n+1-coeff.count('?'))%2==1: print("Yes")
else: print("No")
else:
if coeff[0]=='0': print("Yes")
else: print("No")
else:
# k is not 0
# check if human moves last
if (n+1)%2==0: print("Yes")
else: print("No")
``` | output | 1 | 24,318 | 19 | 48,637 |
Provide tags and a correct Python 3 solution for this coding contest problem.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won. | instruction | 0 | 24,319 | 19 | 48,638 |
Tags: math
Correct Solution:
```
n,k = map(int,input().split())
s = 0
a = 0
l = []
f = False
for i in range(n+1):
v = input()
if v == '?':
a += 1
if k == 0 and i == 0:
f = True
elif a==0:
l.append(int(v))
l.reverse()
if a == 0 and k != 0:
for i in l:
s = k*s + i
if s > 10**9 or s < -10**9:
break
if k == 0 and ((not f and l[-1] == 0) or (f and (n-a)%2==0)):
print("Yes")
elif k == 0:
print("No")
elif (a == 0 and s == 0) or (n%2 == 1 and a > 0):
print("Yes")
else:
print("No")
``` | output | 1 | 24,319 | 19 | 48,639 |
Provide tags and a correct Python 3 solution for this coding contest problem.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won. | instruction | 0 | 24,320 | 19 | 48,640 |
Tags: math
Correct Solution:
```
n, k = map(int,input().split())
a = []
for i in range(n+1):
a.extend(input().split())
if k == 0:
if a[0] == '0': print('Yes')
elif a[0] == '?' and (n - a.count('?'))% 2 == 0: print('Yes')
else: print('No')
elif '?' in a:
if n % 2 == 0: print('No')
else: print('Yes')
else:
a = list(map(int, a))[::-1]
res = a[0]
for i in range(1, n+1):
res = a[i] + res * k
if res > 10**11 or res < -10**11:
print('No')
exit(0)
if res == 0: print('Yes')
else: print('No')
``` | output | 1 | 24,320 | 19 | 48,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won. | instruction | 0 | 24,321 | 19 | 48,642 |
Tags: math
Correct Solution:
```
n, k = map(int, input().split())
a = [input() for _ in range(n + 1)]
c = len([_ for _ in a if _ == '?'])
print('Yes' if k == 0 and (a[0] == '0' or a[0] == '?' and (n + 1 - c) % 2 == 1) or k != 0 and (c > 0 and n % 2 == 1 or c == 0 and sum([_ * pow(k, i, 10**15 + 91) for i, _ in enumerate(map(int, a))]) % (10**15 + 91) == 0) else 'No')
``` | output | 1 | 24,321 | 19 | 48,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
Submitted Solution:
```
n,k = [int(x) for x in input().split()]
L=[]
done = 0
for i in range(n+1):
c=input()
if c is '?':
L.append('?')
else:
L.append(int(c))
done += 1
left = n + 1 - done
if done%2 == 0:
chance = 0
else:
chance = 1
if k==0:
if L[0] is '?':
print('Yes' if chance == 1 else 'No')
else:
print('Yes' if L[0] == 0 else 'No')
elif left == 0:
for i in range(n, 0,-1):
L[i-1] += L[i]*k
if not (-10000000000<L[i-1]<10000000000):
L[0]=-1
break
print('Yes' if L[0] == 0 else 'No')
elif left%2 == 0:
if chance == 0:
print('Yes')
else:
print('No')
else:
if chance == 1:
print('Yes')
else:
print('No')
``` | instruction | 0 | 24,322 | 19 | 48,644 |
Yes | output | 1 | 24,322 | 19 | 48,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
Submitted Solution:
```
n, k = map(int, input().split())
a = []
check = 0
for _ in range(n + 1):
new_a = input()
if new_a == '?':
check += 1
else:
new_a = int(new_a)
a.append(new_a)
if check > 0:
if k != 0:
if (n + 1) % 2 == 0:
print('Yes')
else:
print('No')
else:
if ((n + 1 - check) % 2 == 1 and a[0] == '?') or a[0] == 0:
print('Yes')
else:
print('No')
else:
module1 = 2**58 - 203
module2 = 2**64 - 59
result1 = result2 = result3 = 0
for c in a[::-1]:
result1 = (result1 * k + c) % module1
result2 = (result2 * k + c) % module2
result3 = (result3 * k + c) % (module1 + module2)
if result1 == 0 and result2 == 0 and result3 == 0:
print('Yes')
else:
print('No')
``` | instruction | 0 | 24,323 | 19 | 48,646 |
Yes | output | 1 | 24,323 | 19 | 48,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
Submitted Solution:
```
import sys
import math
def calculate(A, k, x):
res = 0
if abs(k) >= 2:
for a in reversed(A):
res = k*res + a
if abs(res) > x:
return float('inf')
return res
else:
for a in reversed(A):
res = k*res + a
return res
def solve():
n, k = [int(x) for x in input().split()]
A = ['?' if line == '?\n' else int(line) for line in sys.stdin]
if k == 0:
return A[0] == 0 or A[0] == '?' and (n + 1 - A.count('?')) % 2 == 1
else:
if '?' in A:
return n % 2 == 1
else:
return calculate(A, k, 10000) == 0
print('Yes' if solve() else 'No')
``` | instruction | 0 | 24,324 | 19 | 48,648 |
Yes | output | 1 | 24,324 | 19 | 48,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
Submitted Solution:
```
n,k = map(int,input().split(" "))
mas=[-100000000000000]*(n+1)
d = 0
limit = 10**10
for i in range(n+1):
s= input()
if s=="?":
d+=1
else:
mas[i]=int(s)
if k == 0 and mas[0] == 0:
print("Yes")
elif k == 0 and mas[0] != 0 :
if mas[0]==-100000000000000:
if (n-d)%2!=0:
print("No")
else:
print("Yes")
else:
print("No")
else:
if d!=0:
if n%2==0:
print("No")
else:
print("Yes")
else:
b=mas[n]
for i in range(n-1,0,-1):
b=(mas[i]+b*k)
if abs(b)>limit:
print("No")
break
else:
print("Yes") if (b*k==-mas[0]) else print("No")
``` | instruction | 0 | 24,325 | 19 | 48,650 |
Yes | output | 1 | 24,325 | 19 | 48,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
Submitted Solution:
```
#!/usr/bin/python3
def main():
n, k = map(int, input().split())
seq = ['?'] * (n + 1)
pows = [1] * (n + 1)
turns = 0
for i in range(n + 1):
s = input()
if (s != '?'):
seq[i] = int(s)
turns += 1
if i >= 1:
pows[i] = abs(k) * pows[i - 1]
cur_func = 0
for i in range(n, -1, -1):
cur_func = k * cur_func
if (seq[i] != '?'):
cur_func += seq[i]
cur_func = abs(cur_func)
if k == 0 and seq[0] == '?':
print ("Yes" if turns % 2 == 1 else "No")
#print(cur_func, seq)
for i in range(n, -1, -1):
if seq[i] == '?':
if turns % 2 == 0: # computer
cur_func += pows[i] * (10000)
else:
cur_func = max(0, cur_func - pows[i] * 10000)
turns += 1
if (cur_func == 0):
print("Yes")
else:
print("No")
main()
``` | instruction | 0 | 24,326 | 19 | 48,652 |
No | output | 1 | 24,326 | 19 | 48,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
Submitted Solution:
```
n, k = map(int,input().split())
a = []
for i in range(n+1):
a.extend(input().split())
if k == 0:
if a[0] == '0': print('Yes')
elif (n - a.count('?'))% 2 == 0: print('Yes')
else: print('No')
elif '?' in a:
if n % 2 == 0: print('No')
else: print('Yes')
else:
a = list(map(int, a))[::-1]
res = a[0]
for i in range(1, n+1):
res = a[i] + res * k
if res > 10**11 or res < -10**11:
print('No')
exit(0)
if res == 0: print('Yes')
else: print('No')
``` | instruction | 0 | 24,327 | 19 | 48,654 |
No | output | 1 | 24,327 | 19 | 48,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
Submitted Solution:
```
n,k = map(int,input().split())
koeff = [0]*(n+1)
turn = 0
qs = 0
for i in range(n+1):
koeff[i] = input()
if koeff[i]!='?':
turn = (turn+1)%2
else:
qs +=1
if k == 0:
if koeff[-1] == '0':
print('Yes')
elif koeff[-1] == '?':
if turn == 0:
print('No')
else:
print('Yes')
else:
print('No')
elif qs == 0:
b = [0]*(n+1)
b[0] = float(koeff[-1])
for i in range(1,n):
b[i] = b[i-1]*k+float(koeff[n-i])
#print(*b)
if b[-1] == 0:
print('Yes')
else:
print('No')
else:
if (n+1)%2 == 0:
print('Yes')
else:
print('No')
``` | instruction | 0 | 24,328 | 19 | 48,656 |
No | output | 1 | 24,328 | 19 | 48,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynomial
P(x) = anxn + an - 1xn - 1 + ... + a1x + a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x) = x - k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x) = B(x)Q(x), where B(x) is also some polynomial.
Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k.
The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤ ai ≤ 10 000). Each of integers ai (and even an) may be equal to 0.
Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.
Output
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
Examples
Input
1 2
-1
?
Output
Yes
Input
2 100
-10000
0
1
Output
Yes
Input
4 5
?
1
?
1
?
Output
No
Note
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
Submitted Solution:
```
n,k = map(int,input().split())
koeff = [0]*(n+1)
turn = 0
qs = 0
for i in range(n+1):
koeff[i] = input()
if koeff[i]!='?':
turn = (turn+1)%2
else:
qs +=1
if k == 0:
if koeff[-1] == '0':
print('Yes')
elif koeff[-1] == '?':
if turn == 0:
print('No')
else:
print('Yes')
else:
print('No')
elif qs == 0:
b = [0]*(n+1)
b[0] = float(koeff[-1])
for i in range(1,n+1):
b[i] = b[i-1]*k+float(koeff[n-i])
#print(*b)
if abs(b[-1]) < 10**(-9):
print('Yes')
else:
print('No')
else:
if (n+1)%2 == 0:
print('Yes')
else:
print('No')
``` | instruction | 0 | 24,329 | 19 | 48,658 |
No | output | 1 | 24,329 | 19 | 48,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N.
We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.
When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead.
Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
Constraints
* 2 \leq N \leq 2500
* 1 \leq M \leq 5000
* 1 \leq A_i, B_i \leq N
* 1 \leq C_i \leq 10^5
* 0 \leq P \leq 10^5
* All values in input are integers.
* Vertex N can be reached from Vertex 1.
Input
Input is given from Standard Input in the following format:
N M P
A_1 B_1 C_1
:
A_M B_M C_M
Output
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`.
Examples
Input
3 3 10
1 2 20
2 3 30
1 3 45
Output
35
Input
2 2 10
1 2 100
2 2 100
Output
-1
Input
4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
Output
0
Submitted Solution:
```
import sys
input = sys.stdin.readline
N, M, P = map(int, input().split())
INF = 10 ** 9
#入力
# 入力は1-index
# 内部で0-indexにして処理
G = []
for _ in range(M): #M個の辺の情報を受け取る
A, B, C = map(int, input().split()) #lからrへ重みsの辺が存在
G += [[A - 1, B - 1, P - C]] #有向グラフのときはここだけ
check = [False] * N
d = [INF] * N #距離を記録
def shortest_path(s): #S番目の頂点から各頂点への最短距離を求める
s -= 1
d[s] = 0
j = 0
while j < N - 1:
for i in range(M): #無向グラフのときは辺は実質的には2倍
e = G[i]
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
j += 1
j = 0
while j < N:
for i in range(M):
e = G[i]
if d[e[0]] == INF:
continue
if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + e[2]
check[e[1]] = True
if check[e[0]]:
check[e[1]] = True
j += 1
shortest_path(1)
if check[N - 1]:
print (-1)
else:
ans = d[N - 1]
print (max(0, -ans))
# print (d)
``` | instruction | 0 | 24,533 | 19 | 49,066 |
Yes | output | 1 | 24,533 | 19 | 49,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N.
We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.
When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead.
Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
Constraints
* 2 \leq N \leq 2500
* 1 \leq M \leq 5000
* 1 \leq A_i, B_i \leq N
* 1 \leq C_i \leq 10^5
* 0 \leq P \leq 10^5
* All values in input are integers.
* Vertex N can be reached from Vertex 1.
Input
Input is given from Standard Input in the following format:
N M P
A_1 B_1 C_1
:
A_M B_M C_M
Output
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`.
Examples
Input
3 3 10
1 2 20
2 3 30
1 3 45
Output
35
Input
2 2 10
1 2 100
2 2 100
Output
-1
Input
4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
Output
0
Submitted Solution:
```
def resolve():
def BF(s, n, edge, inf=float("inf")):
d = [inf for i in range(n)]
d[s] = 0
for i in range(n * 2):
for before, after, dist in edge:
if before != inf and d[before] + dist < d[after]:
if i < n:
d[after] = d[before] + dist
else:
d[after] = -inf
return d
n, m, p = map(int, input().split())
inf = float("inf")
edge = [list(map(int, input().split())) for _ in range(m)]
edge = [[x - 1, y - 1, p - z] for x, y, z in edge]
ans = -BF(0, n, edge, inf)[-1]
print(max(0, ans) if ans < inf else -1)
if __name__ == "__main__":
resolve()
``` | instruction | 0 | 24,534 | 19 | 49,068 |
Yes | output | 1 | 24,534 | 19 | 49,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N.
We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.
When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead.
Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
Constraints
* 2 \leq N \leq 2500
* 1 \leq M \leq 5000
* 1 \leq A_i, B_i \leq N
* 1 \leq C_i \leq 10^5
* 0 \leq P \leq 10^5
* All values in input are integers.
* Vertex N can be reached from Vertex 1.
Input
Input is given from Standard Input in the following format:
N M P
A_1 B_1 C_1
:
A_M B_M C_M
Output
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`.
Examples
Input
3 3 10
1 2 20
2 3 30
1 3 45
Output
35
Input
2 2 10
1 2 100
2 2 100
Output
-1
Input
4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
Output
0
Submitted Solution:
```
N,M,P = map(int, input().split())
es = []
for i in range(M):
a,b,c = map(int, input().split())
es.append((a-1, b-1, c))
INF = float("inf")
d = [INF for _ in range(N)]
d[0] = 0
"""
頂点Nに向かうまでに関係ない閉路に注意する
無限にコインを拾える場合、
・ある閉路を一周したときの得点と支払いの収支がプラス
・その閉路からゴールまで行ける
である。これがない場合、全てのノードを経由してゴールまで行く(N-1回移動)までにコインの枚数が最大になる
なので、一回ベルマンフォード法をやった後もう一回行って一回目と2回目でゴールまでのコイン枚数に変化があればゴ、
ールに行くまでの道に無限にコインをとれる閉路があるといえる
"""
def solve(start, f):
for i in range(N):
for a,b,c, in es:
if d[a] != INF and d[a] + (-c) + P < d[b]:
# 2週目と区別する。2週目で更新される部分は-INFとか適当に置いておくと、ゴールまでの影響がわかる
if f == 0:
d[b] = d[a] + (-c) + P
else:
d[b] = -INF
return d[-1]
first=solve(0,0)
second=solve(0, 1)
if first != second:
print(-1)
else:
print(max(-first, 0))
``` | instruction | 0 | 24,535 | 19 | 49,070 |
Yes | output | 1 | 24,535 | 19 | 49,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N.
We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.
When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead.
Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
Constraints
* 2 \leq N \leq 2500
* 1 \leq M \leq 5000
* 1 \leq A_i, B_i \leq N
* 1 \leq C_i \leq 10^5
* 0 \leq P \leq 10^5
* All values in input are integers.
* Vertex N can be reached from Vertex 1.
Input
Input is given from Standard Input in the following format:
N M P
A_1 B_1 C_1
:
A_M B_M C_M
Output
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`.
Examples
Input
3 3 10
1 2 20
2 3 30
1 3 45
Output
35
Input
2 2 10
1 2 100
2 2 100
Output
-1
Input
4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
Output
0
Submitted Solution:
```
N, M, P = map(int, input().split())
edges = []
toE = [[] for _ in range(N)]
frE = [[] for _ in range(N)]
for _ in range(M):
fr, to, c = map(int, input().split())
fr -= 1
to -= 1
edges.append((fr, to, -(c - P)))
toE[fr].append(to)
frE[to].append(fr)
def getVisitedList(s, edges):
visited = [False] * N
st = [s]
visited[s] = True
while st:
now = st.pop()
for to in edges[now]:
if not visited[to]:
visited[to] = True
st.append(to)
return visited
canGo = getVisitedList(0, toE)
canBack = getVisitedList(N - 1, frE)
def sol():
minDist = [10**18] * N
minDist[0] = 0
for i in range(N + 1):
for fr, to, c in edges:
d = minDist[fr] + c
if minDist[to] > d:
if i == N and canGo[fr] and canBack[to]:
return -1
minDist[to] = d
return max(0, -minDist[N - 1])
print(sol())
``` | instruction | 0 | 24,536 | 19 | 49,072 |
Yes | output | 1 | 24,536 | 19 | 49,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N.
We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.
When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead.
Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
Constraints
* 2 \leq N \leq 2500
* 1 \leq M \leq 5000
* 1 \leq A_i, B_i \leq N
* 1 \leq C_i \leq 10^5
* 0 \leq P \leq 10^5
* All values in input are integers.
* Vertex N can be reached from Vertex 1.
Input
Input is given from Standard Input in the following format:
N M P
A_1 B_1 C_1
:
A_M B_M C_M
Output
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`.
Examples
Input
3 3 10
1 2 20
2 3 30
1 3 45
Output
35
Input
2 2 10
1 2 100
2 2 100
Output
-1
Input
4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
Output
0
Submitted Solution:
```
INF = 10 ** 15
MOD = 10 ** 9 + 7
def beruman(n,edges,start = 0,negative_loop = False):
ans = False #startを含む負の閉路が存在するか
dist = [INF] * n
dist[start] = 0
for i in range(n):
update = False
for a,b,c in edges:
if dist[a] != INF and dist[b] > dist[a] + c:
dist[b] = dist[a] + c
update = True
if not update:
break
if n != 1 and i == n - 1:
ans = True
if negative_loop:
return dist,ans
else:
return dist
def dfs(G,can_reach,start):
stack = [start]
can_reach[start] = True
while stack:
v = stack.pop()
for e in G[v]:
if can_reach[e]:
continue
stack.append(e)
can_reach[e] = True
return can_reach
def main():
N,M,P = map(int,input().split())
edges = []
G = [[] for _ in range(N)]
G_inv = [[] for _ in range(N)]
for _ in range(M):
a,b,c = map(int,input().split())
a -= 1
b -= 1
edges.append((a,b,P - c))
G[a].append(b)
G_inv[b].append(a)
can_reach_from_start = [False] * N
can_reach_from_goal = [False] * N
dfs(G,can_reach_from_start,0)
dfs(G_inv,can_reach_from_goal,N - 1)
edge = []
for a,b,c in edges:
if (can_reach_from_goal[a] and can_reach_from_start[a]
and can_reach_from_start[b] and can_reach_from_goal[b]):
edge.append((a,b,c))
dist,flag = beruman(N,edge,0,True)
if flag:
print(-1)
else:
print(max(-dist[-1],0))
if __name__ == '__main__':
main()
``` | instruction | 0 | 24,537 | 19 | 49,074 |
No | output | 1 | 24,537 | 19 | 49,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N.
We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.
When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead.
Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
Constraints
* 2 \leq N \leq 2500
* 1 \leq M \leq 5000
* 1 \leq A_i, B_i \leq N
* 1 \leq C_i \leq 10^5
* 0 \leq P \leq 10^5
* All values in input are integers.
* Vertex N can be reached from Vertex 1.
Input
Input is given from Standard Input in the following format:
N M P
A_1 B_1 C_1
:
A_M B_M C_M
Output
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`.
Examples
Input
3 3 10
1 2 20
2 3 30
1 3 45
Output
35
Input
2 2 10
1 2 100
2 2 100
Output
-1
Input
4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
Output
0
Submitted Solution:
```
import sys
input = sys.stdin.buffer.readline
def main():
N,M,P = map(int,input().split())
def BellmanFord(edges,v,source):
INF = float("inf")
dist = [INF for _ in range(v)]
dist[source-1] = 0
for i in range(2*v+1):
for now,fol,cost in edges:
if (dist[now] != INF and dist[fol]>dist[now]+cost):
dist[fol] = dist[now]+cost
if i > v-1:
dist[fol] = -INF
if dist[fol] == -INF:
return -1
else:
return max(0,-1*dist[v-1])
edges = []
for _ in range(M):
a,b,c = map(int,input().split())
edges.append((a-1,b-1,P-c))
print(BellmanFord(edges,N,1))
if __name__ == "__main__":
main()
``` | instruction | 0 | 24,538 | 19 | 49,076 |
No | output | 1 | 24,538 | 19 | 49,077 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N.
We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.
When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead.
Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
Constraints
* 2 \leq N \leq 2500
* 1 \leq M \leq 5000
* 1 \leq A_i, B_i \leq N
* 1 \leq C_i \leq 10^5
* 0 \leq P \leq 10^5
* All values in input are integers.
* Vertex N can be reached from Vertex 1.
Input
Input is given from Standard Input in the following format:
N M P
A_1 B_1 C_1
:
A_M B_M C_M
Output
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`.
Examples
Input
3 3 10
1 2 20
2 3 30
1 3 45
Output
35
Input
2 2 10
1 2 100
2 2 100
Output
-1
Input
4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
Output
0
Submitted Solution:
```
N,M,P = map(int,input().split())
edges = []
for m in range(M):
A,B,C = map(int,input().split())
edges.append((A-1,B-1,P-C))
#print(edges)
inf = float('inf')
def search_by_bellman_ford(edges,V,start):
dist = [inf]*V
dist[start] = 0
for i in range(V):
for edge in edges:
u,v,w = edge
if u == inf:
continue
if dist[v] > dist[u]+w:
dist[v] = dist[u]+w
if i == V-1:
dist[v] = -inf # nagative cycle
return dist
dist = search_by_bellman_ford(edges,N,0)
#print(dist)
ans = -dist[N-1]
print(max(0,ans) if ans != inf else -1)
``` | instruction | 0 | 24,539 | 19 | 49,078 |
No | output | 1 | 24,539 | 19 | 49,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N.
We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.
When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead.
Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
Constraints
* 2 \leq N \leq 2500
* 1 \leq M \leq 5000
* 1 \leq A_i, B_i \leq N
* 1 \leq C_i \leq 10^5
* 0 \leq P \leq 10^5
* All values in input are integers.
* Vertex N can be reached from Vertex 1.
Input
Input is given from Standard Input in the following format:
N M P
A_1 B_1 C_1
:
A_M B_M C_M
Output
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`.
Examples
Input
3 3 10
1 2 20
2 3 30
1 3 45
Output
35
Input
2 2 10
1 2 100
2 2 100
Output
-1
Input
4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
Output
0
Submitted Solution:
```
from collections import defaultdict, deque
N, M, P = map(int, input().split())
G = defaultdict(lambda: defaultdict(lambda: 0))
G_rev = defaultdict(lambda: defaultdict(lambda: 0))
for _ in range(M):
A, B, C = map(int, input().split())
G[A][B] = P - C
G_rev[B][A] = 1
reachable_N = [0] * (N + 1)
reachable_N[N] = 1
queue = deque([N])
while len(queue) > 0:
p = queue.popleft()
for q in G_rev[p].keys():
if reachable_N[q] == 0:
reachable_N[q] = 1
queue.append(q)
reachable_1 = [0] * (N + 1)
reachable_1[1] = 1
queue = deque([1])
while len(queue) > 0:
p = queue.popleft()
for q in G[p].keys():
if reachable_1[q] == 0:
reachable_1[q] = 1
queue.append(q)
reachable = [reachable_1[i] * reachable_N[i] for i in range(N + 1)]
dist = [10000000000] * (N + 1)
res = 0
dist[1] = 0
queue = deque([1])
cnt = 0
update = True
while update:
update = False
for p in range(1, N + 1):
if reachable[p] == 0:
continue
for q in G[p].keys():
if reachable[q] == 0:
pass
elif dist[p] + G[p][q] < dist[q]:
dist[q] = dist[p] + G[p][q]
update = True
cnt += 1
if cnt > N:
res = -1
break
if res == -1:
print(res)
else:
assert dist[N] < 10000000000
print(max(0, -dist[N]))
``` | instruction | 0 | 24,540 | 19 | 49,080 |
No | output | 1 | 24,540 | 19 | 49,081 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES" | instruction | 0 | 24,870 | 19 | 49,740 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
n,k=map(int,input().split())
S=[input().strip() for i in range(n)]
SET=set(S)
ANS=0
for i in range(n-1):
for j in range(i+1,n):
rest=[]
for l in range(k):
if S[i][l]==S[j][l]:
rest+=S[i][l]
else:
rest+=chr(236-ord(S[i][l])-ord(S[j][l]))
if "".join(rest) in SET:
ANS+=1
print(ANS//3)
``` | output | 1 | 24,870 | 19 | 49,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES" | instruction | 0 | 24,871 | 19 | 49,742 |
Tags: brute force, data structures, implementation
Correct Solution:
```
class Trie:
def __init__(self, N):
self.N = N
self.tree = [[-1,-1,-1,0]]
def add(self, s):
tree = self.tree
cur = 0
for i in range(self.N):
if (tree[cur][s[i]] == -1):
tree.append([-1,-1,-1,0])
tree[cur][s[i]] = len(tree)-1
cur = tree[cur][s[i]]
tree[cur][3] += 1
def count(self, s):
tree = self.tree
cur = 0
for i in range(self.N):
if (tree[cur][s[i]] == -1):
return 0
cur = tree[cur][s[i]]
return tree[cur][3]
# returns the string that can be matched with a,b
def match(a, b):
return [a[i] if a[i] == b[i] else 3-a[i]-b[i] for i in range(len(a))]
def change(s):
return [0 if s[i] == 'S' else (1 if s[i] == 'E' else 2) for i in range(len(s))]
n, k = map(int,input().split())
s = [change(input()) for i in range(n)]
trie = Trie(k)
for i in range(n):
trie.add(s[i])
cnt = 0
for i in range(n):
for j in range(i+1,n):
m = match(s[i],s[j])
cnt += trie.count(m) - (s[i] == m) - (s[j] == m)
print(cnt//3)
``` | output | 1 | 24,871 | 19 | 49,743 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES" | instruction | 0 | 24,872 | 19 | 49,744 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
import math
from collections import defaultdict,Counter
# input=sys.stdin.readline
# def print(x):
# sys.stdout.write(str(x)+"\n")
# sys.stdout=open("CP2/output.txt",'w')
# sys.stdin=open("CP2/input.txt",'r')
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# mod=pow(10,9)+7
n,k=map(int,input().split())
l=[]
s1=set()
for i in range(n):
s=input()
l.append(s)
s1.add(s)
ans=0
for i in range(n-2):
for j in range(i+1,n):
s2=''
for kk in range(k):
if l[i][kk]==l[j][kk]:
s2+=l[i][kk]
else:
if(l[i][kk]=='T' and l[j][kk]=='E' or l[i][kk]=='E' and l[j][kk]=='T'):
s2+='S'
elif(l[i][kk]=='T' and l[j][kk]=='S' or l[i][kk]=='S' and l[j][kk]=='T'):
s2+='E'
elif(l[i][kk]=='S' and l[j][kk]=='E' or l[i][kk]=='E' and l[j][kk]=='S'):
s2+='T'
if s2 in s1:
ans+=1
s1.remove(l[i])
print(ans//2)
``` | output | 1 | 24,872 | 19 | 49,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES" | instruction | 0 | 24,873 | 19 | 49,746 |
Tags: brute force, data structures, implementation
Correct Solution:
```
n ,m = map(int,(input().split()))
cards={}
cardsL=[]
ans={}
for i in range(n):
card=input()
cards[card]=i
cardsL.append(card)
def getCard3(A,B,m):
card3=""
for i in range(m):
if A[i]==B[i]:
card3+=A[i]
elif A[i]!="T" and B[i]!="T":
card3+="T"
elif A[i]!="E" and B[i]!="E":
card3+="E"
elif A[i]!="S" and B[i]!="S":
card3+="S"
return card3
res=0
for i in range(n-1):
for j in range(i+1,n-1):
CardT=getCard3(cardsL[i],cardsL[j],m)
temp=cards.get(CardT,0)
if temp>j:
res+=1
print(res)
``` | output | 1 | 24,873 | 19 | 49,747 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES" | instruction | 0 | 24,874 | 19 | 49,748 |
Tags: brute force, data structures, implementation
Correct Solution:
```
n, k = map(int, input().split(' '))
g = []
for z in range(n):
c = input()[:k]
h = []
for i, f in enumerate(c):
if f == "S": l = 0
elif f == "E": l = 1
else: l = 2
h.append(l)
g.append(tuple(h))
t = set(g)
p = 0
for i in range(len(g)):
a = g[i]
for j in range(i+1, len(g)):
b = g[j]
n = []
for z in range(k):
if a[z] == b[z]:
n.append(a[z]); continue
else:
n.append(3-a[z]-b[z])
if tuple(n) in t:
p += 1
print(p//3)
``` | output | 1 | 24,874 | 19 | 49,749 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES" | instruction | 0 | 24,875 | 19 | 49,750 |
Tags: brute force, data structures, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import Counter
N, K = map(int, input().split())
Ss = [input().rstrip() for _ in range(N)]
D = Counter(Ss)
ans = 0
for v in D.values():
ans += v*(v-1)*(v-2)//6
p = 0
for i in range(N-1):
S1 = Ss[i]
for j in range(i+1, N):
S2 = Ss[j]
remain_S = ""
for k in range(K):
if S1[k] == S2[k]:
remain_S += S1[k]
else:
for s in 'TES':
if s != S1[k] and s != S2[k]:
remain_S += s
break
if remain_S in D and remain_S != S1:
p += D[remain_S]
ans += p//3
print(ans)
``` | output | 1 | 24,875 | 19 | 49,751 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES" | instruction | 0 | 24,876 | 19 | 49,752 |
Tags: brute force, data structures, implementation
Correct Solution:
```
n,k=map(int,input().split())
l=[]
for i in range(n):
l.append(input())
# for i in l:
# s.add(i)
ans=0
# print(dic)
for i in range(n):
s=set()
for jj in range(i+1,n):
s.add(l[jj])
for j in range(i+1,n):
to_find=""
for kk in range(k):
if(l[i][kk]==l[j][kk]):
to_find+=l[i][kk]
else:
for ss in ['S','E','T']:
if ss not in l[i][kk] and ss not in l[j][kk]:
to_find+=ss
break
# print(to_find)
# dic[l[i]]-=1
# dic[l[j]]-=1
# s.remove(l[i])
s.remove(l[j])
if to_find in s:
# print(l[i],l[j],to_find)
ans+=1
# s.add(l[i])
# s.add(l[j])
# dic[l[i]]+=1
# dic[l[j]]+=1
# dic[l[j]]-=1
# s.remove(l[i])
print(ans)
``` | output | 1 | 24,876 | 19 | 49,753 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES" | instruction | 0 | 24,877 | 19 | 49,754 |
Tags: brute force, data structures, implementation
Correct Solution:
```
# returns the string that can be matched with a,b
def match(a, b, mp):
c = ''
for i in range(len(a)):
if (a[i] == b[i]):
c += a[i]
else:
c += mp[a[i]+b[i]]
return c
n, k = map(int,input().split())
s = [input() for i in range(n)]
st = set()
for i in range(n):
st.add(s[i])
mp = { 'SE':'T', 'ES':'T', 'ST':'E', 'TS':'E', 'TE':'S', 'ET':'S' }
cnt = 0
for i in range(n):
for j in range(i+1,n):
m = match(s[i],s[j],mp)
cnt += (m in st)
print(cnt//3)
``` | output | 1 | 24,877 | 19 | 49,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES"
Submitted Solution:
```
"""
// Author : snape_here - Susanta Mukherjee
"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
def gcd(x, y):
while y:
x, y = y, x % y
return x
# Python Program for recursive binary search (Taken from GFG).
def binarySearch (arr, l, r, x):
if r >= l:
mid = l + (r - l)//2
if arr[mid] == x:
return True
elif arr[mid] > x:
return binarySearch(arr, l, mid-1, x)
else:
return binarySearch(arr, mid + 1, r, x)
else:
return False
def main():
for i in range(1):
l=[]
n,k1=mi()
for i in range(n):
s=si()
l.append(s)
l.sort()
c=0
for i in range(n):
for j in range(i+1,n):
ans=""
for k in range(k1):
if(l[i][k]==l[j][k]):
ans+=l[i][k]
else:
a=['S','E','T']
a.remove(l[i][k])
a.remove(l[j][k])
ans+=a[0]
if(binarySearch(l,j+1,n-1,ans)):
c+=1
print(c)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | instruction | 0 | 24,878 | 19 | 49,756 |
Yes | output | 1 | 24,878 | 19 | 49,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES"
Submitted Solution:
```
n,k=map(int,input().split())
S=[input().strip() for i in range(n)]
SET=set(S)
ANS=0
for i in range(n-1):
s0=S[i]
for j in range(i+1,n):
s1=S[j]
rest=""
for l in range(k):
if s0[l]==s1[l]:
rest+=s0[l]
else:
rest+=chr(236-ord(s0[l])-ord(s1[l]))
if rest in SET:
ANS+=1
print(ANS//3)
``` | instruction | 0 | 24,879 | 19 | 49,758 |
Yes | output | 1 | 24,879 | 19 | 49,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES"
Submitted Solution:
```
import math
import sys
from collections import defaultdict,Counter,deque,OrderedDict
import bisect
#sys.setrecursionlimit(1000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#INF = 10 ** 18
#MOD = 1000000000 + 7
from itertools import accumulate,groupby
import sys
mod = 1000000007
n,k = ilele()
l = [input() for i in range(n)]
if n<=2:
print(0)
else:
s = list(set(l))
mark = {i:1 for i in s}
comp = {"ST":"E", "TS":"E", "SE":"T", "ES":"T", "ET":"S", "TE":"S"}
ans = 0
for i in range(n-1):
for j in range(i+1,n):
s1 = ""
for w in range(k):
if l[i][w]==l[j][w]:
s1+=l[i][w]
else:
s1+=comp[l[i][w]+l[j][w]]
ans+= mark.get(s1,0)
print(ans//3)
``` | instruction | 0 | 24,880 | 19 | 49,760 |
Yes | output | 1 | 24,880 | 19 | 49,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES"
Submitted Solution:
```
from collections import Counter
n,k=list(map(int,input().split()))
a=list()
for i in range(0,n):
q=input()
a.append(q)
c=Counter(a)
ans=0
for i in range(0,n-1):
for j in range(i+1,n):
s1=a[i]
s2=a[j]
q="SET"
s=""
for p in range(0,k):
if(s1[p]!=s2[p]):
l=[0]*3
if(s1[p]=='S' or s2[p]=='S'):
l[0]=1
if(s1[p]=='E' or s2[p]=='E'):
l[1]=1
if(s1[p]=='T' or s2[p]=='T'):
l[2]=1
for u in range(0,3):
if(l[u]==0):
s=s+q[u]
else:
s=s+s1[p]
#print(s)
#s="".join(s)
ans=ans+c[s]
print(ans//3)
``` | instruction | 0 | 24,881 | 19 | 49,762 |
Yes | output | 1 | 24,881 | 19 | 49,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES"
Submitted Solution:
```
import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect #c++ upperbound
import math
import heapq
def modinv(n,p):
return pow(n,p-2,p)
def cin():
return map(int,sin().split())
def ain(): #takes array as input
return list(map(int,sin().split()))
def sin():
return input()
def inin():
return int(input())
import math
def Divisors(n) :
l = []
for i in range(1, int(math.sqrt(n) + 1)) :
if (n % i == 0) :
if (n // i == i) :
l.append(i)
else :
l.append(i)
l.append(n//i)
return l
"""*******************************************************"""
def main():
n,m=cin()
a=[]
d={}
for i in range(n):
s=sin()
a.append(s)
if s not in d:
d[s]=1
else:
d[s]+=1
ans=0
e={}
for i in range(n):
for j in range(i+1,n):
x=""
for k in range(m):
if(a[i][k]==a[j][k]):
x+=a[i][k]
else:
if(a[i][k]=="S"):
if(a[j][k]=="E"):
x+="T"
else:
x+="E"
elif(a[i][k]=="E"):
if(a[j][k]=="S"):
x+="T"
else:
x+="E"
else:
if(a[j][k]=="S"):
x+="E"
else:
x+="S"
if (x in d and d[x]>0):
# print(x,d,i,j)
p=""
aa=[]
aa.append(x)
aa.append(a[i])
aa.append(a[j])
aa.sort()
p+=aa[0]+"-"+aa[1]+"-"+aa[2]
# print(p)
if p not in e:
ans+=1
e[p]=1
print(ans)
######## Python 2 and 3 footer by Pajenegod and c1729
# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.
# So on cf, use PyPy2 for best string performance.
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill(): pass
return super(FastIO,self).read()
def readline(self):
while self.newlines == 0:
s = self._fill(); self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s:self.buffer.write(s.encode('ascii'))
self.read = lambda:self.buffer.read().decode('ascii')
self.readline = lambda:self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# Cout implemented in Python
import sys
class ostream:
def __lshift__(self,a):
sys.stdout.write(str(a))
return self
cout = ostream()
endl = '\n'
# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
conv = ord if py2 else lambda x:x
A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
try:
while True:
if s[i] >= b'0' [0]:
numb = 10 * numb + conv(s[i]) - 48
elif s[i] == b'-' [0]: sign = -1
elif s[i] != b'\r' [0]:
A.append(sign*numb)
numb = zero; sign = 1
i += 1
except:pass
if s and s[-1] >= b'0' [0]:
A.append(sign*numb)
return A
if __name__== "__main__":
main()
``` | instruction | 0 | 24,882 | 19 | 49,764 |
No | output | 1 | 24,882 | 19 | 49,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES"
Submitted Solution:
```
n, k = tuple(map(int, input().strip().split()))
cartas, buscadas, sets = [], set(), 0
for i in range(n-1):
carta1 = input()
if carta1 in buscadas:
sets += 1
for carta2 in cartas:
buscada = ""
for let in range(k):
c1 = carta1[let]
c2 = carta2[let]
if c1 == c2:
buscada += c1
elif (c1 == "S" and c2 == "E") or (c1 == "E" and c2 == "S"):
buscada += "T"
elif (c1 == "S" and c2 == "T") or (c1 == "T" and c2 == "S"):
buscada += "E"
else:
buscada += "S"
buscadas.add(buscada)
cartas.append(carta1)
cartafinal = input()
if cartafinal in buscadas:
sets += 1
print(sets)
``` | instruction | 0 | 24,883 | 19 | 49,766 |
No | output | 1 | 24,883 | 19 | 49,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
<image>
Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
Input
The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.
Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.
Output
Output a single integer — the number of ways to choose three cards that form a set.
Examples
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
Note
In the third example test, these two triples of cards are sets:
1. "SETT", "TEST", "EEET"
2. "TEST", "ESTE", "STES"
Submitted Solution:
```
n, k = list(map(int, input().split()))
data = set()
mapping = {"S": 0, "E": 1, "T": 2}
for _ in range(n):
data.add(tuple(map(mapping.get, input())))
def find(x, y):
res = []
for i in range(k):
res.append((3 - (x[i] + y[i]) % 3) % 3)
return tuple(res)
res = 0
vec_data = sorted(data)
for i, x in enumerate(vec_data):
c = 0
for j in range(i + 1, len(data)):
y = vec_data[j]
z = find(x, y)
if z in data:
c += 1
res += c // 2
print(res)
``` | instruction | 0 | 24,884 | 19 | 49,768 |
No | output | 1 | 24,884 | 19 | 49,769 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.