message stringlengths 2 28.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 21 109k | cluster float64 7 7 | __index_level_0__ int64 42 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 80,025 | 7 | 160,050 |
Tags: combinatorics, dp, math
Correct Solution:
```
n,m=map(int,input().split())
a=[0]*100001
Mod=1000000007
a[1],a[2]=2,4
for i in range(3,max(n,m)+1):
a[i]=(a[i-1]+a[i-2])%Mod
print((a[n]+a[m]-2)%Mod,flush=False)
``` | output | 1 | 80,025 | 7 | 160,051 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 80,026 | 7 | 160,052 |
Tags: combinatorics, dp, math
Correct Solution:
```
MOD = 10 ** 9 + 7
n, m = map(int, input().split())
fib = [1] * (max(n, m) + 2)
for i in range(2, max(n, m) + 2):
fib[i] = fib[i - 1] + fib[i - 2]
fib[i] %= MOD
print(((fib[m] + fib[n]) * 2 - 2) % MOD)
``` | output | 1 | 80,026 | 7 | 160,053 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 80,027 | 7 | 160,054 |
Tags: combinatorics, dp, math
Correct Solution:
```
n, m = map(int, input().split())
mod = 10**9+7
a = []
a.append(0)
a.append(2)
a.append(4)
for i in range(3, max(n, m)+1):
a.append((a[i-1]+a[i-2])%mod)
print((a[m]-2 + a[n])%mod)
``` | output | 1 | 80,027 | 7 | 160,055 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 80,028 | 7 | 160,056 |
Tags: combinatorics, dp, math
Correct Solution:
```
r=[int(x) for x in input().split()]
fibonacci=[0 for i in range(100001)]
fibonacci[0]=1
fibonacci[1]=1
for i in range(99999):
fibonacci[i+2]=(fibonacci[i+1]+fibonacci[i]) % 1000000007
print(((2*((fibonacci[r[0]]+fibonacci[r[1]]) % 1000000007)-2+1000000007) % 1000000007))
``` | output | 1 | 80,028 | 7 | 160,057 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 80,029 | 7 | 160,058 |
Tags: combinatorics, dp, math
Correct Solution:
```
n, m = map(int, input().split())
dp0n = 1
dp1n = 1
dp0m = 1
dp1m = 1
dpn, dpm = 2, 2
for i in range(3, n + 1):
dp0n, dp1n, dpn = dp1n % 1000000007, dpn % 1000000007, (dpn + dp1n) % 1000000007
for i in range(3, m + 1):
dp0m, dp1m, dpm = dp1m % 1000000007, dpm % 1000000007, (dpm + dp1m) % 1000000007
if n == 1:
dpn = 1
if m == 1:
dpm = 1
print((dpm * 2 + dpn * 2 - 2) % 1000000007)
``` | output | 1 | 80,029 | 7 | 160,059 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 80,030 | 7 | 160,060 |
Tags: combinatorics, dp, math
Correct Solution:
```
def main():
mod = 1000000007
a = [1,1,1]
b = [1,1,1]
c = [1,1,1]
a[1] = 2
a[2] = 4
b[1] = 0
b[2] = 2
c[1] = 0
c[2] = 2
for i in range(3,100001):
a.append(a[i-1]+a[i-2])
a[i] %= mod
b.append(b[i-1]+b[i-2])
b[i] %= mod
c.append((c[i-1]+b[i])%mod)
n,m = input().split()
n = int(n)
m = int(m)
print((a[n]+c[m])%mod)
main()
``` | output | 1 | 80,030 | 7 | 160,061 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
arr = [2,4]
n,m = map(int,input().split(" "))
for i in range(2,max(n,m)):
arr.append(arr[i-1]+arr[i-2])
print((arr[n-1]+arr[m-1]-2)%(10**9+7))
``` | instruction | 0 | 80,031 | 7 | 160,062 |
Yes | output | 1 | 80,031 | 7 | 160,063 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
n,m=map(int,input().split())
a=[0]*100001
a[0]=1
a[1]=1
p =1000000007
for i in range(2,100001):
a[i]=(a[i-1]+a[i-2])%p
print(((a[n]+a[m]-1)*2)%p)
``` | instruction | 0 | 80,032 | 7 | 160,064 |
Yes | output | 1 | 80,032 | 7 | 160,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
import sys
#sys.stdin = open('in', 'r')
#n = int(input())
n,m = map(int, input().split())
if n < m:
n,m = m,n
if n == 1 and m == 1:
print(2)
elif n == 2 and m == 2:
print(6)
else:
md = 1000000007
def Fn(n):
a,b = 1, 1
for i in range(2, n + 1):
a, b = (a + b) % md, a
return a
print((2*Fn(n)+2*Fn(m) - 2)% md)
#sys.stdout.write('YES\n')
#sys.stdout.write(f'{res}\n')
#sys.stdout.write(f'{y1} {x1} {y2} {x2}\n')
``` | instruction | 0 | 80,033 | 7 | 160,066 |
Yes | output | 1 | 80,033 | 7 | 160,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
N, M = map(int, input().split())
mod = 10**9+7
L = max(N, M) + 1
dp = [[1, 1] for _ in range(L+1)]
dp[1][0] = 1
dp[1][1] = 1
for l in range(2, L+1):
dp[l][0] = (dp[l-1][1] + dp[l-2][1]) % mod
dp[l][1] = (dp[l-1][0] + dp[l-2][0]) % mod
ans = dp[N][0] + dp[N][1] + dp[M][0] + dp[M][1] - 2
if ans < 0: ans += mod
ans %= mod
print(ans)
``` | instruction | 0 | 80,034 | 7 | 160,068 |
Yes | output | 1 | 80,034 | 7 | 160,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
''' CODED WITH LOVE BY SATYAM KUMAR '''
from sys import stdin, stdout
import heapq
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 6) # max depth of recursion
threading.stack_size(2 ** 27) # new thread will get stack of such size
fac_warm_up = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
class MergeFind:
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.num_sets = n
self.lista = [[_] for _ in range(n)]
def find(self, a):
to_update = []
while a != self.parent[a]:
to_update.append(a)
a = self.parent[a]
for b in to_update:
self.parent[b] = a
return self.parent[a]
def merge(self, a, b):
a = self.find(a)
b = self.find(b)
if a == b:
return
if self.size[a] < self.size[b]:
a, b = b, a
self.num_sets -= 1
self.parent[b] = a
self.size[a] += self.size[b]
self.lista[a] += self.lista[b]
def set_size(self, a):
return self.size[self.find(a)]
def __len__(self):
return self.num_sets
def display(string_to_print):
stdout.write(str(string_to_print) + "\n")
def prime_factors(n): # n**0.5 complex
factors = dict()
for i in range(2, math.ceil(math.sqrt(n)) + 1):
while n % i == 0:
if i in factors:
factors[i] += 1
else:
factors[i] = 1
n = n // i
if n > 2:
factors[n] = 1
return (factors)
def all_factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
def fibonacci_modP(n, MOD):
if n < 2: return 1
return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(
fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD
def factorial_modP_Wilson(n, p):
if (p <= n):
return 0
res = (p - 1)
for i in range(n + 1, p):
res = (res * cached_fn(InverseEuler, i, p)) % p
return res
def binary(n, digits=20):
b = bin(n)[2:]
b = '0' * (digits - len(b)) + b
return b
def is_prime(n):
"""Returns True if n is prime."""
if n < 4:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
def generate_primes(n):
prime = [True for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
return prime
factorial_modP = []
def warm_up_fac(MOD):
global factorial_modP, fac_warm_up
if fac_warm_up: return
factorial_modP = [1 for _ in range(fac_warm_up_size + 1)]
for i in range(2, fac_warm_up_size):
factorial_modP[i] = (factorial_modP[i - 1] * i) % MOD
fac_warm_up = True
def InverseEuler(n, MOD):
return pow(n, MOD - 2, MOD)
def nCr(n, r, MOD):
global fac_warm_up, factorial_modP
if not fac_warm_up:
warm_up_fac(MOD)
fac_warm_up = True
return (factorial_modP[n] * (
(pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD)) % MOD)) % MOD
def get_int():
return int(stdin.readline().strip())
def get_tuple():
return map(int, stdin.readline().split())
def get_list():
return list(map(int, stdin.readline().split()))
memory = dict()
def clear_cache():
global memory
memory = dict()
def cached_fn(fn, *args):
global memory
if args in memory:
return memory[args]
else:
result = fn(*args)
memory[args] = result
return result
def ncr(n, r):
return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))
def binary_search(i, li):
fn = lambda x: li[x] - x // i
x = -1
b = len(li)
while b >= 1:
while b + x < len(li) and fn(b + x) > 0: # Change this condition 2 to whatever you like
x += b
b = b // 2
return x
# -------------------------------------------------------------- MAIN PROGRAM
TestCases = False
optimise_for_recursion = True # Can not be used clubbed with TestCases WHen using recursive functions, use Python 3
def main():
n, m = get_tuple()
p, q = 1, 1
r1 = 1
for i in range(1, n):
r1 = p + q
p = q
q = r1
p, q = 1, 1
r2 = 1
for i in range(1, m):
r2 = p + q
p = q
q = r2
#print(r1, r2)
print(2*(r1+r2-1))
# --------------------------------------------------------------------- END=
if TestCases:
for i in range(get_int()):
main()
else:
main() if not optimise_for_recursion else threading.Thread(target=main).start()
``` | instruction | 0 | 80,035 | 7 | 160,070 |
No | output | 1 | 80,035 | 7 | 160,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
a,b=map(int,input().split())
t=max(a,b)
j=min(a,b)
a,b=t,j
dp=[2,4]
for i in range(2,a+1):
dp.append(0)
if a<3:
row=dp[a-1]
else:
for i in range(2,a):
dp[i]=dp[i-1]+dp[i-2]
# print(dp)
row=dp[a-1]
dp=[row,row+2]
for i in range(2,b+1):
dp.append(0)
if b<3:
row=dp[b-1]
else:
for i in range(2,b):
dp[i]=dp[i-1]+dp[i-2]
row=dp[b-1]
print(row%(10**9+7))
``` | instruction | 0 | 80,036 | 7 | 160,072 |
No | output | 1 | 80,036 | 7 | 160,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
n, m = map(int, input().split())
mod = 10**9+7
a = []
a.append(0)
a.append(2)
a.append(4)
for i in range(3, m+1):
a.append((a[i-1]+a[i-2])%mod)
print((a[m]-2 + pow(2, n-1, mod)*2)%mod)
``` | instruction | 0 | 80,037 | 7 | 160,074 |
No | output | 1 | 80,037 | 7 | 160,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
n, m = map(int, input().split())
mod = 10**9+7
a = []
a.append(0)
a.append(2)
a.append(4)
for i in range(3, m+1):
a.append((a[i-1]+a[i-2])%mod)
print(a[m]-2 + pow(2, n-1, mod)*2)
``` | instruction | 0 | 80,038 | 7 | 160,076 |
No | output | 1 | 80,038 | 7 | 160,077 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image> | instruction | 0 | 80,443 | 7 | 160,886 |
Tags: constructive algorithms, implementation
Correct Solution:
```
import sys
n, m, k = [int(x) for x in input().split()]
L, C = [(-1, 0) for i in range(n)], [(-1, 0) for i in range(m)]
for i, line in enumerate(sys.stdin):
t, r, c = [int(x) for x in line.split()]
if t == 1:
L[r-1] = (i, c)
else:
C[r-1] = (i, c)
for i in range(n):
sys.stdout.write(' '.join(str(L[i][1]) if L[i][0] > C[j][0] else str(C[j][1]) for j in range(m)) + '\n')
``` | output | 1 | 80,443 | 7 | 160,887 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image> | instruction | 0 | 80,444 | 7 | 160,888 |
Tags: constructive algorithms, implementation
Correct Solution:
```
from sys import stdin
def main():
n, m, q = map(int, stdin.readline().split())
rid = [-1] * n
rc = [-1] * n
cid = [-1] * m
cc = [-1] * m
for i in range(q):
t, x, y = map(int, stdin.readline().split())
if t == 1:
rid[x - 1] = i
rc[x - 1] = y - 1
else:
cid[x - 1] = i
cc[x - 1] = y - 1
ans = [[0 for _ in range(m)] for _ in range(n)]
query = []
for i in range(n):
query.append((rid[i], rc[i], i))
for i in range(m):
query.append((cid[i], cc[i], n + i))
query.sort()
for i in range(len(query)):
idx, c, t = query[i]
if c == -1:
continue
if t < n:
for j in range(m):
ans[t][j] = c + 1
else:
for j in range(n):
ans[j][t - n] = c + 1
for row in ans:
print(*row)
if __name__ == "__main__":
main()
``` | output | 1 | 80,444 | 7 | 160,889 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image> | instruction | 0 | 80,445 | 7 | 160,890 |
Tags: constructive algorithms, implementation
Correct Solution:
```
def fill_column(num, color):
global canvas
for i in range(n):
canvas[i][num] = color
def fill_row(num, color):
global canvas
for i in range(m):
canvas[num][i] = color
(n, m, k) = map(int, input().split())
canvas = [[0 for j in range(m)] for i in range(n)]
(T, num, color) = (0, 0, 0)
a = []
T1 = [-1 for i in range(n)]
T2 = [-1 for j in range(m)]
for i in range(k):
(T, num, color) = map(int, input().split())
a.append((T, num - 1, color))
if T == 1:
T1[num - 1] = i
else:
T2[num - 1] = i
for i in range(k):
if a[i][0] == 1:
if T1[a[i][1]] == i:
fill_row(a[i][1], a[i][2])
else:
if T2[a[i][1]] == i:
fill_column(a[i][1], a[i][2])
for i in range(n):
for j in range(m):
print(canvas[i][j], end = ' ')
print()
``` | output | 1 | 80,445 | 7 | 160,891 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image> | instruction | 0 | 80,446 | 7 | 160,892 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,m,k = map(int,input().split())
t = [[0]*m for i in range(n)]
used = set()
a = []
for i in range(k):
q, b, c = tuple(map(int,input().split()))
b = b - 1
a.append((q, b, c))
a = a[::-1]
for i in range(k):
if a[i][0:2] not in used:
if a[i][0] == 1:
for s in range(m):
if t[a[i][1]][s] == 0:
t[a[i][1]][s] = a[i][2]
else:
for s in range(n):
if t[s][a[i][1]] == 0:
t[s][a[i][1]] = a[i][2]
used.add(a[i][0:2])
for i in range(n):
for j in range(m):
print(t[i][j], end = ' ')
print()
``` | output | 1 | 80,446 | 7 | 160,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image> | instruction | 0 | 80,447 | 7 | 160,894 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n, m, k = map(int, input().split())
A = [0] * n
for i in range(n):
A[i] = [0,0]
B = [0] * m
for i in range(m):
B[i] = [0,0]
for i in range(k):
per = input().split()
if per[0] == '1':
A[int(per[1])-1] = [int(per[2]), i+1]
else:
B[int(per[1])-1] = [int(per[2]), i+1]
ans = [0] * n
for i in range(n):
ans[i] = [0] * m
for i in range(n):
for j in range(m):
if A[i][1] > B[j][1]:
ans[i][j] = A[i][0]
else:
ans[i][j] = B[j][0]
for i in ans:
print(' '.join(map(str,i)))
``` | output | 1 | 80,447 | 7 | 160,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image> | instruction | 0 | 80,448 | 7 | 160,896 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n,m,k=map(int,input().split())
c=[(0,0)]*(m+1)
r=[(0,0)]*(n+1)
for i in range(k):
q,a,b=map(int,input().split())
if q==1: r[a]=(i+1,b)
else: c[a]=(i+1,b)
for i in range(n):
s=""
for j in range(m):
t=r[i+1][1]
if c[j+1][0]>r[i+1][0]: t=c[j+1][1]
s+=str(t)+' '
print(s)
# Made By Mostafa_Khaled
``` | output | 1 | 80,448 | 7 | 160,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image> | instruction | 0 | 80,449 | 7 | 160,898 |
Tags: constructive algorithms, implementation
Correct Solution:
```
from sys import stdin, stdout
def main():
(n, m, k) = map(int, stdin.readline().strip().split(' '))
r = [0] * n
c = [0] * m
a = [0] * (k + 1)
for i in range(1, k + 1):
l, xi, a[i] = map(int, stdin.readline().strip().split(' '))
if l == 1:
r[xi-1] = i
else:
c[xi-1] = i
for i in range(n):
l = []
for j in range(m):
l.append(str(a[max(r[i], c[j])]))
print(' '.join(l))
main()
``` | output | 1 | 80,449 | 7 | 160,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image> | instruction | 0 | 80,450 | 7 | 160,900 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n, m, k = map(int, input().split())
c = [(0, 0)] * m
r = [(0, 0)] * n
for i in range(k):
t, idx, x = map(int, input().split())
if t == 1: r[idx - 1] = (i + 1, x)
else: c[idx - 1] = (i + 1, x)
res = [[0] * m for i in range(n)]
for i in range(n):
for j in range(m):
res[i][j] = c[j][1] if c[j][0] > r[i][0] else r[i][1]
[print(*i) for i in res]
``` | output | 1 | 80,450 | 7 | 160,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image>
Submitted Solution:
```
n, m, k = map(int, input().split())
mat = [{}, {}]
for i in range(k):
t, x, c = map(int, input().split())
mat[t - 1][x - 1] = (i, c)
res = []
for i in [0, 1]:
for k, v in mat[i].items():
res.append((v[0], i, k, v[1]))
res.sort()
ans = [[0] * m for _ in range(n)]
for _, t, x, c in res:
if t == 0:
for i in range(m):
ans[x][i] = c
else:
for i in range(n):
ans[i][x] = c
for l in ans:
print(*l)
``` | instruction | 0 | 80,451 | 7 | 160,902 |
Yes | output | 1 | 80,451 | 7 | 160,903 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image>
Submitted Solution:
```
n,m,k=[int(x)for x in input().split()]
a=[]
r=[(0,0)]*n
c=[(0,0)]*m
for i in range(n):a.append([0]*m)
for _ in range(k):
x,y,z=[int(t)for t in input().split()]
if x==1:r[y-1]=(_,z)
else:c[y-1]=(_,z)
for i in range(n):
for j in range(m):
a[i][j]=max(r[i],c[j])[1]
print(*a[i])
``` | instruction | 0 | 80,452 | 7 | 160,904 |
Yes | output | 1 | 80,452 | 7 | 160,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image>
Submitted Solution:
```
def getnums():
raw = input()
raw = raw.split()
return [int(num) for num in raw]
n, m, k = getnums()
a = [[0 for j in range(m + 1)] for i in range(n + 1)]
r = [False for i in range(n + 1)]
c = [False for j in range(m + 1)]
info = [getnums() for i in range(k)]
def draw(t, num, col):
if t == 1:
for i in range(1, m + 1):
if a[num][i] == 0:
a[num][i] = col
else:
for i in range(1, n + 1):
if a[i][num] == 0:
a[i][num] = col
i = k - 1
while i >= 0:
if info[i][0] == 1:
val = info[i][1]
if not r[val]:
r[val] = True
draw(1, val, info[i][2])
else:
val = info[i][1]
if not c[val]:
c[val] = True
draw(2, val, info[i][2])
i = i - 1
for i in range(1, n + 1):
for j in range(1, m):
print(a[i][j], end = ' ')
print(a[i][m])
``` | instruction | 0 | 80,453 | 7 | 160,906 |
Yes | output | 1 | 80,453 | 7 | 160,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image>
Submitted Solution:
```
def main():
from sys import stdin, stdout
n, m, op = map(int, stdin.readline().split())
hor = dict()
vert = dict()
for i in range(op):
a, b, c = map(int, input().split())
b -= 1
if a == 1:
hor[b] = (c, i)
else:
vert[b] = (c, i)
for i in range(n):
for j in range(m):
if i not in hor:
hor[i] = (0, -1)
if j not in vert:
vert[j] = (0, -1)
if hor[i][1] > vert[j][1]:
stdout.write(str(hor[i][0]) + ' ')
else:
stdout.write(str(vert[j][0]) + ' ')
stdout.write('\n')
main()
``` | instruction | 0 | 80,454 | 7 | 160,908 |
Yes | output | 1 | 80,454 | 7 | 160,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image>
Submitted Solution:
```
n,m,k = map(int, input().split())
A = [0] * n
B = [0] * m
C = dict()
for i in range(k):
per = input().split()
if per[0] == '1':
A[int(per[1])-1] = int(per[2])
C['0'+per[1]] = i
else:
B[int(per[1])-1] = int(per[2])
C['1'+per[1]] = i
ans = [0] * n
for i in range(n):
ans[i] = [0] * m
D = []
for i in C:
D.append([i, C[i]])
D.sort(key = lambda x: (x[1]))
for i in D:
if i[0][0] == '0':
per = int(i[0][1])-1
for i in range(m):
ans[per][i] = A[per]
else:
per = int(i[0][1])-1
for j in range(n):
ans[j][per] = B[per]
for i in ans:
print(' '.join(map(str, i)))
``` | instruction | 0 | 80,455 | 7 | 160,910 |
No | output | 1 | 80,455 | 7 | 160,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image>
Submitted Solution:
```
n,m,k=map(int,input().split())
row = [(0, 0)] * n
col = [(0, 0)] * m
for i in range(k):
a, b, c = map(int, input().split())
if a == 1:
row[b - 1] = (i, c)
else:
col[b - 1] = (i, c)
for i in range(n):
for j in range(m):
if row[i][0]>col[j][0]:
print(row[i][1],end=' ')
else:
print(col[j][1],end=' ')
print()
``` | instruction | 0 | 80,456 | 7 | 160,912 |
No | output | 1 | 80,456 | 7 | 160,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image>
Submitted Solution:
```
def main():
n, m, k = map(int, input().split())
rows = [(0, 0)] * n
cols = [(0, 0)] * m
for i in range(0, k):
op, rc, a = map(int, input().split())
if op == 1:
rows[rc - 1] = (a, i)
else:
cols[rc - 1] = (a, i)
for i in range(0, n):
for j in range(0, m):
row = rows[i]
col = cols[j]
if row[1] < col[1]:
print(col[0], end=' ')
else:
print(row[0], end=' ')
print()
main()
``` | instruction | 0 | 80,457 | 7 | 160,914 |
No | output | 1 | 80,457 | 7 | 160,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row ri in color ai;
2. Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.
Your program has to print the resulting table after k operation.
Input
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next k lines contains the description of exactly one query:
* 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
* 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.
Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1
Note
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
<image>
Submitted Solution:
```
def iterate_row (lis, row, n, m, a) :
for i in range (m) :
lis[row * m + i] = a
def iterate_col (lis, col, n, m, a) :
for i in range (n) :
lis[i * m + col] = a
n, m, k = map (int, input ().split ())
lis = [0] * n * m
for i in range (k) :
operation, r, a = map (int, input ().split ())
if operation == 1 :
r -= 1
iterate_row (lis, r, n, m, a)
else :
r -= 1
iterate_col (lis, r, n, m, a)
j = 0
print (lis)
for i in range (n * m) :
print (lis[i], end = ' ')
j += 1
if j == m :
j = 0
print ()
``` | instruction | 0 | 80,458 | 7 | 160,916 |
No | output | 1 | 80,458 | 7 | 160,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an N \times M grid. The square at the i-th row and j-th column will be denoted as (i,j). Particularly, the top-left square will be denoted as (1,1), and the bottom-right square will be denoted as (N,M). Takahashi painted some of the squares (possibly zero) black, and painted the other squares white.
We will define an integer sequence A of length N, and two integer sequences B and C of length M each, as follows:
* A_i(1\leq i\leq N) is the minimum j such that (i,j) is painted black, or M+1 if it does not exist.
* B_i(1\leq i\leq M) is the minimum k such that (k,i) is painted black, or N+1 if it does not exist.
* C_i(1\leq i\leq M) is the maximum k such that (k,i) is painted black, or 0 if it does not exist.
How many triples (A,B,C) can occur? Find the count modulo 998244353.
Constraints
* 1 \leq N \leq 8000
* 1 \leq M \leq 200
* N and M are integers.
Partial Score
* 1500 points will be awarded for passing the test set satisfying N\leq 300.
Constraints
* 1 \leq N \leq 8000
* 1 \leq M \leq 200
* N and M are integers.
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of triples (A,B,C), modulo 998244353.
Examples
Input
2 3
Output
64
Input
4 3
Output
2588
Input
17 13
Output
229876268
Input
5000 100
Output
57613837
Submitted Solution:
```
a=int(input())
b=int(input())
ans=pow(2,a*b)%998244353
print(ans)
``` | instruction | 0 | 80,686 | 7 | 161,372 |
No | output | 1 | 80,686 | 7 | 161,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an N \times M grid. The square at the i-th row and j-th column will be denoted as (i,j). Particularly, the top-left square will be denoted as (1,1), and the bottom-right square will be denoted as (N,M). Takahashi painted some of the squares (possibly zero) black, and painted the other squares white.
We will define an integer sequence A of length N, and two integer sequences B and C of length M each, as follows:
* A_i(1\leq i\leq N) is the minimum j such that (i,j) is painted black, or M+1 if it does not exist.
* B_i(1\leq i\leq M) is the minimum k such that (k,i) is painted black, or N+1 if it does not exist.
* C_i(1\leq i\leq M) is the maximum k such that (k,i) is painted black, or 0 if it does not exist.
How many triples (A,B,C) can occur? Find the count modulo 998244353.
Constraints
* 1 \leq N \leq 8000
* 1 \leq M \leq 200
* N and M are integers.
Partial Score
* 1500 points will be awarded for passing the test set satisfying N\leq 300.
Constraints
* 1 \leq N \leq 8000
* 1 \leq M \leq 200
* N and M are integers.
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of triples (A,B,C), modulo 998244353.
Examples
Input
2 3
Output
64
Input
4 3
Output
2588
Input
17 13
Output
229876268
Input
5000 100
Output
57613837
Submitted Solution:
```
def burger(l):
if not l:
return 'P'
s = 'B' + burger(l - 1) + 'P' + burger(l - 1) + 'B'
return s
s = ''
n, x = map(int, input().split())
print(burger(n)[:x].count('P'))
``` | instruction | 0 | 80,687 | 7 | 161,374 |
No | output | 1 | 80,687 | 7 | 161,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino has a lot of red and blue bricks and a large box. She will build a tower of these bricks in the following manner.
First, she will pick a total of N bricks and put them into the box. Here, there may be any number of bricks of each color in the box, as long as there are N bricks in total. Particularly, there may be zero red bricks or zero blue bricks. Then, she will repeat an operation M times, which consists of the following three steps:
* Take out an arbitrary brick from the box.
* Put one red brick and one blue brick into the box.
* Take out another arbitrary brick from the box.
After the M operations, Joisino will build a tower by stacking the 2 \times M bricks removed from the box, in the order they are taken out. She is interested in the following question: how many different sequences of colors of these 2 \times M bricks are possible? Write a program to find the answer. Since it can be extremely large, print the count modulo 10^9+7.
Constraints
* 1 \leq N \leq 3000
* 1 \leq M \leq 3000
Input
Input is given from Standard Input in the following format:
N M
Output
Print the count of the different possible sequences of colors of 2 \times M bricks that will be stacked, modulo 10^9+7.
Examples
Input
2 3
Output
56
Input
1000 10
Output
1048576
Input
1000 3000
Output
693347555
Submitted Solution:
```
# -*- coding: utf-8 -*-
#import time
#start=time.time()
temp=input().split()
N=int(temp[0])
M=int(temp[1])
INF=10**9+7
#Ans=0
#動的計画法で解きます
#dp1は、[not goto 0, already 0]の場合の数とする。
#dp=[[0 for j in range(N+1)] for i in range(2*M+1)]
def DP():
dp1=[[0 for j in range(N+1)]]
dp2=[[0 for j in range(N+1)]]
dp2[0][0]=1
for i in range(1,N+1):
dp1[0][i]=1
ans=0
all=0
#少しずつ下に進めていきます
for i in range(2*M):
dp1+=[[x+y for(x,y) in zip(dp1[i][0:N],dp1[i][1:N+1])]]
dp2+=[[x+y for(x,y) in zip(dp2[i][0:N],dp2[i][1:N+1])]]
#偶数回目の取り出す場合
if i%2==0:
dp2[i+1][0]+=dp1[i+1][0]
dp1[i+1][0]=0
dp1[i+1]+=[0]
dp2[i+1]+=[0]
#奇数回目の取り出す場合(取り出さないことを+1として考えます)
else:
dp1[i+1].insert(0,0)
dp2[i+1].insert(0,dp2[i][0])
for j in range(N+1):
dp1[i+1][j]%=INF
dp2[i+1][j]%=INF
for j in range(N+1):
ans+=dp2[2*M][j]
return ans
all=DP()
#end=time.time()
print(all%INF)
``` | instruction | 0 | 80,704 | 7 | 161,408 |
No | output | 1 | 80,704 | 7 | 161,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino has a lot of red and blue bricks and a large box. She will build a tower of these bricks in the following manner.
First, she will pick a total of N bricks and put them into the box. Here, there may be any number of bricks of each color in the box, as long as there are N bricks in total. Particularly, there may be zero red bricks or zero blue bricks. Then, she will repeat an operation M times, which consists of the following three steps:
* Take out an arbitrary brick from the box.
* Put one red brick and one blue brick into the box.
* Take out another arbitrary brick from the box.
After the M operations, Joisino will build a tower by stacking the 2 \times M bricks removed from the box, in the order they are taken out. She is interested in the following question: how many different sequences of colors of these 2 \times M bricks are possible? Write a program to find the answer. Since it can be extremely large, print the count modulo 10^9+7.
Constraints
* 1 \leq N \leq 3000
* 1 \leq M \leq 3000
Input
Input is given from Standard Input in the following format:
N M
Output
Print the count of the different possible sequences of colors of 2 \times M bricks that will be stacked, modulo 10^9+7.
Examples
Input
2 3
Output
56
Input
1000 10
Output
1048576
Input
1000 3000
Output
693347555
Submitted Solution:
```
# -*- coding: utf-8 -*-
temp=input().split()
N=int(temp[0])
M=int(temp[1])
INF=10**9+7
Ans=0
#動的計画法で解きます
#dp1は、[not goto 0, already 0]の場合の数とする。
#dp=[[0 for j in range(N+1)] for i in range(2*M+1)]
dp1=[[[0,0] for j in range(N+1)] for i in range(2*M+1)]
"""
def DP0():
ans=0
#少しずつ下に進めていきます
for i in range(2*M):
#偶数回目の取り出す場合
if i%2==0:
for j in range(N+1):
dp[i+1][j]+=dp[i][j]
if j!=0:
dp[i+1][j-1]+=dp[i][j]
#奇数回目の取り出す場合(取り出さないことを+1として考えます)
else:
for j in range(N+1):
dp[i+1][j]+=dp[i][j]
if j!=N:
dp[i+1][j+1]+=dp[i][j]
for j in range(N+1):
dp[i+1][j]%=INF
ans=sum(dp[i+1])%INF
for i in range(2*M+1):
pass
#print(dp[i])
#print(ans)
return ans
"""
def DP1():
ans=0
#少しずつ下に進めていきます
for i in range(2*M):
#print(i)
#偶数回目の取り出す場合
if i%2==0:
"""
#0に行く場合の処理
dp1[i+1][0][1]+=dp1[i][0][1]+dp1[i][1][0]+dp1[i][1][1]
dp1[i+1][1][0]+=dp1[i][1][0]
dp1[i+1][1][1]+=dp1[i][1][1]
"""
for j in range(N+1):
dp1[i+1][j]=dp1[i][j]
if 0<j:
dp1[i+1][j-1][0]+=dp1[i][j][0]
dp1[i+1][j-1][1]+=dp1[i][j][1]
dp1[i+1][0][1]+=dp1[i+1][0][0]
dp1[i+1][0][0]=0
dp1[i+1][N]=[0,0]
#奇数回目の取り出す場合(取り出さないことを+1として考えます)
else:
for j in range(N+1):
if j!=N:
dp1[i+1][j+1]=dp1[i][j]
dp1[i+1][j][0]+=dp1[i][j][0]
dp1[i+1][j][1]+=dp1[i][j][1]
for j in range(N+1):
dp1[i+1][j][0]%=INF
dp1[i+1][j][1]%=INF
for j in range(N+1):
ans+=dp1[2*M][j][1]
return ans
dp1[0][0][1]=1
for i in range(1,N+1):
dp1[0][i][0]=1
Ans=DP1()
Ans%=INF
print(Ans)
``` | instruction | 0 | 80,705 | 7 | 161,410 |
No | output | 1 | 80,705 | 7 | 161,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino has a lot of red and blue bricks and a large box. She will build a tower of these bricks in the following manner.
First, she will pick a total of N bricks and put them into the box. Here, there may be any number of bricks of each color in the box, as long as there are N bricks in total. Particularly, there may be zero red bricks or zero blue bricks. Then, she will repeat an operation M times, which consists of the following three steps:
* Take out an arbitrary brick from the box.
* Put one red brick and one blue brick into the box.
* Take out another arbitrary brick from the box.
After the M operations, Joisino will build a tower by stacking the 2 \times M bricks removed from the box, in the order they are taken out. She is interested in the following question: how many different sequences of colors of these 2 \times M bricks are possible? Write a program to find the answer. Since it can be extremely large, print the count modulo 10^9+7.
Constraints
* 1 \leq N \leq 3000
* 1 \leq M \leq 3000
Input
Input is given from Standard Input in the following format:
N M
Output
Print the count of the different possible sequences of colors of 2 \times M bricks that will be stacked, modulo 10^9+7.
Examples
Input
2 3
Output
56
Input
1000 10
Output
1048576
Input
1000 3000
Output
693347555
Submitted Solution:
```
# -*- coding: utf-8 -*-
temp=input().split()
N=int(temp[0])
M=int(temp[1])
INF=10**9+7
#Ans=0
#動的計画法で解きます
#dp1は、[not goto 0, already 0]の場合の数とする。
#dp=[[0 for j in range(N+1)] for i in range(2*M+1)]
dp1=[[0 for j in range(N+1)]]
dp2=[[0 for j in range(N+1)]]
dp2[0][0]=1
for i in range(1,N+1):
dp1[0][i]=1
#少しずつ下に進めていきます
for i in range(2*M):
#偶数回目の取り出す場合
if i%2==0:
dp1+=[[x+y for(x,y) in zip(dp1[i][0:N],dp1[i][1:N+1])]+[0]]
dp2+=[[x+y for(x,y) in zip(dp2[i][0:N],dp2[i][1:N+1])]+[0]]
dp2[i+1][0]+=dp1[i+1][0]
dp1[i+1][0]=0
#奇数回目の取り出す場合(取り出さないことを+1として考えます)
else:
dp1+=[[0]+[x+y for(x,y) in zip(dp1[i][0:N],dp1[i][1:N+1])]]
dp2+=[[dp2[i][0]]+[x+y for(x,y) in zip(dp2[i][0:N],dp2[i][1:N+1])]]
for j in range(N+1):
dp1[i+1][j]%=INF
dp2[i+1][j]%=INF
ans=0
for j in range(N+1):
ans+=dp2[2*M][j]
print(ans%INF)
``` | instruction | 0 | 80,706 | 7 | 161,412 |
No | output | 1 | 80,706 | 7 | 161,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1). | instruction | 0 | 80,902 | 7 | 161,804 |
Tags: implementation
Correct Solution:
```
q = int(input())
for i in range(q):
[n, m] = [int(w) for w in input().split()]
obr = n * [None]
for x in range(n):
obr[x] = list(input())
r_pocty_ciernych = n * [None]
for x in range(n):
ciernych = 0
for y in range(m):
if obr[x][y] == '*':
ciernych += 1
r_pocty_ciernych [x] = ciernych
najviac_r = max(r_pocty_ciernych)
s_pocty_ciernych = m * [None]
for y in range(m):
ciernych = 0
for x in range(n):
if obr[x][y] == '*':
ciernych += 1
s_pocty_ciernych [y] = ciernych
najviac_s = max(s_pocty_ciernych)
najcernejsie_r = []
for x in range(n):
if r_pocty_ciernych[x] == najviac_r:
najcernejsie_r.append(x)
najcernejsie_s = []
for y in range(m):
if s_pocty_ciernych[y] == najviac_s:
najcernejsie_s.append(y)
uspesne = False
for j in najcernejsie_r:
if uspesne:
break
for k in najcernejsie_s:
if obr[j][k] == '.':
uspesne = True
break
if uspesne:
print(m + n -najviac_r - najviac_s - 1)
else:
print(m + n -najviac_r - najviac_s)
``` | output | 1 | 80,902 | 7 | 161,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1). | instruction | 0 | 80,903 | 7 | 161,806 |
Tags: implementation
Correct Solution:
```
import sys
import math
from collections import defaultdict,deque
input = sys.stdin.readline
def inar():
return [int(el) for el in input().split()]
def main():
t=int(input())
for _ in range(t):
n,m=inar()
matrix=[]
for i in range(n):
matrix.append(list(input().strip()))
row=[0]*n
col=[0]*m
for i in range(n):
for j in range(m):
if matrix[i][j]==".":
col[j]+=1
row[i]+=1
ans=10**10
for i in range(n):
for j in range(m):
minus=0
if matrix[i][j]==".":
minus=1
ans=min(ans,row[i]+col[j]-minus)
print(ans)
if __name__ == '__main__':
main()
``` | output | 1 | 80,903 | 7 | 161,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1). | instruction | 0 | 80,904 | 7 | 161,808 |
Tags: implementation
Correct Solution:
```
from sys import stdin
def ii(): return int(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline()
for _ in range(ii()):
a=[]
r=[]
c=[]
n, m=mi()
for i in range(n):
a.append(si())
r.append(a[i].count('.'))
for j in range(m):
x=0
for i in range(n):
if a[i][j]=='.':
x+=1
c.append(x)
ans=n+m-1
for i in range(n):
for j in range(m):
ans=min(ans, r[i]+c[j]-(a[i][j]=='.'))
print(ans)
``` | output | 1 | 80,904 | 7 | 161,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1). | instruction | 0 | 80,905 | 7 | 161,810 |
Tags: implementation
Correct Solution:
```
t = int(input())
for y in range(t):
n, m = map(int, input().split())
x = []
rowindex = -1
colindex = -1
r = -1
rows =[]
for i in range(n):
x += [input()]
cnt = x[-1].count('*')
if(cnt > r):
rowindex = i
r = cnt
rows = [i]
elif(cnt==r):
rows+=[i]
c = -1
cols = []
for i in range(m):
count = 0
for j in range(n):
if(x[j][i]=='*'):
count += 1
if(count > c):
c = count
colindex = i
cols = [i]
elif(count==c):
cols+= [i]
ans = m*n+1
flag = 0
for i in rows:
for j in cols:
if(x[i][j]=='.'):
flag = 1
print(n +m-r-c-flag)
``` | output | 1 | 80,905 | 7 | 161,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1). | instruction | 0 | 80,906 | 7 | 161,812 |
Tags: implementation
Correct Solution:
```
def check(x, y, vert, gor, matrix):
if matrix[y][x] == 1:
return gor[y] + vert[x] - 1
else:
return gor[y] + vert[x]
q = int(input())
for i in range(q):
n, m = map(int, input().split())
vert = [0 for i in range(m)]
gor = []
matrix = []
for s in range(n):
inp = [int(i == '.') for i in list(input())]
for u in range(m):
vert[u] += inp[u]
gor.append(sum(inp))
matrix.append(inp)
minh = 10e9
for y in range(n):
for x in range(m):
u = check(x, y, vert, gor, matrix)
if u < minh:
minh = u
print(minh)
``` | output | 1 | 80,906 | 7 | 161,813 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1). | instruction | 0 | 80,907 | 7 | 161,814 |
Tags: implementation
Correct Solution:
```
for _ in range(int(input())):
row, col = [int(x) for x in input().split()]
grid = [[x for x in input()] for _ in range(row)]
rowc, colc = [0] * row, [0] * col
for i in range(row):
for j in range(col):
if grid[i][j] == "*":
rowc[i] += 1
colc[j] += 1
ans = int(10e18)
for i in range(row):
for j in range(col):
k = rowc[i] + colc[j] - (grid[i][j] == "*")
ans = min(row + col - 1 - k, ans)
print(ans)
``` | output | 1 | 80,907 | 7 | 161,815 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1). | instruction | 0 | 80,908 | 7 | 161,816 |
Tags: implementation
Correct Solution:
```
import sys
z = int(input())
for _ in range(z):
ans = 99999999
n,m = map(int, sys.stdin.readline().split())
df = []
for _ in range(n):
df.append(sys.stdin.readline())
l = [df[i].count('.') for i in range(n)]
df2 = list(map(list, zip(*df)))
w = [df2[i].count('.') for i in range(m)]
for i in range(n):
ans1 = l[i]
x = w.copy()
for j in range(m):
if df[i][j] == '.':
x[j] -= 1
ans2 = min(x)
#print(ans1, ans2)
ans = min(ans, ans1 + ans2)
print(ans)
``` | output | 1 | 80,908 | 7 | 161,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1). | instruction | 0 | 80,909 | 7 | 161,818 |
Tags: implementation
Correct Solution:
```
T=int(input())
for _ in range(0,T):
n,m=map(int,input().split())
arr=[]
for i in range(0,n):
s=input()
arr.append(s)
ans=n+m-1
L1=[]
L2=[]
for i in range(n):
c=0
for j in range(m):
if(arr[i][j]=='.'):
c+=1
L1.append((i,c))
#ans1=min(ans1,c)
for i in range(m):
c=0
for j in range(n):
if(arr[j][i]=='.'):
c+=1
L2.append((i,c))
#ans2=min(ans2,c)
for i in range(0,len(L1)):
for j in range(0,len(L2)):
c=L1[i][1]+L2[j][1]
if(arr[L1[i][0]][L2[j][0]]=='.'):
c-=1
ans=min(ans,c)
print(ans)
``` | output | 1 | 80,909 | 7 | 161,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1).
Submitted Solution:
```
q=int(input())
for i in range(q):
n,m=map(int,input().split())
T=[]
R,C=[0]*n,[0]*m
for j in range(n):
row=input()
R[j]=row.count("*")
T.append(row)
for k in range(m):
if row[k]=="*":
C[k]+=1
ans=n+m-1
for j in range(n):
for k in range(m):
if T[j][k]=="*":
ans=min(ans,n+m-1-R[j]-C[k]+1)
else:
ans=min(ans,n+m-1-R[j]-C[k])
print(ans)
``` | instruction | 0 | 80,910 | 7 | 161,820 |
Yes | output | 1 | 80,910 | 7 | 161,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1).
Submitted Solution:
```
q=int(input())
for i in range(q):
w,e=map(int,input().split())
r=[0]*w
for j in range(w):
r[j]=input()
t=[0]*e
mx=[-1]
m=-1
for k in range(w):
sum=0
for j in range(e):
if r[k][j]=='*':t[j]+=1;sum+=1
if sum>m:mx=[k];m=sum
elif sum==m:mx.append(k)
mq=-1
mxq=[-1]
for j in range(e):
if t[j]>mq:mq=t[j];mxq=[j]
elif t[j]==mq:mxq.append(j)
true=False
for j in mx:
for k in mxq:
if r[j][k]=='.':true=True
if true:print(w-m+e-mq-1)
else:print(w-m+e-mq)
``` | instruction | 0 | 80,911 | 7 | 161,822 |
Yes | output | 1 | 80,911 | 7 | 161,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1).
Submitted Solution:
```
import sys
import math
from collections import defaultdict,Counter
input=sys.stdin.readline
def print_(x):
sys.stdout.write(str(x)+" ")
def rInt():
return int(input())
def rList():
arr = input().split()
return arr
def cInt(arr):
res = []
for itr in arr:
res.append(int(itr))
return res
def pList(arr):
for _ in arr:
print_(_)
test_cases=rInt()
for test_case in range(test_cases):
inp = rList()
n = int(inp[0])
m = int(inp[1])
mat = []
s=""
for row in range(n):
s=input()
mat.append(s)
rowC=[]
colC=[]
for row in mat:
cnt = 0
for _ in row:
if _ == '.':
cnt+=1
rowC.append(cnt)
for col in range(m):
cnt = 0
for row in mat:
if row[col]=='.':
cnt+=1
colC.append(cnt)
rC=0
ans = 10**6
for row in mat:
for cC in range(m):
cnt = rowC[rC]+colC[cC]
if row[cC] == '.':
cnt-=1
ans = min(ans,cnt)
rC+=1
print(ans)
``` | instruction | 0 | 80,912 | 7 | 161,824 |
Yes | output | 1 | 80,912 | 7 | 161,825 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1).
Submitted Solution:
```
for _ in range(int(input())):
n,m=map(int,input().split())
a=[]
for i in range(n):
x=input()
a.append(x)
X=[]
Y=[]
for i in range(n):
c=0
for j in range(m):
if(a[i][j]=="."):
c+=1
X.append(c)
D=m*n*10
for i in range(m):
c=0
for j in range(n):
if(a[j][i]=="."):
c+=1
Y.append(c)
for i in range(n):
for j in range(m):
if(a[i][j]=="."):
D=min(D,X[i]+Y[j]-1)
else:
D=min(D,X[i]+Y[j])
print(D)
``` | instruction | 0 | 80,913 | 7 | 161,826 |
Yes | output | 1 | 80,913 | 7 | 161,827 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1).
Submitted Solution:
```
T = input()
T = int(T)
for i in range(T):
n, m = input().split()
n = int(n)
m = int(m)
count_col = [0 for _ in range(m)]
count_row = [0 for _ in range(n)]
matrix = []
best_r = -1
for r in range(n):
char_input = input()
matrix.append(char_input)
for j in range(len(char_input)):
char = char_input[j]
if char == '*':
count_row[r] += 1
count_col[j] += 1
if best_r == -1 or count_row[best_r] < count_row[r]:
best_r = r
best_c = -1
for c in range(len(count_col)):
if best_c == -1 or count_col[best_c] < count_col[c]:
best_c = c
result = m + n - (count_row[best_r] + count_col[best_c])
if matrix[best_r][best_c] == '.':
result -= 1
print(result)
``` | instruction | 0 | 80,914 | 7 | 161,828 |
No | output | 1 | 80,914 | 7 | 161,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1).
Submitted Solution:
```
q=int(input())
y=[]
for i in range(q):
n,m=map(int,input().split())
s=[0 for i in range(m)]
t=m
ind=0
u=0
for i in range(n):
k=input()
l=0
for i in range(m):
if k[i]=='.':
l+=1
s[i]+=1
if t>l:
t=l
ind=i
if s[ind]==min(s):
u=2
y+=[t+min(s)-u]
for i in y:
print(i)
``` | instruction | 0 | 80,915 | 7 | 161,830 |
No | output | 1 | 80,915 | 7 | 161,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.
You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1 ≤ x ≤ n and 1 ≤ y ≤ m, such that all cells in row x and all cells in column y are painted black.
For examples, each of these pictures contain crosses:
<image>
The fourth picture contains 4 crosses: at (1, 3), (1, 5), (3, 3) and (3, 5).
Following images don't contain crosses:
<image>
You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.
What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?
You are also asked to answer multiple independent queries.
Input
The first line contains an integer q (1 ≤ q ≤ 5 ⋅ 10^4) — the number of queries.
The first line of each query contains two integers n and m (1 ≤ n, m ≤ 5 ⋅ 10^4, n ⋅ m ≤ 4 ⋅ 10^5) — the number of rows and the number of columns in the picture.
Each of the next n lines contains m characters — '.' if the cell is painted white and '*' if the cell is painted black.
It is guaranteed that ∑ n ≤ 5 ⋅ 10^4 and ∑ n ⋅ m ≤ 4 ⋅ 10^5.
Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.
Example
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.
The first 5 pictures already contain a cross, thus you don't have to paint anything.
You can paint (1, 3), (3, 1), (5, 3) and (3, 5) on the 6-th picture to get a cross in (3, 3). That'll take you 4 minutes.
You can paint (1, 2) on the 7-th picture to get a cross in (4, 2).
You can paint (2, 2) on the 8-th picture to get a cross in (2, 2). You can, for example, paint (1, 3), (3, 1) and (3, 3) to get a cross in (3, 3) but that will take you 3 minutes instead of 1.
There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1, 1): paint (1, 2) and (2, 1).
Submitted Solution:
```
t = int(input())
for _ in range(t):
n,m = map(int,input().split())
l = []
l1 = []
for i in range(n):
k = list(input())
l.append(k)
l1.append(k)
ans1 = 10**18
ans2 = 10**18
final = set()
for i in range(n):
count = 0
la = set()
for j in range(m):
if l[i][j] == '*':
count+=1
else:
la.add((i,j))
ans1 = min(ans1,m-count)
if ans1 == m-count :
final = la
for i in range(m):
count = 0
for j in range(n):
if l[j][i] == '*' or (j,i) in final:
count+=1
ans2 = min(ans2,n-count)
z1 = ans1+ans2
final = set()
ans1 = 10**18
ans2 = 10**18
for i in range(m):
count = 0
la = set()
for j in range(n):
if l[j][i] == '*':
count+=1
else:
la.add((j,i))
ans1 = min(ans1,n-count)
if ans1 == n-count :
final = la
for i in range(n):
count = 0
for j in range(m):
if l[i][j] == '*' or (i,j) in final:
count+=1
ans2 = min(ans2,m-count)
z2 = ans1+ans2
print(min(z1,z2))
``` | instruction | 0 | 80,916 | 7 | 161,832 |
No | output | 1 | 80,916 | 7 | 161,833 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.