message stringlengths 2 28.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 21 109k | cluster float64 7 7 | __index_level_0__ int64 42 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path.
<image>
You're given a painted grid in the input. Tell Lenny if the grid is convex or not.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid.
It's guaranteed that the grid has at least one black cell.
Output
On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes.
Examples
Input
3 4
WWBW
BWWW
WWWB
Output
NO
Input
3 1
B
B
W
Output
YES
Submitted Solution:
```
#author: riyan
def cprf(p1, p2, grid):
path = True
for r in range(min([p1[0], p2[0]]), max([p1[0], p2[0]]) + 1):
c = p1[1]
if grid[r][c] == 'W':
path = False
break
if path:
for c in range(min([p1[1], p2[1]]), max([p1[1], p2[1]]) + 1):
r = p1[0]
if grid[r][c] == 'W':
path = False
break
return path
def cpcf(p1, p2, grid):
path = True
for c in range(min([p1[1], p2[1]]), max([p1[1], p2[1]]) + 1):
r = p1[0]
if grid[r][c] == 'W':
path = False
break
if path:
for r in range(min([p1[0], p2[0]]), max([p1[0], p2[0]]) + 1):
c = p1[1]
if grid[r][c] == 'W':
path = False
break
return path
if __name__ == '__main__':
grid = []
n, m = map(int, input().strip().split())
for i in range(n):
grid.append(list(input().strip()))
bps = []
for i in range(n):
for j in range(m):
if grid[i][j] == 'B':
bps.append((i, j))
ans = True
for bp1 in bps:
for bp2 in bps:
way1 = cprf(bp1, bp2, grid)
way2 = cpcf(bp1, bp2, grid)
if not (way1 and way2):
ans = False
break
if not ans:
break
if ans:
print('YES')
else:
print('NO')
``` | instruction | 0 | 97,294 | 7 | 194,588 |
No | output | 1 | 97,294 | 7 | 194,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path.
<image>
You're given a painted grid in the input. Tell Lenny if the grid is convex or not.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid.
It's guaranteed that the grid has at least one black cell.
Output
On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes.
Examples
Input
3 4
WWBW
BWWW
WWWB
Output
NO
Input
3 1
B
B
W
Output
YES
Submitted Solution:
```
# Author : raj1307 - Raj Singh
# Date : 02.01.2020
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li(): return list(mi())
def dmain():
sys.setrecursionlimit(100000000)
threading.stack_size(40960000)
thread = threading.Thread(target=main)
thread.start()
#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import ceil,floor,log,sqrt,factorial
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading
#from itertools import permutations
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[1]
def sort2(l):return sorted(l, key=getKey)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]
def powerMod(x,y,p):
res = 1
x %= p
while y > 0:
if y&1:
res = (res*x)%p
y = y>>1
x = (x*x)%p
return res
def gcd(x, y):
while y:
x, y = y, x % y
return x
def isPrime(n) : # Check Prime Number or not
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def read():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def main():
#for _ in range(ii()):
n,c=mi()
f=1
l=[]
mark=[]
for i in range(n):
l.append(si())
x=[]
for j in l[i]:
if j=='B':
x.append(0)
else:
x.append(1)
mark.append(x)
m=mark[:]
if n==1 and c==1:
print('YES')
exit()
for i in range(n):
for j in range(c):
if l[i][j]=='B':
#m[i][j]=1
for k in range(j+1,c): #Right
if l[i][k]=='W':
break
m[i][k]=1
for x in range(i-1,-1,-1):
if l[x][k]=='W':
break
m[i][k]=1
for x in range(i+1,n):
if l[x][k]=='W':
break
m[i][k]=1
for k in range(j-1,-1,-1): #Left
if l[i][k]=='W':
break
m[i][k]=1
for x in range(i-1,-1,-1):
if l[x][k]=='W':
break
m[x][k]=1
for x in range(i+1,n):
if l[x][k]=='W':
break
m[x][k]=1
for k in range(i-1,-1,-1): #Up
if l[k][j]=='W':
break
m[k][j]=1
for x in range(j-1,-1,-1):
if l[k][x]=='W':
break
m[k][x]=1
for x in range(j+1,c):
if l[k][x]=='W':
break
m[k][x]=1
for k in range(i+1,n): #Down
if l[k][j]=='W':
break
m[k][j]=1
for x in range(j-1,-1,-1):
if l[k][x]=='W':
break
m[k][x]=1
for x in range(j+1,c):
if l[k][x]=='W':
break
m[k][x]=1
if m==[[1]*c]*n:
print('YES')
else:
print('NO')
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
#read()
main()
#dmain()
# Comment Read()
``` | instruction | 0 | 97,295 | 7 | 194,590 |
No | output | 1 | 97,295 | 7 | 194,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path.
<image>
You're given a painted grid in the input. Tell Lenny if the grid is convex or not.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid.
It's guaranteed that the grid has at least one black cell.
Output
On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes.
Examples
Input
3 4
WWBW
BWWW
WWWB
Output
NO
Input
3 1
B
B
W
Output
YES
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
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)
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
def main():
n, m = map(int, input().split())
a = []
for i in range(n):
t = input()
k = []
for j in t:
if j == 'W':
k.append(0)
if j == 'B':
k.append(1)
a.append(k)
reach1 = [[] for i in range(2600)]
blacks=[]
for i in range(n):
for j in range(m):
if a[i][j]:
blacks.append(i*m+j)
t = i
while t >= 0:
reach1[i*m+j].append(t*n+j)
t -= 1
t=i+1
while t<n:
reach1[i * m + j].append(t * m + j)
t +=1
t=j-1
while t >= 0:
reach1[i*m+j].append(i*n+t)
t -= 1
t=j+1
while t<m:
reach1[i * m + j].append(i* m + t)
t+=1
f=1
# print(blacks)
# print(reach1)
for i in blacks:
k=set(reach1[i])
k.add(i)
for j in blacks:
if j!=i:
for m in reach1[j]:
k.add(m)
for m in blacks:
if m not in k:
f=0
if f:
print('YES')
else:
print('NO')
return
if __name__ == "__main__":
main()
``` | instruction | 0 | 97,296 | 7 | 194,592 |
No | output | 1 | 97,296 | 7 | 194,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path.
<image>
You're given a painted grid in the input. Tell Lenny if the grid is convex or not.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 50) — the size of the grid. Each of the next n lines contains m characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid.
It's guaranteed that the grid has at least one black cell.
Output
On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes.
Examples
Input
3 4
WWBW
BWWW
WWWB
Output
NO
Input
3 1
B
B
W
Output
YES
Submitted Solution:
```
#author: riyan
def solve(n, m):
grid = []
for i in range(n):
grid.append(input().strip())
cnt = 0
for j in range(1, m):
if grid[i][j] != grid[i][j - 1]:
cnt += 1
if (cnt > 2) or (cnt == 2 and grid[i][0] == 'B'):
return False
for j in range(m):
cnt = 0
for i in range(n):
if grid[i][j] != grid[i - 1][j]:
cnt += 1
if (cnt > 2) or (cnt == 2 and grid[0][j] == 'B'):
return False
bps = []
for i in range(n):
for j in range(m):
if grid[i][j] == 'B':
bp1 = (i, j)
for k in range(len(bps)):
bp2 = bps[k]
if not ( (grid[bp1[0]][bp2[1]] == 'B') or (grid[bp2[0]][bp1[1]] == 'B') ):
return False
bps.append((i, j))
return True
if __name__ == '__main__':
n, m = map(int, input().strip().split())
ans = solve(n, m)
if ans:
print('YES')
else:
print('NO')
``` | instruction | 0 | 97,297 | 7 | 194,594 |
No | output | 1 | 97,297 | 7 | 194,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kostya is extremely busy: he is renovating his house! He needs to hand wallpaper, assemble furniture throw away trash.
Kostya is buying tiles for bathroom today. He is standing in front of a large square stand with tiles in a shop. The stand is a square of n × n cells, each cell of which contains a small tile with color c_{i,\,j}. The shop sells tiles in packs: more specifically, you can only buy a subsquare of the initial square.
A subsquare is any square part of the stand, i. e. any set S(i_0, j_0, k) = \\{c_{i,\,j}\ |\ i_0 ≤ i < i_0 + k, j_0 ≤ j < j_0 + k\} with 1 ≤ i_0, j_0 ≤ n - k + 1.
Kostya still does not know how many tiles he needs, so he considers the subsquares of all possible sizes. He doesn't want his bathroom to be too colorful. Help Kostya to count for each k ≤ n the number of subsquares of size k × k that have at most q different colors of tiles. Two subsquares are considered different if their location on the stand is different.
Input
The first line contains two integers n and q (1 ≤ n ≤ 1500, 1 ≤ q ≤ 10) — the size of the stand and the limit on the number of distinct colors in a subsquare.
Each of the next n lines contains n integers c_{i,\,j} (1 ≤ c_{i,\,j} ≤ n^2): the j-th integer in the i-th line is the color of the tile in the cell (i,\,j).
Output
For each k from 1 to n print a single integer — the number of subsquares of size k × k with no more than q different colors.
Examples
Input
3 4
1 2 3
4 5 6
7 8 9
Output
9
4
0
Input
4 8
1 2 3 4
5 6 7 8
9 1 2 3
4 5 6 7
Output
16
9
4
0
Note
In the first example all colors are distinct. Kostya doesn't want the subsquare have more than 4 colors, so he can buy any subsquare of size 1 × 1 or 2 × 2, but he can't buy a subsquare of size 3 × 3.
In the second example there are colors that appear multiple times. Because q = 8, Kostya can buy any subsquare of size 1 × 1 and 2 × 2, and any subsquare 3 × 3, because of such subsquare has 7 different colors. He can't buy the whole stand 4 × 4, because there are 9 colors.
Submitted Solution:
```
s=input().split(" ")
n=int(s[0])
q=int(s[1])
l=[]
for i in range(n):
l.append(input().split(" "))
for j in range(n):
l[-1][j]=int(l[-1][j])
x=[]
for i in range(n):
x.append([])
for j in range(n):
x[i].append({l[i][j]:""})
if q==0:
print(0)
s=0
else:
print(n*n)
s=n*n
for p in range(1,n):
if s==0:
break
s=0
x.pop()
for i in range(n-p):
x[i].pop()
for j in range(n-p):
if len(x[i][j])<=q:
for k in range(j,j+p+1):
x[i][j].update({l[i+p][k]:""})
if len(x[i][j])>q:
break
if len(x[i][j])<=q:
for k in range(i,i+p+1):
x[i][j].update({l[k][j+p]:""})
if len(x[i][j])>q:
break
if len(x[i][j])<=q:
s+=1
print(s)
``` | instruction | 0 | 98,131 | 7 | 196,262 |
No | output | 1 | 98,131 | 7 | 196,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kostya is extremely busy: he is renovating his house! He needs to hand wallpaper, assemble furniture throw away trash.
Kostya is buying tiles for bathroom today. He is standing in front of a large square stand with tiles in a shop. The stand is a square of n × n cells, each cell of which contains a small tile with color c_{i,\,j}. The shop sells tiles in packs: more specifically, you can only buy a subsquare of the initial square.
A subsquare is any square part of the stand, i. e. any set S(i_0, j_0, k) = \\{c_{i,\,j}\ |\ i_0 ≤ i < i_0 + k, j_0 ≤ j < j_0 + k\} with 1 ≤ i_0, j_0 ≤ n - k + 1.
Kostya still does not know how many tiles he needs, so he considers the subsquares of all possible sizes. He doesn't want his bathroom to be too colorful. Help Kostya to count for each k ≤ n the number of subsquares of size k × k that have at most q different colors of tiles. Two subsquares are considered different if their location on the stand is different.
Input
The first line contains two integers n and q (1 ≤ n ≤ 1500, 1 ≤ q ≤ 10) — the size of the stand and the limit on the number of distinct colors in a subsquare.
Each of the next n lines contains n integers c_{i,\,j} (1 ≤ c_{i,\,j} ≤ n^2): the j-th integer in the i-th line is the color of the tile in the cell (i,\,j).
Output
For each k from 1 to n print a single integer — the number of subsquares of size k × k with no more than q different colors.
Examples
Input
3 4
1 2 3
4 5 6
7 8 9
Output
9
4
0
Input
4 8
1 2 3 4
5 6 7 8
9 1 2 3
4 5 6 7
Output
16
9
4
0
Note
In the first example all colors are distinct. Kostya doesn't want the subsquare have more than 4 colors, so he can buy any subsquare of size 1 × 1 or 2 × 2, but he can't buy a subsquare of size 3 × 3.
In the second example there are colors that appear multiple times. Because q = 8, Kostya can buy any subsquare of size 1 × 1 and 2 × 2, and any subsquare 3 × 3, because of such subsquare has 7 different colors. He can't buy the whole stand 4 × 4, because there are 9 colors.
Submitted Solution:
```
False
``` | instruction | 0 | 98,132 | 7 | 196,264 |
No | output | 1 | 98,132 | 7 | 196,265 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100 | instruction | 0 | 98,427 | 7 | 196,854 |
"Correct Solution:
```
k,x = map(int,input().split())
for i in range(x-k+1,x+k):
print(i,end=' ')
``` | output | 1 | 98,427 | 7 | 196,855 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100 | instruction | 0 | 98,428 | 7 | 196,856 |
"Correct Solution:
```
a,b =map(int,input().split())
x = list(range(b-a+1, b+a))
print(*x)
``` | output | 1 | 98,428 | 7 | 196,857 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100 | instruction | 0 | 98,429 | 7 | 196,858 |
"Correct Solution:
```
a,b=map(int,input().split())
for i in range(a*2-1):
print(b-a+1+i,end=' ')
``` | output | 1 | 98,429 | 7 | 196,859 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100 | instruction | 0 | 98,430 | 7 | 196,860 |
"Correct Solution:
```
k,x=map(int,input().split())
for i in range(2*k-1):
print(x+1-k+i,end=" ")
``` | output | 1 | 98,430 | 7 | 196,861 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100 | instruction | 0 | 98,431 | 7 | 196,862 |
"Correct Solution:
```
k, x = map(int, input().split())
print(*[i for i in range(x-(k-1), x+k)])
``` | output | 1 | 98,431 | 7 | 196,863 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100 | instruction | 0 | 98,432 | 7 | 196,864 |
"Correct Solution:
```
K,X=input().split()
K=int(K)
X=int(X)
print(*[i+X-K+1 for i in range(2*K-1)])
``` | output | 1 | 98,432 | 7 | 196,865 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100 | instruction | 0 | 98,433 | 7 | 196,866 |
"Correct Solution:
```
K, X = map(int, input().split())
print(*list(range(X-(K-1), X+(K-1)+1)))
``` | output | 1 | 98,433 | 7 | 196,867 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100 | instruction | 0 | 98,434 | 7 | 196,868 |
"Correct Solution:
```
k,x = map(int,input().split())
for i in range(x-k+1,x+k):
print(i)
``` | output | 1 | 98,434 | 7 | 196,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100
Submitted Solution:
```
k,n=map(int,input().split())
for i in range(k*2-1):
print(n-k+i+1)
``` | instruction | 0 | 98,435 | 7 | 196,870 |
Yes | output | 1 | 98,435 | 7 | 196,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100
Submitted Solution:
```
K,X=map(int, input().split())
for x in range(X-K+1,X+K):
print(x,"",end="")
``` | instruction | 0 | 98,436 | 7 | 196,872 |
Yes | output | 1 | 98,436 | 7 | 196,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100
Submitted Solution:
```
k,x = map(int,input().split())
tmp = [i for i in range(x-k+1, x+k)]
print(*tmp)
``` | instruction | 0 | 98,437 | 7 | 196,874 |
Yes | output | 1 | 98,437 | 7 | 196,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100
Submitted Solution:
```
k, x = map(int, input().split())
a = range(x - k + 1, x + k)
print(*a)
``` | instruction | 0 | 98,438 | 7 | 196,876 |
Yes | output | 1 | 98,438 | 7 | 196,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100
Submitted Solution:
```
i = list(map(int,input().split()))
K = i[0]
X = i[1]
print(list(range(X-K+1,X+K)))
``` | instruction | 0 | 98,439 | 7 | 196,878 |
No | output | 1 | 98,439 | 7 | 196,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100
Submitted Solution:
```
K,X=map(int,input().split())
M=[]
for i in range (X-K+1,X+K):
M.append(i)
M.sort()
print(''.join(map(str,M)))
``` | instruction | 0 | 98,440 | 7 | 196,880 |
No | output | 1 | 98,440 | 7 | 196,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100
Submitted Solution:
```
k,x = map(int,input().split())
p = [x-k+1+i for i in range(2*k-1)]
print(q)
``` | instruction | 0 | 98,441 | 7 | 196,882 |
No | output | 1 | 98,441 | 7 | 196,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know that the stone at coordinate X is painted black.
Print all coordinates that potentially contain a stone painted black, in ascending order.
Constraints
* 1 \leq K \leq 100
* 0 \leq X \leq 100
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
K X
Output
Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.
Examples
Input
3 7
Output
5 6 7 8 9
Input
4 0
Output
-3 -2 -1 0 1 2 3
Input
1 100
Output
100
Submitted Solution:
```
k, x = (int(i) for i in input().split())
arr = []
for i in range(-k + 1, 0):
for j in range(0, k + 1):
arr.append(i + j + x)
sorted_list = sorted(list(set(arr)))
if (k == 1):
result = x
result = " ".join(map(str, sorted_list))
print(result)
``` | instruction | 0 | 98,442 | 7 | 196,884 |
No | output | 1 | 98,442 | 7 | 196,885 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170 | instruction | 0 | 98,559 | 7 | 197,118 |
"Correct Solution:
```
n, m = map(int, input().split())
a = list(map(int, input().split()))
i = 0
ans = 0
while True:
t_min = float('inf')
t_max = 0
for j in range(m):
t = a[i % n]
t_min = min(t_min, t)
t_max = max(t_max, t)
i += 1
ans += t_max - t_min
if i % n == 0:
break
print(ans)
``` | output | 1 | 98,559 | 7 | 197,119 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170 | instruction | 0 | 98,560 | 7 | 197,120 |
"Correct Solution:
```
from math import gcd
n, m = map(int, input().split())
alst = list(map(int, input().split()))
loop = m // gcd(n, m)
alst = alst * loop
ans = 0
for i in range(0, loop * n, m):
ans += max(alst[i:i+m]) - min(alst[i:i+m])
print(ans)
``` | output | 1 | 98,560 | 7 | 197,121 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170 | instruction | 0 | 98,561 | 7 | 197,122 |
"Correct Solution:
```
N, M = map(int, input().split())
As = list(map(int, input().split()))
rd = 0
c = 1
N_ = N * c
while(N_ % M != 0):
c += 1
N_ = c * N
rd = N_ // M
As = As * (N_//N + 1)
ls = []
cnt = 0
for i in range(rd):
lstmp = []
for j in range(M):
lstmp.append(As[cnt])
cnt += 1
ls.append(lstmp)
s = 0
for i in ls:
s += max(i)-min(i)
print(s)
``` | output | 1 | 98,561 | 7 | 197,123 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170 | instruction | 0 | 98,562 | 7 | 197,124 |
"Correct Solution:
```
def list_eq(get_num, first):
if first == 1:
return False
for i in range(len(get_num)-1):
if get_num[0] != get_num[i+1]:
return False
return True
a_raw = input().split(' ')
b_raw = input().split(' ')
a = [int(n) for n in a_raw]
b = [int(n) for n in b_raw]
get_num = [0 for _ in range(a[0])]
first=1
next_num=0
res=0
while list_eq(get_num, first) == False:
first=0
weight = []
for i in range(a[1]):
weight.append(b[next_num])
get_num[next_num] += 1
next_num+=1
if next_num > a[0]-1:
next_num = 0
res+=max(weight)-min(weight)
print(res)
``` | output | 1 | 98,562 | 7 | 197,125 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170 | instruction | 0 | 98,563 | 7 | 197,126 |
"Correct Solution:
```
# AOJ 2806: Weight Range
# Python3 2018.7.11 bal4u
def gcd(a, b):
while b != 0:
r = a % b
a, b = b, r
return a
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.extend(a)
step = gcd(N, M)
group = N // step;
ans = 0
for i in range(group):
k = i*step
mi = ma = a[k];
for j in range(1, M):
mi = min(mi, a[k+j])
ma = max(ma, a[k+j])
ans += ma-mi
print(ans)
``` | output | 1 | 98,563 | 7 | 197,127 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170 | instruction | 0 | 98,564 | 7 | 197,128 |
"Correct Solution:
```
N,M = map(int, input().split())
A = list(map(int, input().split()))
a = [0]*M
count = 0
weight = 0
while count != N:
#print("count=",count)
for i in range(M):
if N-1 < count:
count = 0
a[i] = A[count]
count += 1
sa = max(a) - min (a)
#print("a=",a," sa=",sa)
weight += sa
print(weight)
``` | output | 1 | 98,564 | 7 | 197,129 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170 | instruction | 0 | 98,565 | 7 | 197,130 |
"Correct Solution:
```
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
l = 0
ans = 0
while l % N != 0 or l == 0:
min_ = 101
max_ = -1
for i in range(l, l + M):
min_ = min(min_, A[i % N])
max_ = max(max_, A[i % N])
ans += max_ - min_
l += M
print(ans)
``` | output | 1 | 98,565 | 7 | 197,131 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170 | instruction | 0 | 98,566 | 7 | 197,132 |
"Correct Solution:
```
import math
n, m = map(int, input().split())
ball = list(map(int, input().split()))
lcm = n * m // math.gcd(n, m)
ans = 0
for i in range(lcm // m):
data = []
for j in range(m):
d = ball[(i*m+j) % len(ball)]
data.append(d)
ans += (max(data) - min(data))
print(ans)
``` | output | 1 | 98,566 | 7 | 197,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n,m = LI()
a = LI()
r = 0
i = 0
while True:
mi = ma = a[i%n]
for j in range(1,m):
t = a[(i+j)%n]
if mi > t:
mi = t
elif ma < t:
ma = t
r += ma-mi
i += m
if i % n == 0:
break
return r
print(main())
``` | instruction | 0 | 98,567 | 7 | 197,134 |
Yes | output | 1 | 98,567 | 7 | 197,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170
Submitted Solution:
```
def GCD(a, b):
while(b):
a, b = b, a % b
return(a)
def LCM(a, b):
return(a * b // GCD(a, b))
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
lcm = LCM(N, M)
l = []
if(N != lcm):
for i in range(lcm // N):
for j in range(N):
l.append(A[j])
else:
l = A
ans = 0
for i in range(lcm // M):
temp = []
for j in range(M):
temp.append(l[M * i + j])
ans += max(temp) - min(temp)
print(ans)
if __name__ == '__main__':
main()
``` | instruction | 0 | 98,568 | 7 | 197,136 |
Yes | output | 1 | 98,568 | 7 | 197,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170
Submitted Solution:
```
import math
n,m=map(int,input().split())
a=list(map(int,input().split()))*2
gr=n//math.gcd(n,m)
ans=0
for i in range(gr):
test=[]
for j in range(m):
test.append(a[(i*m+j)%n])
test.sort()
ans+=test[-1]-test[0]
print(ans)
``` | instruction | 0 | 98,569 | 7 | 197,138 |
Yes | output | 1 | 98,569 | 7 | 197,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N $, followed by the balls of color $ 1 $. Balls of the same color weigh the same, and balls of color $ i $ weigh $ A_i $.
From this state, take out $ M $ of balls from the beginning of the queue and repeat the process of grouping them. Then stop forming groups when the total number of balls of each color removed from the cue is equal. Please note that the cue contains a sufficient number of balls and the cue will not be empty by the time you stop forming groups.
For example, when $ N = 8, M = 2 $, there are 4 groups of {color 1, color 2}, {color 3, color 4}, {color 5, color 6}, {color 7, color 8}. (At this time, there is one ball of each color). When $ N = 4, M = 3 $, {color 1, color 2, color 3}, {color 4, color 1, color 2}, {color 3, color 4, color 1}, {color 2, color There will be a $ 4 $ group of 3, colors 4} (there are 3 balls of each color each).
At this time, in each group, the difference between the maximum value and the minimum value of the weight of the balls included is called the weight range of that group. Output the sum of the weight ranges for each group.
output
Print the answer in one line. Also, output a line break at the end.
Example
Input
8 2
23 61 57 13 91 41 79 41
Output
170
Submitted Solution:
```
N, M = map(int, input().split())
As = list(map(int, input().split())) * N * M
rd = 0
c = 1
N_ = N * c
while(N_ % M != 0):
c += 1
N_ = c * N
rd = N_ // M
ls = []
cnt = 0
for i in range(rd):
lstmp = []
for j in range(M):
lstmp.append(As[cnt])
cnt += 1
ls.append(lstmp)
s = 0
for i in ls:
s += max(i)-min(i)
print(s)
``` | instruction | 0 | 98,570 | 7 | 197,140 |
No | output | 1 | 98,570 | 7 | 197,141 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 98,710 | 7 | 197,420 |
Tags: combinatorics, dp, math
Correct Solution:
```
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
#from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
#def print(x): return sys.stdout.write(str(x)+'\n')
#sys.setrecursionlimit(100000)
mod=int(1e9+7)
n,m=mdata()
dp=[[2,0,0]]
for i in range(1,m):
dp.append([(2*dp[i-1][0]-dp[i-1][2]+mod)%mod,(dp[i-1][1]+dp[i-1][0]-dp[i-1][2]+mod)%mod,(dp[i-1][0]-dp[i-1][2]+mod)%mod])
cnt=dp[-1][1]
k1=dp[-1][0]-dp[-1][1]
k2=0
for i in range(1,n):
k1,k2=(2*k1-k2+mod)%mod,(k1-k2+mod)%mod
print((cnt+k1)%mod)
``` | output | 1 | 98,710 | 7 | 197,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 98,711 | 7 | 197,422 |
Tags: combinatorics, dp, math
Correct Solution:
```
n, m = [int(i) for i in input().split()]
mod = 1000000007
def fib(number):
a, b = 1, 1
for i in range(number):
a, b = b, (a + b) % mod
return a
print(2 * (fib(n) + fib(m) - 1) % mod)
``` | output | 1 | 98,711 | 7 | 197,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 98,712 | 7 | 197,424 |
Tags: combinatorics, dp, math
Correct Solution:
```
from sys import stdin
input = stdin.readline
MOD = 1_000_000_007
n, m = [int(x) for x in input().split()]
dp = [1, 1]
for i in range(max(n, m) + 1):
dp.append((dp[-2] + dp[-1]) % MOD)
x = dp[m] * 2
y = dp[n] * 2
ans = (x + y - 2) % MOD
print(ans)
``` | output | 1 | 98,712 | 7 | 197,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 98,713 | 7 | 197,426 |
Tags: combinatorics, dp, math
Correct Solution:
```
modulo = 1000000007
inline = [int(x) for x in input().split(' ')]
row = max(inline[0], inline[1])
col = min(inline[0], inline[1])
if row > 1 and col > 1:
rowrec = [0] * row
rowrec[0] = 2
rowrec[1] = 4
for i in range(2, row):
rowrec[i] = (rowrec[i-1]+rowrec[i-2]) % modulo
colrec = [0]*col
colrec[0] = rowrec[row-1]
colrec[1] = 2+colrec[0]
for i in range(2, col):
colrec[i] = (colrec[i-1] + rowrec[i-2]) % modulo
print(colrec[col-1])
else:
theOne = max(row, col)
rowrec = [0] * theOne
if theOne == 1:
print(2)
else:
rowrec[0] = 2
rowrec[1] = 4
for i in range(2, theOne):
rowrec[i] = (rowrec[i - 1] + rowrec[i - 2]) % modulo
print(rowrec[theOne-1])
``` | output | 1 | 98,713 | 7 | 197,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 98,714 | 7 | 197,428 |
Tags: combinatorics, dp, math
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c)-ord('a')
def lcm(a, b): return a*b//lcm(a, b)
mod = 10**9+7
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
# ------------------------------
# f = open('./input.txt')
# sys.stdin = f
def main():
n, m = RL()
if n<m: n, m = m, n
dp = [[0, 0] for _ in range(n+1)]
dp[1] = [1, 1]
dp[0] = [1, 1]
for i in range(2, n+1):
dp[i][0] = max(dp[i][1], (dp[i-1][1]+dp[i-2][1])%mod)
dp[i][1] = max(dp[i][0], (dp[i-1][0]+dp[i-2][0])%mod)
# print(dp)
print((sum(dp[m]) + sum(dp[n]) - 2)%mod)
if __name__ == "__main__":
main()
``` | output | 1 | 98,714 | 7 | 197,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 98,715 | 7 | 197,430 |
Tags: combinatorics, dp, math
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
mod = 10**9+7
def solve(x):
dp = [[0,0] for _ in range(x)]
# same ; different
dp[0] = [0,2]
for i in range(1,x):
dp[i][0] = (dp[i][0]+dp[i-1][1])%mod
dp[i][1] = (dp[i][1]+dp[i-1][0]+dp[i-1][1])%mod
return (dp[x-1][0]+dp[x-1][1])%mod
def main():
n,m = map(int,input().split())
print((solve(n)+solve(m)-2)%mod)
# Fast IO 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")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | output | 1 | 98,715 | 7 | 197,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 98,716 | 7 | 197,432 |
Tags: combinatorics, dp, math
Correct Solution:
```
n,m=map(int,input().split())
mod=10**9+7
B=[1]
W=[1]
BB=[0]
WW=[0]
for i in range(1,100010):
x=W[-1]+WW[-1]
y=B[-1]+BB[-1]
z=B[-1]
w=W[-1]
x%=mod
y%=mod
z%=mod
w%=mod
B.append(x)
W.append(y)
BB.append(z)
WW.append(w)
print((B[n-1]+W[n-1]+BB[n-1]+WW[n-1]+B[m-1]+W[m-1]+BB[m-1]+WW[m-1]-2)%mod)
``` | output | 1 | 98,716 | 7 | 197,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image> | instruction | 0 | 98,717 | 7 | 197,434 |
Tags: combinatorics, dp, math
Correct Solution:
```
n, m = map(int, input().split())
d = [2, 4]
k = 10**9+7
for i in range(2, max(n, m)):
d += [(d[i-1]+d[i-2]) % k]
print((d[m-1]+d[n-1]-2) % k)
``` | output | 1 | 98,717 | 7 | 197,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
mod=10**9+7
def solve(x):
dp=[[0,0] for _ in range(x+1)]
dp[1]=[1,1]
dp[0]=[1,1]
for i in range(2,x+1):
dp[i][0]=(dp[i-2][1]+dp[i-1][1])%mod
dp[i][1]=(dp[i-2][0]+dp[i-1][0])%mod
return (dp[-1][0]+dp[-1][1])%mod
def main():
n,m=map(int,input().split())
print((solve(n)+solve(m)-2)%mod)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | instruction | 0 | 98,718 | 7 | 197,436 |
Yes | output | 1 | 98,718 | 7 | 197,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
from sys import stdin
def input():
return stdin.readline()[:-1]
def intput():
return int(input())
def sinput():
return input().split()
def intsput():
return map(int, sinput())
mod = 10 ** 9 + 7
n, m = intsput()
fib = [2, 2]
for _ in range(100001):
fib.append((fib[-1] + fib[-2]) % mod)
print((fib[n] + fib[m] - 2) % mod)
``` | instruction | 0 | 98,719 | 7 | 197,438 |
Yes | output | 1 | 98,719 | 7 | 197,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
if n == 1 and m == 1:
print(2)
exit()
MOD = 10**9+7
N = max(n, m)
dp = [[0] * 4 for _ in range(N+1)]
for j in range(4):
dp[2][j] = 1
for i in range(2, N):
dp[i+1][0] = dp[i][2]
dp[i+1][1] = dp[i][0]+dp[i][2]
dp[i+1][2] = dp[i][1]+dp[i][3]
dp[i+1][3] = dp[i][1]
for j in range(4):
dp[i+1][j] %= MOD
if n == 1:
print(sum(dp[m])%MOD)
elif m == 1:
print(sum(dp[n])%MOD)
else:
print((sum(dp[n])+sum(dp[m])-2)%MOD)
``` | instruction | 0 | 98,720 | 7 | 197,440 |
Yes | output | 1 | 98,720 | 7 | 197,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
n,m=[int(x) for x in input().split()]
dp=[0]*100001
dp[0]=2
dp[1]=2
dp[2]=4
for i in range(3,100001):
dp[i]=(dp[i-1]*2-dp[i-3])%(10**9+7)
print((dp[n]+dp[m]-2)%(10**9+7))
``` | instruction | 0 | 98,721 | 7 | 197,442 |
Yes | output | 1 | 98,721 | 7 | 197,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
a, b = map(int, input().split())
first = b // 2
second = b - first * 2
print(pow(2, first * ((a + 1) // 2) + second * (a // 2), 10 ** 9 + 7))
``` | instruction | 0 | 98,722 | 7 | 197,444 |
No | output | 1 | 98,722 | 7 | 197,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
a, b = map(int,input().split())
mod = 10**9+7
ans = 0
for n in [a,b]:
A = [[0,0] for i in range(n)]
A[0] = [0,1]
if n > 1:
A[1] = [1,1]
for i in range(2,n):
A[i][0] = A[i-2][1] % mod
A[i][1] = sum(A[i-1]) % mod
# print(A)
ans += (sum(A[-1]) * 2) % mod
print((ans-2) % mod)
``` | instruction | 0 | 98,723 | 7 | 197,446 |
No | output | 1 | 98,723 | 7 | 197,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
''' CODED WITH LOVE BY SATYAM KUMAR '''
from sys import stdin, stdout
import heapq
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 6) # max depth of recursion
threading.stack_size(2 ** 27) # new thread will get stack of such size
fac_warm_up = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
class MergeFind:
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.num_sets = n
self.lista = [[_] for _ in range(n)]
def find(self, a):
to_update = []
while a != self.parent[a]:
to_update.append(a)
a = self.parent[a]
for b in to_update:
self.parent[b] = a
return self.parent[a]
def merge(self, a, b):
a = self.find(a)
b = self.find(b)
if a == b:
return
if self.size[a] < self.size[b]:
a, b = b, a
self.num_sets -= 1
self.parent[b] = a
self.size[a] += self.size[b]
self.lista[a] += self.lista[b]
def set_size(self, a):
return self.size[self.find(a)]
def __len__(self):
return self.num_sets
def display(string_to_print):
stdout.write(str(string_to_print) + "\n")
def prime_factors(n): # n**0.5 complex
factors = dict()
for i in range(2, math.ceil(math.sqrt(n)) + 1):
while n % i == 0:
if i in factors:
factors[i] += 1
else:
factors[i] = 1
n = n // i
if n > 2:
factors[n] = 1
return (factors)
def all_factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
def fibonacci_modP(n, MOD):
if n < 2: return 1
return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(
fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD
def factorial_modP_Wilson(n, p):
if (p <= n):
return 0
res = (p - 1)
for i in range(n + 1, p):
res = (res * cached_fn(InverseEuler, i, p)) % p
return res
def binary(n, digits=20):
b = bin(n)[2:]
b = '0' * (digits - len(b)) + b
return b
def is_prime(n):
"""Returns True if n is prime."""
if n < 4:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
def generate_primes(n):
prime = [True for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
return prime
factorial_modP = []
def warm_up_fac(MOD):
global factorial_modP, fac_warm_up
if fac_warm_up: return
factorial_modP = [1 for _ in range(fac_warm_up_size + 1)]
for i in range(2, fac_warm_up_size):
factorial_modP[i] = (factorial_modP[i - 1] * i) % MOD
fac_warm_up = True
def InverseEuler(n, MOD):
return pow(n, MOD - 2, MOD)
def nCr(n, r, MOD):
global fac_warm_up, factorial_modP
if not fac_warm_up:
warm_up_fac(MOD)
fac_warm_up = True
return (factorial_modP[n] * (
(pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD)) % MOD)) % MOD
def get_int():
return int(stdin.readline().strip())
def get_tuple():
return map(int, stdin.readline().split())
def get_list():
return list(map(int, stdin.readline().split()))
memory = dict()
def clear_cache():
global memory
memory = dict()
def cached_fn(fn, *args):
global memory
if args in memory:
return memory[args]
else:
result = fn(*args)
memory[args] = result
return result
def ncr(n, r):
return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))
def binary_search(i, li):
fn = lambda x: li[x] - x // i
x = -1
b = len(li)
while b >= 1:
while b + x < len(li) and fn(b + x) > 0: # Change this condition 2 to whatever you like
x += b
b = b // 2
return x
# -------------------------------------------------------------- MAIN PROGRAM
TestCases = False
optimise_for_recursion = True # Can not be used clubbed with TestCases WHen using recursive functions, use Python 3
def main():
n, m = get_tuple()
p, q = 1, 1
r1 = 1
for i in range(1, n):
r1 = p + q
p = q
q = r1
p, q = 1, 1
r2 = 1
for i in range(1, m):
r2 = p + q
p = q
q = r2
#print(r1, r2)
print(2*(r1+r2-1))
# --------------------------------------------------------------------- END=
if TestCases:
for i in range(get_int()):
main()
else:
main() if not optimise_for_recursion else threading.Thread(target=main).start()
``` | instruction | 0 | 98,724 | 7 | 197,448 |
No | output | 1 | 98,724 | 7 | 197,449 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.
To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n rows and m columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.
Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo 10^9 + 7.
Input
The only line contains two integers n and m (1 ≤ n, m ≤ 100 000), the number of rows and the number of columns of the field.
Output
Print one integer, the number of random pictures modulo 10^9 + 7.
Example
Input
2 3
Output
8
Note
The picture below shows all possible random pictures of size 2 by 3.
<image>
Submitted Solution:
```
n, m = map(int, input().split())
b = n*m + 2
print(b%(10**9+7))
``` | instruction | 0 | 98,725 | 7 | 197,450 |
No | output | 1 | 98,725 | 7 | 197,451 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.