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.
During cleaning the coast, Alice found n piles of stones. The i-th pile has a_i stones.
Piles i and i + 1 are neighbouring for all 1 β€ i β€ n - 1. If pile i becomes empty, piles i - 1 and i + 1 doesn't become neighbouring.
Alice is too lazy to remove these stones, so she asked you to take this duty. She allowed you to do only the following operation:
* Select two neighboring piles and, if both of them are not empty, remove one stone from each of them.
Alice understands that sometimes it's impossible to remove all stones with the given operation, so she allowed you to use the following superability:
* Before the start of cleaning, you can select two neighboring piles and swap them.
Determine, if it is possible to remove all stones using the superability not more than once.
Input
The first line contains a single integer t (1 β€ t β€ 10^4) β the number of test cases.
The first line of each test case contains the single integer n (2 β€ n β€ 2 β
10^5) β the number of piles.
The second line of each test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the number of stones in each pile.
It is guaranteed that the total sum of n over all test cases doesn't exceed 2 β
10^5.
Output
For each test case, print YES or NO β is it possible to remove all stones using the superability not more than once or not.
Example
Input
5
3
1 2 1
3
1 1 2
5
2 2 2 1 3
5
2100 1900 1600 3000 1600
2
2443 2445
Output
YES
YES
YES
YES
NO
Note
In the first test case, you can remove all stones without using a superability: [1, 2, 1] β [1, 1, 0] β [0, 0, 0].
In the second test case, you can apply superability to the second and the third piles and then act like in the first testcase.
In the third test case, you can apply superability to the fourth and the fifth piles, thus getting a = [2, 2, 2, 3, 1].
In the fourth test case, you can apply superability to the first and the second piles, thus getting a = [1900, 2100, 1600, 3000, 1600].
Submitted Solution:
```
def ke(x: list):
y = x.copy()
y.append(0)
for i in range(0, len(y) - 1):
if y[i] > y[i + 1]:
return False
else:
y[i + 1] -= y[i]
y[i] = 0
return True
t = int(input())
for cas in range(0, t):
n = int(input())
v = list(map(int, input().split()))
if ke(v):
print("YES")
continue
z = v.copy()
z[0], z[1] = z[1], z[0]
if ke(z):
print("YES")
continue
z = v.copy()
z[n - 2], z[n - 1] = z[n - 1], z[n - 2]
if ke(z):
print("YES")
continue
zuo = [0] * n
you = [0] * n
z = v.copy()
for i in range(0, n - 1):
if z[i] > z[i + 1]:
for j in range(i + 1, n):
zuo[j] = -1
break
else:
z[i + 1] -= z[i]
zuo[i + 1] = z[i + 1]
z[i] = 0
z = v.copy()
for i in range(n - 1, 0, -1):
if z[i] > z[i - 1]:
for j in range(i - 1, -1, -1):
you[j] = -1
break
else:
z[i - 1] -= z[i]
you[i - 1] = z[i - 1]
z[i] = 0
z = v.copy()
for i in range(1, n - 2):
if zuo[i - 1] != -1 and you[i + 2] != -1 and ke([zuo[i - 1], z[i + 1], z[i], you[i + 2]]):
print("YES")
continue
print("NO")
```
No
| 14,400 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Tags: implementation
Correct Solution:
```
n , m = map(int , input().split())
l=[]
lhs = m
rhs=0
t=0
for i in range(n):
temp = str(input())
if t==1 or temp.count('.')!=len(temp):
t=1
l.append(temp)
if '*' in temp:
lhs = min(lhs , temp.index('*'))
rhs = max(rhs , temp.rfind('*'))
t=0
x = l[::-1]
i=0
while t==0:
if x[i] == m*'.':
x.remove(x[i])
i=i-1
else:
t=1
i = i+1
ans = x[::-1]
for i in ans:
print(i[lhs:rhs+1])
```
| 14,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Tags: implementation
Correct Solution:
```
import sys
def main():
inp = sys.stdin.read().strip().split('\n')
m, n = map(int, inp[0].split())
s = inp[1:]
x, y = set(), set()
for i in range(m):
for j in range(n):
if s[i][j] == '*':
x.add(i); y.add(j)
out = []
for i in range(min(x), max(x)+1):
out.append(s[i][min(y):max(y)+1])
return out
print(*main(), sep='\n')
```
| 14,402 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Tags: implementation
Correct Solution:
```
s=input().split()
a=int(s[0])
b=int(s[1])
lis=[]
ans=[]
col=[]
for i in range(a):
k=input()
lis.append(k)
if(lis[i].find("*")!=-1):
col.append(i)
ans.append(lis[i].find("*"))
if(lis[i].rfind("*")!=-1):
ans.append(lis[i].rfind("*"))
ans.sort()
for i in range(col[0],col[len(col)-1]+1):
print(lis[i][ans[0]:ans[len(ans)-1]+1])
```
| 14,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Tags: implementation
Correct Solution:
```
n,m=[int(s) for s in input().split()]
a=[]
up=-1
down=n
left=m
right=-1
for i in range(n):
s=input()
a.append(s)
if s.find('*')!=-1:
if up==-1: up=i
down=i
p=s.find('*')
if p<left:
left=p
p=s.rfind('*')
if p>right:
right=p
for i in range(up,down+1):
print(a[i][left:right+1])
```
| 14,404 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
A = [input() for _ in range(n)]
min_x, max_x = n, 0
min_y, max_y = m, 0
for i in range(n):
for j in range(m):
if A[i][j] == '*':
min_x, max_x = min(min_x, i), max(max_x, i)
min_y, max_y = min(min_y, j), max(max_y, j)
for x in range(min_x, max_x+1):
print(A[x][min_y:max_y+1])
```
| 14,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Tags: implementation
Correct Solution:
```
X = list(map(int, input().split()))
Picture, FirstRow, LastRow, First, Last = [], X[0], 0, X[1], 0
for i in range(X[0]):
Temp = input()
Picture.append(Temp)
if "*" in Temp:
FirstRow = min(FirstRow, i)
LastRow = i
First = min(First, Temp.index("*"))
Last = max(Last, X[1] - Temp[::-1].index("*"))
for i in range(FirstRow, LastRow + 1):
print(Picture[i][First:Last])
# UB_CodeForces
# Advice: Falling down is an accident, staying down is a choice
# Location: Here in Bojnurd
# Caption: So Close man!! Take it easy!!!!
# CodeNumber: 646
```
| 14,406 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Tags: implementation
Correct Solution:
```
T_ON = 0
DEBUG_ON = 1
MOD = 998244353
def solve():
n, m = read_ints()
M = []
for r in range(n):
M.append(input())
r1 = n
r2 = 0
c1 = m
c2 = 0
for r in range(n):
for c in range(m):
if M[r][c] == '*':
r1 = min(r1, r)
r2 = max(r2, r)
c1 = min(c1, c)
c2 = max(c2, c)
for r in range(r1, r2 + 1):
print(M[r][c1:c2+1])
def main():
T = read_int() if T_ON else 1
for i in range(T):
solve()
def debug(*xargs):
if DEBUG_ON:
print(*xargs)
from collections import *
import math
#---------------------------------FAST_IO---------------------------------------
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#----------------------------------IO_WRAP--------------------------------------
def read_int():
return int(input())
def read_ints():
return list(map(int, input().split()))
def print_nums(nums):
print(" ".join(map(str, nums)))
def YES():
print("YES")
def Yes():
print("Yes")
def NO():
print("NO")
def No():
print("No")
def First():
print("First")
def Second():
print("Second")
#----------------------------------FIB--------------------------------------
def fib(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
def fib_ns(n):
assert n >= 1
f = [0 for _ in range(n + 1)]
f[0] = 0
f[1] = 1
for i in range(2, n + 1):
f[i] = f[i - 1] + f[i - 2]
return f
#----------------------------------MOD--------------------------------------
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def xgcd(a, b):
"""return (g, x, y) such that a*x + b*y = g = gcd(a, b)"""
x0, x1, y0, y1 = 0, 1, 1, 0
while a != 0:
(q, a), b = divmod(b, a), a
y0, y1 = y1, y0 - q * y1
x0, x1 = x1, x0 - q * x1
return b, x0, y0
def lcm(a, b):
d = gcd(a, b)
return a * b // d
def is_even(x):
return x % 2 == 0
def is_odd(x):
return x % 2 == 1
def modinv(a, m):
"""return x such that (a * x) % m == 1"""
g, x, _ = xgcd(a, m)
if g != 1:
raise Exception('gcd(a, m) != 1')
return x % m
def mod_add(x, y):
x += y
while x >= MOD:
x -= MOD
while x < 0:
x += MOD
return x
def mod_mul(x, y):
return (x * y) % MOD
def mod_pow(x, y):
if y == 0:
return 1
if y % 2:
return mod_mul(x, mod_pow(x, y - 1))
p = mod_pow(x, y // 2)
return mod_mul(p, p)
def mod_inv(y):
return mod_pow(y, MOD - 2)
def mod_div(x, y):
# y^(-1): Fermat little theorem, MOD is a prime
return mod_mul(x, mod_inv(y))
#---------------------------------PRIME---------------------------------------
def is_prime(n):
if n == 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i:
return False
return True
def gen_primes(n):
"""
generate primes of [1..n] using sieve's method
"""
P = [True for _ in range(n + 1)]
P[0] = P[1] = False
for i in range(int(n ** 0.5) + 1):
if P[i]:
for j in range(2 * i, n + 1, i):
P[j] = False
return P
#---------------------------------MAIN---------------------------------------
main()
```
| 14,407 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
b = []
for i in range(n):
b.append(input())
x = []
for c in zip(*b):
for r in range(n):
if c[r] == '*':
x.append(r)
y = []
for r in b:
for c in range(m):
if r[c] == '*':
y.append(c)
for r in b[min(x) : max(x) + 1]:
print(''.join(r[min(y) : max(y) + 1]))
```
| 14,408 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Submitted Solution:
```
n,m=map(int,input().split())
arr=[]
arr1=[]
for i in range(0,n):
arr.append(input())
for i in range(0,n):
for j in range(0,m):
if arr[i][j]=='*':
arr1.append((i,j))
minx=10000
maxx=-1
miny=10000
maxy=-1
for i in range(0,len(arr1)):
if minx>arr1[i][0]:
minx=arr1[i][0]
if maxx<arr1[i][0]:
maxx=arr1[i][0]
if miny>arr1[i][1]:
miny=arr1[i][1]
if maxy<arr1[i][1]:
maxy=arr1[i][1]
for i in range(minx,maxx+1):
for j in range(miny,maxy+1):
if j!=maxy:
print(arr[i][j],end="")
else:
print(arr[i][j])
# 15 3
# ...
# ...
# ...
# .**
# ...
# ...
# *..
# ...
# .*.
# ..*
# ..*
# *..
# ..*
# ...
# ...
```
Yes
| 14,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Submitted Solution:
```
x, y = map(int, input().split())
q = [input() for i in range(x)]
t = 0
while q[t] == '.' * y:
t += 1
b = x
while q[b-1] == '.' * y:
b -= 1
l = 0
while sum(i[l] == '*' for i in q) == 0:
l += 1
r = y
while sum(i[r-1] == '*' for i in q) == 0:
r -= 1
print('\n'.join(i[l:r] for i in q[t:b]))
```
Yes
| 14,410 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Submitted Solution:
```
n,m = map(int,input().split())
t = []
for i in range(n):
t.append(input())
minx,miny = float("inf"),float("inf")
maxx,maxy = float("-inf"),float("-inf")
for i in range(n):
flag = 0
for j in range(m):
if t[i][j] == "*":
flag = 1
break
if flag == 1:
minx = min(minx,j)
for i in range(n):
flag = 0
for j in range(m-1,-1,-1):
if t[i][j] == "*":
flag = 1
break
if flag == 1:
maxx = max(maxx,j)
for i in range(m):
flag = 0
for j in range(n):
if t[j][i] == "*":
flag = 1
break
if flag == 1:
miny = min(miny,j)
for i in range(m):
flag = 0
for j in range(n-1,-1,-1):
if t[j][i] == "*":
flag = 1
break
if flag == 1:
maxy = max(maxy,j)
for i in range(miny,maxy+1):
for j in range(minx,maxx+1):
print(t[i][j],end="")
print()
```
Yes
| 14,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Submitted Solution:
```
n, m = map(int, input().split())
grid = [input() for i in range(n)]
minr, maxr, minc, maxc = n, -1, m, -1
for i in range(n):
for j in range(m):
if grid[i][j] == '*':
minr = min(minr, i)
maxr = max(maxr, i)
minc = min(minc, j)
maxc = max(maxc, j)
for i in range(minr, maxr+1):
print(grid[i][minc:maxc+1])
```
Yes
| 14,412 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Submitted Solution:
```
a, b = map(int, input().split())
ma = []
mi = []
x = []
for i in range(a):
t = input()
x.append(t)
se = []
c =-1
for i in x:
c = c+1
if "*" in i:
se.append(c)
y = i.find('*')
mi.append(y)
z = i[::-1].find('*')
ma.append(b - 1 - z)
lower = min(mi)
upper = max(ma)
start = min(se)
end = max(se)
for j in range(int(start), int(end)):
print(x[j][lower:upper + 1])
```
No
| 14,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Submitted Solution:
```
n, m = map(int, input().split())
arr = []
patt = []
for i in range(n):
k = input()
arr.append(k)
check = []
for i in arr:
a = [(x, y) for x, y in enumerate(i) if y == '*']
if len(a) > 0:
check.append(a)
z = 0
for i in range(n):
if arr[i].count('*')!=0:
z = i
break
for i in range(z,n):
patt.append(arr[i])
patt = patt[::-1]
for i in patt:
if i.count('*')!=0:
z = patt.index(i)
break
patt = patt[z:]
patt = patt[::-1]
mini = min(check)[0][0]
maxi = max(check)[-1][0]
arr = []
for i in patt:
arr.append(i[mini:maxi+1])
print('\n'.join(arr))
```
No
| 14,414 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Submitted Solution:
```
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
h,w=LI()
l=[S() for _ in range(h)]
y1=x1=0
f=False
for i in range(h):
for j in range(w):
if l[i][j]=='*':
y1=i
x1=j
f=True
break
if f:
break
y2=x2=0
f=False
for i in range(h)[::-1]:
for j in range(w)[::-1]:
if l[i][j]=='*':
y2=i
x2=j
f=True
break
if f:
break
# print(x1,y1,x2,y2)
for i in range(y1,y2+1):
ans=''
for j in range(x1,x2+1):
ans+=l[i][j]
print(ans)
main()
# print(main())
```
No
| 14,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input
The first line of the input data contains numbers n and m (1 β€ n, m β€ 50), n β amount of lines, and m β amount of columns on Bob's sheet. The following n lines contain m characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Examples
Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***
Input
3 3
***
*.*
***
Output
***
*.*
***
Submitted Solution:
```
# https://codeforces.com/problemset/problem/14/A
n, m = map(int, input().split())
first = float('inf')
last = float('-inf')
new = list()
for i in range(n):
line = input()
for j in range(m):
if line[j] == "*":
first = min(j, first)
new.append(line)
break
for j in range(m - 1, -1, -1):
if line[j] == "*":
last = max(j + 1, last)
break
for i in new:
print(i[first: last])
```
No
| 14,416 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Tags: binary search
Correct Solution:
```
I=lambda:map(int,input().split())
n,c=I()
a,b=[],[]
for _ in range(n):x,y=I();a.append(x);b.append(y)
f=lambda x:sum(1+a[i]*x//b[i]for i in range(n))
l=-1
r=10**9
while l<r-1:
m=(l+r)//2
if f(m)<c:l=m
else:r=m
L=r
l=-1
r=10**9
while l<r-1:
m=(l+r)//2
if f(m)<=c:l=m
else:r=m
while f(r)>c:r-=1
if r<1:r=1
if L<1:L=1
if f(r)!=c:print(0)
else:print(r-L+1)
```
| 14,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Tags: binary search
Correct Solution:
```
def f(x, t):
y = x
while sum((y * a) // b for a, b in t) < c: y += 1000000
while y - x > 1:
z = (x + y) // 2
d = sum((z * a) // b for a, b in t)
if d < c: x = z
else: y = z
return y
n, c = map(int, input().split())
c -= n
t = [tuple(map(int, input().split())) for i in range(n)]
x = sum(a / b for a, b in t)
if x:
x = f(int(c / x), t)
print((int(x > 0) + min((b - (x * a) % b - 1) // a for a, b in t if a > 0)) if sum((x * a) // b for a, b in t) == c else 0)
else: print(0 if c else -1)
```
| 14,418 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Tags: binary search
Correct Solution:
```
I=lambda:map(int,input().split())
n,c=I()
a,b=[],[]
for _ in range(n):x,y=I();a.append(x);b.append(y)
if max(a)==0:print([0,-1][n==c]);exit()
def f(x):
r=0
for i in range(n):
r+=1+a[i]*x//b[i]
if r>c:break
return r
l=-1
r=10**18
while l<r-1:
m=(l+r)//2
if f(m)<c:l=m
else:r=m
L=r
l=-1
r=10**18
while l<r-1:
m=(l+r)//2
if f(m)<=c:l=m
else:r=m
while f(r)>c:r-=1
if r<1:r=1
if L<1:L=1
if f(r)!=c:print(0)
else:print(r-L+1)
```
| 14,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Tags: binary search
Correct Solution:
```
a=[]
b=[]
n=0
def cal(x):
p=0
global n,a,b
for i in range(n):
p+=((a[i]*x)//b[i])
return p
n,c=map(int,input().split())
c-=n
if c < 0:
print(0)
exit(0)
a=[0]*n
b=[0]*n
for i in range(n):
a[i],b[i]=map(int,input().split())
L=1
R=10**18
lower=R+1
while L<=R :
m=(L+R)>>1
if cal(m) >= c:
lower=m
R=m-1
else: L=m+1
L=lower
R=10**18
upper=R+1
while L<=R :
m=(L+R)>>1
if cal(m) > c:
upper=m
R=m-1
else: L=m+1
print(upper-lower)
```
| 14,420 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Tags: binary search
Correct Solution:
```
n,c = map(int,input().split())
from sys import stdin
lst,q = [],0
for i in range(n):
a,b = map(int,stdin.readline().split())
lst.append([a,b])
q=max(q,b*c)
def cout(x):
res=n
for i,item in enumerate(lst):
y,z=item[0],item[1]
res+=(x*y//z)
return res
l,r=0,q
while l+1<r:
mid = (l+r)//2
result=cout(mid)
if result<c:l=mid
elif result>c:r=mid
else:break
from sys import exit
if r-l==1:
if cout(l)!=c and cout(r)!=c:print(0);exit()
i,j=l,mid
while i+1<j:
middle=(i+j)//2
if cout(middle)==c:j=middle
else:i=middle
i2,j2=mid,r
while i2+1<j2:
middle2=(i2+j2)//2
if cout(middle2)==c:i2=middle2
else:j2=middle2
if i2==j:
if cout(j)!=c:print(0);exit()
print(i2-j+1)
```
| 14,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Tags: binary search
Correct Solution:
```
n,c = map(int,input().split())
from sys import stdin
lst,q,zero = [],0,0
for i in range(n):
a,b = map(int,stdin.readline().split())
lst.append([a,b])
q=max(q,b*c)
if a==0:zero+=1
def cout(x):
res=n
for i,item in enumerate(lst):
y,z=item[0],item[1]
res+=(x*y//z)
return res
from sys import exit
if zero==n:
if n==c:print(-1)
else:print(0)
exit()
l,r=0,q
while l+1<r:
mid = (l+r)//2
result=cout(mid)
if result<c:l=mid
elif result>c:r=mid
else:break
if r-l==1:
if cout(l)!=c and cout(r)!=c:print(0);exit()
i,j=l,mid
while i+1<j:
middle=(i+j)//2
if cout(middle)==c:j=middle
else:i=middle
i2,j2=mid,r
while i2+1<j2:
middle2=(i2+j2)//2
if cout(middle2)==c:i2=middle2
else:j2=middle2
if i2==j:
if cout(j)!=c:print(0);exit()
print(i2-j+1)
```
| 14,422 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Tags: binary search
Correct Solution:
```
n, c = map(int, input().split())
a = []
b = []
for i in range(n):
aa, bb = map(int, input().split())
a.append(aa)
b.append(bb)
def all_zero():
for aa in a:
if aa > 0: return False
return True
def days(x):
c = 0
for aa, bb in zip(a, b):
c += 1 + aa*x//bb
return c
def run():
if n > c: return 0
if all_zero(): return -1 if n == c else 0
lo = 1
hi = int(2e18)
while lo < hi:
mid = (lo + hi) // 2
if days(mid) < c: lo = mid+1
else: hi = mid
if days(lo) != c: return 0
ans0 = lo
lo = 1
hi = int(2e18)
while lo < hi:
mid = (lo + hi + 1) // 2
if days(mid) > c: hi = mid-1
else: lo = mid
if days(lo) != c: return 0
return lo - ans0 + 1
print(run())
```
| 14,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Tags: binary search
Correct Solution:
```
input=__import__('sys').stdin.readline
def check(x):
tmp=0
for i in range(n):
tmp+=(1 + (lis[i][0]*x)//lis[i][1])
return tmp
def zer(lis):
for i in lis:
if i[0]>0:
return False
return True
n,c = map(int,input().split())
lis=[]
c1=0
for _ in range(n):
a,b = map(int,input().split())
lis.append([a,b])
if n>c:
print(0)
exit()
if zer(lis):
if n==c:
print(-1)
else:
print(0)
exit()
#max
ans=0
l=0
r=100000000000000000000
while l<=r:
mid = l + (r-l)//2
if check(mid)>c:
r=mid-1
else:
l=mid+1
if check(l)==c:
ans=l
else:
ans=r
l=0
r=100000000000000000000
while l<=r:
mid = l +(r-l)//2
if check(mid)>=c:
r=mid-1
else:
l=mid+1
#print(ans,l,r)
if r!=-1:
print(max(0,ans-r))
else:
print(max(0,ans-l))
```
| 14,424 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
def main():
n , c = map(int , input().split())
data = []
for i in range(n):
a,b = map(int , input().split())
data.append([a , b])
def cond(x , typ):
days = 0
for i in data:
days += 1
presents = i[0] * x
days += presents // i[1]
if typ == 1:
return [days >= c , days]
else:
return [days <= c , days]
l = 1
r = int(1e18)
ans1 = -1
days1 = -1
while l <= r:
mid = l + (r - l) // 2
llll = cond(mid , 1)
if llll[0]:
ans1 = mid
days1 = llll[1]
r = mid - 1
else:
l = mid + 1
l = 1
r = int(1e18)
ans2 = -1
days2 = -1
while l <= r:
mid = l + (r - l) // 2
llll = cond(mid , 2)
if llll[0]:
ans2 = mid
days2 = llll[1]
l = mid + 1
else:
r = mid - 1
# print(ans1 , days1 , ans2 , days2)
if days1 == c and days2 == c:
print(ans2 - ans1 + 1)
else:
print(0)
return
if __name__ == "__main__":
main()
```
Yes
| 14,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
n,c=map(int,input().split())
a=[0 for i in range(10001)]
b=a[:]
for i in range(n):
a[i],b[i]=map(int,input().split())
def chi():
if c<n:
print(0)
import sys
sys.exit(0)
if sum(a)==0:
if c==n:
print(-1)
else:
print(0)
import sys
sys.exit(0)
def ch(day):
ans=0
for i in range(n):
ans+=(1+a[i]*day//b[i])
return ans
def fm():
l=1
r=2**100
while r-l>1:
mi=(l+r)>>1
if ch(mi)>c:
r=mi
else:l=mi
r+=5
while r>0 and ch(r)>c:r-=1
return r
def fl():
l = 1
r = 2 ** 100
while r - l > 1:
mi = (l + r) >> 1
if ch(mi) < c:
l = mi
else:
r = mi
l=max(1,l-5)
while ch(l) < c: l += 1
return l
chi()
print(fm()-fl()+1)
```
Yes
| 14,426 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
import sys
n,c = map(int,sys.stdin.readline().split())
a = []
b = []
maxi = 0
for i in range (n):
t1,t2 = map (int,sys.stdin.readline().split())
a.append(t1)
b.append(t2)
if (b[i]*c//a[i] > maxi ):
maxi = b[i]*c//a[i]
def letstry(x, a, b):
"""try the result we search for and return the number of days it takes for that value x"""
res = 0 # total number of day
for i in range (len(a)):
res += x*a[i] // b[i] +1
return res
def bsl (l,r,val,a,b):
"""search the farthest position on the left that satisfy """
l1=l
r1 =r
res =-1
while l1 <= r1 :
mid = (l1+r1)//2
if (letstry (mid,a,b)< val):
l1 = mid +1
if (letstry(mid,a,b) > val):
r1 = mid -1
if (letstry(mid,a,b) == val):
res = mid
r1 = mid-1
return res
def bsr (l,r,val,a,b):
""" search the farthest positon on the right that satisfy the constrain """
l1=l
r1 =r
res =-1
while l1 <= r1 :
mid = (l1+r1)//2
if (letstry (mid,a,b)< val):
l1 = mid +1
if (letstry(mid,a,b) > val):
r1 = mid -1
if (letstry(mid,a,b) == val):
res = mid
l1 = mid +1
return res
r = bsr(1,maxi,c,a,b)
l = bsl(1,maxi,c,a,b)
#print (l," ",r)
#print (maxi)
if l > r or l==-1 or r ==-1:
print (0)
else :
print (r-l +1)
```
Yes
| 14,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
input=__import__('sys').stdin.readline
def check(x):
tmp=0
for i in range(n):
tmp+=(1 + (lis[i][0]*x)//lis[i][1])
return tmp
n,c = map(int,input().split())
lis=[]
c1=0
for _ in range(n):
a,b = map(int,input().split())
lis.append([a,b])
c1=max(c1,a)
if c1==0:
print(-1)
exit()
#max
ans=0
l=0
r=100000000000000000000
while l<=r:
mid = l + (r-l)//2
if check(mid)>c:
r=mid-1
else:
l=mid+1
if check(l)==c:
ans=l
else:
ans=r
l=0
r=100000000000000000000
while l<=r:
mid = l +(r-l)//2
if check(mid)>=c:
r=mid-1
else:
l=mid+1
#print(ans,l,r)
if r!=-1:
print(max(0,ans-r))
else:
print(max(0,ans-l))
```
Yes
| 14,428 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
n,c=list(map(int,input().split()))
d,lis,m=c-n,[],0
def check(x):
days=0
for ele in lis:
y=(x*ele[0])//ele[1]
days+=y
return days
for _ in range(n):
lis.append(list(map(int,input().split())))
low,high=0,1000000000
while low<=high:
mid=low+(high-low)//2
c=check(mid)
if(c>d):
high=mid-1
elif(c<d):
low=mid+1
else:
mn=mid
high=mid-1
low,high=0,1000000000
while low<=high:
mid=low+(high-low)//2
c=check(mid)
if(c>d):
high=mid-1
elif(c<d):
low=mid+1
else:
mx=mid
low=mid+1
print(mx-mn+1)
```
No
| 14,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
n, c = map(int, input().split())
a = []
b = []
for i in range(n):
aa, bb = map(int, input().split())
a.append(aa)
b.append(bb)
def all_zero():
for aa in a:
if aa > 0: return False
return True
def days(x):
c = 0
for aa, bb in zip(a, b):
c += 1 + aa*x//bb
return c
def run():
if n > c: return 0
if all_zero(): return -1 if n == c else 0
lo = 0
hi = int(2e18)
while lo < hi:
mid = (lo + hi) // 2
if days(mid) < c: lo = mid+1
else: hi = mid
ans0 = lo
lo = 0
hi = int(2e18)
while lo < hi:
mid = (lo + hi + 1) // 2
if days(mid) > c: hi = mid-1
else: lo = mid
return lo - ans0 + 1
print(run())
```
No
| 14,430 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
n,c=list(map(int,input().split()))
d,lis,m=c-n,[],0
def check(x):
days=0
for ele in lis:
y=(x*ele[0])//ele[1]
if(y>d or days>d):
return False
days+=y
if(days==d):
return True
else:
return False
for _ in range(n):
e,f=list(map(int,input().split()))
m=max(m,f//e)
lis.append([e,f])
x,low,cnt,mn,mx=m*d,m,0,m*d,0
for i in range(low,x):
if check(i):
mn=min(mn,i)
mx=max(mx,i)
print(mx-mn+1)
```
No
| 14,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
# ========= /\ /| |====/|
# | / \ | | / |
# | /____\ | | / |
# | / \ | | / |
# ========= / \ ===== |/====|
# code
def main():
n , c = map(int ,input().split())
a = []
for i in range(n):
x,y = map(int ,input().split())
a.append((x,y))
def cod(x):
s = c - n
for i in a:
s -= ((i[0] * x) // i[1])
if s < 0:
return -1
return 0 if s == 0 else 1
M = 2 * 10**19
l = 0
u = M
a1 = -1
while l <= u:
m = l + (u - l) // 2
p = cod(m)
# print(p , m , l , u)
if p <= 0:
u = m - 1
a1 = m
else:
l = m + 1
l = 0
u = M
a2 = 0
while l <= u:
m = l + (u - l) // 2
p = cod(m)
if p == -1:
u = m - 1
else:
l = m + 1
a2 = m
if a2 == M:
print(-1)
else:
if a1 > a2:
print(0)
else:
print(a2 - a1 + 1)
return
if __name__ == "__main__":
main()
```
No
| 14,432 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Tags: brute force, constructive algorithms, implementation, number theory
Correct Solution:
```
def hexa(n):
l=[]
l.append(0)
l.append(1)
i=2
while n not in l:
l.append(l[i-1]+l[i-2])
i=i+1
m=l.index(n)
if n==1:
return("1 0 0")
elif n==2:
return("0 1 1")
elif n==0:
return("0 0 0")
elif n==3:
return("1 1 1")
else:
return(str(l[m-1])+" "+str(l[m-3])+" "+str(l[m-4]))
n=int(input())
print(hexa(n))
```
| 14,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Tags: brute force, constructive algorithms, implementation, number theory
Correct Solution:
```
n=int(input())
if n==0:
print(0,0,0)
elif n==1:
print(0,0,1)
elif n==2:
print(0,1,1)
else:
old = 0
i = 1
old = 1
vold= 1
while i<n:
vold = old
old = i
i= old+vold
print(0,old,vold)
```
| 14,434 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Tags: brute force, constructive algorithms, implementation, number theory
Correct Solution:
```
def f(num):
global fib
for i in fib:
for j in fib:
for k in fib:
if i + j + k == num:
print(i, j, k)
return
print("I'm too stupid to solve this problem")
n = int(input())
fib = [0, 1]
while fib[-1] + fib[-2] < 1e9:
fib.append(fib[-1] + fib[-2])
f(n)
# [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657,
# 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352,
# 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733]
```
| 14,435 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Tags: brute force, constructive algorithms, implementation, number theory
Correct Solution:
```
n=int(input())
fibo=[0,1]
for i in range(50):
fibo.append(fibo[i+1]+fibo[i])
i=fibo.index(n)
if i>2:
print(fibo[i-2],fibo[i-2],fibo[i-3])
elif n==1:
print('0 0 1')
elif n==0:
print("0 0 0")
```
| 14,436 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Tags: brute force, constructive algorithms, implementation, number theory
Correct Solution:
```
def binarysearch(L,left,right,k):
mid=(left+right)//2
if(L[left]==k):
return left
elif(L[right]==k):
return right
elif(L[mid]==k):
return mid
elif(L[right]<k) or (L[left]>k):
return -1
elif(L[mid]<k):
return binarysearch(L,mid+1,right,k)
elif(L[mid]>k):
return binarysearch(L,left,mid,k)
else:
return -1
def theorem(n):
if(n==0):
return '0'+' '+'0'+' '+'0'
elif(n==1):
return '1'+' '+'0'+' '+'0'
elif(n==2):
return '1'+' '+'1'+' '+'0'
elif(n==3):
return '1'+' '+'1'+' '+'1'
else:
L=[0,1,1]+[-1]*(43)
for i in range(2,len(L)):
L[i]=L[i-1]+L[i-2]
k=binarysearch(L,0,len(L)-1,n)
return str(L[k-2])+" "+str(L[k-2])+" "+str(L[k-3])
n=int(input())
print(theorem(n))
```
| 14,437 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Tags: brute force, constructive algorithms, implementation, number theory
Correct Solution:
```
# Name : Jugal Kishore Chanda
# East West University
# Dept of Cse
n = int(input())
print("0 0 {}".format(n))
```
| 14,438 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Tags: brute force, constructive algorithms, implementation, number theory
Correct Solution:
```
n = int(input())
re_list = [0]
a, b = 0, 1
while b < n:
re_list.append(b)
a, b = b, a+b
if n == 0:
print("0 0 0")
elif n == 1:
print("0 0 1")
else:
print(0, re_list[-2], re_list[-1])
```
| 14,439 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Tags: brute force, constructive algorithms, implementation, number theory
Correct Solution:
```
def calc(foo):
if foo == 2:
print("0 1 1")
return
if foo == 3:
print("1 1 1")
return
if foo == 0:
print("0 0 0")
return
if foo == 1:
print("1 0 0")
return
fibo = [0, 1]
while fibo[-1] < foo and fibo[-1] + fibo[-2] < foo:
fibo.append(fibo[-1] + fibo[-2])
verifier = fibo[-1] + fibo[-3] + fibo[-4]
if verifier != foo:
print("I'm too stupid to solve this problem")
return
print(fibo[-1], fibo[-3], fibo[-4])
return
num = int(input())
calc(num)
```
| 14,440 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Submitted Solution:
```
#119A
def main():
from sys import stdin, stdout
a=[0,1,1]
for _ in range(43):
a.append(a[-1]+a[-2])
#print(a)
#print(len(a))
#print(a[-1])
n = int(stdin.readline())
if n==0:
print(0,0,0)
return
fp = 0
sp = 45
while fp<sp:
if a[fp]+a[sp] == n:
break
elif a[fp]+a[sp] < n:
fp+=1
elif a[fp]+a[sp] > n:
sp-=1
if a[fp]+a[sp]==n:
stdout.write(str(a[fp])+' '+str(a[sp-2])+' '+str(a[sp-1])+'\n')
else:
stdout.write("I'm too stupid to solve this problem\n")
if __name__=='__main__':
main()
```
Yes
| 14,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Submitted Solution:
```
t=int(input())
c=0
d=1
a=[0,1]
while d<t:
sum=c+d
a.append(sum)
c=d
d=sum
x=0
w=1
j=0
k=0
l=0
if t==0:
print("0 0 0")
w=0
elif t==1:
print("0 0 1")
w=0
elif t==2:
print("0 1 1")
w=0
else:
while x+2<a.index(t)-1:
if a[len(a)-2]+a[len(a)-4]+a[len(a)-5]==t:
print(f"{a[len(a)-5]} {a[len(a)-4]} {a[len(a)-2]}")
w=0
break
else:
x+=1
if w==1:
print("I'm too stupid to solve this problem")
```
Yes
| 14,442 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Submitted Solution:
```
buffer=[1,1,2,3,5]
n=int(input())
if n==0:
print(0,0,0)
elif n==1:
print(1,0,0)
elif n==2:
print(1,0,1)
elif n==3:
print(1,1,1)
else:
while buffer[-1]!=n:
buffer.append(buffer[-1]+buffer[-2])
del(buffer[0])
print(buffer[0],buffer[1],buffer[3])
```
Yes
| 14,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Submitted Solution:
```
b=[1]
def fib(b):
if n==0:
mm=[0,0,0]
return (" ".join(map(str,mm)))
if n==1:
mm=[1,0,0]
return (" ".join(map(str,mm)))
a=1
i=0
while a<n+1:
b.append(a)
a=a+b[i]
i=i+1
dd=[0]
dd.append(b[len(b)-3])
dd.append(b[len(b)-2])
return (" ".join(map(str,dd)))
n=int(input())
ans=fib(b)
print(ans)
```
Yes
| 14,444 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Submitted Solution:
```
n=int(input())
l=[]
l.append(0)
l.append(1)
ind=2
while (l[ind-1]+l[ind-2])<=n:
l.append(l[ind-1]+l[ind-2])
ind+=1
#print(l)
f=l[ind-3]
s=l[ind-3]
t=l[ind-4]
print(str(f)+' '+str(s)+' '+str(t))
```
No
| 14,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Submitted Solution:
```
import math
n = int(input())
if n==1:
print(0,0,1)
elif n==0:
print(0,0,0)
elif n==2:
print(0,1,1)
elif n==3:
print(1,1,1)
elif n>=5:
te=n*1.625
te=math.floor(te)
te1=te-n
te2=n-te1
te3=te1-te2
te4=te2-te3
print(te4,te3,te1)
```
No
| 14,446 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Submitted Solution:
```
n = int(input())
a = [1, 1]
while a[len(a) - 1] < n:
a.append(a[len(a) - 1] + a[len(a) - 2])
if n < 3:
print("I'm too stupid to solve this problem")
elif n == 3:
print(1, 1, 1)
else:
b = len(a)
print(a[b - 2], a[b - 4], a[b - 5])
```
No
| 14,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.
Input
The input contains of a single integer n (0 β€ n < 109) β the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.
Output
Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Examples
Input
3
Output
1 1 1
Input
13
Output
2 3 8
Submitted Solution:
```
n=int(input())
def fib_to(k):
fibs = [0, 1]
for i in range(2, k+1):
fibs.append(fibs[-1] + fibs[-2])
return fibs
a=fib_to(50)
z=a.index(n)
if(n>1):
print('0'+' '+str(a[z-2])+' '+str(a[z-1]))
else:
print("I'm too stupid to solve this problem")
```
No
| 14,448 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Tags: data structures, implementation
Correct Solution:
```
from sys import stdin, stdout
n,m,k = map(int, stdin.readline().split())
g = [stdin.readline().split() for i in range(n)]
r = [i for i in range(n+1)]
c = [i for i in range(m+1)]
ans = []
for i in range(k):
t,x,y = stdin.readline().split()
x,y = int(x), int(y)
if t == 'c':
c[x],c[y] = c[y],c[x]
elif t == 'r':
r[x],r[y] = r[y],r[x]
else:
ans.append(g[r[x]-1][c[y]-1])
stdout.write('\n'.join(ans))
```
| 14,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Tags: data structures, implementation
Correct Solution:
```
n,m,k=map(int,input().split())
a=[input().split() for _ in ' '*n]
r={str(i):i-1 for i in range(1,n+1)}
c={str(i):i-1 for i in range(1,m+1)}
ans=[]
for _ in range(k):
ch,x,y=input().split()
if ch=='c':
c[x],c[y]=c[y],c[x]
elif ch=='r':
r[x], r[y] = r[y], r[x]
else:
ans.append(a[r[x]][c[y]])
print('\n'.join(ans))
```
| 14,450 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Tags: data structures, implementation
Correct Solution:
```
n, m, k = map(int, input().split())
R = {str(i): i - 1 for i in range(n+1)}
C = {str(i): i - 1 for i in range(m+1)}
ans = []
l = [input().split() for i in range(n)]
for i in range(k):
q, x, y = input().split()
if q == 'c':
C[x], C[y] = C[y], C[x]
elif q == 'r':
R[x], R[y] = R[y], R[x]
else:
ans.append(l[R[x]][C[y]])
print('\n'.join(ans))
```
| 14,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Tags: data structures, implementation
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#n=int(input())
#arr = list(map(int, input().split()))
n,m,k= map(int, input().split())
g=[]
for i in range(n):
l=list(map(int, input().split()))
g.append(l)
r=[i for i in range(1001)]
cc=[i for i in range(1001)]
for i in range(k):
ch,x,y=input().split()
x=int(x)
y=int(y)
if ch=="g":
#v1=x if r[x]==0 else r[x]
v1=r[x]
v2=cc[y]
#v2=y if cc[y]==0 else cc[y]
print(g[v1-1][v2-1])
elif ch=="c":
temp=cc[x]
cc[x]=cc[y]
cc[y]=temp
else:
temp=r[x]
r[x]=r[y]
r[y]=temp
```
| 14,452 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Tags: data structures, implementation
Correct Solution:
```
from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
# from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *
####################################---fast-input-output----#########################################
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = read(self._fd, max(fstat(self._fd).st_size, 8192))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = read(self._fd, max(fstat(self._fd).st_size, 8192))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
stdin, stdout = IOWrapper(stdin), IOWrapper(stdout)
graph, mod, szzz = {}, 10**9 + 7, lambda: sorted(zzz())
def getStr(): return input()
def getInt(): return int(input())
def listStr(): return list(input())
def getStrs(): return input().split()
def isInt(s): return '0' <= s[0] <= '9'
def input(): return stdin.readline().strip()
def zzz(): return [int(i) for i in input().split()]
def output(answer, end='\n'): stdout.write(str(answer) + end)
def lcd(xnum1, xnum2): return (xnum1 * xnum2 // gcd(xnum1, xnum2))
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
#################################################---Some Rule For Me To Follow---#################################
"""
--instants of Reading problem continuously try to understand them.
--If you Know some-one , Then you probably don't know him !
--Try & again try, maybe you're just one statement away!
"""
##################################################---START-CODING---###############################################
n,m,k=zzz()
g=[]
for i in range(n):g.append(zzz())
r,c=list(range(n+9)),list(range(m+9))
for i in range(k):
s,x,y=input().split()
x,y=int(x),int(y)
if s=='g':p,q=r[x],c[y];output(g[p-1][q-1])
elif s=='r':r[x],r[y]=r[y],r[x]
else:c[x],c[y]=c[y],c[x]
```
| 14,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Tags: data structures, implementation
Correct Solution:
```
n,m,k=list(map(int,input().split()))
matrix=[input().split() for i in range(n)]
row=[i for i in range(n)]
col=[i for i in range(m)]
ans=[]
for i in range(k):
s,x,y=input().split()
x,y=int(x)-1,int(y)-1
if s=="c":
col[x],col[y]=col[y],col[x]
elif s=="r":
row[x],row[y]=row[y],row[x]
else:
ans.append(matrix[row[x]][col[y]])
print("\n".join(ans))
```
| 14,454 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Tags: data structures, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
n ,m ,k = map(int ,input().split())
row ,col ,Data,ans = [], [],[],[]
for i in range(n):
row.append(i)
a = list(input().split())
Data.append(a)
for i in range(m):
col.append(i)
for _ in range(k):
s ,x ,y = input().split()
x , y = int(x)-1 ,int(y)-1
if s == 'g':
ans.append(Data[row[x]][col[y]])
elif s == 'r':
tmp = row[x]
row[x] = row[y]
row[y] = tmp
elif s == 'c' :
tmp = col[x]
col[x] = col[y]
col[y] = tmp
print('\n'.join(ans))
```
| 14,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Tags: data structures, implementation
Correct Solution:
```
z=input().split()
n=int(z[0])
m=int(z[1])
k=int(z[2])
m_chis=[]
m_chis=[input().split() for i in range(n)]
row=[i for i in range(n)]
col=[i for i in range(m)]
otvet=[]
for i in range(k):
v=input().split()
x=int(v[1])-1
y=int(v[2])-1
if v[0]=='c':
col[x],col[y]=col[y],col[x]
elif v[0]=='r':
row[x],row[y]=row[y],row[x]
elif v[0]=='g':
otvet.append(m_chis[row[x]][col[y]])
#print(m_chis[row[x]][col[y]])
print("\n".join(otvet))
```
| 14,456 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Submitted Solution:
```
# Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
# mod=10**9+7
# sys.setrecursionlimit(10**6)
# mxm=sys.maxsize
# from functools import lru_cache
def main():
n,m,k=map(int,input().split())
arr=[]
for _ in range(n):
arr.append(list(map(int,input().split())))
r=dict()
c=dict()
for i in range(n):
r[i]=i
for i in range(m):
c[i]=i
for _ in range(k):
s,x,y=input().split()
x=int(x)-1
y=int(y)-1
if s=='c':
c[x],c[y]=c[y],c[x]
elif s=='r':
r[x],r[y]=r[y],r[x]
else:
print(arr[r[x]][c[y]])
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# endregion
if __name__ == '__main__':
main()
```
Yes
| 14,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Submitted Solution:
```
n, m, k = map(int, input().split())
t = [input().split() for i in range(n)]
c = {str(i): i - 1 for i in range(m + 1)}
r = {str(i): i - 1 for i in range(n + 1)}
ans = []
for i in range(k):
s, x, y = input().split()
if s == 'c': c[x], c[y] = c[y], c[x]
elif s == 'r': r[x], r[y] = r[y], r[x]
else: ans.append(t[r[x]][c[y]])
print('\n'.join(ans))
```
Yes
| 14,458 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Submitted Solution:
```
X = list(map(int, input().split()))
Row, Column = {str(i):i-1 for i in range(1, X[0]+1)}, {str(i):i-1 for i in range(1,X[1]+1)}
Ans = []
Cosmic = [input().split() for i in range(X[0])]
for _ in range(X[-1]):
Temp = input().split()
if Temp[0] == "c":
Column[Temp[1]], Column[Temp[2]] = Column[Temp[2]], Column[Temp[1]]
elif Temp[0] == "r":
Row[Temp[1]], Row[Temp[2]] = Row[Temp[2]], Row[Temp[1]]
else:
Ans.append(Cosmic[Row[Temp[1]]][Column[Temp[2]]])
print('\n'.join(Ans))
# Hope the best for Ravens member
```
Yes
| 14,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Submitted Solution:
```
n,m,k=list(map(int,input().split()))
matrix=[input().split() for i in range(n)]
row=[j for j in range(n)]
col=[j for j in range(m)]
ans=[]
for i in range(k):
s,x,y=input().split()
x=int(x)-1
y=int(y)-1
if s=="c":
col[x],col[y]=col[y],col[x]
elif s=="r":
row[x],row[y]=row[y],row[x]
else:
ans.append(matrix[row[x]][col[y]])
print("\n".join(ans))
```
Yes
| 14,460 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Submitted Solution:
```
def cosmicTables(n,m,k,li1,li2):
for i in range(k):
if li2[i][0] == 'c':
for j in range(n):
li1[j][int(li2[i][1])-1],li1[j][int(li2[i][2])-1] = li1[j][int(li2[i][2])-1],li1[j][int(li2[i][1])-1]
# print(li2)
elif li2[i][0] == "r":
for j in range(m):
li1[int(li2[i][1])-1][j],li1[int(li2[i][2])-1][j] =li1[int(li2[i][2])-1][j],li1[int(li2[i][1])-1][j]
# print(li1)
elif li2[i][0] == "g":
print(li1[int(li2[i][1])-1][int(li2[i][2])-1])
n,m,k = input().split()
li1=[]
for i in range(int(n)):
a=[x for x in input().split()]
li1.append(a)
print(li1)
li2=[]
for i in range(int(k)):
a=[x for x in input().split()]
li2.append(a)
print(li2)
cosmicTables(int(n),int(m),int(k),li1,li2)
```
No
| 14,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Submitted Solution:
```
z=input().split()
n=int(z[0])
m=int(z[1])
k=int(z[2])
m_chis=[]
m_zap=[]
for i in range(n):
v=input().split()
for j in range(m):
v[j]=int(v[j])
m_chis.append(v)
for i in range(k):
v=input().split()
v[1]=int(v[1])
v[2]=int(v[2])
m_zap.append(v)
print(m_chis)
for i in range(k):
if m_zap[i][0]=='c':
for j in range(n):
tmp=m_chis[j][m_zap[i][1]-1]#a
m_chis[j][m_zap[i][1]-1]=m_chis[j][m_zap[i][2]-1]#b
m_chis[j][m_zap[i][2]-1]=tmp
'''m_chis[j][m_zap[i][1]-1],m_chis[j][m_zap[i][2]-1]=m_chis[j][m_zap[i][2]-1],m_chis[j][m_zap[i][1]-1]'''
elif m_zap[i][0]=='r':
m_chis[m_zap[i][1]-1],m_chis[m_zap[i][2]-1]=m_chis[m_zap[i][2]-1],m_chis[m_zap[i][1]-1]
elif m_zap[i][0]=='g':
print(m_chis[m_zap[i][1]-1][m_zap[i][2]-1])
#print(m_chis)
```
No
| 14,462 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Submitted Solution:
```
from sys import stdin,stdout
a,b,c=map(int,stdin.readline().split())
ans=[]
z1=[stdin.readline() for _ in " "*a]
co={str(i+1):i for i in range(b)}
r={str(i+1):i for i in range(a)};j=0
for _ in range(c):
x,y,z=stdin.readline().split()
if x=='r':r[y],r[z]=r[z],r[y]
elif x=='c':co[y],co[z]=co[z],co[y]
else:ans.append(z1[r[y]][co[z]])
stdout.write('\n'.join(ans))
```
No
| 14,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n Γ m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1000, 1 β€ k β€ 500000) β the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each β the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 β€ p β€ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "Ρ", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 β€ x, y β€ m, x β y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 β€ x, y β€ n, x β y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 β€ x β€ n, 1 β€ y β€ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns β from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
Submitted Solution:
```
__author__ = 'asmn'
n,m,k=tuple(map(int,input().split()))
mat=[[int(j) for j in input().split()] for i in range(n)]
ri=[i for i in range(n)]
ci=[i for i in range(m)]
ans=''
for _k in range(k):
s,x,y=input().split()
x,y=int(x)-1,int(y)-1
if s=='c':
ci[x],ci[y]=ci[y],ci[x]
elif s=='r':
ri[x],ri[y]=ri[y],ri[x]
else:
ans+=str(mat[ri[x]][ci[y]])+'\''
print(ans)
```
No
| 14,464 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 β€ li β€ ri β€ |s|). The answer to the query is the number of substrings of string s[li... ri], which are palindromes.
String s[l... r] = slsl + 1... sr (1 β€ l β€ r β€ |s|) is a substring of string s = s1s2... s|s|.
String t is called a palindrome, if it reads the same from left to right and from right to left. Formally, if t = t1t2... t|t| = t|t|t|t| - 1... t1.
Input
The first line contains string s (1 β€ |s| β€ 5000). The second line contains a single integer q (1 β€ q β€ 106) β the number of queries. Next q lines contain the queries. The i-th of these lines contains two space-separated integers li, ri (1 β€ li β€ ri β€ |s|) β the description of the i-th query.
It is guaranteed that the given string consists only of lowercase English letters.
Output
Print q integers β the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.
Examples
Input
caaaba
5
1 1
1 4
2 3
4 6
4 5
Output
1
7
3
4
2
Note
Consider the fourth query in the first test case. String s[4... 6] = Β«abaΒ». Its palindrome substrings are: Β«aΒ», Β«bΒ», Β«aΒ», Β«abaΒ».
Tags: dp, hashing, strings
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
def main():
# n, k = map(int, input().split())
# s = input()
s=input()
n=len(s)
palin = [[0 for _ in range(n)] for _ in range(n)]
dp = [[0 for _ in range(n)] for _ in range(n)]
for sz in range(n):
for i in range(n - sz):
j = i + sz
if sz == 0:
palin[i][j] = 1
elif s[i] == s[j]:
if sz == 1:
palin[i][j] = 1
else:
palin[i][j] = palin[i + 1][j - 1]
else:
palin[i][j] = int(s[i] == s[j] and palin[i + 1][j - 1])
for sz in range(n):
for i in range(n - sz):
j = i + sz
if sz == 0:
dp[i][j] = 1
else:
dp[i][j] = dp[i][j - 1] + dp[i + 1][j] - dp[i + 1][j - 1] + palin[i][j]
# print(*dp,sep='\n')
for _ in range(int(input())):
l, r = list(map(int, input().split()))
print(dp[l - 1][r - 1])
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
for t in range(1):main()#int(input())): main()
```
| 14,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 β€ li β€ ri β€ |s|). The answer to the query is the number of substrings of string s[li... ri], which are palindromes.
String s[l... r] = slsl + 1... sr (1 β€ l β€ r β€ |s|) is a substring of string s = s1s2... s|s|.
String t is called a palindrome, if it reads the same from left to right and from right to left. Formally, if t = t1t2... t|t| = t|t|t|t| - 1... t1.
Input
The first line contains string s (1 β€ |s| β€ 5000). The second line contains a single integer q (1 β€ q β€ 106) β the number of queries. Next q lines contain the queries. The i-th of these lines contains two space-separated integers li, ri (1 β€ li β€ ri β€ |s|) β the description of the i-th query.
It is guaranteed that the given string consists only of lowercase English letters.
Output
Print q integers β the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.
Examples
Input
caaaba
5
1 1
1 4
2 3
4 6
4 5
Output
1
7
3
4
2
Note
Consider the fourth query in the first test case. String s[4... 6] = Β«abaΒ». Its palindrome substrings are: Β«aΒ», Β«bΒ», Β«aΒ», Β«abaΒ».
Submitted Solution:
```
s=input()
n=len(s)
mark=[]
dp=[]
for i in range(n):
mark.append([0]*n)
dp.append([0]*n)
for i in range(0,n):
for j in range(0,n):
if i+j>=n or i-j<0 :break
if s[i-j]==s[i+j]:
print(i-j,' ',i+j)
mark[i-j][i+j]=1
else : break
for j in range(1,n):
if i+j>=n or i-j+1<0:break
if s[i-j+1]==s[i+j]:
print(i-j+1,' ',i+j)
mark[i-j+1][i+j]=1
else : break
for i in range(n-1,-1,-1):
dp[i][i]=1
for j in range(i+1,n,1):
dp[i][j]=dp[i+1][j]+dp[i][j-1]+mark[i][j]
if i+1<=j-1:dp[i][j]-=dp[i+1][j-1]
q=int(input())
while q>0:
q-=1
A=list(map(int,input().split()))
A[0]-=1
A[1]-=1
print(dp[A[0]][A[1]])
```
No
| 14,466 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 β€ li β€ ri β€ |s|). The answer to the query is the number of substrings of string s[li... ri], which are palindromes.
String s[l... r] = slsl + 1... sr (1 β€ l β€ r β€ |s|) is a substring of string s = s1s2... s|s|.
String t is called a palindrome, if it reads the same from left to right and from right to left. Formally, if t = t1t2... t|t| = t|t|t|t| - 1... t1.
Input
The first line contains string s (1 β€ |s| β€ 5000). The second line contains a single integer q (1 β€ q β€ 106) β the number of queries. Next q lines contain the queries. The i-th of these lines contains two space-separated integers li, ri (1 β€ li β€ ri β€ |s|) β the description of the i-th query.
It is guaranteed that the given string consists only of lowercase English letters.
Output
Print q integers β the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.
Examples
Input
caaaba
5
1 1
1 4
2 3
4 6
4 5
Output
1
7
3
4
2
Note
Consider the fourth query in the first test case. String s[4... 6] = Β«abaΒ». Its palindrome substrings are: Β«aΒ», Β«bΒ», Β«aΒ», Β«abaΒ».
Submitted Solution:
```
s=str(input())
dp=[[0 for i in range(len(s))]for j in range(len(s))]
for i in range(len(s)):
dp[i][i]=1
n=len(s)
for i in range(n-1):
if s[i]==s[i+1]:
dp[i][i+1]=1
# print(dp)
for i in range(2,n):
for j in range(n-i):
# print(i,
# j)
if s[j]==s[i+j] and dp[j+1][i+j-1]:
dp[j][i+j]=1
a=[]
for j in range(n):
c=0
for i in range(n):
c+=dp[i][j]
a.append(c)
prefix=[a[0]]
for i in range(1,n):
prefix.append(prefix[i-1]+a[i])
for _ in range(int(input())):
u,v=map(int,input().split())
# print(u,v)
print(prefix[v-1]-prefix[u-1]+1)
```
No
| 14,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 β€ li β€ ri β€ |s|). The answer to the query is the number of substrings of string s[li... ri], which are palindromes.
String s[l... r] = slsl + 1... sr (1 β€ l β€ r β€ |s|) is a substring of string s = s1s2... s|s|.
String t is called a palindrome, if it reads the same from left to right and from right to left. Formally, if t = t1t2... t|t| = t|t|t|t| - 1... t1.
Input
The first line contains string s (1 β€ |s| β€ 5000). The second line contains a single integer q (1 β€ q β€ 106) β the number of queries. Next q lines contain the queries. The i-th of these lines contains two space-separated integers li, ri (1 β€ li β€ ri β€ |s|) β the description of the i-th query.
It is guaranteed that the given string consists only of lowercase English letters.
Output
Print q integers β the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.
Examples
Input
caaaba
5
1 1
1 4
2 3
4 6
4 5
Output
1
7
3
4
2
Note
Consider the fourth query in the first test case. String s[4... 6] = Β«abaΒ». Its palindrome substrings are: Β«aΒ», Β«bΒ», Β«aΒ», Β«abaΒ».
Submitted Solution:
```
s = input()
n = len(s) + 1
dp = [[0] * n for i in range(n)]
for i in range(n):
p, q = i, i
while q < n - 1 and p >= 0:
if s[p] == s[q]:
dp[p][q] += 1
p, q = p - 1, q + 1
for i in range(n):
p, q = i, i + 1
while q < n - 1 and p >= 0:
if s[p] == s[q]:
dp[p][q] += 1
p, q = p - 1, q + 1
for i in range(n):
for j in range(i + 1, n):
dp[i][j] += dp[i][j - 1]
for j in range(n):
for i in range(j - 1, -1, -1):
dp[i][j] += dp[i + 1][j]
Q = int(input())
for i in range(Q):
l, r = map(int, input().split())
print(dp[l - 1][r - 1])
```
No
| 14,468 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 β€ li β€ ri β€ |s|). The answer to the query is the number of substrings of string s[li... ri], which are palindromes.
String s[l... r] = slsl + 1... sr (1 β€ l β€ r β€ |s|) is a substring of string s = s1s2... s|s|.
String t is called a palindrome, if it reads the same from left to right and from right to left. Formally, if t = t1t2... t|t| = t|t|t|t| - 1... t1.
Input
The first line contains string s (1 β€ |s| β€ 5000). The second line contains a single integer q (1 β€ q β€ 106) β the number of queries. Next q lines contain the queries. The i-th of these lines contains two space-separated integers li, ri (1 β€ li β€ ri β€ |s|) β the description of the i-th query.
It is guaranteed that the given string consists only of lowercase English letters.
Output
Print q integers β the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.
Examples
Input
caaaba
5
1 1
1 4
2 3
4 6
4 5
Output
1
7
3
4
2
Note
Consider the fourth query in the first test case. String s[4... 6] = Β«abaΒ». Its palindrome substrings are: Β«aΒ», Β«bΒ», Β«aΒ», Β«abaΒ».
Submitted Solution:
```
s = input()
n = len(s) + 1
dp = [[0] * n for i in range(n)]
for i in range(n):
p, q = i, i
while q < n - 1 and p >= 0:
if s[p] == s[q]:
dp[p][q] += 1
p, q = p - 1, q + 1
for i in range(n):
p, q = i, i + 1
while q < n - 1 and p >= 0:
if s[p] == s[q]:
dp[p][q] += 1
p, q = p - 1, q + 1
for i in range(n):
for j in range(1, n):
dp[i][j] += dp[i][j - 1]
for j in range(n):
for i in range(n - 2, -1, -1):
dp[i][j] += dp[i + 1][j]
Q = int(input())
for i in range(Q):
l, r = map(int, input().split())
print(dp[l - 1][r - 1])
```
No
| 14,469 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Tags: brute force
Correct Solution:
```
n = input()
while True:
n = int(n)
n += 1
n = str(n)
flag = 0
for i in range(4):
for j in range(4):
if i==j:
continue
if n[i] == n[j]:
flag = 1
break
if flag == 1:
break
if flag == 0:
print(n)
break
```
| 14,470 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Tags: brute force
Correct Solution:
```
nn=int(input())
for i in range(nn+1,nn*1000):
l=len(str(i))
if len(set(str(i)))==l:
print(i)
break
```
| 14,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Tags: brute force
Correct Solution:
```
import sys
inp = sys.stdin
y = int(inp.readline()) + 1
def check_dif(num):
s = str(num)
ok = 1
for i in range(len(s)):
if s[i] in s[i + 1:]:
ok = 0
return ok
while check_dif(y) == 0:
y += 1
print(y)
```
| 14,472 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Tags: brute force
Correct Solution:
```
n= int(input())
x = n+1
z=list()
while(True):
n = x
l = []
while(n>0):
t = n%10
l.append(t)
n = n//10
p = set(l)
if(len(p)==len(l)):
l.reverse()
z = l
break
x+=1
for i in z:
print(i,end="")
```
| 14,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Tags: brute force
Correct Solution:
```
year = int(input())
a = 0
while a == 0:
year += 1
s_year = list(str(year))
s_year = set(s_year)
if len(s_year) > 3:
a = 1
print(year)
```
| 14,474 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Tags: brute force
Correct Solution:
```
t=int(input())+1
while True:
if len(set(str(t)))==len(str(t)):
print(t)
break
t=t+1
```
| 14,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Tags: brute force
Correct Solution:
```
y = int(input())
for i in range(y+1,9999,1):
z= str(i)
if z[0] != z[1] and z[0] != z[2] and z[0] != z[3] and z[1] != z[2] and z[1] != z[3] and z[2] != z[3] :
print(int(z))
break
```
| 14,476 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Tags: brute force
Correct Solution:
```
import math
a = input()
a = int(a)
a = a + 1
while True:
b = (a/1000)
b = math.floor(b)
c = ((a%1000)/100)
c = math.floor(c)
d = (((a%1000)%100)/10)
d = math.floor(d)
e = (((a%1000)%100)%10)
e = math.floor(e)
a = (b*1000) + (c*100) + (d*10) + e
if((b==c) or (b==d) or (b==e) or (c==d) or (c==e) or (d==e)):
a = a + 1
continue
else:
a = int(a)
print(a)
break
```
| 14,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Submitted Solution:
```
year = input()
for num in range(int(year)+1, 10001):
yearString = str(num)
if len(set(yearString)) == 4:
print(yearString)
break
```
Yes
| 14,478 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Submitted Solution:
```
n = int(input())
def is_beaufiful(num):
num = str(num)
vals = [num.count(v) == 1 for v in num]
return all(vals)
answer = n + 1
while not is_beaufiful(answer):
answer += 1
print(answer)
```
Yes
| 14,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Submitted Solution:
```
y = int(input())
a = 0
b = 0
c = 0
d = 0
while a == b or a == c or a == d or b == c or b == d or c == d:
y += 1
a = y // 1000
b = y // 100 % 10
c = y // 10 % 10
d = y % 10
print(y)
```
Yes
| 14,480 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Submitted Solution:
```
# cook your dish here
n = int(input())
s = False
while s==False:
n+=1
if(len(set(str(n))) == 4):
s = True
print(n)
```
Yes
| 14,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Submitted Solution:
```
y = int(input())
for i in range(y+1, 9001):
s = str(i)
if len(set(s)) == len(s):
print(i)
break
```
No
| 14,482 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Submitted Solution:
```
if __name__ == '__main__':
numb = int(input())
result = ""
for i in range(numb+1, 9001):
list1 = list(str(i))
list2 = set(list1)
if len(list1) == len(list2):
for i in list1:
result += str(i)
print(result)
break
```
No
| 14,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Submitted Solution:
```
def by(x): # x is int
lx = list(str(x))
sx = set(str(x))
if len(lx) == len(sx):
return 1
def nby(x):
t = x
while by(t) != 1:
t += 1
continue
return t
y = int(input())
print(nby(y))
```
No
| 14,484 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 β€ y β€ 9000) β the year number.
Output
Print a single integer β the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
Input
1987
Output
2013
Input
2013
Output
2014
Submitted Solution:
```
year = int(input())
def check(a,b,c,d):
if a==b or a ==c or a==d or b==c or b==d or c==d:
return False
else:
return True
while True:
year+=1
yearstr=str(year)
if check(yearstr[0],yearstr[1],yearstr[2],yearstr[3]):
print(year)
break
print(check(2,0,1,3))
```
No
| 14,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Tags: combinatorics, number theory
Correct Solution:
```
from sys import stdin, stdout
def main():
n, p = 2000, 1000000007
factorial = [1] * (n + 1)
for i in range(2, n + 1):
factorial[i] = i * factorial[i - 1] % p
n, m = readline()
on = sorted(readline())
off = []
for i in range(1, m):
c = on[i] - on[i - 1] - 1
if c > 0:
off.append(c)
answer = pow(2, sum(off) - len(off), p) * factorial[n - m] % p
off = [on[0] - 1] + off + [n - on[m - 1]]
for x in off:
answer = answer * pow(factorial[x], p - 2, p) % p
return answer
def readline():
return map(int, stdin.readline().strip().split())
if __name__ == '__main__':
stdout.write(str(main()) + '\n')
```
| 14,486 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Tags: combinatorics, number theory
Correct Solution:
```
import math
def myfunc(value):
if value == 0:
return 1
total = 1
for num in range(2, value+1):
total = total * num
return total
n, m = map(int, input().split())
mylist = sorted(list(map(int, input().split())))
value = myfunc(n-m)
temp = myfunc(mylist[0]-1)
total = value // temp
for i in range(1,m):
values = mylist[i]-mylist[i-1]
temp = myfunc(values-1)
total = total // temp
if mylist[i]- mylist[i-1] != 1:
values = mylist[i]-mylist[i-1]
temp = (values-2)
total = total * 2 ** temp
temp = myfunc(n-mylist[m-1])
total = total // temp
print(total % 1000000007 )
```
| 14,487 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Tags: combinatorics, number theory
Correct Solution:
```
def f(p):
d = 1
for i in range(2, p + 1):
d *= i
return d
n, m = map(int, input().split())
l = list(map(int, input().split()))
if n == m:
print(1)
else:
l.sort()
for i in range(m):
l[i] -= 1
k = []
sm = n - m
if l[0] > 1:
k.append([l[0], 1])
for i in range(1, len(l)):
k.append([l[i] - l[i - 1] - 1, 2 ** (max(0, l[i] - l[i - 1] - 2))])
if l[-1] < n - 1:
k.append([n - 1 - l[-1], 1])
ans = f(sm)
for c in k:
ans //= f(c[0])
for c in k:
ans *= c[1]
print(ans % 1000000007)
```
| 14,488 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Tags: combinatorics, number theory
Correct Solution:
```
#source: https://www.programmersought.com/article/2581544332/
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
twodList = [[0 for _ in range(1005)] for _ in range(1005)]
powTee = [0 for _ in range(1005)]
powTee[0] = 1
twodList[0][0] = 1
for i in range(1, 1005):
twodList[i][0] = 1
for j in range(1, i + 1):
twodList[i][j] = (twodList[i - 1][j] + twodList[i - 1][j - 1]) % 1000000007
twodList[i][i] = 1
powTee[i] = (powTee[i - 1] * 2) % 1000000007
n, m = get_ints()
inputListy = get_list()
inputListy.sort()
numby = n - m
roubles = twodList[numby][inputListy[0] - 1]
numby -= inputListy[0] - 1
for i in range(1, m):
x = inputListy[i] - inputListy[i - 1] - 1
if x > 0:
roubles = ((roubles * twodList[numby][x] % 1000000007) * powTee[x - 1])
else:
roubles = roubles * twodList[numby][x] % 1000000007
numby -= x
roubles = (roubles * twodList[numby][n - inputListy[m - 1]]) % 1000000007
print(roubles)
```
| 14,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Tags: combinatorics, number theory
Correct Solution:
```
MOD = int(1e9+7)
n, m = map(int, input().split())
arr = sorted(list(map(int, input().split())))
fact = [1]
for i in range(1, 1000):
fact.append((fact[-1] * i) % MOD)
def fast_power(b, e):
res = 1
while e > 0:
if e % 2 == 1:
res = res * b % MOD
b = b * b % MOD
e //= 2
return res
def inv_mod(b):
return fast_power(b, MOD - 2)
res = fact[n - m]
for i in range(1, m):
mid = arr[i] - arr[i - 1] - 1
if mid > 0:
res = res * inv_mod(fact[mid]) % MOD
if mid > 1:
res = res * fast_power(2, mid-1) % MOD
if arr[0] > 1:
res = res * inv_mod(fact[arr[0] - 1]) % MOD
if arr[m - 1] < n:
res = res * inv_mod(fact[n - arr[m-1]]) % MOD
print(res)
```
| 14,490 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Tags: combinatorics, number theory
Correct Solution:
```
def fac(n):
if n == 0:
return 1
mul = 1
for i in range(2,n+1):
mul *= i
return mul
n,m = (int(t) for t in input().split(' '))
gen = (int(t) for t in input().split(' '))
v = []
for i in gen:
v.append(i)
v.sort()
ans = fac(n-m)
#print(type(ans))
ans //= fac(v[0]-1)
for i in range(1,len(v)):
# print('#')
ans //= fac(v[i]-v[i-1]-1)
if v[i]-v[i-1]-1 != 0:
ans *= 2**(v[i]-v[i-1]-2)
ans //= fac(n-v[len(v)-1])
print('%d' % (ans%(int(1e9)+7)))
```
| 14,491 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Tags: combinatorics, number theory
Correct Solution:
```
def bpow(a, b):
if b==0 or a==1:
return 1
if b%2 != 0:
return a * bpow(a, b-1) % mod
else:
c = bpow(a, b/2) % mod
return c * c % mod
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [0] + a + [n+1]
a = sorted(a)
fa = list()
fa.append(1)
mod = 1000000007
for i in range(1, 2010):
fa.append(fa[i-1] * i)
fa[i] %= mod
ans1 = 1
ans2 = 1
s = 0
for i in range(0, m+1):
ans1 *= fa[a[i+1] - a[i] - 1]
s+= a[i+1] - a[i] - 1
ans1 %= mod
if i > 0 and i < m and a[i+1] - a[i] > 1:
ans2*= pow(2, a[i+1] - a[i] - 2, mod)
ans2%= mod
print((fa[s] * pow(ans1, mod-2, mod) * ans2)%mod)
```
| 14,492 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Tags: combinatorics, number theory
Correct Solution:
```
from sys import stdin, stdout
def main():
p = 1000000007 # Constante brindada por el problema
n, m = readline()
on = sorted(readline()) # Se ordena de menor a mayor los elementos del conjunto de luces encendidas
off = [] # Conjunto de cardinalidades de los segmentos de luces apagadas
sum_ = 0
for i in range(1, m): # Se analizan todos los segmentos interiores
c = on[i] - on[i - 1] - 1
if c > 0:
off.append(c)
sum_ += c
factorial = [1] * (on[0] + sum_ + n - on[-1])
for i in range(2, len(factorial)): # Factoriales modulo p hasta la cantidad de luces apagadas
factorial[i] = i * factorial[i - 1] % p
answer = pow(2, sum_ - len(off), p) * factorial[n - m] % p # Se calcula el numerador de la expresion
off.append(on[0] - 1) # Se agregan los segmentos exteriores
off.append(n - on[-1])
for x in off: # Se agrega al calculo los elementos del denominador
answer = answer * pow(factorial[x], p - 2, p) % p # Se utiliza el inverso multiplicativo
return answer
def readline(): # Metodo para leer una linea completa, dividirla en elementos y convertirlos en numeros enteros
return map(int, stdin.readline().strip().split())
if __name__ == '__main__':
stdout.write(str(main()) + '\n')
```
| 14,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Submitted Solution:
```
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
l1=[]
l1.append(l[0]-1)
for i in range(m-1):
l1.append(l[i+1]-l[i]-1)
f1=[1]*1001
f2=[1]*1001
mod=10**9+7
a=1
b=1
for i in range(1,1001):
a*=i
a%=mod
f1[i]=a
b*=pow(i,mod-2,mod)
b%=mod
f2[i]=b
ans=1
n-=m
ans*=f1[n]*f2[l1[0]]*f2[n-l1[0]]
ans%=mod
n-=l1[0]
for i in range(1,len(l1)):
if l1[i]>0:
ans*=f1[n]*f2[l1[i]]*f2[n-l1[i]]*pow(2,l1[i]-1,mod)
ans%=mod
n-=l1[i]
print(ans)
```
Yes
| 14,494 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Submitted Solution:
```
mod = 1000000007
fact = [1] * 2000
for i in range(1, 2000):
fact[i] = fact[i - 1] * i % mod
n, m = map(int, input().split())
a = sorted(map(int, input().split()))
b = []
for i in range (1, m):
x = a[i] - a[i - 1] - 1
if (x > 0):
b.append(x)
count = pow(2, sum(b) - len(b), mod) * fact[n - m] % mod
b = [a[0] - 1] + b + [n - a[-1]]
for i in b:
count = count * pow(fact[i], mod - 2, mod) % mod
print(count)
```
Yes
| 14,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Submitted Solution:
```
mod=10**9+7
n,m=[int(x) for x in input().split()]
light=[False for x in range(n+1)]
marr=[int(x) for x in input().split()]
for i in range(m):
light[marr[i]]=True
counta=0;countb=0
for i in range(1,n+1):
if light[i]==False:
counta+=1
else:
break
for i in reversed(range(1,n+1)):
if light[i]==False:
countb+=1
else:
break
else:
countb=0
arr=[]
start=False;count=0
for i in range(1,n+1):
if start==False:
if light[i]==True:
start=True
else:
if light[i]==False:
count+=1
else:
if count>0:arr.append(count);count=0;#start=False
#else:start=False
fact=[None for x in range(n+1)];fact[0]=1
for i in range(1,n+1):
fact[i]=i*fact[i-1]
ans=fact[n-m]//(fact[counta]*fact[countb])
ans=int(ans)
for item in arr:
ans=ans//fact[item]
for item in arr:
ans=(ans*pow(2,item-1,mod))%mod
print(ans%mod)
```
Yes
| 14,496 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Submitted Solution:
```
import itertools
import math
def countEndgames(grid):
ls = []
for elt, gp in itertools.groupby(grid):
if elt == '.':
ls.append(len(list(gp)))
tot = 1
for i,g in enumerate(ls):
if i==0 and grid[0] == '.' or i==(len(ls)-1) and grid[-1] == '.':
continue
tot *= 2**(g-1)
tot *= math.factorial(sum(ls))
for g in ls:
tot //= math.factorial(g)
return tot % (10**9+7)
n,x = map(int, input().split())
ls = list(map(int, input().split()))
grid = ['.' for i in range(n)]
for x in ls:
grid[x-1] = '#'
print(countEndgames(grid))
```
Yes
| 14,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Submitted Solution:
```
def f(p):
d = 1
for i in range(2, p + 1):
d *= i
return d
n, m = map(int, input().split())
l = list(map(int, input().split()))
if n == m:
print(1)
else:
l.sort()
for i in range(m):
l[i] -= 1
k = []
sm = n - m
if l[0] > 1:
k.append([l[0], 1])
for i in range(1, len(l)):
k.append([l[i] - l[i - 1] - 1, 2 ** (l[i] - l[i - 1] - 2)])
if l[-1] < n - 1:
k.append([n - 1 - l[-1], 1])
ans = f(sm)
for c in k:
ans //= f(c[0])
for c in k:
ans *= c[1]
print(ans % 1000000007)
```
No
| 14,498 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is already switched on.
He knows the initial state of lights and he's wondering how many different ways there exist to switch all the lights on. Please find the required number of ways modulo 1000000007 (109 + 7).
Input
The first line of the input contains two integers n and m where n is the number of lights in the sequence and m is the number of lights which are initially switched on, (1 β€ n β€ 1000, 1 β€ m β€ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of lights which are initially switched on.
Output
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109 + 7).
Examples
Input
3 1
1
Output
1
Input
4 2
1 4
Output
2
Input
11 2
4 8
Output
6720
Submitted Solution:
```
def bpow(a, b):
if b==0 or a==1:
return 1
if b%2 != 0:
return a * bpow(a, b-1) % mod
else:
c = bpow(a, b/2) % mod
return c * c % mod
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [0] + a + [n+1]
fa = list()
fa.append(1)
mod = 1000000007
for i in range(1, 1001):
fa.append(fa[i-1] * i)
fa[i] %= mod
ans1 = 1
ans2 = 1
s = 0
for i in range(0, m+1):
ans1 *= fa[a[i+1] - a[i] - 1]
s+= a[i+1] - a[i] - 1
ans1 %= mod
if i > 0 and i < m and a[i+1] - a[i] > 1:
ans2*= pow(2, a[i+1] - a[i] - 2, mod)
ans2%= mod
print((fa[s] * pow(ans1, mod-2, mod) * ans2)%mod)
```
No
| 14,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.