text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Only T milliseconds left before the start of well-known online programming contest Codehorses Round 2017.
Polycarp needs to download B++ compiler to take part in the contest. The size of the file is f bytes.
Polycarp's internet tariff allows to download data at the rate of one byte per t0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages:
* download a1 bytes at the rate of one byte per t1 milliseconds, paying p1 burles for the package;
* download a2 bytes at the rate of one byte per t2 milliseconds, paying p2 burles for the package.
Polycarp can buy any package many times. When buying a package, its price (p1 or p2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.
Find the minimum amount of money Polycarp has to spend to download an f bytes file no more than in T milliseconds.
Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages.
Input
The first line contains three integer numbers f, T and t0 (1 ≤ f, T, t0 ≤ 107) — size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff.
The second line contains a description of the first additional package. The line contains three integer numbers a1, t1 and p1 (1 ≤ a1, t1, p1 ≤ 107), where a1 is maximal sizes of downloaded data (in bytes), t1 is time to download one byte (in milliseconds), p1 is price of the package (in burles).
The third line contains a description of the second additional package. The line contains three integer numbers a2, t2 and p2 (1 ≤ a2, t2, p2 ≤ 107), where a2 is maximal sizes of downloaded data (in bytes), t2 is time to download one byte (in milliseconds), p2 is price of the package (in burles).
Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.
Output
Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in T milliseconds. If there is no solution, print the only integer -1.
Examples
Input
120 964 20
26 8 8
13 10 4
Output
40
Input
10 200 20
1 1 1
2 2 3
Output
0
Input
8 81 11
4 10 16
3 10 12
Output
28
Input
8 79 11
4 10 16
3 10 12
Output
-1
Note
In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26·5 = 130 bytes) in 120·8 = 960 milliseconds (960 ≤ 964). He spends 8·5 = 40 burles on it.
In the second example Polycarp has enough time to download 10 bytes. It takes 10·20 = 200 milliseconds which equals to upper constraint on download time.
In the third example Polycarp has to buy one first additional package and one second additional package.
In the fourth example Polycarp has no way to download the file on time.
Submitted Solution:
```
f = 0
T = 0
t0 = 0
a1 = 0
t1 = 0
p1 = 0
a2 = 0
t2 = 0
p2 = 0
R = 0
def func(leftt, leftb, mid):
global f, T, t0, a1, t1, p1, a2, t2, p2, R
ft = 0
if (mid == R):
ft += (mid - 1) * a2;
keks = (leftt - (mid - 1) * a2 * t2) // t2
ft += keks;
else:
ft += (leftt - mid * a2 * t2) // t0
ft += mid * a2
return ft >= leftb
def keks(cnt):
global f, T, t0, a1, t1, p1, a2, t2, p2, R
ks = cnt * a1
if (ks * t1 >= T):
g = (cnt - 1) * a1 + (T - (cnt - 1) * t1 * a1) // t1
if (g >= f):
return cnt * p1
return 1e18
if (ks >= f):
return cnt * p1
leftt = T - ks * t1
leftb = f - ks
if (t2 < t0):
r = (leftt) // (a2 * t2) + 1
R = r
diff = leftb * t0 - leftt
sf = t0 - t2
keks = (diff * t2 + sf - 1) // sf
if (keks % a2 != 0):
keks+= a2 - keks % a2
keks //= a2
keks //= t2
ans = 1e18
for i in range(keks, keks + 1):
l = i
if (l >= 0 and l <= r):
if (func(leftt, leftb, l)):
ans = min(ans, cnt * p1 + l * p2)
if (func(leftt, leftb, 0)):
ans = min(ans, cnt * p1)
return ans;
else:
if (func(leftt, leftb, 0)):
return cnt * p
return 1e18;
def main():
global f, T, t0, a1, t1, p1, a2, t2, p2, R
f, T, t0 = map(int, input().split())
a1, t1, p1 = map(int, input().split())
a2, t2, p2 = map(int, input().split())
ans = 1e18;
if (t0 * f <= T):
ans = 0;
print(ans)
return
ll = 0;
rr = T // (t1 * a1) + 1
for g in range(ll, rr + 1):
ans = min(ans, keks(g))
if (ans > 9e17):
print(-1)
return
print(ans)
main()
```
No
| 94,100 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Only T milliseconds left before the start of well-known online programming contest Codehorses Round 2017.
Polycarp needs to download B++ compiler to take part in the contest. The size of the file is f bytes.
Polycarp's internet tariff allows to download data at the rate of one byte per t0 milliseconds. This tariff is already prepaid, and its use does not incur any expense for Polycarp. In addition, the Internet service provider offers two additional packages:
* download a1 bytes at the rate of one byte per t1 milliseconds, paying p1 burles for the package;
* download a2 bytes at the rate of one byte per t2 milliseconds, paying p2 burles for the package.
Polycarp can buy any package many times. When buying a package, its price (p1 or p2) is prepaid before usage. Once a package is bought it replaces the regular tariff until package data limit is completely used. After a package is consumed Polycarp can immediately buy a new package or switch to the regular tariff without loosing any time. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.
Find the minimum amount of money Polycarp has to spend to download an f bytes file no more than in T milliseconds.
Note that because of technical reasons Polycarp can download only integer number of bytes using regular tariff and both packages. I.e. in each of three downloading modes the number of downloaded bytes will be integer. It means that Polycarp can't download a byte partially using the regular tariff or/and both packages.
Input
The first line contains three integer numbers f, T and t0 (1 ≤ f, T, t0 ≤ 107) — size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff.
The second line contains a description of the first additional package. The line contains three integer numbers a1, t1 and p1 (1 ≤ a1, t1, p1 ≤ 107), where a1 is maximal sizes of downloaded data (in bytes), t1 is time to download one byte (in milliseconds), p1 is price of the package (in burles).
The third line contains a description of the second additional package. The line contains three integer numbers a2, t2 and p2 (1 ≤ a2, t2, p2 ≤ 107), where a2 is maximal sizes of downloaded data (in bytes), t2 is time to download one byte (in milliseconds), p2 is price of the package (in burles).
Polycarp can buy any package many times. Once package is bought it replaces the regular tariff until package data limit is completely used. While a package is in use Polycarp can't buy another package or switch back to the regular internet tariff.
Output
Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in T milliseconds. If there is no solution, print the only integer -1.
Examples
Input
120 964 20
26 8 8
13 10 4
Output
40
Input
10 200 20
1 1 1
2 2 3
Output
0
Input
8 81 11
4 10 16
3 10 12
Output
28
Input
8 79 11
4 10 16
3 10 12
Output
-1
Note
In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26·5 = 130 bytes) in 120·8 = 960 milliseconds (960 ≤ 964). He spends 8·5 = 40 burles on it.
In the second example Polycarp has enough time to download 10 bytes. It takes 10·20 = 200 milliseconds which equals to upper constraint on download time.
In the third example Polycarp has to buy one first additional package and one second additional package.
In the fourth example Polycarp has no way to download the file on time.
Submitted Solution:
```
f = 0
T = 0
t0 = 0
a1 = 0
t1 = 0
p1 = 0
a2 = 0
t2 = 0
p2 = 0
R = 0
def func(leftt, leftb, mid):
global f, T, t0, a1, t1, p1, a2, t2, p2, R
ft = 0
if (mid == R):
ft += (mid - 1) * a2;
keks = (leftt - (mid - 1) * a2 * t2) // t2
ft += keks;
else:
ft += (leftt - mid * a2 * t2) // t0
ft += mid * a2
return ft >= leftb
def keks(cnt):
global f, T, t0, a1, t1, p1, a2, t2, p2, R
ks = cnt * a1
if (ks * t1 >= T):
g = (cnt - 1) * a1 + (T - (cnt - 1) * t1 * a1) // t1
if (g >= f):
return cnt * p1
return 1e18
if (ks >= f):
return cnt * p1
leftt = T - ks * t1
leftb = f - ks
if (t2 < t0):
r = (leftt) // (a2 * t2) + 1
R = r
diff = leftb * t0 - leftt
sf = t0 - t2
keks = (diff * t2 + sf - 1) // sf
if (keks % a2 != 0):
keks+= a2 - keks % a2
keks //= a2
keks //= t2
ans = 1e18
for i in range(keks - 1, keks + 2):
l = i
if (l >= 0 and l <= r):
if (func(leftt, leftb, l)):
ans = min(ans, cnt * p1 + l * p2)
l = r;
if (func(leftt, leftb, l)):
ans = min(ans, cnt * p1 + l * p2)
return ans;
else:
if (func(leftt, leftb, 0)):
return cnt * p
return 1e18;
def main():
global f, T, t0, a1, t1, p1, a2, t2, p2, R
f, T, t0 = map(int, input().split())
a1, t1, p1 = map(int, input().split())
a2, t2, p2 = map(int, input().split())
ans = 1e18;
if (t0 * f <= T):
ans = 0;
print(ans)
return
ll = 0;
rr = T // (t1 * a1) + 1
for g in range(ll, rr + 1):
ans = min(ans, keks(g))
if (ans > 9e17):
print(-1)
return
print(ans)
main()
```
No
| 94,101 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.
At each step he selects one of his guests A, who pairwise introduces all of his friends to each other. After this action any two friends of A become friends. This process is run until all pairs of guests are friends.
Arseny doesn't want to spend much time doing it, so he wants to finish this process using the minimum number of steps. Help Arseny to do it.
Input
The first line contains two integers n and m (1 ≤ n ≤ 22; <image>) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends.
Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n; u ≠ v), which means that people with numbers u and v are friends initially. It's guaranteed that each pair of friends is described not more than once and the graph of friendship is connected.
Output
In the first line print the minimum number of steps required to make all pairs of guests friends.
In the second line print the ids of guests, who are selected at each step.
If there are multiple solutions, you can output any of them.
Examples
Input
5 6
1 2
1 3
2 3
2 5
3 4
4 5
Output
2
2 3
Input
4 4
1 2
1 3
1 4
3 4
Output
1
1
Note
In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.
In the second test case guest number 1 is a friend of all guests, so he can pairwise introduce all guests in one step.
Tags: bitmasks, brute force, dp, graphs
Correct Solution:
```
from collections import defaultdict
def count(x):
c=0
while x > 0:
c+=1
x &= (x-1)
return c
n,m=map(int,input().split())
g=defaultdict(list)
for _ in range(m):
u, v = map(int,input().split())
u-=1;v-=1
g[u].append(v)
g[v].append(u)
mask1=0;mask2=0;MAX=(1<<n)-1
a=[0]*(1 << n)
dp=[MAX]*(1 << n)
if m == (n*(n-1))//2:
print(0)
exit(0)
for i,j in g.items():
mask1 = (1 << i);mask2=0;mask2 |= mask1
for k in j:
mask2 |= (1 << k)
dp[mask2]=mask1
a[mask1]=mask2
for i in range(0,(1 << n)-1):
if dp[i] != MAX:
#print('HEllo')
temp = dp[i] ^ i
for j in range(n):
if temp & (1 << j) != 0:
nmask = i | a[(1 << j)]
dp[nmask]=dp[i] | (1 << j) if count(dp[i] | (1 << j)) < count(dp[nmask]) else dp[nmask]
ans = []
for i in range(n):
if dp[-1] & (1 << i) != 0:
ans.append(i+1)
print(len(ans))
print(*ans)
```
| 94,102 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.
At each step he selects one of his guests A, who pairwise introduces all of his friends to each other. After this action any two friends of A become friends. This process is run until all pairs of guests are friends.
Arseny doesn't want to spend much time doing it, so he wants to finish this process using the minimum number of steps. Help Arseny to do it.
Input
The first line contains two integers n and m (1 ≤ n ≤ 22; <image>) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends.
Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n; u ≠ v), which means that people with numbers u and v are friends initially. It's guaranteed that each pair of friends is described not more than once and the graph of friendship is connected.
Output
In the first line print the minimum number of steps required to make all pairs of guests friends.
In the second line print the ids of guests, who are selected at each step.
If there are multiple solutions, you can output any of them.
Examples
Input
5 6
1 2
1 3
2 3
2 5
3 4
4 5
Output
2
2 3
Input
4 4
1 2
1 3
1 4
3 4
Output
1
1
Note
In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.
In the second test case guest number 1 is a friend of all guests, so he can pairwise introduce all guests in one step.
Submitted Solution:
```
a,b=map(int,input().split())
if a>b:
b,a=a,b
if a==1 and b==1:
print('YES')
print(1)
elif a==1 and b<=3:
print('NO')
elif a==1:
if b%2==1:
m=[i for i in range(1,b+1)]
for i in range(0,b//2,2):
m[i],m[-i-1]=m[-i-1],m[i]
m.append(m.pop(b//2))
print(' '.join(map(str,m)))
else:
if b==4:
print('2 3 1 4')
else:
x=b//2-1
z=1
m=[]
for i in range(b):
if i%2==1:
m.append(z+x)
else:
m.append(z)
z+=1
print(' '.join(map(str, m)))
else:
print('YES')
m = []
x = 1
for i in range(a):
if i % 2 == 0:
m.append([str(z) for z in range(x, x + b)])
else:
m.append(list(reversed([str(z) for z in range(x, x + b)])))
x += b
for i in range(1, b, 2):
x = m[0][i]
for j in range(1, a):
m[j - 1][i] = m[j][i]
m[a - 1][i] = x
for i in m:
print(' '.join(i))
```
No
| 94,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.
At each step he selects one of his guests A, who pairwise introduces all of his friends to each other. After this action any two friends of A become friends. This process is run until all pairs of guests are friends.
Arseny doesn't want to spend much time doing it, so he wants to finish this process using the minimum number of steps. Help Arseny to do it.
Input
The first line contains two integers n and m (1 ≤ n ≤ 22; <image>) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends.
Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n; u ≠ v), which means that people with numbers u and v are friends initially. It's guaranteed that each pair of friends is described not more than once and the graph of friendship is connected.
Output
In the first line print the minimum number of steps required to make all pairs of guests friends.
In the second line print the ids of guests, who are selected at each step.
If there are multiple solutions, you can output any of them.
Examples
Input
5 6
1 2
1 3
2 3
2 5
3 4
4 5
Output
2
2 3
Input
4 4
1 2
1 3
1 4
3 4
Output
1
1
Note
In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.
In the second test case guest number 1 is a friend of all guests, so he can pairwise introduce all guests in one step.
Submitted Solution:
```
from collections import defaultdict as dd, deque
import sys
n,m = map(int,input().split())
E = dd(list)
for _ in range(m):
a,b = [int(x)-1 for x in input().split()]
E[a].append(b)
E[b].append(a)
# FC?
fc = True
for node in E:
if len(E[node]) < n-1:
fc = False
break
if fc:
print(0)
sys.exit(0)
leaves = {node for node in E if len(E[node])==1}
best = 10000000
beststart = None
for start in range(n):
Q = deque()
friends = {start}
for node in E[start]:
Q.append(node)
friends.add(node)
count = 0
while Q:
cur = Q.pop()
for neigh in E[cur]:
if neigh not in friends and neigh not in leaves:
friends.add(neigh)
count += 1
Q.append(neigh)
if count < best:
best = count
beststart = start
Q = deque()
friends = {beststart}
for node in E[beststart]:
Q.append(node)
friends.add(node)
order = []
while Q:
cur = Q.pop()
for neigh in E[cur]:
if neigh not in friends and neigh not in leaves:
friends.add(neigh)
order.append(neigh)
Q.append(neigh)
print(best+1)
print(*[x+1 for x in order],beststart+1)
```
No
| 94,104 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.
At each step he selects one of his guests A, who pairwise introduces all of his friends to each other. After this action any two friends of A become friends. This process is run until all pairs of guests are friends.
Arseny doesn't want to spend much time doing it, so he wants to finish this process using the minimum number of steps. Help Arseny to do it.
Input
The first line contains two integers n and m (1 ≤ n ≤ 22; <image>) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends.
Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n; u ≠ v), which means that people with numbers u and v are friends initially. It's guaranteed that each pair of friends is described not more than once and the graph of friendship is connected.
Output
In the first line print the minimum number of steps required to make all pairs of guests friends.
In the second line print the ids of guests, who are selected at each step.
If there are multiple solutions, you can output any of them.
Examples
Input
5 6
1 2
1 3
2 3
2 5
3 4
4 5
Output
2
2 3
Input
4 4
1 2
1 3
1 4
3 4
Output
1
1
Note
In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.
In the second test case guest number 1 is a friend of all guests, so he can pairwise introduce all guests in one step.
Submitted Solution:
```
def impo(u,v):
if u not in svz:
svz[u]=[]
if v not in svz:
svz[v]=[]
svz[u]+=[v]
svz[v]+=[u]
n,m=map(int,input().split())
svz={}
friends=[]
for i in range(m):
u,v=map(int,input().split())
impo(u,v)
while True:
try:
max_len=max(map(len,svz.values()))
except:
print(0)
quit()
for i in svz.keys():
i,num=svz[i],i
if len(i)==max_len:
getnew=None
for j in i:
for k in i:
if k==j:
continue
try:
if j in svz[k]:
continue
except:
pass
getnew=num
impo(j,k)
if getnew!=None:
friends+=[getnew]
break
if sum(map(len,svz.values()))/n==n-1:
break
print(len(friends))
print(' '.join(map(str,friends)))
```
No
| 94,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.
At each step he selects one of his guests A, who pairwise introduces all of his friends to each other. After this action any two friends of A become friends. This process is run until all pairs of guests are friends.
Arseny doesn't want to spend much time doing it, so he wants to finish this process using the minimum number of steps. Help Arseny to do it.
Input
The first line contains two integers n and m (1 ≤ n ≤ 22; <image>) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends.
Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n; u ≠ v), which means that people with numbers u and v are friends initially. It's guaranteed that each pair of friends is described not more than once and the graph of friendship is connected.
Output
In the first line print the minimum number of steps required to make all pairs of guests friends.
In the second line print the ids of guests, who are selected at each step.
If there are multiple solutions, you can output any of them.
Examples
Input
5 6
1 2
1 3
2 3
2 5
3 4
4 5
Output
2
2 3
Input
4 4
1 2
1 3
1 4
3 4
Output
1
1
Note
In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.
In the second test case guest number 1 is a friend of all guests, so he can pairwise introduce all guests in one step.
Submitted Solution:
```
def minindex(arr):
r = 0
min = float('inf')
i = 0
for e in arr:
if(min > e):
min = e
r = i
i += 1
return r
def maxindex(arr):
r = 0
max = float('-inf')
i = 0
for e in arr:
if(max < e):
max = e
r = i
i += 1
return r
def lenh(arr,i):
if len(addedarr) and (i not in addedarr):
return float('-inf')
r = 0
for e in arr:
r += (e not in addedarr)
return r
n,m = (int(e) for e in input().split(' '))
arr = [[] for i in range(n)]
for i in range(m):
ind1,ind2 = (int(e)-1 for e in input().split(' '))
arr[ind1].append(ind2)
arr[ind2].append(ind1)
if 2*m==n*(n-1):
print(0)
else:
res = []
addedarr = set()
while len(addedarr)<n:
i = maxindex(lenh(e,i) for i,e in enumerate(arr))
res.append(i)
addedarr |= set(arr[i])
addedarr.add(i)
print(len(res))
for e in res:
print(e+1,end=' ')
"""
5 6
1 2
1 3
2 3
2 5
3 4
4 5
2
2 3
"""
```
No
| 94,106 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Tags: constructive algorithms, data structures
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
i=0
b=[]
while i+1<n:
if a[i]==a[i+1]:
a[i+1]=a[i]+1
if len(b)>0:
a[i]=b.pop()
else:
i=i+1
else:
b.append(a[i])
i=i+1
b.append(a[-1])
print(len(b))
print(*b)
```
| 94,107 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Tags: constructive algorithms, data structures
Correct Solution:
```
stk = []
n = input()
n = int(n)
lst = input()
lst = lst.split()
for a in lst:
stk.append(int(a))
while len(stk) > 1:
if stk[-1] == stk[-2]:
b = stk[-1]
stk.pop()
stk.pop()
stk.append(b + 1)
else:
break
print(len(stk))
for a in stk:
print(a , end=" ")
```
| 94,108 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Tags: constructive algorithms, data structures
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
arr = [0 for i in range(n)]
m = 0
for i in range(n):
x = a[i]
while m > 0 and arr[m - 1] == x:
arr[m - 1] = 0
x += 1
m -= 1
arr[m] = x
m += 1
print(m)
print(*arr[:m])
```
| 94,109 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Tags: constructive algorithms, data structures
Correct Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
n = mint()
a = []
for i in mints():
if len(a) > 0 and a[-1] == i:
a[-1] += 1
while len(a) > 1 and a[-2] == a[-1]:
a.pop()
a[-1] += 1
else:
a.append(i)
print(len(a))
print(*a)
```
| 94,110 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Tags: constructive algorithms, data structures
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
b[0] = a[0]
j = 1
for i in range(1, n):
b[j] = a[i]
while j > 0 and b[j] == b[j - 1]:
j -= 1
b[j] += 1
j += 1
print(j)
for i in range(j):
print(b[i], end=' ')
```
| 94,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Tags: constructive algorithms, data structures
Correct Solution:
```
n = int(input())
ls = input().split()
st = []
for i in range(n):
x = int(ls[i])
while len(st) > 0 and x == st[-1]:
x += 1
st.pop()
st.append(x)
print(len(st))
for x in st:
print("{} ".format(x), end="")
```
| 94,112 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Tags: constructive algorithms, data structures
Correct Solution:
```
n, m = int(input()), 0
b = [int(t) for t in input().split()]
a = []
for i in range(n):
a.append(b[i])
while len(a) > 1 and a[-2] == a[-1]:
del a[-1]
a[-1] += 1
print(len(a))
print(" ".join([str(t) for t in a]))
```
| 94,113 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Tags: constructive algorithms, data structures
Correct Solution:
```
# https://codeforces.com/problemset/problem/926/E
input()
stack1 = [int(i) for i in input().split()]
stack1.reverse()
stack2 = []
while stack1:
transfer = stack1.pop()
while stack2 and stack2[-1] == transfer:
stack2.pop()
transfer += 1
stack2.append(transfer)
print(len(stack2))
print(" ".join([str(i) for i in stack2]))
```
| 94,114 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
stack = []
i = 0
x = a[i]
while True:
if len(stack) == 0:
stack.append(x)
i += 1
if i == n:
break
x = a[i]
else:
if x == stack[-1]:
del stack[-1]
x += 1
else:
stack.append(x)
i += 1
if i == n:
break
x = a[i]
print(len(stack))
print(" ".join([str(x) for x in stack]))
```
Yes
| 94,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Submitted Solution:
```
n=int(input())
x=[int(i) for i in input().split()]
otv=[]
i=0
while i<n:
if len(otv)<2:
otv.append(x[i])
i+=1
continue
if otv[len(otv)-1]==otv[len(otv)-2]:
otv.pop()
otv[len(otv)-1]+=1
else:
otv.append(x[i])
i+=1
while len(otv)>=2 and otv[len(otv)-1]==otv[len(otv)-2]:
otv.pop()
otv[len(otv)-1]+=1
print(len(otv))
for i in otv:
print(i,end=" ")
```
Yes
| 94,116 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Submitted Solution:
```
n, m = int(input()), 0
b = [int(t) for t in input().split()]
a = []
for i in range(n):
a.append(b[i])
while len(a) > 1 and a[-2] == a[-1]:
del a[-1]
a[-1] *= 2
print(len(a))
print(" ".join([str(t) for t in a]))
```
No
| 94,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
b,s,l=[],0,len(a)+1
while s<l:
for i in range(0,len(a)-1):
if a[i]==a[i+1]:
a[i]=a[i]+1
del a[i+1]
s=s+1
break
s=s+1
print(a)
print(len(a))
for i in a:
print(i,end=' ')
```
No
| 94,118 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of positive integers a1, a2, ..., an.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a single integer x + 1 on their place. This way the number of elements in the sequence is decreased by 1 on each step.
You stop performing the operation when there is no pair of equal consecutive elements.
For example, if the initial sequence is [5, 2, 1, 1, 2, 2], then after the first operation you get [5, 2, 2, 2, 2], after the second — [5, 3, 2, 2], after the third — [5, 3, 3], and finally after the fourth you get [5, 4]. After that there are no equal consecutive elements left in the sequence, so you stop the process.
Determine the final sequence after you stop performing the operation.
Input
The first line contains a single integer n (2 ≤ n ≤ 2·105) — the number of elements in the sequence.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In the first line print a single integer k — the number of elements in the sequence after you stop performing the operation.
In the second line print k integers — the sequence after you stop performing the operation.
Examples
Input
6
5 2 1 1 2 2
Output
2
5 4
Input
4
1000000000 1000000000 1000000000 1000000000
Output
1
1000000002
Input
7
4 10 22 11 12 5 6
Output
7
4 10 22 11 12 5 6
Note
The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third operation the sequence is [1000000002].
In the third example there are no two equal consecutive elements initially, so the sequence does not change.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
arr = [0 for i in range(n)]
m = 0
for i in range(n):
x = a[i]
while m > 0 and arr[m - 1] == x:
arr[m - 1] = 0
x += 1
m -= 1
arr[m] = x
m += 1
print(arr)
```
No
| 94,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Tags: binary search, math, number theory
Correct Solution:
```
import math
import bisect
import sys
def flrt(exp,x):
l=max(0,math.floor(x**(1/exp))-3)
r= math.floor(x**(1/exp))+3
while l<r:
mid=(l+r)//2
if mid**exp<=x:
l=mid+1
else:
r=mid
return l-1
def c1(r):
ans=set()
pr = [5,7,11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61]
for i in pr:
x=2
while x**i <= r:
val=x**i
b2=flrt(2,val)
b3=flrt(3,val)
if b2**2 != val and b3**3 != val:
ans.add(val)
x+=1
return ans
def solve(r, pc):
if r==0:
return 0
a=[2,3]
ans=0
for i in range(1,2**len(a)):
tot=0
mult=1
for j,x in enumerate(a):
if i&(1<<j):
mult*=x
tot+=1
d= flrt(mult,r)
ans+= d if tot%2 else -d
return ans + bisect.bisect_right(pc,r)
lp=0
rp=len(pc)
while lp<rp:
mid = (lp+rp)//2
if pc[mid] <= r:
lp = mid+1
else:
rp = mid
return ans + lp
q = int(input())
pc= c1(1e18+1)
pca=list(pc)
pca.sort()
for i in range(q):
l,r = [int(x) for x in sys.stdin.readline().split()]
ans=solve(r,pca)-solve(l-1,pca)
print(ans)
```
| 94,120 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Tags: binary search, math, number theory
Correct Solution:
```
import sys
readline = sys.stdin.buffer.readline
J = set()
for i in range(2000):
J.add(i**2)
J.add(i**3)
Ri = set()
for p in range(5, 61, 2):
if p%3 == 0:
continue
for base in range(2, 10**9):
if base in J:
continue
bp = pow(base, p)
if bp > 10**18:
break
Ri.add(bp)
Ri = list(Ri)
Ri.sort()
LL = len(Ri)
def calc(x):
res = 0
ng = 10**9+1
ok = 0
while abs(ok-ng) > 1:
med = (ok+ng)//2
if med*med <= x:
ok = med
else:
ng = med
res += ok
ng = 10**6+1
ok = 0
while abs(ok-ng) > 1:
med = (ok+ng)//2
if med*med*med <= x:
ok = med
else:
ng = med
res += ok
ng = 10**3+1
ok = 0
while abs(ok-ng) > 1:
med = (ok+ng)//2
if med*med*med*med*med*med <= x:
ok = med
else:
ng = med
res -= ok
ng = LL
ok = -1
while abs(ok-ng) > 1:
med = (ok+ng)//2
if Ri[med] <= x:
ok = med
else:
ng = med
res += ok+1
return res
Q = int(readline())
Ans = [None]*Q
for qu in range(Q):
L, R = map(int, readline().split())
Ans[qu] = calc(R) - calc(L-1)
print('\n'.join(map(str, Ans)))
```
| 94,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Tags: binary search, math, number theory
Correct Solution:
```
import math
import bisect
import sys
def flrt(exp,x):
l=max(0,math.floor(x**(1/exp))-3)
r= math.floor(x**(1/exp))+3
while l<r:
mid=(l+r)//2
if mid**exp<=x:
l=mid+1
else:
r=mid
return l-1
def c1(r):
ans=set()
pr = [5,7,11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61]
for i in pr:
x=2
while x**i <= r:
val=x**i
b2=flrt(2,val)
b3=flrt(3,val)
if b2**2 != val and b3**3 != val:
ans.add(val)
x+=1
return ans
def solve(r, pc):
if r==0:
return 0
a=[2,3]
ans=0
for i in range(1,2**len(a)):
tot=0
mult=1
for j,x in enumerate(a):
if i&(1<<j):
mult*=x
tot+=1
d= flrt(mult,r)
ans+= d if tot%2 else -d
return ans + bisect.bisect_right(pc,r)
lp=0
rp=len(pc)
while lp<rp:
mid = (lp+rp)//2
if pc[mid] <= r:
lp = mid+1
else:
rp = mid
return ans + lp
q = int(input())
pc= c1(1e18+1)
pca=list(pc)
pca.sort()
for i in range(q):
l,r = [int(x) for x in sys.stdin.readline().split()]
ans=solve(r,pca)-solve(l-1,pca)
sys.stdout.write(str(ans)+'\n')
```
| 94,122 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Submitted Solution:
```
from math import sqrt
def isnps(x):
return sqrt(x)%1 != 0
MAX = 10**18
sp = set()
for p in range(3, 60):
maxx = int(10**(18/p))
for i in range(2, maxx):
if isnps(i**p):
sp.add(i**p)
sp = list(sp)
sp.sort()
def bs(a,val):
low,high=0,len(a)-1
while low<=high:
mid=(low+high)//2
if a[mid]>=val:
high=mid-1
else:
low=mid+1
return high
q = int(input())
for t in range(q):
l, r = map(int, input().split())
ps = int(sqrt(r)) - int(sqrt(l-1))
print(ps,end=' ')
i = bs(sp, r)
j = bs(sp, l)
ps += i-j
print(ps)
```
No
| 94,123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Submitted Solution:
```
def count(n):
P = 60
m = [ 0, 0, 1, 1, 0, 1,-1, 1, 0, 0,
-1, 1, 0, 1,-1,-1, 0, 1, 0, 1,
0,-1,-1, 1, 0, 0,-1, 0, 0, 1,
1, 1, 0,-1,-1,-1, 0, 1,-1,-1,
0, 1, 1, 1, 0, 0,-1, 1, 0, 0,
0,-1, 0, 1, 0,-1, 0,-1,-1, 1 ]
c = 1
x = 3
for i in range(2, P):
if m[i]:
if x == 2:
if x**i > n:
x = 1
else:
x = int(pow(n, 1/i))
if (x + 1)**i == n:
x += 1
c += (x-1) * m[i]
return c
q = int(input())
for _ in range(q):
l, r = map(int, input().split())
ans = count(r) - count(l-1)
print(ans)
```
No
| 94,124 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Submitted Solution:
```
q=int(input())
def root(x,n):
l=0
r=x
while(r-l>1):
mid=(r+l)//2
if(mid**n>x):
r=mid
else:
l=mid
return l
def calc(x):
if(x==0):
return 1
dp=[0]*70
sm=0
for i in range(62):
j=63-i
#dp[j]=root(x,j)
dp[j]=int(x**(1/j))
for m in range(2,1000):
if(j*m>63):
break
dp[j]-=dp[j*m]
sm+=dp[j]
return sm
for i in range(q):
l,r=map(int,input().split())
print(calc(r)-calc(l-1))
```
No
| 94,125 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Submitted Solution:
```
# -*- coding: utf-8 -*-
#import numpy as np
from itertools import combinations, accumulate
from functools import reduce
from math import floor
maxp = 60
mark = [1]*maxp
mark[0] = 0
mark[1] = 1
i = 2
primes = []
while i < maxp:
if mark[i]:
primes.append(i)
p = i; k = p;
while p*k < maxp:
mark[p*k] = 0
k += 1
i += 1
prods = list(accumulate(primes,lambda x,y: x*y))
combs = []
r = 1
while prods[r-1] < 60:
combs.append(list(combinations(primes,r)))
r += 1
def f(k,R):
"""
{x | 2 <= x <= R and x = a^k, a > 0, k >= 2 } = {x | 2 <= x <= floor(R^(1/k))}
"""
ls = int(floor(R**(1/k)))
return max(ls-1,0)
def solve(L,R):
ret = 0
r = 0
for comb in combs:
r += 1
for t in comb:
sign = -1 + 2*(r%2)
k = reduce(lambda x,y: x*y, t)
ret += sign*f(k,R)
ret -= sign*f(k,L-1)
return ret + (1 if L == 1 else 0)
Q = int(input())
for i in range(Q):
L,R = map(int,input().split())
print(solve(L,R))
```
No
| 94,126 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Grisha come to a contest and faced the following problem.
You are given an array of size n, initially consisting of zeros. The elements of the array are enumerated from 1 to n. You perform q operations on the array. The i-th operation is described with three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n) and means that you should add x_i to each of the elements with indices l_i, l_i + 1, …, r_i. After all operations you should find the maximum in the array.
Grisha is clever, so he solved the problem quickly.
However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?"
Help Grisha, find all integers y between 1 and n such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to y.
Input
The first line contains two integers n and q (1 ≤ n, q ≤ 10^{4}) — the length of the array and the number of queries in the initial problem.
The following q lines contain queries, one per line. The i-th of these lines contains three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n), denoting a query of adding x_i to the segment from l_i-th to r_i-th elements of the array, inclusive.
Output
In the first line print the only integer k, denoting the number of integers from 1 to n, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations.
In the next line print these k integers from 1 to n — the possible values of the maximum. Print these integers in increasing order.
Examples
Input
4 3
1 3 1
2 4 2
3 4 4
Output
4
1 2 3 4
Input
7 2
1 5 1
3 7 2
Output
3
1 2 3
Input
10 3
1 1 2
1 1 3
1 1 6
Output
6
2 3 5 6 8 9
Note
Consider the first example. If you consider the subset only of the first query, the maximum is equal to 1. If you take only the second query, the maximum equals to 2. If you take the first two queries, the maximum becomes 3. If you take only the fourth query, the maximum becomes 4. If you take the fourth query and something more, the maximum becomes greater that n, so you shouldn't print it.
In the second example you can take the first query to obtain 1. You can take only the second query to obtain 2. You can take all queries to obtain 3.
In the third example you can obtain the following maximums:
* You can achieve the maximim of 2 by using queries: (1).
* You can achieve the maximim of 3 by using queries: (2).
* You can achieve the maximim of 5 by using queries: (1, 2).
* You can achieve the maximim of 6 by using queries: (3).
* You can achieve the maximim of 8 by using queries: (1, 3).
* You can achieve the maximim of 9 by using queries: (2, 3).
Submitted Solution:
```
from itertools import permutations
n, q = list(map(int, input().split()))
s = [int(0) for i in range(n)]
maxC = 0
maxValues = []
qList = []
for i in range(q):
l, r, x = list(map(lambda x: int(x) - 1, input().split()))
x += 1
qList.append((l, r, x))
lst = list(permutations(range(q)))[:10]
while lst:
posl = lst.pop(0)
sCopy = s.copy()
for ind in posl:
l, r, x = qList[int(ind)]
for j in range(l, r + 1):
sCopy[j] += x
currentMax = max(sCopy)
if currentMax not in maxValues and currentMax <= n:
maxValues.append(currentMax)
maxC += 1
print(maxC)
print(*sorted(maxValues))
```
No
| 94,127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Grisha come to a contest and faced the following problem.
You are given an array of size n, initially consisting of zeros. The elements of the array are enumerated from 1 to n. You perform q operations on the array. The i-th operation is described with three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n) and means that you should add x_i to each of the elements with indices l_i, l_i + 1, …, r_i. After all operations you should find the maximum in the array.
Grisha is clever, so he solved the problem quickly.
However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?"
Help Grisha, find all integers y between 1 and n such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to y.
Input
The first line contains two integers n and q (1 ≤ n, q ≤ 10^{4}) — the length of the array and the number of queries in the initial problem.
The following q lines contain queries, one per line. The i-th of these lines contains three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n), denoting a query of adding x_i to the segment from l_i-th to r_i-th elements of the array, inclusive.
Output
In the first line print the only integer k, denoting the number of integers from 1 to n, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations.
In the next line print these k integers from 1 to n — the possible values of the maximum. Print these integers in increasing order.
Examples
Input
4 3
1 3 1
2 4 2
3 4 4
Output
4
1 2 3 4
Input
7 2
1 5 1
3 7 2
Output
3
1 2 3
Input
10 3
1 1 2
1 1 3
1 1 6
Output
6
2 3 5 6 8 9
Note
Consider the first example. If you consider the subset only of the first query, the maximum is equal to 1. If you take only the second query, the maximum equals to 2. If you take the first two queries, the maximum becomes 3. If you take only the fourth query, the maximum becomes 4. If you take the fourth query and something more, the maximum becomes greater that n, so you shouldn't print it.
In the second example you can take the first query to obtain 1. You can take only the second query to obtain 2. You can take all queries to obtain 3.
In the third example you can obtain the following maximums:
* You can achieve the maximim of 2 by using queries: (1).
* You can achieve the maximim of 3 by using queries: (2).
* You can achieve the maximim of 5 by using queries: (1, 2).
* You can achieve the maximim of 6 by using queries: (3).
* You can achieve the maximim of 8 by using queries: (1, 3).
* You can achieve the maximim of 9 by using queries: (2, 3).
Submitted Solution:
```
def getMax(n_max, values):
for vs in values:
if len(vs) > 0:
asd = dynamic[tuple(vs)]
if len(asd) == 0:
getMaxes(n_max, 0, vs, asd)
def getMaxes(n_max, current, values, asd):
if len(values) == 0 and n_max >= current and current > 0:
asd.add(current)
for v in values:
if current + values[0] < n_max:
getMaxes(n_max, current + values[0], values[1:], asd)
if current < n_max:
getMaxes(n_max, current, values[1:], asd)
n, q = map(int, input().split())
values = [[] for _ in range(n)]
total = set()
dynamic = {}
for _ in range(q):
l, r, value = map(int, input().split())
if value < n:
for i in range(l - 1, r):
values[i].append(value)
elif value == n:
total.add(value)
for p in values:
if len(p) > 0:
dynamic[tuple(p)] = set()
getMax(n, values)
total = []
for a in dynamic.values():
total.extend(a)
print(len(total))
if len(total) > 0:
print(' '.join([str(v) for v in sorted(total)]))
```
No
| 94,128 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Grisha come to a contest and faced the following problem.
You are given an array of size n, initially consisting of zeros. The elements of the array are enumerated from 1 to n. You perform q operations on the array. The i-th operation is described with three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n) and means that you should add x_i to each of the elements with indices l_i, l_i + 1, …, r_i. After all operations you should find the maximum in the array.
Grisha is clever, so he solved the problem quickly.
However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?"
Help Grisha, find all integers y between 1 and n such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to y.
Input
The first line contains two integers n and q (1 ≤ n, q ≤ 10^{4}) — the length of the array and the number of queries in the initial problem.
The following q lines contain queries, one per line. The i-th of these lines contains three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n), denoting a query of adding x_i to the segment from l_i-th to r_i-th elements of the array, inclusive.
Output
In the first line print the only integer k, denoting the number of integers from 1 to n, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations.
In the next line print these k integers from 1 to n — the possible values of the maximum. Print these integers in increasing order.
Examples
Input
4 3
1 3 1
2 4 2
3 4 4
Output
4
1 2 3 4
Input
7 2
1 5 1
3 7 2
Output
3
1 2 3
Input
10 3
1 1 2
1 1 3
1 1 6
Output
6
2 3 5 6 8 9
Note
Consider the first example. If you consider the subset only of the first query, the maximum is equal to 1. If you take only the second query, the maximum equals to 2. If you take the first two queries, the maximum becomes 3. If you take only the fourth query, the maximum becomes 4. If you take the fourth query and something more, the maximum becomes greater that n, so you shouldn't print it.
In the second example you can take the first query to obtain 1. You can take only the second query to obtain 2. You can take all queries to obtain 3.
In the third example you can obtain the following maximums:
* You can achieve the maximim of 2 by using queries: (1).
* You can achieve the maximim of 3 by using queries: (2).
* You can achieve the maximim of 5 by using queries: (1, 2).
* You can achieve the maximim of 6 by using queries: (3).
* You can achieve the maximim of 8 by using queries: (1, 3).
* You can achieve the maximim of 9 by using queries: (2, 3).
Submitted Solution:
```
[n, q] = [int(x) for x in input().split()]
plus, minus = [[] for x in range(n + 1)], [[] for x in range(n + 1)]
ok, dp = [0] * (n + 1), [0] * (n + 1)
for i in range(q):
[L, R, val] = [int(x) for x in input().split()]
plus[L].append(val)
minus[R].append(val)
def Plus(v):
for i in range(n, v - 1, -1):
dp[i] += dp[i - v]
def Minus(v):
for i in range(v, n + 1):
dp[i] -= dp[i - v]
dp[0] = 1
for i in range(1, n + 1):
for j in plus[i]:
Plus(j)
for j in range(1, n + 1):
ok[j] = max(ok[j], dp[j])
for j in minus[i]:
Minus(j)
ans = []
for i in range(1, n + 1):
if ok[i] > 0:
print(i, ok[i])
ans.append(i)
print(len(ans))
print(' '.join([str(x) for x in ans]))
```
No
| 94,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Grisha come to a contest and faced the following problem.
You are given an array of size n, initially consisting of zeros. The elements of the array are enumerated from 1 to n. You perform q operations on the array. The i-th operation is described with three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n) and means that you should add x_i to each of the elements with indices l_i, l_i + 1, …, r_i. After all operations you should find the maximum in the array.
Grisha is clever, so he solved the problem quickly.
However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?"
Help Grisha, find all integers y between 1 and n such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to y.
Input
The first line contains two integers n and q (1 ≤ n, q ≤ 10^{4}) — the length of the array and the number of queries in the initial problem.
The following q lines contain queries, one per line. The i-th of these lines contains three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n), denoting a query of adding x_i to the segment from l_i-th to r_i-th elements of the array, inclusive.
Output
In the first line print the only integer k, denoting the number of integers from 1 to n, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations.
In the next line print these k integers from 1 to n — the possible values of the maximum. Print these integers in increasing order.
Examples
Input
4 3
1 3 1
2 4 2
3 4 4
Output
4
1 2 3 4
Input
7 2
1 5 1
3 7 2
Output
3
1 2 3
Input
10 3
1 1 2
1 1 3
1 1 6
Output
6
2 3 5 6 8 9
Note
Consider the first example. If you consider the subset only of the first query, the maximum is equal to 1. If you take only the second query, the maximum equals to 2. If you take the first two queries, the maximum becomes 3. If you take only the fourth query, the maximum becomes 4. If you take the fourth query and something more, the maximum becomes greater that n, so you shouldn't print it.
In the second example you can take the first query to obtain 1. You can take only the second query to obtain 2. You can take all queries to obtain 3.
In the third example you can obtain the following maximums:
* You can achieve the maximim of 2 by using queries: (1).
* You can achieve the maximim of 3 by using queries: (2).
* You can achieve the maximim of 5 by using queries: (1, 2).
* You can achieve the maximim of 6 by using queries: (3).
* You can achieve the maximim of 8 by using queries: (1, 3).
* You can achieve the maximim of 9 by using queries: (2, 3).
Submitted Solution:
```
from itertools import permutations
n, q = list(map(int, input().split()))
s = [int(0) for i in range(n)]
maxC = 0
maxValues = []
qList = []
for i in range(q):
l, r, x = list(map(lambda x: int(x) - 1, input().split()))
x += 1
qList.append((l, r, x))
lst = list(permutations(range(q)))[:(2**q // 3)]
while lst:
posl = lst.pop(0)
sCopy = s.copy()
for ind in posl:
l, r, x = qList[int(ind)]
for j in range(l, r + 1):
sCopy[j] += x
currentMax = max(sCopy)
if currentMax not in maxValues and currentMax <= n:
maxValues.append(currentMax)
maxC += 1
print(maxC)
print(*sorted(maxValues))
```
No
| 94,130 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
"Correct Solution:
```
n=int(input())
ans=10**n - 2*9**n + 8**n
print(ans%(10**9 + 7))
```
| 94,131 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
"Correct Solution:
```
n=int(input())
m=((10**n)-(2*(9**n))+(8**n))%1000000007
print(m)
```
| 94,132 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
"Correct Solution:
```
N=int(input())
ans=(10**N-9**N-9**N+8**N)%(10**9+7)
print(ans)
```
| 94,133 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
"Correct Solution:
```
n=int(input())
print((10**n+8**n-2*9**n)%(10**9+7))
```
| 94,134 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
"Correct Solution:
```
n=int(input())
a=10**n+8**n-2*(9**n)
print(a%(10**9+7))
```
| 94,135 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
"Correct Solution:
```
n=int(input())
x=10**n
y=9**n
z=8**n
print((x-y*2+z)%(10**9+7))
```
| 94,136 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
"Correct Solution:
```
N=int(input())
x=(10**N-2*(9**N)+8**N)%(10**9+7)
print(x)
```
| 94,137 |
Provide a correct Python 3 solution for this coding contest problem.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
"Correct Solution:
```
n=int(input())
print((10**n-(2*9**n-8**n))%(10**9+7))
```
| 94,138 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n=int(input())
mod=10**9+7
print((10**n-(2*9**n)+8**n)%mod)
```
Yes
| 94,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
MOD=10**9+7
n=int(input())
ans= 10**n - 9**n - 9**n + 8**n
print(ans%MOD)
```
Yes
| 94,140 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
N=int(input())
print((10**N-8**N-(2*(9**N-8**N)))%(10**9+7))
```
Yes
| 94,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n=int(input())
a=10**n-2*(9**n)+8**n
print(a%(10**9+7))
```
Yes
| 94,142 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n=int(input())
print(pow(10,n,10**9+7)-2*pow(9,n,10**9+7)+pow(8,n,10**9+7))
```
No
| 94,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n = int(input())
x = n*(n-1)*2(10**(n-2))
print(x%(10**9 + 7))
```
No
| 94,144 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n = int(input())
if (n == 1)or(n==0):
print(0)
else:
if n==2:
print(2)
else:
ans = (10**(n-3))*54
print(ans)
```
No
| 94,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?
* 0 \leq A_i \leq 9
* There exists some i such that A_i=0 holds.
* There exists some i such that A_i=9 holds.
The answer can be very large, so output it modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer modulo 10^9 + 7.
Examples
Input
2
Output
2
Input
1
Output
0
Input
869121
Output
2511445
Submitted Solution:
```
n=int(input())
P=1000000007
print((pow(10,n,P)-pow(8,n,P)) % P)
```
No
| 94,146 |
Provide a correct Python 3 solution for this coding contest problem.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
"Correct Solution:
```
n,m,k = map(int,input().split())
mod = 998244353
ans = 0
fact = [1,1]
finv = [1,1]
for i in range(2, n+1):
fact += [fact[i-1] * i % mod]
finv += [pow(fact[i], mod-2, mod)]
def comb(n,k, mod):
return (fact[n] * finv[k] * finv[n-k]) % mod
for i in range(0, k+1):
ans += m * pow(m-1, n-i-1, mod) * comb(n-1, i, mod)
ans %= mod
print(ans)
```
| 94,147 |
Provide a correct Python 3 solution for this coding contest problem.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
"Correct Solution:
```
MOD = 998244353
FACT_MAX = 2 * 10 ** 5
fact = [1] * FACT_MAX
for i in range(1, FACT_MAX):
fact[i] = fact[i - 1] * i % MOD
def comb(n, r):
return fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD) % MOD
N, M, K = map(int, input().split())
total = 0
for k in range(K + 1):
total = (total + comb(N - 1, k) * M * pow(M - 1, N - k - 1, MOD)) % MOD
print(total)
```
| 94,148 |
Provide a correct Python 3 solution for this coding contest problem.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
"Correct Solution:
```
def cmb(n,r,mod):
if r<0 or r>n:return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
mod=998244353
n,m,k=map(int,input().split())
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,n):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1]%mod))
ans=m*(m-1)**(n-1)
for i in range(k):
ans +=(m*pow(m-1,n-2-i,mod))*cmb(n-1,i+1,mod)
ans %=mod
print(ans%mod)
```
| 94,149 |
Provide a correct Python 3 solution for this coding contest problem.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
"Correct Solution:
```
MOD = 998244353
fac = [1] * (3 * 10 ** 5)
for i in range(len(fac) - 1):
fac[i + 1] = fac[i] * (i + 1) % MOD
def comb(n, k):
return fac[n] * pow(fac[n - k], MOD - 2, MOD) * pow(fac[k], MOD - 2, MOD) % MOD
n, m, k = map(int, input().split())
ans = 0
for a in range(n, n - k - 1, -1):
ans += m * pow(m - 1, a - 1, MOD) * comb(n - 1, a - 1) % MOD
print(ans % MOD)
```
| 94,150 |
Provide a correct Python 3 solution for this coding contest problem.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
"Correct Solution:
```
n, m, k = map(int, input().split())
MOD = 998244353
ans = 0
c = 1
for i in range(k + 1):
ans = (ans + m * pow(m - 1, n - i - 1, MOD) * c) % MOD
c = (c * (n - 1 - i) * pow(i + 1, MOD - 2, MOD)) % MOD
# print(f"{ans = }, {c = }")
print(ans)
```
| 94,151 |
Provide a correct Python 3 solution for this coding contest problem.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
"Correct Solution:
```
def main():
n, m, k = map(int, input().split())
MOD = 998244353
ans = 0
c = 1
for i in range(k + 1):
ans += (((m * pow(m - 1, n - i - 1, MOD)) % MOD) * c) % MOD
ans %= MOD
c = (c * (n - 1 - i) * pow(i + 1, MOD - 2, MOD)) % MOD
print(ans % MOD)
if __name__ == '__main__':
main()
```
| 94,152 |
Provide a correct Python 3 solution for this coding contest problem.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
"Correct Solution:
```
n,m,k=map(int,input().split())
mod=998244353
if m==1:print(0 if k!=n-1 else 1);exit()
fact=[1]*(n-1+1)
inv=[1]*(n-1+1)
for i in range(2,n-1+1):
fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(n-1,1,-1):
inv[i-1]=inv[i]*i%mod
ans=0
po=pow(m-1,n-1,mod)*m%mod
ue=fact[n-1]
iii=pow(m-1,mod-2,mod)%mod
for i in range(k+1):
ans+=ue*inv[n-1-i]%mod*inv[i]%mod*po%mod
po*=iii
po%=mod
print(ans%mod)
```
| 94,153 |
Provide a correct Python 3 solution for this coding contest problem.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
"Correct Solution:
```
N, M, K = map(int, input().split())
mod = 998244353
fact = [1 for i in range(N+1)]
fact_inv = [1 for i in range(N+1)]
for i in range(1, N+1):
fact[i] = fact[i-1] * i %mod
fact_inv[i] = pow(fact[i], mod-2, mod)
ans = 0
for k in range(K+1):
x = M *pow(M-1, N-1-k, mod) *fact[N-1] *fact_inv[k] *fact_inv[N-1-k]
ans += x %mod
ans = ans %mod
print(ans)
```
| 94,154 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
Submitted Solution:
```
#E
n,m,k = list(map(int,input().split()))
fac = [1]*n
finv = [1]*n
inv = [1]*n
MOD = 998244353
for i in range(2,n):
fac[i] = fac[i-1]*i%MOD
inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
def comb(n,k):
return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
ans = 0
for i in range(k+1):
# print(comb(n-1,i),m*(m-1)**(n-i-1))
ans += comb(n-1,i)*m*pow(m-1,n-i-1,MOD)%MOD
ans %= MOD
print(ans)
```
Yes
| 94,155 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
Submitted Solution:
```
MOD = 998244353
N, M, K = map(int, input().split())
Mp = [0]*(K+1)
nck = [0]*(K+1)
nck[0] = 1
ans = 0
comb = 1
for i in range(K+1):
t = 1
t *= M
t %= MOD
t *= pow(M-1, N-1-i, MOD)
t %= MOD
t *= comb
t %= MOD
ans += t
ans %= MOD
comb *= N-1-i
comb %= MOD
comb *= pow(i+1, MOD-2, MOD)
comb %= MOD
print(ans)
```
Yes
| 94,156 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
Submitted Solution:
```
# coding: utf-8
def solve(*args: str) -> str:
n, m, k = map(int, args[0].split())
mod = 998244353
if m == 1 and n-1 == k:
return str(1)
ncr = 1
p = m*pow(m-1, n-1, mod) % mod
ret = p
inv = pow(m-1, mod-2, mod)
for i in range(1, k+1):
ncr = (ncr * (n-i)*pow(i, mod-2, mod)) % mod
p = (p*inv) % mod
ret += p*ncr % mod
return str(ret % mod)
if __name__ == "__main__":
print(solve(*(open(0).read().splitlines())))
```
Yes
| 94,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
Submitted Solution:
```
n, m, k = map(int, input().split())
ans = 0
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 998244353
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, n + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(k + 1):
ans = (ans + m * pow(m - 1, n - 1 - i, mod) * cmb(n-1,i, mod)) % mod
print(ans)
```
Yes
| 94,158 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
Submitted Solution:
```
N,M,K=map(int, input().split())
MOD=998244353
ans=0
temp2=1
temp3=1
for i in range(K+1):
if i == 0:
temp1=M*(M-1)**(N-1)%MOD
temp=temp1*temp2%MOD
ans+=temp
#print(temp)
else:
temp1=M*(M-1)**(N-1-i)%MOD
temp2*=(N-i)
temp3*=i
temp=temp1*temp2*temp3%MOD
ans+=temp
#print(temp)
print(ans%MOD)
```
No
| 94,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
Submitted Solution:
```
N, M, K = map(int, input().split())
MOD = 998244353
MAX = 2 * 10 ** 5 + 1
# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
# Inverse
inv = [0] * (MAX + 1)
inv[1] = 1
# Inverse factorial
finv = [0] * (MAX + 1)
finv[0] = 1
finv[1] = 1
for i in range(2, MAX + 1):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def comb(n, k):
if n < k or k < 0:
return 0
return (fac[n] * finv[k] * finv[n - k]) % MOD
ans = 0
for k in range(K + 1):
ans += (comb(N - 1, k) * M * pow(M - 1, N - k - 1, MOD)) % MOD
print(ans)
```
No
| 94,160 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
Submitted Solution:
```
n,m,k=map(int,input().split())
mod=998244353
ans=m*((m-1)**(n-1))%mod
print(ans)
```
No
| 94,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N blocks arranged in a row. Let us paint these blocks.
We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.
Find the number of ways to paint the blocks under the following conditions:
* For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.
* There may be at most K pairs of adjacent blocks that are painted in the same color.
Since the count may be enormous, print it modulo 998244353.
Constraints
* All values in input are integers.
* 1 \leq N, M \leq 2 \times 10^5
* 0 \leq K \leq N - 1
Input
Input is given from Standard Input in the following format:
N M K
Output
Print the answer.
Examples
Input
3 2 1
Output
6
Input
100 100 0
Output
73074801
Input
60522 114575 7559
Output
479519525
Submitted Solution:
```
def e_colorful_blocks(MOD=998244353):
N, M, K = [int(i) for i in input().split()]
# dp[i][k]: i 番目まで見たときに、同じ色で塗られている組が k 組である
dp = [[0] * (K + 1) for _ in range(N)]
dp[0][0] = M
for i in range(N - 1):
for k in range(min(i, K) + 1):
if k == K:
dp[i + 1][k] += dp[i][k] * (M - 1) # 異なる色で塗るしかない
dp[i + 1][k] %= MOD
else:
dp[i + 1][k] += dp[i][k] * (M - 1) # 左と異なる色で塗る
dp[i + 1][k + 1] += dp[i][k] # 左と同じ色で塗る
dp[i + 1][k] %= MOD
dp[i + 1][k + 1] %= MOD
return sum([dp[N - 1][k] for k in range(K + 1)]) % MOD
print(e_colorful_blocks())
```
No
| 94,162 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
"Correct Solution:
```
from fractions import gcd
N, M = map(int, input().split())
A = list(map(int, input().split()))
a = A[0]
n = 1
while a % 2 == 0:
n *= 2
a //= 2
lcm = 1
for a in A:
if a % n != 0 or a % (2 * n) == 0:
print(0)
exit()
lcm = lcm * a // gcd(lcm, a)
if lcm // 2 > M:
print(0)
exit()
print((M - lcm // 2) // lcm + 1)
```
| 94,163 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
"Correct Solution:
```
from fractions import gcd
from functools import reduce
N, M, *A = map(int, open(0).read().split())
Y = reduce(lambda a, b: a * b // gcd(a, b), A)
print(M // (Y // 2) - (M // Y) if all((Y // a) % 2 for a in A) else 0)
```
| 94,164 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
"Correct Solution:
```
from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = 1
num = a[0]
bin = 1
while num % 2 == 0:
bin *= 2
num //= 2
for num in a:
l = (l * num // 2) // gcd(l, num // 2)
if num % bin != 0 or num % (bin * 2) == 0:
print(0)
exit()
print((m + l) // (2 * l))
```
| 94,165 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
"Correct Solution:
```
from math import gcd
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [i // 2 for i in A]
lcd = 1
for a in A:
lcd *= a // gcd(lcd, a)
for a in A:
if lcd // a % 2 == 0:
print(0)
exit()
print((M//lcd+1)//2)
```
| 94,166 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
"Correct Solution:
```
from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [a[i]//2 for i in range(n)]
lcm_a = 1
for i in range(n):
lcm_a = (lcm_a * b[i]) // gcd(lcm_a, b[i])
for i in range(n):
if (lcm_a//b[i]) % 2 == 0:
print(0)
exit()
if m < lcm_a:
print(0)
else:
m -= lcm_a
print(1 + m // (lcm_a*2))
```
| 94,167 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
"Correct Solution:
```
N,M = map(int,input().split())
A = list(map(int,input().split()))
s = set()
B = []
for a in A:
t = a & -a
s.add(t)
if len(s) > 1:
print(0)
exit()
B.append(a // t)
from fractions import gcd
l = 1
for b in B:
l = b*l // gcd(b,l)
x = l*t // 2
ans = M//x - M//(2*x)
print(ans)
```
| 94,168 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
"Correct Solution:
```
import sys
def gcd(x,y):
while y:
x,y = y , x % y
return x
n,m=map(int,input().split())
a=tuple(map(int,input().split()))
lcm = 1
for i in a:
lcm = lcm * i // gcd(lcm,i)
for i in a:
if (lcm//i)%2 == 0:
print(0)
sys.exit()
print((m+lcm//2)//lcm)
```
| 94,169 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
"Correct Solution:
```
N, M = map(int, input().split())
A = list(set(map(lambda x : int(x)//2, input().split())))
def gcd(x, y):
return x if y == 0 else gcd(y, x % y)
def lcm(x, y):
return (x * y) // gcd(x, y)
l = A[0]
for a in A[1:]:
l = lcm(l, a)
ans = (M // l + 1) // 2
for a in A[1:]:
if (l // a) % 2 == 0:
ans = 0
break
print(ans)
```
| 94,170 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
import fractions
import sys
n, m = map(int, input().split())
a = list(map(int, input().split()))
lcm = a[0]
for i in range(1, len(a)):
lcm = lcm*a[i]//fractions.gcd(lcm,a[i])
for i in a:
if(lcm//i)%2 == 0:
print(0)
sys.exit()
lcm //= 2
print(m//lcm-(m//(lcm*2)))
```
Yes
| 94,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
from fractions import gcd
def lcm(a,b):
return a*b//gcd(a,b)
n,m=map(int,input().split())
a=list(map(int,input().split()))
h=list(map(lambda x:x//2,a))
l=1
for i in range(n):
l=lcm(l,h[i])
for i in range(n):
if (l//h[i])%2==0:
print(0)
exit()
print((m//l+1)//2)
```
Yes
| 94,172 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
import fractions
import sys
input = sys.stdin.readline
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
n,m = map(int,input().split())
a = list(map(int,input().split()))
g = a[0]
for i in range(1, n):
g = g * a[i] // gcd(g, a[i])
for i in a:
if g // 2 % i == 0:
print(0)
exit()
print(-(-(m * 2 // g)//2))
```
Yes
| 94,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
from math import gcd
from functools import reduce
n,m=map(int,input().split())
lst=list(map(lambda x : int(x)//2,input().split()))
divi=0
x=lst[0]
while x%2==0:
x//=2
divi+=1
for i in range(1,n):
divi2=0
x=lst[i]
while x%2==0:
x//=2
divi2+=1
if divi!=divi2 :
print(0)
exit()
work=reduce(lambda x,y: x*y//gcd(x,y),lst)
print((m//work+1)//2)
```
Yes
| 94,174 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
import numpy
n, m = map(int, input().split())
a = list(map(int, input().split()))
ahalf = [i//2 for i in a]
lcm = numpy.lcm.reduce(ahalf)
ans = 1 + (m - lcm) // (lcm * 2)
print(ans)
```
No
| 94,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
#!/usr/bin/env python3
import sys
def gcd(a, b):
while b: a, b = b, a % b
return abs(a)
def n_lcd(a,b):
return a*b//gcd(a,b)
# lcd of a1*x1+n1 & a2*x2+n2
def lcd(a1, n1, a2, n2, M):
if a1*a2 == 0:
return M, M
x1 = 0
x2 = 0
k1 = n1
k2 = n2
while (k1 != k2)&(k1<M+2)&(k2<M+2):
if k1 < k2:
x1 += 1
k1 = a1*x1 + n1
else:
x2 += 1
k2 = a2*x2 + n2
# print(k1, k2)
return k1, n_lcd(a1, a2)
def solve(N: int, M: int, a: "List[int]"):
a = sorted(list(set(a)))
base = 1
base_n = 0
for i in a:
base_n, base = lcd(base, base_n, i, i//2, M)
if base > M:
print(0)
else:
print((M-base_n)//base + 1)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, M, a)
if __name__ == '__main__':
main()
```
No
| 94,176 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
def main():
n, m = map(int, input().split())
aa = list(map(int, input().split()))
from fractions import gcd
from math import ceil
from functools import reduce
def lcm(x, y):
return x * y // gcd(x, y)
l = reduce(lcm, aa)
h = l // 2
count = ceil((m - h) / l)
print(count)
if __name__ == "__main__":
main()
```
No
| 94,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
import fractions
import math
n, m = map(int, input().split())
a = set(map(int, input().split()))
lcm = 1
for ai in a:
lcm = (lcm * ai) // fractions.gcd(lcm, ai)
print((m+lcm/2) // lcm)
```
No
| 94,178 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
"Correct Solution:
```
p = int(input())
a = list(map(int, input().split()))
MAX = 3000
fact = [1]*(MAX+1)
for i in range(1, MAX+1):
fact[i] = (fact[i-1]*i) % p
inv = [1]*(MAX+1)
for i in range(2, MAX+1):
inv[i] = inv[p % i]*(p-p//i) % p
fact_inv = [1]*(MAX+1)
for i in range(1, MAX+1):
fact_inv[i] = fact_inv[i-1] * inv[i] % p
def comb(n, k):
if n < k:
return 0
return fact[n] * fact_inv[n-k] * fact_inv[k] % p
ans = [0]*p
for i,ai in enumerate(a):
if ai == 1:
ans[-1] += 1
for j in range(p):
ans[j] -= pow(-i,j,p)*comb(p-1,j)
ans[j] %= p
print(*ans[::-1])
```
| 94,179 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
"Correct Solution:
```
class Combi():
def __init__(self, N, mod):
self.power = [1 for _ in range(N+1)]
self.rev = [1 for _ in range(N+1)]
self.mod = mod
for i in range(2, N+1):
self.power[i] = (self.power[i-1]*i) % self.mod
self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
for j in range(N, 0, -1):
self.rev[j-1] = (self.rev[j]*j) % self.mod
def C(self, K, R):
if K < R:
return 0
else:
return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod
def P(self, K, R):
if K < R:
return 0
else:
return (self.power[K])*(self.rev[K-R]) % self.mod
P = int(input())
c = Combi(P-1, P)
A = list(map(int,input().split()))
ans = [0 for i in range(P)]
for i in range(P):
if A[i] != 0:
ans[0] += 1
for j in range(P):
ans[j] -= c.C(P-1, j)*pow(-i, P-1-j,P)
for i in range(P):
ans[i] %= P
print(*ans)
```
| 94,180 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
"Correct Solution:
```
p = int(input())
mod = p
def frac(limit):
frac = [1]*limit
for i in range(2,limit):
frac[i] = i * frac[i-1]%mod
fraci = [None]*limit
fraci[-1] = pow(frac[-1], mod -2, mod)
for i in range(-2, -limit-1, -1):
fraci[i] = fraci[i+1] * (limit + i + 1) % mod
return frac, fraci
frac, fraci = frac(p)
A = list(map(int, input().split()))
C = [0]*p
for i in range(p):
a = A[i]
for j in range(i):
a = (a-C[j]*frac[i]*fraci[i-j])
C[i] = fraci[i]*a%p
B = [0]*p
t = [0]*p
t[0] = 1
for i in range(p):
for j in range(p):
B[j] += t[j]*C[i]
t2 = ([0] + t)[:-1]
t2 = [(a-b*i)%p for a, b in zip(t2, t)]
t = t2[:]
B = [b%p for b in B]
print(*B)
```
| 94,181 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
"Correct Solution:
```
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
def inv(a, mod):
b = mod
p = 1; q = 0
while b > 0:
c = a // b
a, b = b, a%b
p, q = q, p-c*q
return p + mod if p < 0 else p
def guess(mod, y):
n = len(y)
dp = [0] * (n+1)
dp[0] = 1
for i in range(n):
for j in range(i, -1, -1):
dp[j+1] += dp[j]
if dp[j+1] >= mod:
dp[j+1] -= mod
dp[j] = dp[j] * -i % mod
if dp[j] < 0:
dp[j] += mod
f = [0] * (n+1)
f[0] = 1
for i in range(1, n+1):
f[i] = f[i-1] * i % mod
ret = [0] * n
for i in range(n):
den = f[i] * f[n-1-i] % mod
if ((i^n-1)&1) == 1:
den = mod - den
iden = inv(den, mod) * y[i] % mod
minus = 0
for j in range(n-1, -1, -1):
minus = (dp[j+1] + minus * i) % mod
ret[j] = (ret[j] + minus * iden) % mod
return ret
p = ni()
a = na()
f = guess(p, a)
for i in range(p):
sys.stdout.write(str(f[i]) + " ")
```
| 94,182 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
"Correct Solution:
```
def f_polynomal_construction(P, A):
class Combination(object):
"""参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb"""
__slots__ = ["mod", "factorial", "inverse"]
def __init__(self, max_n: int = 10**6, mod: int = 10**9 + 7):
fac, inv = [1], []
fac_append, inv_append = fac.append, inv.append
for i in range(1, max_n + 1):
fac_append(fac[-1] * i % mod)
inv_append(pow(fac[-1], mod - 2, mod))
for i in range(max_n, 0, -1):
inv_append(inv[-1] * i % mod)
self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]
def combination(self, n, r):
if n < 0 or r < 0 or n < r:
return 0
return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod
combination = Combination(P - 1, P)
comb = [combination.combination(P - 1, i) for i in range(P)]
ans = [0] * P
for j, a in enumerate(A):
if a == 0:
continue
# 1-(x-j)^{p-1} = 1 - \sum_{k=0}^{p-1} comb(p-1, p-k-1) * x^{p-k-1} * (-j)^k
# なので、定数項に1を足し、x^k の係数から各々引く
# pow(-j, k, P) としたいが、時間がかかるので tmp に掛けていくことにする
ans[0] += 1
tmp = 1
for k in range(P):
index = P - k - 1
if k > 0:
tmp *= (-j)
tmp %= P
ans[index] -= comb[index] * tmp
ans[index] %= P
return ' '.join(map(str, ans))
P = int(input())
A = [int(i) for i in input().split()]
print(f_polynomal_construction(P, A))
```
| 94,183 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
"Correct Solution:
```
p = int(input())
a = list(map(int, input().split()))
MOD = p
MAX = p + 10
fact = [1] * (MAX + 1) # i!
finv = [1] * (MAX + 1) # (i!)^{-1}
iinv = [1] * (MAX + 1) # i^{-1}
for i in range(2, MAX + 1):
fact[i] = fact[i - 1] * i % MOD
iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * iinv[i] % MOD
def comb(n: int, k: int) -> int:
if n < k or n < 0 or k < 0:
return 0
return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD
b = [0] * p
for j in range(p):
if a[j] == 1:
b[0] += 1
for k in range(p):
b[k] += comb(p - 1, k) * pow(j, p - 1 - k, MOD) * (-1)**(
(p - k) % 2)
b[k] %= MOD
print(*b)
```
| 94,184 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
"Correct Solution:
```
def main():
import sys
input = sys.stdin.readline
p = int(input())
A = list(map(int, input().split()))
ans = [0] * p
for i, a in enumerate(A):
if not a:
continue
ans[-1] += 1
ij = 1
ans[0] = (ans[0] - ij)%p
for j in range(1, p):
ij = (ij * i)%p
ans[j] = (ans[j] - ij)%p
ans.reverse()
print(*ans)
if __name__ == '__main__':
main()
```
| 94,185 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
"Correct Solution:
```
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
def get_factorials(max, mod=None):
"""
階乗 0!, 1!, 2!, ..., max!
:param int max:
:param int mod:
:return:
"""
ret = [1]
n = 1
if mod:
for i in range(1, max + 1):
n *= i
n %= mod
ret.append(n)
else:
for i in range(1, max + 1):
n *= i
ret.append(n)
return ret
def mod_invs(max, mod):
"""
逆元のリスト 0 から max まで
:param int max:
:param int mod:
"""
invs = [1] * (max + 1)
for x in range(2, max + 1):
invs[x] = (-(mod // x) * invs[mod % x]) % mod
return invs
def factorial_invs(max, mod):
"""
階乗 0!, 1!, 2!, ..., max! の逆元
:param int max:
:param int mod:
"""
ret = []
r = 1
for inv in mod_invs(max, mod):
r = r * inv % mod
ret.append(r)
return ret
class Combination:
def __init__(self, max, mod):
"""
:param int max:
:param int mod: 3 以上の素数であること
"""
self._factorials = get_factorials(max, mod)
self._finvs = factorial_invs(max, mod)
self._mod = mod
def ncr(self, n, r):
"""
:param int n:
:param int r:
:rtype: int
"""
if n < r:
return 0
return (
self._factorials[n]
* self._finvs[r]
% self._mod
* self._finvs[n - r]
% self._mod
)
P = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
# A = np.array(A, dtype=int)
# vpow = np.vectorize(lambda a, b: pow(a, b, P))
# mat = []
# for i in range(P):
# mat.append(vpow(i, np.arange(P)))
# print(np.array(mat).sum(axis=1) % P)
# print(np.array(mat).sum(axis=0) % P)
# mat = np.hstack((mat, [[a] for a in A]))
#
# print(mat)
#
# 解説AC
# f(x) = 1−(x - j)^(P - 1) は、x == j のとき1、それ以外のとき0
# A[j] == 1 である j について上記の式を足し合わせる
comb = Combination(max=P - 1, mod=P)
ncr = [comb.ncr(P - 1, i) for i in range(P)]
B = [0] * P
for j, a in enumerate(A):
if a == 0:
continue
pw = 1 # pow(-j, i, P)
for i in range(P):
B[i] -= pw * ncr[i] % P
B[i] %= P
pw = (pw * -j) % P
B[-1] += 1
B[-1] %= P
print(*B[::-1])
```
| 94,186 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
p = int(input())
a = [int(i) for i in input().split()]
ans = [0]*p
for i,j in enumerate(a):
if j == 0:
continue
ans[0] -= p-1
m = 1
for k in range(p):
ans[p-1-k] -= m
ans[p-1-k] %= p
m *= i
m %= p
print(*ans)
```
Yes
| 94,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
#mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
def main():
p = int(ipt())
a = [int(i) for i in ipt().split()]
mod = p
#nCrをmodで割った余りを求める。Nに最大値を入れて使用。
N = 3000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
def cmb(n,r,mod=p):
if r<0 or r>n :
return 0
r = min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
for i in range(2,N+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod % i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
ans = [0]*p
for i in range(p):
if a[i]:
ans[0] += 1
sgn = -1
ji = 1
for j in range(p-1,-1,-1):
ans[j] += sgn*ji*cmb(p-1,j,p)
ji *= i
ji %= p
ans[j] %= p
sgn *= -1
print(" ".join(map(str,ans)))
return None
if __name__ == '__main__':
main()
```
Yes
| 94,188 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
p = int(input())
aaa = list(map(int, input().split()))
coefs = [0] * p
coefs[0] = sum(aaa)
invs = [pow(x, p - 2, p) for x in range(p + 1)]
for i, a in enumerate(aaa):
if a == 0:
continue
b = 1
c = 1
for j in range(p - 1, -1, -1):
coefs[j] = (coefs[j] - b * c) % p
b = -b * i % p
c = c * j * invs[p - j] % p
print(*coefs)
```
Yes
| 94,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
class Combination:
"""階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
def __init__(self, n, MOD):
self.fact = [1]
for i in range(1, n + 1):
self.fact.append(self.fact[-1] * i % MOD)
self.inv_fact = [0] * (n + 1)
self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
for i in reversed(range(n)):
self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
self.MOD = MOD
def inverse(self, k):
"""kの逆元を求める O(1)"""
return (self.inv_fact[k] * self.fact[k - 1]) % self.MOD
def factorial(self, k):
"""k!を求める O(1)"""
return self.fact[k]
def inverse_factorial(self, k):
"""k!の逆元を求める O(1)"""
return self.inv_fact[k]
def permutation(self, k, r):
"""kPrを求める O(1)"""
if k < r:
return 0
return (self.fact[k] * self.inv_fact[k - r]) % self.MOD
def combination(self, k, r):
"""kCrを求める O(1)"""
if k < r:
return 0
return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD
def combination2(self, k, r):
"""kCrを求める O(r)
kが大きいが、r <= nを満たしているときに使用
"""
if k < r:
return 0
res = 1
for l in range(r):
res *= (k - l)
res %= self.MOD
return (res * self.inv_fact[r]) % self.MOD
p = int(input())
a = list(map(int, input().split()))
comb = Combination(p - 1, p)
b = [0] * p
for i in range(p):
for j in range(p):
# (x - j) ^ (p - 1) の係数x^iの部分
tmp = pow(-j, (p - 1 - i), p) * comb.combination(p - 1, i)
b[i] -= a[j] * tmp
b[i] %= p
b[0] = a[0]
print(*b)
```
Yes
| 94,190 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
p = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(p)]
B[0] = A[0]
for i in range(1, p):
B[p-i] = ((-1) * sum(A[1:]))%p
for j in range(p):
A[j] *= j
A[j] %= p
for i in range(p):
if i != p - 1:
print(B[i], end = ' ')
else:
print(B[i], end = '')
```
No
| 94,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
p = int(input())
a = [int(item) for item in input().split()]
fac = [1] + [0] * (p - 1)
facinv = [1] + [0] * (p - 1)
for i in range(1, p):
fac[i] = fac[i-1] * i % p
facinv[i] = facinv[i-1] * pow(i, p-2, p) % p
# print(fac)
# print(facinv)
comb = [0] * p
for i in range(p):
comb[i] = fac[p-1] * facinv[i] * facinv[p-1-i] % p
# print(comb)
ans = [0] * p
ppowp = [[0] * (p + 1) for _ in range(p + 1)]
for i in range(p+1):
val = 1
for j in range(p+1):
ppowp[i][j] = val
val *= i
val %= p
for i, item in enumerate(a):
if item == 1:
ans[0] += 1
# Calc (i - x)**(p - 1)
for j in range(p):
# ans[j] -= pow(i, p-1-j, p) * pow(-1, j, p) * comb[j] % p
if j % 2 == 1:
ans[j] -= ppowp[i][p-1-j] * -1 * comb[j] % p
else:
ans[j] -= ppowp[i][p-1-j] * comb[j] % p
ans[j] %= p
print(" ".join([str(item) for item in ans]))
```
No
| 94,192 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
#!/usr/bin/env python3
import sys
import functools
INF = float("inf")
MOD = 2 # type: int
def power(b, p):
if p == 0:
return 1
elif p == 1:
return b
elif p % 2 == 1:
return b*power(b, p-1)
else:
return power(b*b, p//2)
def solve(p: int, a: "List[int]"):
kaijo = [1]*p
kaijo_inv = [1]*p
for i in range(2, p):
kaijo[i] = (kaijo[i-1]*i) % p
kaijo_inv[i] = power(kaijo[i], p-2) % p
@functools.lru_cache(maxsize=None)
def cmb(n, r):
return (kaijo[n]*kaijo_inv[n-r]*kaijo_inv[r]) % p
b = [0]*p
for ai, av in enumerate(a):
if av == 1:
for i in range(p):
b[i] += -cmb(p-1, i) * power(-ai, p-i-1)
b[i] %= p
b[0] += 1
b[0] %= p
print(*b, sep=" ")
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
p = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(p-1-0+1)] # type: "List[int]"
solve(p, a)
if __name__ == '__main__':
main()
```
No
| 94,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3
Submitted Solution:
```
def f_polynomal_construction(P, A):
class Combination(object):
"""参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb"""
__slots__ = ["mod", "factorial", "inverse"]
def __init__(self, max_n: int = 10**6, mod: int = 10**9 + 7):
fac, inv = [1], []
fac_append, inv_append = fac.append, inv.append
for i in range(1, max_n + 1):
fac_append(fac[-1] * i % mod)
inv_append(pow(fac[-1], mod - 2, mod))
for i in range(max_n, 0, -1):
inv_append(inv[-1] * i % mod)
self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]
def combination(self, n, r):
if n < 0 or r < 0 or n < r:
return 0
return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod
combination = Combination(P - 1, P)
comb = [combination.combination(P - 1, i) for i in range(P)]
ans = [0] * P
for j, a in enumerate(A):
if a == 0:
continue
# 1-(x-j)^{p-1} = 1 - \sum_{k=0}^{p-1} comb(p-1, p-k-1) * x^{p-k-1} * (-j)^k
# なので、定数項に1を足し、x^k の係数から各々引く
# pow(-j, k, P) としたいが、時間がかかるので tmp に掛けていくことにする
ans[0] += 1
tmp = 1
for k in range(P):
index = P - k - 1
# if k > 0:
# tmp *= (-j)
# tmp %= P
# ans[index] -= comb[index] * tmp
ans[index] -= comb[index] * pow(-j, k, P)
ans[index] %= P
return ' '.join(map(str, ans))
P = int(input())
A = [int(i) for i in input().split()]
print(f_polynomal_construction(P, A))
```
No
| 94,194 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
"Correct Solution:
```
import re
ans = max(map(len, re.findall("[ACGT]*", input())))
print(ans)
```
| 94,195 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
"Correct Solution:
```
a="".join(["1" if s in ["A","C","G","T"] else "0" for s in input()])
ans=[len(s) for s in a.split("0")]
print(max(ans))
```
| 94,196 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
"Correct Solution:
```
import re
data = input()
t = re.split('[^ACGT]+', data)
t.sort(key=len, reverse=True)
print(len(t[0]))
```
| 94,197 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
"Correct Solution:
```
import re
ll = list(map(len,re.sub('[^ACGT]',' ', input()).split()))
if len(ll) == 0:print(0)
else:print(max(ll))
```
| 94,198 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than `A`, `C`, `G` and `T`.
Constraints
* S is a string of length between 1 and 10 (inclusive).
* Each character in S is an uppercase English letter.
Input
Input is given from Standard Input in the following format:
S
Output
Print the length of the longest ACGT string that is a substring of S.
Examples
Input
ATCODER
Output
3
Input
HATAGAYA
Output
5
Input
SHINJUKU
Output
0
"Correct Solution:
```
import re
result = re.findall('[ATCG]+',input(),re.S)
if len(result)>0:
print(max(list(map(len,result))))
else:
print(0)
```
| 94,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.