message stringlengths 2 45.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 254 108k | cluster float64 3 3 | __index_level_0__ int64 508 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years. | instruction | 0 | 13,488 | 3 | 26,976 |
Tags: data structures, sortings
Correct Solution:
```
"""
Author - Satwik Tiwari .
4th Oct , 2020 - Sunday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil
from copy import deepcopy
from collections import deque
# from collections import Counter as counter # Counter(list) return a dict with {key: count}
# from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
# from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
#==============================================================================================
#fast I/O region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
mod = 10**9+7
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n") #as stdout.write always print sring.
def testcase(t):
for pp in range(t):
solve(pp)
def printlist(a) :
for p in range(0,len(a)):
out(str(a[p]) + ' ')
def google(p):
print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) : # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
#===============================================================================================
# code here ;))
def bucketsort(order, seq):
buckets = [0] * (max(seq) + 1)
for x in seq:
buckets[x] += 1
for i in range(len(buckets) - 1):
buckets[i + 1] += buckets[i]
new_order = [-1] * len(seq)
for i in reversed(order):
x = seq[i]
idx = buckets[x] = buckets[x] - 1
new_order[idx] = i
return new_order
def ordersort(order, seq, reverse=False):
bit = max(seq).bit_length() >> 1
mask = (1 << bit) - 1
order = bucketsort(order, [x & mask for x in seq])
order = bucketsort(order, [x >> bit for x in seq])
if reverse:
order.reverse()
return order
def long_ordersort(order, seq):
order = ordersort(order, [int(i & 0x7fffffff) for i in seq])
return ordersort(order, [int(i >> 31) for i in seq])
def multikey_ordersort(order, *seqs, sort=ordersort):
for i in reversed(range(len(seqs))):
order = sort(order, seqs[i])
return order
def solve(case):
n = int(inp())
b = []
type = []
for i in range(n):
x,y = sep()
b.append(x)
b.append(y)
type.append(1)
type.append(0)
order = multikey_ordersort(range(2*n),b,type)
have = []
for i in order:
have.append((b[i],type[i]))
# print(have)
year = 0
cnt =0
currin = 0
for i in range(len(have)):
curr = have[i]
if(curr[1] == 1):
currin+=1
else:
currin-=1
if(currin>cnt):
cnt = currin
year = curr[0]
# print(curr,currin,cnt,year)
print(year,cnt)
testcase(1)
# testcase(int(inp()))
``` | output | 1 | 13,488 | 3 | 26,977 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years. | instruction | 0 | 13,490 | 3 | 26,980 |
Tags: data structures, sortings
Correct Solution:
```
n = int(input())
years = []
for i in range(n):
vals = input().split()
years.append((int(vals[0]), 1))
years.append((int(vals[1]), -1))
years.sort()
max_population = 0
population = 0
for year in years:
if year[1] == -1:
population -= 1
else:
population += 1
if population > max_population:
max_population = population
max_year = year[0]
print(max_year, max_population)
``` | output | 1 | 13,490 | 3 | 26,981 |
Provide tags and a correct Python 3 solution for this coding contest problem.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years. | instruction | 0 | 13,491 | 3 | 26,982 |
Tags: data structures, sortings
Correct Solution:
```
dct = {}
for i in range(int(input())):
a,b = map(int,input().split())
dct[a] = dct.get(a,0)+1
dct[b] = dct.get(b,0)-1
cnt = curr = y = 0
for i in sorted(dct.keys()):
curr += dct[i]
if curr > cnt :
cnt = curr
y = i
print(y,cnt)
``` | output | 1 | 13,491 | 3 | 26,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years.
Submitted Solution:
```
# 9 :24
def readInt():
return int(input())
def readLine():
return [int(s) for s in input().split(" ")]
def readString():
return input()
def ask(od):
allData = []
for a,b in od:
allData.append((a,True))
allData.append((b,False))
allData = sorted(allData)
maxL = 0
maxYear = 0
current = 0
for num,b in allData:
if(b):
current += 1
else:
current -= 1
if(current > maxL):
maxL = current
maxYear = num
return maxYear, maxL
# import random
n = readInt()
ret = []
for _ in range(n):
params = readLine()
ret.append((params[0],params[1]))
# ret = []
#
# for _ in range(100000):
# ret.append((random.randint(100000,1000000),random.randint(100000,1000000)))
#
# import time
#
# t0 = time.time()
a,b = ask(ret)
print(a,b)
# t1 = time.time()
# total = t1-t0
# print(total)
``` | instruction | 0 | 13,492 | 3 | 26,984 |
Yes | output | 1 | 13,492 | 3 | 26,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years.
Submitted Solution:
```
n=int(input())
a=[]
for i in range(n):
x,y=map(int,input().split())
a.append([x,1])
a.append([y,-1])
a.sort()
k=0
y=0
m=0
for i in range(len(a)):
k+=a[i][1]
if m<k:
m=k
y=a[i][0]
print(y,m)
``` | instruction | 0 | 13,493 | 3 | 26,986 |
Yes | output | 1 | 13,493 | 3 | 26,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years.
Submitted Solution:
```
n = int(input())
births = []
deaths = []
for i in range(n):
b, d = map(int, input().split())
births.append(b)
deaths.append(d)
births = sorted(births)
deaths = sorted(deaths)
living = 0
i = 0
j = 0
year = 0
current = 0
change = 0
while i < n and j < n:
current = min(births[i], deaths[j])
if births[i] <= current:
change += 1
i += 1
if deaths[j] <= current:
change -= 1
j += 1
if change > living:
living = change
year = current
if i < n:
if change + n - i + 1 > living:
living = change + n - i + 1
year = births[-1]
print(f"{year} {living}")
``` | instruction | 0 | 13,494 | 3 | 26,988 |
Yes | output | 1 | 13,494 | 3 | 26,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years.
Submitted Solution:
```
anos = {}
for _ in range(int(input())):
ini, fim = [int(x) for x in input().split()]
if ini in anos:
anos[ini] += 1
else:
anos[ini] = 1
if fim in anos:
anos[fim] -= 1
else:
anos[fim] = -1
vivos = 0
maior = 0
anoMaior = 0
for ano, saldo in sorted(anos.items()):
vivos += saldo
if maior < vivos:
maior = vivos
anoMaior = ano
print(anoMaior, maior)
``` | instruction | 0 | 13,495 | 3 | 26,990 |
Yes | output | 1 | 13,495 | 3 | 26,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years.
Submitted Solution:
```
import sys, math, itertools, collections, copy
input = sys.stdin.readline
N = int(input())
events = []
for i in range(N):
begin, end = map(int, input().split())
end -= 1
events.append([begin, end])
events.sort(key = lambda x: (x[0], x[1]))
begin = events[0]
ans = 0
cur = 1
second = events[0][0]
for i in range(1, len(events)):
if max(begin[0], events[i][0]) <= min(begin[1], events[i][1]):
cur += 1
ans = max(ans, cur)
if ans == cur:
second = max(begin[0], events[i][0])
else:
ans = max(ans, cur)
cur = 1
begin = events[i]
print(second, ans)
``` | instruction | 0 | 13,496 | 3 | 26,992 |
No | output | 1 | 13,496 | 3 | 26,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years.
Submitted Solution:
```
from sys import stdout, stdin
input = stdin.readline
print = stdout.write
def main():
mp = lambda: map(int, input().strip().split())
it = int
n = it(input())
a = [list(mp()) for _ in [0] * n]
a.sort(key=lambda x: (x[0], -x[1]))
queue = [a[0]]
m = 0
c = 0
y = 0
for i in range(1, n):
if a[i][0] != a[i - 1][0]:
queue.append(a[i])
if a[i][0] >= queue[0][1]:
if c > m:
m = c
y = a[i - 1][0]
queue.pop(0)
c = 0
else:
c += 1
print(str(y) + ' ' + str(m + 1) + '\n')
main()
``` | instruction | 0 | 13,497 | 3 | 26,994 |
No | output | 1 | 13,497 | 3 | 26,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years.
Submitted Solution:
```
import sys
from random import *
from bisect import *
from heapq import *
#from collections import deque
pl=1
from math import gcd,sqrt,ceil
from copy import *
sys.setrecursionlimit(10**5)
if pl:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('outpt.txt','w')
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
t=1
while t>0:
t-=1
n=fi()
maxi=[0]*2
a=[]
for i in range(n):
l,r=mi()
a.append([l,0])
a.append([r-1,1])
a.sort()
c=0
for i in range(n):
if a[i][1]==0:
c+=1
if c>maxi[0]:
maxi=[c,a[i][0]]
else:
c-=1
print(*maxi[::-1])
``` | instruction | 0 | 13,498 | 3 | 26,996 |
No | output | 1 | 13,498 | 3 | 26,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years.
Submitted Solution:
```
n = int(input())
arr = []
ans = []
i = 0
j = 1
count = 0
for _ in range(n):
x = list(map(int,input().split()))
arr.append(x)
arr.sort()
for j in range(n):
if arr[i][1]>arr[j][0] and arr[i][0]<=arr[j][0]:
count += 1
ans.append(arr[j][0])
else:
i += 1
j += 1
print(max(ans),count)
``` | instruction | 0 | 13,499 | 3 | 26,998 |
No | output | 1 | 13,499 | 3 | 26,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mirror Box is a name of a popular game in the Iranian National Amusement Park (INAP). There is a wooden box, 105 cm long and 100 cm high in this game. Some parts of the box's ceiling and floor are covered by mirrors. There are two negligibly small holes in the opposite sides of the box at heights hl and hr centimeters above the floor. The picture below shows what the box looks like.
<image>
In the game, you will be given a laser gun to shoot once. The laser beam must enter from one hole and exit from the other one. Each mirror has a preset number vi, which shows the number of points players gain if their laser beam hits that mirror. Also — to make things even funnier — the beam must not hit any mirror more than once.
Given the information about the box, your task is to find the maximum score a player may gain. Please note that the reflection obeys the law "the angle of incidence equals the angle of reflection".
Input
The first line of the input contains three space-separated integers hl, hr, n (0 < hl, hr < 100, 0 ≤ n ≤ 100) — the heights of the holes and the number of the mirrors.
Next n lines contain the descriptions of the mirrors. The i-th line contains space-separated vi, ci, ai, bi; the integer vi (1 ≤ vi ≤ 1000) is the score for the i-th mirror; the character ci denotes i-th mirror's position — the mirror is on the ceiling if ci equals "T" and on the floor if ci equals "F"; integers ai and bi (0 ≤ ai < bi ≤ 105) represent the x-coordinates of the beginning and the end of the mirror.
No two mirrors will share a common point. Consider that the x coordinate increases in the direction from left to right, so the border with the hole at height hl has the x coordinate equal to 0 and the border with the hole at height hr has the x coordinate equal to 105.
Output
The only line of output should contain a single integer — the maximum possible score a player could gain.
Examples
Input
50 50 7
10 F 1 80000
20 T 1 80000
30 T 81000 82000
40 T 83000 84000
50 T 85000 86000
60 T 87000 88000
70 F 81000 89000
Output
100
Input
80 72 9
15 T 8210 15679
10 F 11940 22399
50 T 30600 44789
50 F 32090 36579
5 F 45520 48519
120 F 49250 55229
8 F 59700 80609
35 T 61940 64939
2 T 92540 97769
Output
120
Note
The second sample is depicted above. The red beam gets 10 + 50 + 5 + 35 + 8 + 2 = 110 points and the blue one gets 120.
The red beam on the picture given in the statement shows how the laser beam can go approximately, this is just illustration how the laser beam can gain score. So for the second sample there is no such beam that gain score 110.
Submitted Solution:
```
print(302)
print("0 1000000")
coord, rad = 2000, 300
for i in range(300):
print(coord, rad)
coord, rad = coord+600, rad-1
print("1000000 1000000")
``` | instruction | 0 | 13,566 | 3 | 27,132 |
No | output | 1 | 13,566 | 3 | 27,133 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).
You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
Input
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).
The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
Examples
Input
4
1 1 1 1
Output
12
Note
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter. | instruction | 0 | 13,621 | 3 | 27,242 |
Tags: dp
Correct Solution:
```
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))
n = int(input())
a = list(map(int, input().split()))
m = sum(a)
M = 10**9+7
dp = [0]*(2*m+1)
ans = 0
dp[m] = 1
val = 0
for i in range(n):
v = a[i]
ndp = [0]*(2*m+1)
for j in range(2*m+1):
if j-v>=0:
ndp[j-v] += dp[j]
if ndp[j-v]>M:
ndp[j-v] -= M
if j+v<=2*m:
ndp[j+v] += dp[j]
if ndp[j+v]>M:
ndp[j+v] -= M
dp = ndp
ans += dp[m]
ans %= M
dp[m] += 1
val += v
print(ans%M)
``` | output | 1 | 13,621 | 3 | 27,243 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).
You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
Input
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).
The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
Examples
Input
4
1 1 1 1
Output
12
Note
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter. | instruction | 0 | 13,622 | 3 | 27,244 |
Tags: dp
Correct Solution:
```
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))
n = int(input())
a = list(map(int, input().split()))
m = sum(a)
M = 10**9+7
dp = [0]*(2*m+1)
ans = 0
dp[m] = 1
val = 0
for i in range(n):
v = a[i]
ndp = [0]*(2*m+1)
for j in range(m-val, m+val+1):
if j-v>=0:
ndp[j-v] += dp[j]
if ndp[j-v]>M:
ndp[j-v] -= M
if j+v<=2*m:
ndp[j+v] += dp[j]
if ndp[j+v]>M:
ndp[j+v] -= M
dp = ndp
ans += dp[m]
ans %= M
dp[m] += 1
val += v
print(ans%M)
``` | output | 1 | 13,622 | 3 | 27,245 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).
You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
Input
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).
The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
Examples
Input
4
1 1 1 1
Output
12
Note
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.
Submitted Solution:
```
__author__ = 'Pavel Mavrin'
n = int(input())
a = [int(x) for x in input().split()]
d = [0] * 10001
dd = [0] * 10001
res = 0
s = 1
for i in range(n):
for j in range(s):
dd[j] = 0
s += a[i]
dd[0] += 1
for j in range(s):
kk = j + a[i]
dd[kk] += d[j]
dd[kk] %= 1000000007
kk = abs(j - a[i])
dd[kk] += d[j]
dd[kk] %= 1000000007
t = d
d = dd
dd = t
res += d[0]
res %= 1000000007
print(res - n)
``` | instruction | 0 | 13,623 | 3 | 27,246 |
No | output | 1 | 13,623 | 3 | 27,247 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).
You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
Input
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).
The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
Examples
Input
4
1 1 1 1
Output
12
Note
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.
Submitted Solution:
```
__author__ = 'Pavel Mavrin'
n = int(input())
a = [int(x) for x in input().split()]
d = [1]
res = 0
for i in range(n):
dd = [0] * (len(d) + a[i])
dd[0] += 1
for j in range(len(d)):
kk = j + a[i]
dd[kk] += d[j]
kk = abs(j - a[i])
dd[kk] += d[j]
d = dd
res += d[0]
print(res - n)
``` | instruction | 0 | 13,624 | 3 | 27,248 |
No | output | 1 | 13,624 | 3 | 27,249 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages. During one stage exactly one symbol of the DNA line is replaced by exactly two other ones. At that overall there are n permissible substitutions. The substitution ai->bici means that any one symbol ai can be replaced with two symbols bici. Every substitution could happen an unlimited number of times.
They say that two creatures with DNA sequences s1 and s2 can have a common ancestor if there exists such a DNA sequence s3 that throughout evolution it can result in s1 and s2, perhaps after a different number of stages. Your task is to find out by the given s1 and s2 whether the creatures possessing such DNA sequences can have a common ancestor. If the answer is positive, you have to find the length of the shortest sequence of the common ancestor’s DNA.
Input
The first line contains a non-empty DNA sequence s1, the second line contains a non-empty DNA sequence s2. The lengths of these lines do not exceed 50, the lines contain only lowercase Latin letters. The third line contains an integer n (0 ≤ n ≤ 50) — the number of permissible substitutions. Then follow n lines each of which describes a substitution in the format ai->bici. The characters ai, bi, and ci are lowercase Latin letters. Lines s1 and s2 can coincide, the list of substitutions can contain similar substitutions.
Output
If s1 and s2 cannot have a common ancestor, print -1. Otherwise print the length of the shortest sequence s3, from which s1 and s2 could have evolved.
Examples
Input
ababa
aba
2
c->ba
c->cc
Output
2
Input
ababa
aba
7
c->ba
c->cc
e->ab
z->ea
b->ba
d->dd
d->ab
Output
1
Input
ababa
aba
1
c->ba
Output
-1
Submitted Solution:
```
#!/usr/bin/env python3
import itertools
import collections
s1 = input().strip()
s2 = input().strip()
n = int(input())
rules = collections.defaultdict(set)
for i in range(n):
rule = input().strip()
target = rule[-2:]
source = rule[0]
rules[target].add(source)
def get_shortest_ancestors(rules, s):
# Create tables for the shortest possible ancestors. Indices are based on, respectively, substring length and starting position in the original string s
ancestor_length = [[l for start_pos in range(len(s)-l+1)] for l in range(len(s)+1)]
ancestor_set = [[set([s[start_pos:start_pos+l]]) for start_pos in range(len(s)-l+1)] for l in range(len(s)+1)]
# Fill in the tables for substrings of length 2 and higher
for l in range(2,len(s)+1):
for start_pos in range(len(s)-l+1):
# Check all possible ways in which the substring s[start_pos:start_pos+l] can be made from two shorter substrings
for l1 in range(1, l):
# Combine shortest possible ancestors of the two substrings s[start_pos:start_pos+l1] and ss[start_pos+l1:start_pos+l] to get the ancestors of s[start_pos:start_pos+l]
ancestors = set()
for (a,b) in itertools.product(ancestor_set[l1][start_pos], ancestor_set[l-l1][start_pos+l1]):
if (a[-1]+b[0]) in rules.keys():
# The end of one ancestor and the start of the other ancestor can be created from one or more rules
for source in rules[a[-1]+b[0]]:
# Add all ancestors that can be created by using the available rules, note: these will always be shorter than simply combining ancestors
ancestors.add(a[:-1]+source+b[1:])
else:
# Simply combine the two ancestors
ancestors.add(a+b)
# Use the new set of ancestors to update te table
ancestor_length[l][start_pos] = min(min(len(a) for a in ancestors), ancestor_length[l][start_pos])
ancestor_set[l][start_pos] = set(a for a in ancestors.union(ancestor_set[l][start_pos]) if len(a) == ancestor_length[l][start_pos])
return ancestor_set[len(s)][0]
shortest_ancestors_s1 = get_shortest_ancestors(rules, s1)
shortest_ancestors_s2 = get_shortest_ancestors(rules, s2)
if (shortest_ancestors_s1.isdisjoint(shortest_ancestors_s2)):
print(-1)
else:
print(len(list(shortest_ancestors_s1)[0]))
``` | instruction | 0 | 13,688 | 3 | 27,376 |
No | output | 1 | 13,688 | 3 | 27,377 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0 | instruction | 0 | 13,738 | 3 | 27,476 |
Tags: implementation
Correct Solution:
```
def rotate_r(ar, row, n):
ar[row] = ar[row][-n:] + ar[row][:-n]
return ar
def rotate_c(ar, m, col):
#c = ar[col][0]
c = ar[m - 1][col]
for i in range(m - 1, 0, -1):
#for i in range(m - 1):
ar[i][col] = ar[i - 1][col]
#ar[col][m - 1] = c
ar[0][col] = c
return ar
def print_matr(ar, n):
for i in range(n):
print(*ar[i])
ar2 = []
n, m, q = map(int, input().split())
#for i in range(n):
# ar = list(map(int, input().split()))
# ar2.append(ar)
query = [0 for i in range(q)]
rows = [0 for i in range(q)]
cols = [0 for i in range(q)]
nums = [0 for i in range(q)]
for i in range(q):
ar = list(map(int, input().split()))
query[i] = ar[0]
if ar[0] == 3:
rows[i] = ar[1] - 1
cols[i] = ar[2] - 1
nums[i] = ar[3]
elif ar[0] == 1:
rows[i] = ar[1] - 1
else:
cols[i] = ar[1] - 1
#print(query)
ans = [[0] * m for i in range(n)]
for i in range(q - 1, -1, -1):
if query[i] == 3:
ans[rows[i]][cols[i]] = nums[i]
#print('\n')
#print_matr(ans, n)
#print("l", rows[i] + 1, cols[i] + 1)
#print(i, nums[i])
elif query[i] == 1:
ans = rotate_r(ans, rows[i], 1)
#print('\n')
#print_matr(ans, n)
else:
ans = rotate_c(ans, n, cols[i])
#print('\n')
#print_matr(ans, n)
#row, n = map(int, input().split())
#print(rotate_r(ar2, 0, n))
print_matr(ans, n)
#ans = rotate_c(ans, n, 0)
#print_matr(ans, n)
``` | output | 1 | 13,738 | 3 | 27,477 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0 | instruction | 0 | 13,739 | 3 | 27,478 |
Tags: implementation
Correct Solution:
```
import itertools
import bisect
import math
from collections import *
import os
import sys
from io import BytesIO, IOBase
ii = lambda: int(input())
lmii = lambda: list(map(int, input().split()))
li = lambda: list(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
def main():
n,m,q=mii()
qq=[]
for test in range(q):
pp=lmii()
qq.append(pp)
qq.reverse()
mat=[]
for i in range(n):
mat.append([0]*m)
for i in range(q):
lst = qq[i]
if lst[0] == 3:
mat[lst[1]-1][lst[2]-1] = lst[3]
elif lst[0] == 2:
d = deque([])
for k in range(n):
d.append(mat[k][lst[1]-1])
d.appendleft(d.pop())
for k in range(n):
mat[k][lst[1]-1]=d[k]
else:
d = deque([])
for k in range(m):
d.append(mat[lst[1]-1][k])
d.appendleft(d.pop())
for k in range(m):
mat[lst[1]-1][k] = d[k]
for i in range(n):
print(*mat[i])
pass
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | output | 1 | 13,739 | 3 | 27,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0 | instruction | 0 | 13,740 | 3 | 27,480 |
Tags: implementation
Correct Solution:
```
a, b, c = map(int, input().split())
arr = []
mat = [[0 for j in range(b)] for i in range(a)]
for i in range(c):
arr.append(input())
arr = arr[::-1]
for command in arr:
arra = [int(i) for i in command.split()]
if arra[0] == 1:
swp = mat[arra[1] - 1][b - 1]
for i in range(b):
mat[arra[1] - 1][i], swp = swp, mat[arra[1] - 1][i]
elif arra[0] == 2:
swp = mat[a - 1][arra[1] - 1]
for i in range(a):
mat[i][arra[1] - 1], swp = swp, mat[i][arra[1] - 1]
else:
mat[arra[1] - 1][arra[2] - 1] = arra[3]
for i in mat:
for j in i:
print(j, end=" ")
print()
``` | output | 1 | 13,740 | 3 | 27,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0 | instruction | 0 | 13,741 | 3 | 27,482 |
Tags: implementation
Correct Solution:
```
f = lambda: map(int, input().split())
n, m, q = f()
p = [[0] * m for j in range(n)]
for t in [list(f()) for k in range(q)][::-1]:
j = t[1] - 1
if t[0] == 1: p[j].insert(0, p[j].pop())
elif t[0] == 2:
s = p[-1][j]
for i in range(n - 1, 0, -1): p[i][j] = p[i - 1][j]
p[0][j] = s
else: p[j][t[2] - 1] = t[3]
for d in p: print(*d)
``` | output | 1 | 13,741 | 3 | 27,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0 | instruction | 0 | 13,742 | 3 | 27,484 |
Tags: implementation
Correct Solution:
```
m,n,q = map(int,input().split())
inps = [map(lambda x: int(x)-1,input().split()) for _ in range(q)]
matrix = [[-1]*n for _ in range(m)]
for x in reversed(inps):
t,c,*cc = x
if t == 0:
matrix[c] = [matrix[c][-1]] + matrix[c][:-1]
elif t == 1:
new = [matrix[i][c] for i in range(m)]
for i,x in enumerate([new[-1]] + new[:-1]):
matrix[i][c] = x
elif t == 2:
matrix[c][cc[0]] = cc[1]
for x in matrix:
print(' '.join(map(lambda v: str(v+1), x)))
``` | output | 1 | 13,742 | 3 | 27,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0 | instruction | 0 | 13,743 | 3 | 27,486 |
Tags: implementation
Correct Solution:
```
inf= list(map(int, input().split()))
n=inf[0]
m=inf[1]
q=inf[2]
quer=[0]*q
mat=[[0 for i in range(m)] for j in range(n)]
for i in range(0, q):
quer[i] =list(map(int, input().split()))
for i in range(q-1, -1, -1):
curr=quer[i]
if curr[0] == 1:
x = curr[1]-1
a = mat[x][m-1]
for j in range(m-1, 0, -1):
mat[x][j] = mat[x][j-1]
mat[x][0] = a
elif curr[0] == 2:
x = curr[1]-1
a = mat[n-1][x]
for j in range(n-1, 0, -1):
mat[j][x] = mat[j-1][x]
mat[0][x] = a
elif curr[0] == 3:
mat[curr[1]-1][curr[2]-1] =curr[3]
for i in range(n):
print(*mat[i])
``` | output | 1 | 13,743 | 3 | 27,487 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0 | instruction | 0 | 13,744 | 3 | 27,488 |
Tags: implementation
Correct Solution:
```
f = lambda: map(int, input().split())
n, m, q = f()
p = [[0] * m for j in range(n)]
for t in [list(f()) for k in range(q)][::-1]:
j = t[1] - 1
if t[0] == 1: p[j].insert(0, p[j].pop())
elif t[0] == 2:
s = p[-1][j]
for i in range(n - 1, 0, -1): p[i][j] = p[i - 1][j]
p[0][j] = s
else: p[j][t[2] - 1] = t[3]
for d in p: print(*d)
# Made By Mostafa_Khaled
``` | output | 1 | 13,744 | 3 | 27,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0 | instruction | 0 | 13,745 | 3 | 27,490 |
Tags: implementation
Correct Solution:
```
n,m,q=(int(z) for z in input().split())
s=[]
res=[]
for i in range(n):
res.append([0]*m)
for i in range(q):
s.append([int(z) for z in input().split()])
while len(s)>0:
if s[-1][0]==3:
res[s[-1][1]-1][s[-1][2]-1]=s[-1][3]
elif s[-1][0]==2:
r=res[-1][s[-1][1]-1]
for i in range(n-1,0,-1):
res[i][s[-1][1]-1]=res[i-1][s[-1][1]-1]
res[0][s[-1][1]-1]=r
else:
r=res[s[-1][1]-1][-1]
for i in range(m-1,0,-1):
res[s[-1][1]-1][i]=res[s[-1][1]-1][i-1]
res[s[-1][1]-1][0]=r
s.pop()
for i in range(n):
print(' '.join(map(str,res[i])))
``` | output | 1 | 13,745 | 3 | 27,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0
Submitted Solution:
```
def main():
n, m, q = map(int, input().split())
nm = ["0"] * (m * n)
qq = [input() for _ in range(q)]
for s in reversed(qq):
k, *l = s.split()
if k == "3":
nm[(int(l[0]) - 1) * m + int(l[1]) - 1] = l[2]
elif k == "2":
j = int(l[0]) - 1
x = nm[j - m]
for i in range((n - 1) * m + j, j, -m):
nm[i] = nm[i - m]
nm[j] = x
else:
j = (int(l[0]) - 1) * m
x = nm[j + m - 1]
for i in range(j + m - 1, j, -1):
nm[i] = nm[i - 1]
nm[j] = x
for i in range(0, n * m, m):
print(' '.join(nm[i:i + m]))
if __name__ == "__main__":
main()
``` | instruction | 0 | 13,746 | 3 | 27,492 |
Yes | output | 1 | 13,746 | 3 | 27,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0
Submitted Solution:
```
nmq = input().split(' ')
n, m, q = int(nmq[0]), int(nmq[1]), int(nmq[2])
mt = []
for i in range(0, n):
mt.append([])
for j in range(0, m):
mt[-1].append((i, j))
res = []
for i in range(0, n):
res.append([])
for j in range(0, m):
res[-1].append(0)
for i in range(0, q):
ins = input().split(' ')
if ins[0] == '1':
r = int(ins[1]) - 1
b = mt[r][0]
for j in range(0, m-1):
mt[r][j] = mt[r][j+1]
mt[r][m-1] = b
if ins[0] == '2':
c = int(ins[1]) - 1
b = mt[0][c]
for j in range(0, n-1):
mt[j][c] = mt[j+1][c]
mt[n-1][c] = b
if ins[0] == '3':
r = int(ins[1]) - 1
c = int(ins[2]) - 1
x = int(ins[3])
p = mt[r][c]
res[p[0]][p[1]] = x
for i in range(0, n):
for j in range(0, m-1):
print(res[i][j],' ', end='')
print(res[i][-1])
``` | instruction | 0 | 13,747 | 3 | 27,494 |
Yes | output | 1 | 13,747 | 3 | 27,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0
Submitted Solution:
```
n, m, q = map(int, input().split())
nm = ["0"] * (m * n)
qq = [input() for _ in range(q)]
for s in reversed(qq):
k, *l = s.split()
if k == "3":
nm[(int(l[0]) - 1) * m + int(l[1]) - 1] = l[2]
elif k == "2":
j = int(l[0]) - 1
x = nm[j - m]
for i in range((n - 1) * m + j, j, -m):
nm[i] = nm[i - m]
nm[j] = x
else:
j = (int(l[0]) - 1) * m
x = nm[j + m - 1]
for i in range(j + m - 1, j, -1):
nm[i] = nm[i - 1]
nm[j] = x
for i in range(0, n * m, m):
print(' '.join(nm[i:i + m]))
``` | instruction | 0 | 13,748 | 3 | 27,496 |
Yes | output | 1 | 13,748 | 3 | 27,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0
Submitted Solution:
```
import sys
import time
from pprint import pprint
from sys import stderr
from itertools import combinations
INF = 10 ** 18 + 3
EPS = 1e-10
MAX_CACHE = 10 ** 9
# Decorators
def time_it(function, output=stderr):
def wrapped(*args, **kwargs):
start = time.time()
res = function(*args, **kwargs)
elapsed_time = time.time() - start
print('"%s" took %f ms' % (function.__name__, elapsed_time * 1000),
file=output)
return res
return wrapped
@time_it
def main():
n, m, q = map(int, input().split())
matrix = [[(x, y) for x in range(m)]
for y in range(n)]
init_matrix = [[0] * m for _ in range(n)]
for _ in range(q):
args = list(map(int, input().split()))
t = args[1] - 1
if args[0] == 1:
matrix[t] = matrix[t][1:] + matrix[t][:1]
elif args[0] == 2:
first = matrix[0][t]
for i in range(n - 1):
matrix[i][t] = matrix[i + 1][t]
matrix[n - 1][t] = first
else:
r = args[2] - 1
x = args[3]
init_matrix[matrix[t][r][1]][matrix[t][r][0]] = x
for row in init_matrix:
print(*row)
def set_input(file):
global input
input = lambda: file.readline().strip()
def set_output(file):
global print
local_print = print
def print(*args, **kwargs):
kwargs["file"] = kwargs.get("file", file)
return local_print(*args, **kwargs)
if __name__ == '__main__':
set_input(open("input.txt", "r") if "MINE" in sys.argv else sys.stdin)
set_output(sys.stdout)
main()
``` | instruction | 0 | 13,749 | 3 | 27,498 |
Yes | output | 1 | 13,749 | 3 | 27,499 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0
Submitted Solution:
```
inf= list(map(int, input().split()))
n=inf[0]
m=inf[1]
q=inf[2]
r=[[i for i in range(m)] for j in range(n)]
c=[[j for i in range(n)] for j in range(m)]
mat=[[0 for j in range(m)] for i in range(n)]
for i in range(q):
inf= list(map(int, input().split()))
if(inf[0]==3):
a=inf[1]-1
b=inf[2]-1
x=inf[3]
mat[c[a][b]][r[a][b]]=x
elif(inf[0]==1):
rn=inf[1]-1
r[rn].append(r[rn][0])
r[rn]=r[rn][1:]
else:
rn=inf[1]-1
c[rn].append(c[rn][0])
c[rn]=c[rn][1:]
for v in range(n):
print(*mat[v])
``` | instruction | 0 | 13,750 | 3 | 27,500 |
No | output | 1 | 13,750 | 3 | 27,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0
Submitted Solution:
```
inf= list(map(int, input().split()))
n=inf[0]
m=inf[1]
q=inf[2]
r=[[i for i in range(m)] for j in range(n)]
c=[[j for i in range(m)] for j in range(n)]
mat=[[0 for j in range(m)] for i in range(n)]
for i in range(q):
inf= list(map(int, input().split()))
if(inf[0]==3):
a=inf[1]-1
b=inf[2]-1
x=inf[3]
mat[c[a][b]][r[a][b]]=x
elif(inf[0]==1):
rn=inf[1]-1
r[rn].append(r[rn][0])
r[rn]=r[rn][1:]
else:
rn=inf[1]-1
temp=c[0][rn]
for j in range(1,n):
c[j-1][rn]=c[j][rn]
c[n-1][rn]=temp
for v in range(n):
print(*mat[v])
``` | instruction | 0 | 13,751 | 3 | 27,502 |
No | output | 1 | 13,751 | 3 | 27,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0
Submitted Solution:
```
inf= list(map(int, input().split()))
n=inf[0]
m=inf[1]
q=inf[2]
r=[[i for i in range(m)] for j in range(n)]
c=[[i for i in range(n)] for j in range(m)]
mat=[[0 for j in range(m)] for i in range(n)]
for i in range(q):
inf= list(map(int, input().split()))
if(inf[0]==3):
a=inf[1]-1
b=inf[2]-1
x=inf[3]
mat[c[b][a]][r[a][b]]=x
elif(inf[0]==1):
rn=inf[1]-1
r[rn].append(r[rn][0])
r[rn]=r[rn][1:]
else:
rn=inf[1]-1
c[rn].append(c[rn][0])
c[rn]=c[rn][1:]
for v in range(n):
print(*mat[v])
``` | instruction | 0 | 13,752 | 3 | 27,504 |
No | output | 1 | 13,752 | 3 | 27,505 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0
Submitted Solution:
```
def main():
n, m, q = map(int, input().split())
nm = ["0"] * (n * m)
a, b, c = m + 1, n - 1, (n - 1) * m
qq = [input() for _ in range(q)]
for s in reversed(qq):
k, *l = s.split()
if k == "3":
row, col, x = l
nm[int(row) * m + int(col) - a] = x
pass
else:
if k == "1":
t = (int(l[0]) - 1) * m
x = nm[t + b]
for i in range(t + b, t, -1):
nm[i] = nm[i - 1]
nm[t] = x
else:
t = int(l[0]) - 1
x = nm[t + c]
for i in range(t + c, t, -m):
nm[i] = nm[i - m]
nm[t] = x
for i in range(0, n * m, m):
print(' '.join(nm[i:i + m]))
if __name__ == "__main__":
main()
``` | instruction | 0 | 13,753 | 3 | 27,506 |
No | output | 1 | 13,753 | 3 | 27,507 |
Provide a correct Python 3 solution for this coding contest problem.
Zombies seem to have become much more intelligent lately – a few have somehow wandered into the base through the automatic gate. Heidi has had to beef up security, and a new gate has been installed. Unfortunately, now the questions being asked are more complicated, and even humans have trouble answering them. Can you still program the robot army to do this reliably?
The new questions are of the following form: a grayscale photograph has been divided into several horizontal pieces, which have been arbitrarily rearranged. The task is to assemble the original image back from these pieces (somewhat like in a jigsaw puzzle). To further delay the zombies, significant Gaussian-distributed noise has been added to the image.
Input
The input format is the same as in the previous version, except that the first line of every question now contains three space-separated numbers h, w and k (1 ≤ h, w ≤ 600, 2 ≤ k ≤ 16) – the height (number of rows) and width (number of columns) of the photograph and the number of pieces, respectively. The number of pieces evenly divides the height, and each piece is of the same height h / k.
Again, there is only one input file to be processed, and the same resources are provided to you as in the previous version (except that now you are given all input images in .bmp format, rather than the first 50).
Output
Your program should print q lines. The i-th line should contain your answer for the i-th question: a space-separated sequence of k numbers π1, π2, ..., πk such that:
* π is a permutation of {1, 2, ..., k}, that is, each number from 1 to k appears exactly once in π,
* for each j = 1, ..., k, πj is the position (index), in the original image, of the piece which is at position j in the input image. (See the illustration below for clarity.)
<image>
The second image from the test set. If the three pieces in the original image are numbered 1, 2, 3 from top to bottom, then the numbering in the image on the right should be 2, 3, 1. The correct answer for this image is thus 2 3 1.
Again, your answers will be accepted if they conform to this format and if at least 75% of them are correct.
Again, you may process the input locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).
Note
The link to download all the necessary materials is http://assets.codeforces.com/files/690/medium_contestant_package.zip | instruction | 0 | 13,762 | 3 | 27,524 |
"Correct Solution:
```
print("""2 1
2 3 1
4 3 2 1
1 3 4 2 5
1 6 11 3 10 9 15 12 7 13 2 5 4 14 8
5 1 3 11 10 7 6 9 13 15 12 4 14 2 8
9 7 2 5 1 10 8 3 4 6
2 1 4 3
4 12 8 2 9 14 5 7 1 6 10 13 15 3 11
11 5 6 8 10 12 7 2 1 4 9 3 13 14 15
11 7 8 4 5 15 13 14 3 9 12 2 1 10 6
12 7 11 4 10 2 5 14 13 1 6 3 9 8 15 16
3 2 1
4 2 1 3 5
1 8 11 15 3 2 7 16 13 4 6 10 9 12 5 14
9 8 6 13 11 10 2 7 14 12 5 4 15 3 1
11 8 9 3 1 14 2 12 4 16 10 7 5 13 15 6
15 5 2 14 3 13 1 7 12 8 4 10 6 11 9
9 7 3 14 2 12 13 5 1 15 11 10 8 4 6
9 7 13 10 15 16 5 3 6 1 2 11 8 4 14 12
6 13 2 11 5 10 3 14 9 1 12 8 16 4 15 7
2 7 16 14 13 8 5 10 4 12 11 1 6 9 3 15
3 2 6 14 7 12 10 9 5 4 8 15 11 13 1
3 11 4 5 14 10 16 9 8 6 7 13 12 1 15 2
4 3 11 9 8 16 6 15 2 13 7 14 10 1 12 5
1 12 9 7 6 5 2 13 14 10 15 8 11 4 3
2 1 3
2 1
1 3 2 6 4 8 7 5
14 7 8 6 1 9 13 5 2 4 11 15 16 10 3 12
1 7 4 3 6 5 2 8
13 7 6 14 12 15 3 5 1 9 8 10 4 11 2
11 2 15 5 14 3 9 10 7 1 12 13 8 6 4
4 2 3 1
16 13 11 14 9 2 15 3 1 5 6 7 12 8 4 10
3 1 4 9 16 15 7 10 6 13 5 11 2 14 12 8
14 16 13 4 9 10 12 8 7 11 3 5 15 6 2 1
3 1 6 5 2 4
14 8 2 10 6 16 9 7 15 4 1 3 11 13 5 12
15 8 10 9 11 12 7 13 5 14 1 4 3 2 6
5 7 3 10 6 12 8 4 11 1 2 9
2 1
13 14 8 6 4 7 5 10 3 11 2 9 15 12 1
2 15 11 13 12 5 3 4 9 8 14 6 10 1 7
3 1 4 2
6 2 16 5 7 10 15 1 8 14 13 4 9 11 3 12
3 1 2
16 4 13 11 7 9 5 2 10 3 6 15 12 14 8 1
2 5 1 9 15 7 3 11 13 4 8 12 6 14 10
6 3 12 14 15 13 7 2 5 16 4 11 8 1 10 9
5 7 11 3 10 15 2 9 4 8 14 13 16 12 1 6
16 1 2 3 7 15 6 12 8 11 10 14 13 4 9 5
6 5 2 10 12 8 4 13 9 11 1 15 3 14 7
12 13 9 1 3 11 4 8 15 14 10 7 16 5 6 2
4 2 3 1
10 3 15 2 12 7 11 4 16 6 13 9 14 8 5 1
6 3 1 5 2 4
14 11 7 5 6 15 3 4 2 10 1 13 8 9 12
10 8 2 11 15 5 1 13 16 12 14 9 6 4 3 7
8 2 15 11 9 12 16 6 13 7 4 5 14 1 10 3
3 9 10 13 6 16 5 4 8 7 12 11 1 15 14 2
1 4 6 12 5 15 2 3 9 13 8 7 14 11 10
6 7 3 2 5 8 1 9 10 4
11 10 12 15 3 13 1 16 2 8 4 5 6 14 7 9
8 1 13 15 7 10 5 9 3 2 6 4 12 11 14
12 6 11 14 3 5 1 8 10 16 15 7 2 9 4 13
3 2 1
4 7 8 2 1 6 5 3
2 1
1 10 14 13 5 11 8 12 16 9 15 6 4 7 2 3
15 9 2 8 1 4 14 13 5 3 12 6 7 11 10
4 1 5 2 3
1 8 3 11 9 5 6 7 4 2 10 12
9 3 14 10 13 6 1 16 2 7 4 11 15 8 12 5
11 10 14 3 9 13 15 16 6 1 2 8 12 7 5 4
11 16 14 3 6 12 4 1 2 8 7 13 10 9 15 5
15 14 4 6 9 5 3 2 13 12 10 11 7 1 8
13 10 15 11 4 16 2 3 14 9 5 6 8 7 12 1
4 3 5 14 6 8 16 10 9 12 2 11 13 15 7 1
1 4 5 10 9 6 8 3 2 7
7 6 15 5 12 13 2 4 3 14 11 1 10 8 9
2 14 9 3 8 7 6 15 10 11 16 5 12 13 1 4
2 5 9 1 11 4 16 6 8 7 12 3 13 10 15 14
3 5 7 14 1 9 6 4 10 8 11 15 2 16 12 13
15 14 10 13 1 5 2 12 4 11 8 9 6 7 3 16
6 1 4 16 2 9 8 5 12 11 10 13 3 7 14 15
16 14 9 8 4 1 7 2 12 10 3 5 11 6 15 13
6 1 5 2 4 3
3 10 4 5 9 6 1 2 7 8
8 1 15 10 12 5 14 11 4 2 3 13 7 9 6
5 13 12 7 9 1 10 4 15 8 3 2 14 6 11
2 3 6 1 4 5
1 15 13 6 7 11 12 2 14 4 8 9 3 10 5
14 7 8 6 12 13 16 15 3 10 11 9 1 4 5 2
7 2 4 13 9 1 15 8 12 11 6 3 5 14 10
3 4 5 6 15 8 9 10 14 12 11 13 7 2 1
4 11 5 12 8 14 10 7 3 9 16 13 15 1 6 2
2 6 3 1 4 5
6 5 7 9 2 8 3 1 4 10
14 7 15 11 1 4 3 13 5 10 6 9 8 2 12
15 14 5 3 7 4 1 9 11 6 10 2 12 13 8
16 14 3 7 13 2 6 1 10 12 9 4 5 8 11 15
3 8 5 10 12 11 4 6 7 9 2 1
11 3 5 4 12 8 1 2 6 7 9 10
3 11 6 16 13 15 5 2 12 7 14 8 10 9 4 1
6 5 1 4 3 2
1 4 2 10 12 11 9 5 6 13 3 14 15 8 7
7 13 10 5 2 12 6 3 8 4 15 11 1 9 14
12 5 7 8 1 9 10 15 6 4 14 13 3 2 11
2 5 3 9 13 4 7 12 6 14 10 11 15 1 8
5 4 2 6 1 3
4 8 9 1 5 13 11 7 3 12 2 6 14 15 10
2 1
11 5 7 9 15 2 8 14 3 13 10 12 1 6 4
5 14 15 4 13 6 8 10 7 12 2 11 16 3 9 1
12 8 7 2 3 9 15 5 11 6 4 14 13 1 10
14 7 11 13 2 3 12 1 10 9 5 8 4 15 6
6 4 3 5 1 2 7 8
1 9 13 4 6 14 11 7 2 15 12 8 5 10 3 16
3 5 1 8 2 9 7 12 4 11 10 6
2 5 4 9 11 12 13 6 3 1 15 10 8 7 14
13 6 8 11 12 15 1 2 10 9 7 14 3 5 4
2 11 15 12 5 8 9 1 14 10 4 3 6 7 13
5 8 16 3 10 6 14 7 1 15 12 9 13 2 11 4
10 12 1 16 11 4 2 15 6 7 13 14 5 3 8 9
1 2 5 3 4
6 5 1 4 2 3
8 4 7 5 6 1 2 3
4 2 3 1
4 5 6 8 3 1 2 9 10 7
1 8 10 12 14 13 16 11 9 4 3 2 7 5 15 6
2 1
14 8 1 15 11 2 9 7 3 12 10 4 5 13 6
15 13 8 2 7 11 6 5 14 9 10 12 3 4 1
2 1
8 4 5 10 6 1 14 13 12 9 2 3 11 15 7
10 3 6 8 5 11 14 16 7 1 9 2 13 4 15 12
7 5 6 2 4 1 8 3
10 2 7 9 11 6 1 8 3 5 12 4
4 2 3 1
3 13 9 7 11 15 14 10 5 2 16 12 4 8 1 6
1 6 10 4 15 5 3 13 7 12 9 2 8 11 14
2 7 14 16 13 8 3 15 12 11 1 4 6 5 10 9
4 3 1 2 5
3 4 11 7 15 1 13 10 9 14 16 12 5 8 2 6
4 9 14 7 12 3 10 5 13 1 2 11 8 6 15
10 9 16 13 7 3 12 4 15 8 5 1 11 2 6 14
2 1
14 4 1 2 13 6 3 5 12 10 7 9 15 8 11
3 4 1 6 2 5
5 10 4 6 2 8 11 9 1 7 3 13 15 14 12
2 4 1 3
16 14 12 11 7 3 2 6 1 9 4 10 15 13 5 8
14 16 1 4 15 12 2 11 5 8 10 9 6 13 7 3
4 2 1 3
8 11 3 4 1 10 14 6 13 7 15 2 12 5 9
""")
``` | output | 1 | 13,762 | 3 | 27,525 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667 | instruction | 0 | 14,082 | 3 | 28,164 |
"Correct Solution:
```
n,k,t,u,v,l = map(int,input().split())
D = []
for i in range(n):
d = int(input())
D.append(d)
A = [0]*l
special = 0
nomal = 0
ninzin = 0
for i in range(l):
if i == special:
if ninzin == 0:
nomal = 0
else:
special = i + v*t
ninzin = ninzin-1
if i in D:
if nomal != 0 and ninzin < k:
ninzin += 1
else:
special = i + v*t
nomal += 1
if nomal != 0:
A[i] = 1
print(A.count(0)/u + A.count(1)/v)
``` | output | 1 | 14,082 | 3 | 28,165 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667 | instruction | 0 | 14,083 | 3 | 28,166 |
"Correct Solution:
```
import sys
EPS = 1e-12
def main():
n,k,t,u,v,l = map(int, sys.stdin.readline().split())
carrots = [0] * 10001
for i in range(n):
carrots[ int(sys.stdin.readline()) ] = 1
remain_time = 0
carrot_count = 0
ans = 0
for i in range(0,l):
#print("kyori:{}\tremain_time:{}\tcarrot_count:{}\tans:{}".format(i,remain_time,carrot_count,ans))
# ???????????????????????????????????????
if carrots[i] == 1:
carrot_count += 1
# ?????????????¶?????????????????????????
if carrot_count > k:
remain_time = t
carrot_count -= 1
if remain_time > 0 + EPS:
# ????????????????????£???????????¶???
if remain_time * v >= 1.0:
ans += 1 / v
remain_time -= 1 / v
else:
if carrot_count > 0:
ans += 1 / v
carrot_count -= 1
remain_time = t - (1 - (remain_time * v)) / v
else:
ans += remain_time
ans += (1 - (remain_time * v)) / u
remain_time = 0
else:
remain_time = 0
# ????????????????????£???????????¶???
if carrot_count > 0:
ans += 1 / v
carrot_count -= 1
remain_time = t - 1 / v
else:
ans += 1 / u
print("{:.9f}".format(ans))
if __name__ == '__main__':
main()
``` | output | 1 | 14,083 | 3 | 28,167 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667 | instruction | 0 | 14,084 | 3 | 28,168 |
"Correct Solution:
```
carrot,maxstock,duration,normal,fast,goal = ((int(n) for n in input().split(" ")))
stack,used = [],0
for c in range(carrot):
newcar = int(input())
stack = list(filter(lambda x:x>newcar,stack))
if len(stack) == 0:
stack.append(newcar + (fast * duration))
used += fast*duration
else:
if len(stack) == maxstock + 1:
used += fast*duration - (stack[0]-newcar)
stack = list(map(lambda x:x+(fast*duration - (stack[0]-newcar)),stack))
else:
stack.append(stack[-1]+fast * duration)
used += fast*duration
if stack[-1] > goal:
used -= stack[-1] - goal
print((goal - used) / normal + used / fast)
``` | output | 1 | 14,084 | 3 | 28,169 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667 | instruction | 0 | 14,085 | 3 | 28,170 |
"Correct Solution:
```
def get_carrot() :
global speed, stock, U, K, i, T, accel_time
if speed == U :
speed = V
accel_time = T
elif stock == K :
accel_time = T
else :
stock += 1
i += 1
def accel_time_end() :
global stock, accel_time, T, U, speed
if stock > 0 :
accel_time += T
stock -= 1
else :
speed = U
N, K, T, U, V, L = map(int, input().split())
carrot=[]
for i in range(N) :
carrot.append(int(input()))
stock = 0
time = 0
accel_time = 0
i = 0
speed = U
now = 0
while True :
if i < N :
if accel_time == 0 :
time += (carrot[i] - now) / speed
now = carrot[i]
get_carrot()
elif (carrot[i] - now) < accel_time * speed :
time_tmp = (carrot[i] - now) / speed
time += time_tmp
accel_time -= time_tmp
now = carrot[i]
get_carrot()
elif accel_time * speed < (carrot[i] - now) :
now += accel_time * speed
time += accel_time
accel_time = 0
accel_time_end()
elif accel_time * speed == (carrot[i] - now) :
now = carrot[i]
time += accel_time
accel_time = 0
accel_time_end()
get_carrot()
else :
if ( accel_time * speed < L - now ) and accel_time != 0:
now += accel_time * speed
time += accel_time
accel_time = 0
accel_time_end()
else :
time += (L - now) / speed
now += (L - now)
print('{:.10f}'.format(time))
break
``` | output | 1 | 14,085 | 3 | 28,171 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667 | instruction | 0 | 14,086 | 3 | 28,172 |
"Correct Solution:
```
n,k,t,u,v,l = map(int,input().split())
time = 0
line = [0 for _ in range(l)]
carrots_line = [0 for _ in range(l)]
boost = False
carrots = 0
boost_dist = 0
for _ in range(n):
carrots_line[int(input())-1] = 1
for i in range(l):
if boost:
line[i] = 1
boost_dist -= 1
else:
pass
if boost_dist == 0:
if carrots_line[i] == 1:
boost_dist = v*t
boost = True
else:
if carrots > 0:
carrots -= 1
boost_dist = v*t
boost = True
else:
boost = False
else:
if carrots_line[i] == 1:
if carrots+1 > k:
boost_dist = v*t
else:
carrots += 1
boost = True
boost_run = sum(line)
ans = boost_run / v + (l - boost_run) / u
print(ans)
``` | output | 1 | 14,086 | 3 | 28,173 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667 | instruction | 0 | 14,087 | 3 | 28,174 |
"Correct Solution:
```
N, K, T, U, V, L = map(int, input().split())
Dlist = []
for i in range(N):
Dlist.append(int(input()))
t = 0 # 経過時間
v = U # 速度(初期値はU)
timer = 0
Sto = 0 # 手持ちのにんじん
for i in range(1,L+1):
t += 1/v
if v==V:
timer += 1/v
if i in Dlist:
Sto += 1
if v==U:
v = V
Sto -= 1
timer = 0
elif timer<T:
if Sto>K:
Sto -= 1
timer = 0
elif Sto>0:
Sto -= 1
timer = 0
else:
v = U
else:
if v==V:
if Sto>0 and timer>T-1/V:
v = V
timer = 0
Sto -= 1
elif Sto==0:
if timer>T-1/V:
v = U
print(f'{t:.9f}')
``` | output | 1 | 14,087 | 3 | 28,175 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667 | instruction | 0 | 14,088 | 3 | 28,176 |
"Correct Solution:
```
# your code goes he
#carrot 22 2298
N,K,T,U,V,L=(int(i) for i in input().split())
#r=int(input())
s=0
c=0
h=0
TV=T*V
D=[int(input()) for i in range(N)]
D.append(L)
r=D[0]
for i in range(N):
h+=1
if h>K:
h-=1
c=TV
Ds=D[i+1]-D[i]
if c>0:
if Ds>c:
Ds-=c
s+=c
c=0
else:
c-=Ds
s+=Ds
Ds=0
while Ds>0 and h>0:
h-=1
if Ds>TV:
Ds-=TV
s+=TV
else:
c=TV-Ds
s+=Ds
Ds=0
if Ds>0:
r+=Ds
r/=U
s/=V
print(r+s)
``` | output | 1 | 14,088 | 3 | 28,177 |
Provide a correct Python 3 solution for this coding contest problem.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667 | instruction | 0 | 14,089 | 3 | 28,178 |
"Correct Solution:
```
from collections import deque
from heapq import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def main():
n, k, t, u, v, l = MI()
hp = []
# (位置、イベントの種類、時間)として、ヒープに突っ込んでいく
# イベントの種類は
# 0 ゴールする
# 1 ニンジン効果終わる(+食べる)
# 2 ニンジン拾う(+食べる)
# 時間が必要なのは1番だけで他のイベントの時は-1を突っ込んである
heappush(hp, (l, 0, -1))
for _ in range(n):
d = int(input())
heappush(hp, (d, 2, -1))
# 「最後に速さが変わった時間、位置」と「ニンジンの数」
time = pos = caro_n = 0
# ニンジン効果中ならTrue
boost = False
cancel=deque()
while hp:
here, e, now = heappop(hp)
if e == 2:
if boost:
if caro_n==k:
cancel.append(pos+v*t)
time += (here - pos) / v
pos=here
heappush(hp, (here + v * t, 1, time + t))
else:
caro_n += 1
else:
time += (here - pos) / u
pos = here
boost = True
heappush(hp, (here + v * t, 1, time + t))
if e == 1:
if cancel and here==cancel[0]:
cancel.popleft()
continue
if caro_n:
pos=here
time=now
caro_n -= 1
heappush(hp, (here + v * t, 1, now + t))
else:
time = now
pos = here
boost = False
if e == 0:
uv = v if boost else u
print(time + (l - pos) / uv)
exit()
main()
``` | output | 1 | 14,089 | 3 | 28,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667
Submitted Solution:
```
n,k,t,u,v,l,*d=map(int,open(0).read().split())
ans = d[0]/u
fin = d[0]
fastend = d[0] + v*t
stack = 0
for now in d[1:]:
while stack and fastend < now:
ans += (fastend - fin)/v
fin = fastend
fastend += v*t
stack -=1
if fastend < now:
ans += (fastend - fin)/v + (now - fastend)/u
fin = now
fastend = now + v*t
elif fastend == now:
ans += (fastend - fin)/v
fin = now
fastend = now + v*t
elif stack == k:
ans += (now - fin)/v
fin = now
fastend = now + v*t
else:
stack += 1
while stack and fastend <= l:
ans += (fastend - fin)/v
fin = fastend
fastend += v*t
stack -= 1
if fastend > l:
print(ans + (l - fin)/v)
else:
ans += (fastend - fin)/v
fin = fastend
print(ans + (l - fin)/u)
``` | instruction | 0 | 14,090 | 3 | 28,180 |
Yes | output | 1 | 14,090 | 3 | 28,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667
Submitted Solution:
```
N, K, T, U, V, L = map(int, input().split())
ans = 0
l = 0
t = 0
k = 0
for _ in range(N + 1):
if _ == N:
d = L
else:
d = int(input())
length = d - l
l = d
while t > 0 or k > 0:
if t > 0:
if t * V >= length:
tmp = (t * V - length) / V
ans += t - tmp
t = tmp
if K > k:
k += 1
else:
t = T
length = 0
break
else:
length = length - t * V
ans += t
t = 0
if k > 0:
k -= 1
t = T
elif k > 0:
k -= 1
t = T
if length > 0:
ans += length / U
if K > k:
k += 1
else:
t = T
print(ans)
``` | instruction | 0 | 14,091 | 3 | 28,182 |
Yes | output | 1 | 14,091 | 3 | 28,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n,k,t,u,v,l = LI()
d = [I() for _ in range(n)] + [l]
cd = ck = ct = 0
r = 0
for di in d:
while ct < di and ck > 0:
ct += t * v
ck -= 1
if ct >= di:
r += (di - cd) / v
else:
r += (ct - cd) / v
r += (di - ct) / u
ct = di
ck += 1
if ck > k:
ck = k
ct = di + t * v
cd = di
return '{:0.9f}'.format(r)
print(main())
``` | instruction | 0 | 14,092 | 3 | 28,184 |
Yes | output | 1 | 14,092 | 3 | 28,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667
Submitted Solution:
```
N, K, T, U, V, L = map(int, input().split())
ans = 0
l = 0
t = 0
k = 0
for _ in range(N + 1):
if _ == N:
d = L
else:
d = int(input())
length = d - l
l = d
if t != 0:
if t * V > length:
tmp = (t * V - length) / V
ans += t - tmp
t = tmp
if K > k:
k += 1
else:
t = T
continue
else:
length = length - t * V
ans += t
t = 0
if k != 0:
k -= 1
t = T
if t * V > length:
tmp = (t * V - length) / V
ans += t - tmp
t = tmp
if K > k:
k += 1
else:
t = T
continue
else:
length = length - t * V
ans += t
t = 0
ans += length / U
if K > k:
k += 1
else:
t = T
print(ans)
``` | instruction | 0 | 14,093 | 3 | 28,186 |
No | output | 1 | 14,093 | 3 | 28,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667
Submitted Solution:
```
carrot,maxstock,duration,normal,fast,goal = ((int(n) for n in input().split(" ")))
stack,used = [],0
for c in range(carrot):
newcar = int(input())
stack = list(filter(lambda x:x>newcar,stack))
if len(stack) == 0:
stack.append(newcar + (fast * duration))
used += fast*duration
else:
if len(stack) == maxstock + 1:
used += fast*duration - (stack[0]-newcar)
stack = list(map(lambda x:x+(fast*duration - (stack[0]-newcar)),stack))
print(used)
else:
stack.append(stack[-1]+fast * duration)
used += fast*duration
if stack[-1] > goal:
used -= stack[-1] - goal
print((goal - used) / normal + used / fast)
``` | instruction | 0 | 14,094 | 3 | 28,188 |
No | output | 1 | 14,094 | 3 | 28,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667
Submitted Solution:
```
N, K, T, U, V, L = map(int, input().split())
ans = 0
l = 0
t = 0
k = 0
for _ in range(N + 1):
print(ans, l, t, k)
if _ == N:
d = L
else:
d = int(input())
length = d - l
l = d
while t > 0 or k > 0:
if t > 0:
if t * V >= length:
tmp = (t * V - length) / V
ans += t - tmp
t = tmp
if K > k:
k += 1
else:
t = T
length = 0
break
else:
length = length - t * V
ans += t
t = 0
if k > 0:
k -= 1
t = T
elif k > 0:
k -= 1
t = T
if length > 0:
ans += length / U
if K > k:
k += 1
else:
t = T
print(ans)
``` | instruction | 0 | 14,095 | 3 | 28,190 |
No | output | 1 | 14,095 | 3 | 28,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road.
There are some carrots along the way, and rabbits can accelerate by eating carrots. Rabbits run at U meters per second when not accelerating, but by eating carrots, the speed is V meters per second from the last carrot eaten to T seconds later. Rabbits can also carry up to K carrots without eating them. Even if you have a carrot, the running speed does not change.
Assuming that it does not take long to bring and eat carrots, I would like to find the shortest time required to reach the goal.
Input
N K T U V L
D1
...
DN
N is the number of carrots, L is the distance from the start to the goal (meters), and Di (1 ≤ i ≤ N) is the distance from the start where the i-th carrot is located (meters).
1 ≤ N ≤ 200, 1 ≤ K ≤ N, 1 ≤ T ≤ 10,000, 1 ≤ U <V ≤ 10,000, 2 ≤ L ≤ 10,000, 0 <D1 <D2 <... <DN <L. All input values are integers.
Output
Output the shortest required time (seconds) on one line. Absolute errors of 10-6 or less are allowed.
Examples
Input
1 1 1 2 3 100
50
Output
49.500000000
Input
3 1 1 2 3 100
49
50
51
Output
48.666666667
Submitted Solution:
```
N, K, T, U, V, L = map(int, input().split())
ans = 0
l = 0
t = 0
k = 0
for _ in range(N + 1):
if _ == N:
d = L
else:
d = int(input())
length = d - l
l = d
while t > 0 or k > 0:
if t > 0:
if t * V >= length:
tmp = (t * V - length) / V
ans += t - tmp
t = tmp
if K > k:
k += 1
else:
t = T
length = 0
break
else:
length = length - t * V
ans += t
t = 0
if k > 0:
k -= 1
t = T
if k > 0:
k -= 1
t = T
ans += length / U
if K > k:
k += 1
else:
t = T
print(ans)
``` | instruction | 0 | 14,096 | 3 | 28,192 |
No | output | 1 | 14,096 | 3 | 28,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r × c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad.
Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say a, passes by another country b, they change the dominant religion of country b to the dominant religion of country a.
In particular, a single use of your power is this:
* You choose a horizontal 1 × x subgrid or a vertical x × 1 subgrid. That value of x is up to you;
* You choose a direction d. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST;
* You choose the number s of steps;
* You command each country in the subgrid to send a missionary group that will travel s steps towards direction d. In each step, they will visit (and in effect convert the dominant religion of) all s countries they pass through, as detailed above.
* The parameters x, d, s must be chosen in such a way that any of the missionary groups won't leave the grid.
The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a 1 × 4 subgrid, the direction NORTH, and s = 2 steps.
<image>
You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country.
What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism?
With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all countries, you must also admit your mortality and say so.
Input
The first line of input contains a single integer t (1 ≤ t ≤ 2⋅ 10^4) denoting the number of test cases.
The first line of each test case contains two space-separated integers r and c denoting the dimensions of the grid (1 ≤ r, c ≤ 60). The next r lines each contains c characters describing the dominant religions in the countries. In particular, the j-th character in the i-th line describes the dominant religion in the country at the cell with row i and column j, where:
* "A" means that the dominant religion is Beingawesomeism;
* "P" means that the dominant religion is Pushingittoofarism.
It is guaranteed that the grid will only contain "A" or "P" characters. It is guaranteed that the sum of the r ⋅ c in a single file is at most 3 ⋅ 10^6.
Output
For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so.
Example
Input
4
7 8
AAPAAAAA
PPPPAAAA
PPPPAAAA
APAAPPPP
APAPPAPP
AAAAPPAP
AAAAPPAA
6 5
AAAAA
AAAAA
AAPAA
AAPAP
AAAPP
AAAPP
4 4
PPPP
PPPP
PPPP
PPPP
3 4
PPPP
PAAP
PPPP
Output
2
1
MORTAL
4
Note
In the first test case, it can be done in two usages, as follows:
Usage 1:
<image>
Usage 2:
<image>
In the second test case, it can be done with just one usage of the power.
In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL". | instruction | 0 | 14,265 | 3 | 28,530 |
Tags: implementation, math
Correct Solution:
```
from sys import stdin
rstr = lambda: stdin.readline().strip()
rstr_2d = lambda n: [rstr() for _ in range(n)]
rints = lambda: [int(x) for x in stdin.readline().split()]
out = []
for _ in range(int(input())):
n, m = rints()
mat, row, col, su = rstr_2d(n), [0] * n, [0] * m, 0
for i in range(n):
for j in range(m):
if mat[i][j] == 'A':
row[i] += 1
col[j] += 1
su += 1
if not su:
out.append('MORTAL')
elif su == n * m:
out.append('0')
elif m in [row[0], row[-1]] or n in [col[0], col[-1]]:
out.append('1')
elif 'A' in [mat[0][0], mat[0][-1], mat[-1][0], mat[-1][-1]] or max(row) == m or max(col) == n:
out.append('2')
elif any([row[0], row[-1], col[0], col[-1]]):
out.append('3')
else:
out.append('4')
print('\n'.join(out))
``` | output | 1 | 14,265 | 3 | 28,531 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.