description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | import sys
from itertools import islice
for s in islice(sys.stdin, 2, None, 2):
a = (*map(int, s.split()),)
n = len(a)
r = 2 * n - 1
m = 0
for i in range(n - 2):
if a[i] < a[i + 1] > a[i + 2]:
m = 0
else:
m += 1
r += m
print(r) | IMPORT FOR VAR FUNC_CALL VAR VAR NUMBER NONE NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | def perms3orbigger(x):
return x * (x + 1) // 2 - (x + x) + 1
def isWeird3v2(l, h):
return p[l] > p[l + 1] or p[l + 1] < p[l + 2]
def extendsv2(l, h):
return p[h - 2] < p[h - 1] or p[h - 3] > p[h - 2]
def pretendsv2(l, h):
return p[l + 1] < p[l + 2] or p[l] > p[l + 1]
def countWeirds(lo, hi):
if lo + 3 > hi:
return 0
if lo + 3 == hi:
return int(isWeird3v2(lo, hi))
tophit = bothit = False
if isWeird3v2((midlo := (lo + hi - 1) // 2 - 1), (midhi := midlo + 3)):
while (midhi == hi or extendsv2(midlo, (midhi := midhi + 1))) and (
midlo == lo or pretendsv2((midlo := midlo - 1), midhi)
):
if (tophit := midhi == hi) and (bothit := midlo == lo):
return perms3orbigger(hi - lo)
return (
-perms3orbigger(midhi - midlo - 2)
+ (perms3orbigger(midhi - lo - 1) if bothit else countWeirds(lo, midhi - 1))
+ (perms3orbigger(hi - midlo - 1) if tophit else countWeirds(midlo + 1, hi))
)
for _ in range(int(input())):
n = int(input())
p = list(map(int, input().split()))
ans = n + n - 1
if n > 2:
ans += countWeirds(0, n)
print(ans) | FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER FUNC_DEF RETURN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF BIN_OP VAR NUMBER VAR RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | t = int(input())
for _ in range(t):
n = int(input())
A = [int(x) for x in input().split()]
inc = [0] * n
dec = [0] * n
inc[n - 1] = dec[n - 1] = 1
ans = 0
for i in range(n - 1):
j = n - 2 - i
if A[j] > A[j + 1]:
dec[j] = dec[j + 1] + 1
inc[j] = 1
else:
inc[j] = inc[j + 1] + 1
dec[j] = 1
for i in range(n):
if inc[i] > 1:
ans += inc[i]
elif dec[i] > 1:
ans += dec[i]
k = i + dec[i]
if k < n:
ans += inc[k]
else:
ans += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | numInp = lambda: int(input())
lstImp = lambda: list(map(int, input().split()))
strImp = lambda: input()
spacedStrImp = lambda: list(input())
seperateImp = lambda: map(int, input().split())
for i in range(int(input())):
lenOfPermutation = numInp()
permutation = lstImp()
ans = 0
check = 0
previous = 1
current = 1
for i in range(lenOfPermutation - 1):
previous = current
if permutation[i] <= permutation[i + 1]:
current = 1
else:
current = 0
if previous == 1 and not current:
ans += (check + 1) * check // 2
check = 0
check += 1
ans += (check + 1) * check // 2 + lenOfPermutation
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | for _ in range(int(input())):
N = int(input())
A = list(map(int, input().split()))
if N == 1:
print(1)
elif N == 2:
print(3)
else:
C = 2
F = A[1] > A[0]
final = 0
for i in range(2, N):
if not F or F and A[i] > A[i - 1]:
if not F and A[i] > A[i - 1]:
F = True
C += 1
else:
final += C * (C + 1) // 2
if final > C * (C + 1) // 2:
final -= 1
C = 2
F ^= True
if C > 0:
final += C * (C + 1) // 2
if final > C * (C + 1) // 2:
final -= 1
print(final) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | for _ in range(int(input())):
n = int(input())
p = list(map(int, input().split()))
incr = [(1) for _ in range(n)]
decr = [(1) for _ in range(n)]
for i in range(1, n):
if p[i] < p[i - 1]:
decr[i] += decr[i - 1]
if p[n - 1 - i] < p[n - i]:
incr[n - 1 - i] += incr[n - i]
summ = 0
for i in range(n):
summ += incr[i] * decr[i]
print(summ) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | for _ in range(int(input())):
ans = 0
n = int(input())
ls = list(map(int, input().split(" ")))
ls.insert(0, 0)
ls.append(0)
t = 0
ct = 0
for i in range(n + 2):
if i == 0 or i == n + 1:
continue
if ls[i - 1] < ls[i] and ls[i] > ls[i + 1]:
t = t + 1
ct = ct + 1
ans = ans + t * (t + 1) // 2
t = 1
else:
t = t + 1
ans = ans + t * (t + 1) // 2
print(ans - ct) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | t = int(input())
for i in range(t):
n = int(input())
a = [abs(int(x)) for x in input().split()]
sets = []
lflag = False
start = 0
for end in range(n - 1):
if not lflag:
if a[end] < a[end + 1]:
lflag = True
elif a[end] > a[end + 1]:
sets.append([start, end])
temp = end
while a[temp] == a[end]:
start = temp
temp -= 1
lflag = False
sets.append([start, n - 1])
ans = 0
for i in range(len(sets)):
l = sets[i][1] - sets[i][0] + 1
ans += l * (l + 1) / 2
if i < len(sets) - 1 and sets[i + 1][0] <= sets[i][1]:
l = sets[i][1] - sets[i + 1][0] + 1
ans -= l * (l + 1) / 2
print(int(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | for _ in range(int(input())):
n = int(input())
p = list(map(int, input().split()))
count = 1
up = False
ans = 0
for i in range(1, n):
if p[i] > p[i - 1]:
count += 1
up = True
elif up:
ans += (count - 1) * count // 2
up = False
count = 2
else:
count += 1
ans += (count - 1) * count // 2 + n
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | def weirdArr(n, p):
hills = [0]
for i in range(1, n - 1):
if p[i] > p[i - 1] and p[i] > p[i + 1]:
hills.append(i)
hills.append(n - 1)
ans = 0
for i in range(0, len(hills) - 1):
leng = hills[i + 1] - hills[i] + 1
ans += leng * (leng - 1) // 2
ans += n
return ans
t = int(input())
for _ in range(t):
n = int(input())
p = [int(x) for x in input().split()]
ans = weirdArr(n, p)
print(ans) | FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
i = 0
ans = n
while i < n:
j = i
while j + 1 < n:
if a[j] > a[j + 1]:
if j - 1 >= i and a[j - 1] > -a[j]:
break
a[j] = -a[j]
j += 1
k = j - i + 1
ans += k * (k + 1) // 2 - k
i = max(i + 1, j)
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | T = int(input())
for _ in range(T):
N = int(input())
P = list(map(int, input().split()))
if N == 1:
print(1)
else:
peaks = []
if P[0] > P[1]:
peaks.append(0)
for i in range(1, N - 1):
if P[i - 1] < P[i] and P[i + 1] < P[i]:
peaks.append(i)
if P[N - 1] > P[N - 2]:
peaks.append(N - 1)
peak_gaps = [peaks[0] - 0]
for i in range(1, len(peaks)):
peak_gaps.append(peaks[i] - peaks[i - 1])
peak_gaps.append(N - 1 - peaks[-1])
count = N
for i in peak_gaps:
count += i * (i + 1) // 2
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | def solve(n, arr):
res = 0
decreasing = [0] * n
increasing = [0] * n
for i in range(1, n):
decreasing[i] = i if arr[i] < arr[i - 1] else decreasing[i - 1]
increasing[i] = i if arr[i] > arr[i - 1] else increasing[i - 1]
for i in range(n):
res += i - decreasing[i] + 1
res += i - increasing[i]
if increasing[decreasing[i]] < increasing[i]:
res += decreasing[i] - increasing[decreasing[i]]
return res
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
print(solve(n, arr)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | for _ in range(int(input())):
N = int(input())
P = list(map(int, input().split()))
if N == 1:
print(1)
elif N == 2:
print(3)
else:
l = [("D" if i == 0 or P[i] < P[i - 1] else "I") for i in range(N)]
inI = False
nDs = nIs = 0
ans = 0
for c in l:
if c == "D":
if inI:
inI = False
nDs, nIs = 1, 0
nDs += 1
ans += nDs
inI = False
else:
nIs += 1
ans += nDs + nIs
inI = True
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | for _ in range(int(input())):
n = int(input())
p = list(map(int, input().split()))
hills = []
for i in range(1, n - 1):
if p[i - 1] < p[i] and p[i] > p[i + 1]:
hills.append(i)
hills.append(n - 1)
length = []
prev = 0
for hill in hills:
length.append(hill - prev + 1)
prev = hill
ans = 0
for num in length:
ans += num * (num + 1) // 2
print(ans - len(hills) + 1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | for _ in range(int(input())):
n = int(input())
p = list(map(int, input().split()))
ans = 0
p[0] *= -1
count = 1
flag = 0
for i in range(1, n):
if -p[i] > p[i - 1]:
count += 1
p[i] *= -1
elif p[i] > p[i - 1]:
count += 1
else:
p[i - 1] *= -1
if -p[i] > p[i - 1]:
p[i] *= -1
count = (count + 1) * count // 2
if flag != 0:
count -= 1
flag += 1
ans += count
count = 2
count = (count + 1) * count // 2
if flag != 0:
count -= 1
ans += count
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | t = int(input())
while t != 0:
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(1)
else:
ord1 = [0] * (n - 1)
sum1 = 0
for i in range(0, n - 1):
if a[i] < a[i + 1]:
ord1[i] = 1
else:
ord1[i] = 0
cur = ord1[0]
j = 0
counts = [0] * n
counts[0] = 1
for i in range(0, n - 1):
if ord1[i] == cur:
counts[j] += 1
elif cur == 0:
cur = 1
counts[j] += 1
else:
j = j + 1
counts[j] = 2
cur = 0
k = 0
for i in range(0, n):
m = counts[i]
if m > 0:
sum1 += m * (m + 1) // 2
k = k + 1
k = k - 1
print(sum1 - k)
t = t - 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | for _ in range(int(input())):
N = int(input())
numbers = input().split()
for i in range(N):
numbers[i] = int(numbers[i])
counter = 0
initial = 1
count = 0
for i in range(N):
try:
if numbers[i] > numbers[i - 1] and numbers[i] > numbers[i + 1]:
counter += 1
order = i + 1
total = order - initial + 1
count += int(total * (total + 1) / 2)
initial = order
except IndexError:
pass
if counter == 0:
print(int(N * (N + 1) / 2))
else:
total = N - initial + 1
count += int(total * (total + 1) / 2)
count -= counter
print(count) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
An array A is called *weird* if it can be sorted in non-decreasing order by applying the given operation any number of times:
Select any index i (1 β€ i β€ |A|) and set A_{i} := -A_{i}.
For example: A = [2, 1, 3] is *weird* since after applying the operation at i = 1, A becomes [-2, 1, 3] which is sorted.
JJ has a permutation P of length N. He wants to find the number of subarrays of P which are *weird*. Can you help him?
------ Input Format ------
- The first line contains a single integer T β the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N β the size of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} denoting the permutation P.
------ Output Format ------
For each test case, output on a new line the number of *weird* subarrays of P.
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$P$ is a permutation.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
2 3 1
3
2 1 3
4
1 2 3 4
----- Sample Output 1 ------
5
6
10
----- explanation 1 ------
Test Case 1: Weird subarrays of $P$ are: $[2], [3], [1], [2, 3], [3, 1]$.
Test Case 2: Weird subarrays of $P$ are: $[2], [1], [3], [2, 1], [1, 3], [2, 1, 3]$. | s = int(input())
for i in range(0, s):
x = input()
n = list(map(int, input().split()))
dp = [[1, 1] for k in range(0, len(n))]
for k in range(1, len(n)):
if n[k] > n[k - 1]:
dp[k][0] = dp[k - 1][0] + 1
else:
dp[k][1] = dp[k - 1][1] + 1
dp[k][0] = dp[k][1]
c1 = 0
for i in range(0, len(n)):
x1 = max(dp[i])
c1 = c1 + x1
print(c1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | inputlist = list(map(int, input().split()))
m = inputlist[0]
k = inputlist[1]
def row(n):
if n == 1:
return 2
elif n == 2:
return 4
else:
i = 2
a = 2
b = 4
while i < n:
c = a + b
a = b
b = c
i += 1
return c
print((row(m) + row(k) - 2) % (10**9 + 7)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | n, m = map(int, input().split())
if n == 1 and m == 1:
print(2)
else:
k1 = max(n, m)
k2 = min(n, m)
l = [2] * k1
l[1] = 4
for i in range(2, k1):
l[i] = (l[i - 1] + l[i - 2]) % 1000000007
ans = l[k1 - 1]
for i in range(1, k2):
ans += (l[i] - l[i - 1]) % 1000000007
print(ans % 1000000007) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
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 \le n, m \le 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] | n, m = map(int, input().split())
modulo = 10**9 + 7
combs = 0
r = 1
r_next = 2
a = min(n, m)
b = max(n, m)
for i in range(3, a + 1):
r, r_next = r_next, (r + r_next) % modulo
combs += r_next if a > 1 else 1
for i in range(max(3, a + 1), b + 1):
r, r_next = r_next, (r + r_next) % modulo
combs += r_next if b > 1 else 1
combs -= 1
combs *= 2
print(combs % modulo) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
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 \le n, m \le 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] | from sys import stdin
height, width = map(int, stdin.readline().rstrip().split())
def fib(n):
if n < 2:
return n
a, b = [0, 1]
for i in range(0, n):
a, b = [b, a + b]
return a
def solve(height, width):
x = fib(width + 1) * 2
return (x - 2 + fib(height + 1) * 2) % (pow(10, 9) + 7)
print(solve(height, width)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR LIST VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
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 \le n, m \le 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] | def patate(l):
n = lst[0]
m = lst[1]
resultat = (fibo(n) + fibo(m) - 1) * 2
print(resultat % 1000000007)
def fibo(n):
if n == 0:
return 1
if n == 1:
return 1
if n % 2 == 0:
return fibo(n / 2) ** 2 + fibo(n / 2 - 1) ** 2
a = fibo((n - 1) / 2)
b = fibo((n - 1) / 2 - 1)
return a * (2 * b + a)
lst = list(map(int, input().split()))
patate(lst) | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER RETURN BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
a = []
for i in range(100001):
a.append(0)
a[0] = 0
a[1] = 2
a[2] = 4
for i in range(3, 100001):
a[i] = (a[i - 1] % 1000000007 + a[i - 2] % 1000000007) % 1000000007
print((a[n] % 1000000007 + a[m] % 1000000007 - 2) % 1000000007) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | from sys import stdin
input = stdin.readline
MOD = 1000000007
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) | ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | MOD = 1000000007
def fib(n):
a = b = 1
for _ in range(n):
a, b = b, (a + b) % MOD
return a
def main():
n, m = map(int, input().split())
print((fib(n) + fib(m) - 1) * 2 % MOD)
main() | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR |
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 \le n, m \le 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] | N = int(100000.0 + 3)
MOD = int(1000000000.0 + 7)
memo = [0] * N
def dp():
memo[0] = 2
memo[1] = 2
for i in range(2, N):
memo[i] = (memo[i - 1] + memo[i - 2]) % MOD
n, m = map(int, input().split())
dp()
print((memo[n] + -1 + memo[m] - 1) % MOD) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR |
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 \le n, m \le 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] | nm = 10**9 + 7
n, m = map(int, input().split())
mi = max(n, m)
fb = [0] * (mi + 2)
fb[1] = 1
for i in range(2, mi + 2):
fb[i] = (fb[i - 1] + fb[i - 2]) % nm
print(2 * (fb[n + 1] + fb[m + 1] - 1) % nm) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR |
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 \le n, m \le 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] | import sys
a, b = map(int, sys.stdin.readline().split())
pp = pow(10, 9) + 7
fib = [[0, 1], [1, 1]]
def MatDiv(a, b):
res = [[0, 0], [0, 0]]
res[0][0] = (a[0][0] * b[0][0] + a[0][1] * b[1][0]) % pp
res[0][1] = (a[0][0] * b[0][1] + a[0][1] * b[1][1]) % pp
res[1][0] = (a[1][0] * b[0][0] + a[1][1] * b[1][0]) % pp
res[1][1] = (a[1][0] * b[1][0] + a[1][1] * b[1][1]) % pp
return res
def BinPow(x, p):
if p == 1:
return fib
res = BinPow(x, p // 2)
if p % 2 == 0:
return MatDiv(res, res)
else:
return MatDiv(MatDiv(res, res), x)
tmp = BinPow(fib.copy(), a)
tmp2 = BinPow(fib.copy(), b)
print(((tmp[0][0] + tmp[0][1] + tmp2[0][0] + tmp2[0][1]) * 2 - 2) % pp) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER VAR |
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 \le n, m \le 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] | Mod = 1000000007
def f(x):
a = 0
b = 2
for i in range(x):
b = (a + b) % Mod
a = (b - a) % Mod
return b % Mod
n, m = map(int, input().split())
print((f(n) + f(m) - 2) % Mod) | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
dp0n = 1
dp1n = 1
dp0m = 1
dp1m = 1
dpn, dpm = 2, 2
for i in range(3, n + 1):
dp0n, dp1n, dpn = dp1n % 1000000007, dpn % 1000000007, (dpn + dp1n) % 1000000007
for i in range(3, m + 1):
dp0m, dp1m, dpm = dp1m % 1000000007, dpm % 1000000007, (dpm + dp1m) % 1000000007
if n == 1:
dpn = 1
if m == 1:
dpm = 1
print((dpm * 2 + dpn * 2 - 2) % 1000000007) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | n, m = [int(x) for x in input().split()]
p = 10**9 + 7
x = [0] * max(n, m)
x[0:1] = [1, 2]
for i in range(2, max(n, m)):
x[i] = (x[i - 1] + x[i - 2]) % p
print(2 * (x[n - 1] + x[m - 1] - 1) % p) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR |
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 \le n, m \le 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] | 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]) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
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 \le n, m \le 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] | n, m = map(int, input().split())
a = [0] * 10**6
Mod = int(pow(10, 9) + 7)
a[1], a[2] = 2, 4
for i in range(3, max(n, m) + 1):
a[i] = (a[i - 1] + a[i - 2]) % Mod
print((a[n] + a[m] - 2) % Mod, flush=False) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER |
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 \le n, m \le 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] | 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)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | n, m = map(int, input().split())
a = [0] * 100001
_, a[1], a[2], i = 1000000007, 2, 4, 3
while i <= max(n, m):
a[i] = a[i - 1] + a[i - 2]
i += 1
print((a[n] + a[m] - 2) % _) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR |
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 \le n, m \le 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] | n, m = [int(i) for i in input().split()]
def fib(n):
a, b = 1, 1
for i in range(n):
a, b = b, (a + b) % 1000000007
return a
res1 = 2 * (fib(n) + fib(m) - 1) % 1000000007
print(res1) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | n, m = list(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
) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR |
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 \le n, m \le 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] | 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] = sum(A[i - 2]) % mod
A[i][1] = sum(A[i - 1]) % mod
ans += sum(A[-1]) * 2 % mod
print((ans - 2) % mod) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR LIST VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER LIST NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR |
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 \le n, m \le 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] | M = 10**9 + 7
f = [1, 1, 2]
for i in range(1, 10**5 + 3):
f.append((f[-1] + f[-2]) % M)
n, m = map(int, input().split())
ans = 2 * f[n] % M
ans += 2 * (f[m] - 1)
ans %= M
print(ans) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | e = 10**9 + 7
n, m = map(int, input().split())
a = 0
b = 2
for i in range(n):
c = (a + b) % e
a = b
b = c
ans = b
a = 2
b = 2
for i in range(m - 1):
ans = (ans + a) % e
c = (a + b) % e
a = b
b = c
print(ans) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | mod = int(10**9 + 7)
n, m = map(int, input().split())
dp = [1, 1]
for x in range(2, max(n, m) + 1):
dp.append(0)
dp[x] = (dp[x - 1] + dp[x - 2]) % mod
sol = 2 * (dp[n] + dp[m] - 1) % mod % mod
print(sol) | ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | from sys import stdin
n, m = [int(i) for i in stdin.readline().strip().split()]
s = min(n, m)
t = max(n, m)
c = (t + 1) * [2]
for i in range(2, t + 1):
c[i] = c[i - 1] + c[i - 2]
res = c[t] + c[s] - 2
print(res % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | n, m = map(int, input().split())
l = list()
l.append(1)
l.append(1)
for i in range(2, 100001):
l.append((l[i - 2] + l[i - 1]) % (10**9 + 7))
print(2 * (l[n] + l[m] - 1) % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | n, m = map(int, input().split())
fib = [1, 1]
for i in range(max(n, m)):
fib.append(fib[-1] + fib[-2])
print(2 * (fib[n] + fib[m] - 1) % 1000000007) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER |
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 \le n, m \le 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] | M = 10**9 + 7
array = [0] * 100001
array[0] = 1
array[1] = 1
def fib(n):
if array[n] == 0:
array[n] = (fib(n - 1) + fib(n - 2)) % M
return array[n]
for i in range(1, 100001):
fib(i)
n, m = map(int, input().split())
print((array[n] + array[m] - 1) * 2 % M) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_DEF IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR |
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 \le n, m \le 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] | n, m = map(int, input().strip().split())
if n > m:
len = n
else:
len = m
f = [1, 1]
for i in range(len):
x = (f[i] + f[i + 1]) % 1000000007
f.append(x)
print((f[n] + f[m] - 1) * 2 % 1000000007) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
if n > m:
n, m = m, n
if n == 1 and m == 1:
print(2)
exit()
dp = [([0] * m) for _ in range(4)]
dp[0][1] = 1
dp[1][1] = 1
dp[2][1] = 1
dp[3][1] = 1
for i in range(2, m):
dp[0][i] += dp[2][i - 1]
dp[1][i] += dp[0][i - 1]
dp[1][i] += dp[2][i - 1]
dp[2][i] += dp[1][i - 1]
dp[2][i] += dp[3][i - 1]
dp[3][i] += dp[1][i - 1]
dp[0][i] %= MOD
dp[1][i] %= MOD
dp[2][i] %= MOD
dp[3][i] %= MOD
lr = 0
ud = 0
for i in range(4):
lr += dp[i][m - 1]
ud += dp[i][n - 1]
if n == 1:
print(lr % MOD)
exit()
else:
print((lr + ud - 2) % MOD) | IMPORT ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR |
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 \le n, m \le 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] | def mi():
return map(int, input().split())
mod = 10**9 + 7
n, m = mi()
a = 0
b = 2
n, m = min(m, n), max(m, n)
for i in range(m):
c = a + b
a = b
b = c
ba = b
b -= 2
a = 0
b = 2
for i in range(n):
c = a + b
a = b
b = c
ba += b - 2
ba %= mod
print(ba) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
dp = [0] * 100001
dp[0], dp[1] = 1, 1
MOD = 1000000007
for i in range(2, 100001):
dp[i] = (dp[i - 2] + dp[i - 1]) % MOD
print(2 * (dp[n] + dp[m] - 1) % MOD) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR |
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 \le n, m \le 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] | import sys
input = sys.stdin.readline
mod = 10**9 + 7
n, m = map(int, input().split())
dp = [1, 1]
for i in range(2, max(n, m) + 1):
dp.append((dp[i - 1] + dp[i - 2]) % mod)
print(2 * (dp[n] + dp[m] - 1) % mod) | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR |
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 \le n, m \le 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] | md = 10**9 + 7
n, m = map(int, input().split())
if n == 1 and m == 1:
print(2)
else:
a = [(0) for _ in range(max(n, m))]
a[0] = 2 % md
a[1] = 4 % md
for i in range(2, max(n, m)):
a[i] = (a[i - 1] + a[i - 2]) % md
b = [(0) for _ in range(n)]
b[0] = a[m - 1]
for i in range(1, n):
x = 0 if i <= 2 else i - 2
b[i] = (b[x] % md + a[i - 1]) % md
print(b[-1]) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER |
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 \le n, m \le 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] | ch = input()
L = [int(i) for i in ch.split()]
a = L[0]
b = L[1]
if a > b:
a, b = b, a
d = {(1): 1, (2): 0}
for i in range(1, b):
x = d[1]
y = d[2]
d[2] = x + y
d[1] = y
nb = d[1] + 2 * d[2]
d = {(1): 1, (2): 0}
for i in range(1, a):
x = d[1]
y = d[2]
d[2] = x + y
d[1] = y
nb2 = d[1] + 2 * d[2]
print(2 * (nb + nb2 - 1) % (10**9 + 7)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | a, b = map(int, input().split())
x, y = 0, 1
ans = 0
for i in range(a):
x, y = y, x + y
y %= 1000000007
x %= 1000000007
ans += y
x, y = 0, 1
for i in range(b):
x, y = y, x + y
y %= 1000000007
x %= 1000000007
ans += y
print((ans - 1) * 2 % 1000000007) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | 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) | FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
F = [(0) for _ in range(100005)]
F[1] = 1
F[2] = 2
for i in range(3, max(n, m) + 1):
F[i] = (F[i - 1] + F[i - 2]) % 1000000007
print((2 * (F[n] + F[m] - 1) + 1000000007) % 1000000007) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | l = [0] * (10**6 + 1)
l[2] = 2
mod = 10**9 + 7
n, m = [int(i) for i in input().split()]
for i in range(3, max(m, n) + 1):
l[i] = (l[i - 1] + l[i - 2]) % mod
res = 0
for i in range(n + 1):
res += l[i]
for j in range(m + 1):
res += l[j]
print((2 + res) % mod) | ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR |
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 \le n, m \le 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] | arr = [2, 4]
n, m = map(int, input().split(" "))
for i in range(2, max(n, m)):
arr.append(arr[i - 1] + arr[i - 2])
print((arr[n - 1] + arr[m - 1] - 2) % (10**9 + 7)) | ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | a = list(map(int, input().split()))
T = max(a[0], a[1])
tab = [(1) for k in range(T + 1)]
for k in range(2, T + 1):
tab[k] = (tab[k - 1] + tab[k - 2]) % int(1000000000.0 + 7)
print(2 * (tab[a[0]] + tab[a[1]] - 1) % int(1000000000.0 + 7)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER |
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 \le n, m \le 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] | mod = 10**9 + 7
def getAns(maxSide):
if maxSide == 1:
return 2
if maxSide == 2:
return 4
dpSide = [0] * maxSide
for i in range(len(dpSide)):
dpSide[i] = [0, 0]
dpSide[0] = [1, 1]
dpSide[1] = [2, 2]
f = True
for i in range(1, len(dpSide) - 1):
dpSide[i + 1][0] += dpSide[i][1]
dpSide[i + 1][1] += dpSide[i][0]
dpSide[i + 1][1] += dpSide[i - 1][0]
dpSide[i + 1][0] += dpSide[i - 1][1]
dpSide[i + 1][0] %= mod
dpSide[i + 1][1] %= mod
return sum(dpSide[maxSide - 1]) % mod
n, m = map(int, input().split())
print((getAns(n) + getAns(m) - 2) % mod) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR |
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 \le n, m \le 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] | def task_1(n, m):
counts = 8
last = 0
current = 1
fn = fm = None
for i in range(0, max(n, m) + 1):
if n == i:
fn = current
if m == i:
fm = current
last, current = current, last + current
counts = 2 * (fn + fm - 1)
print(counts % (10**9 + 7))
def __starting_point():
n, m = map(int, input().rstrip().split())
task_1(n, m)
__starting_point() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NONE FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
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 \le n, m \le 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] | import sys
input = sys.stdin.readline
def read_i():
return list(map(int, input().split()))
class Combinations:
def __init__(self, max_num, mod):
self.mod = mod
self.factorials = [1]
for i in range(1, max_num + 1):
self.factorials.append(self.factorials[-1] * i % mod)
self.invs = [pow(self.factorials[-1], mod - 2, mod)]
for i in reversed(range(1, max_num + 1)):
self.invs.append(self.invs[-1] * i % mod)
self.invs = self.invs[::-1]
def __call__(self, n, k):
return self.factorials[n] * self.invs[k] * self.invs[n - k] % self.mod
n, m = read_i()
MOD = 10**9 + 7
combinations = Combinations(max(n, m), MOD)
res = 0
for i in range(n // 2 + 1):
res += combinations(n - i, i)
res %= MOD
for i in range(m // 2 + 1):
res += combinations(m - i, i)
res %= MOD
res = 2 * (res - 1 + MOD) % MOD
print(res) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
md = 10**9 + 7
dp = [(-1) for i in range(10**5 + 1)]
dp[:3] = [0, 1, 2]
for i in range(3, 10**5 + 1):
dp[i] = (dp[i - 1] % md + dp[i - 2] % md) % md
print(2 * (dp[n] + dp[m] - 1) % md) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR |
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 \le n, m \le 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] | MOD = 1000000007
n, m = map(int, input().split())
L = [1, 2, 3, 5, 8, 14, 21, 34, 55, 89]
for i in range(n):
t = (L[-1] + L[-2]) % MOD
L.append(t % MOD)
dp = []
dp.append(L[n - 1] * 2 % MOD)
for i in range(2):
t = (dp[-1] + 2) % MOD
dp.append(t % MOD)
for i in range(m):
t1 = 2 * dp[-1] % MOD
t2 = dp[-3] % MOD
t = (t1 - t2) % MOD
dp.append(t % MOD)
print(dp[m - 1] % MOD) | ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR |
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 \le n, m \le 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] | P = 10**9 + 7
n, m = tuple([int(x) for x in input().split()])
mx = max(n, m)
vals = []
for i in range(mx):
if i == 0 or i == 1:
vals.append(i + 1)
else:
new_val = (vals[-1] + vals[-2]) % P
vals.append(new_val)
x = (vals[n - 1] + vals[m - 1]) % P
x = (x - 1) % P
x = x * 2 % P
print(x) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | dp = [int(0)] * 100005
n, m = map(int, input().split())
N = max(n, m)
dp[1], dp[2] = 2, 4
Mod = 10**9 + 7
for i in range(3, N + 1):
dp[i] = (dp[i - 1] + dp[i - 2]) % Mod
ans = dp[n]
for i in range(2, m + 1):
ans = (ans + dp[i] - dp[i - 1]) % Mod
ans = (ans + Mod) % Mod
print(ans) | ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | mod = 10**9 + 7
f = [1] * 100001
for i in range(2, 100001):
f[i] = (f[i - 1] + f[i - 2]) % mod
n, m = map(int, input().split())
print(2 * (f[n] + f[m] - 1) % mod) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR |
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 \le n, m \le 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] | def main():
mod = 1000000007
a = [1, 1, 1]
b = [1, 1, 1]
c = [1, 1, 1]
a[1] = 2
a[2] = 4
b[1] = 0
b[2] = 2
c[1] = 0
c[2] = 2
for i in range(3, 100001):
a.append(a[i - 1] + a[i - 2])
a[i] %= mod
b.append(b[i - 1] + b[i - 2])
b[i] %= mod
c.append((c[i - 1] + b[i]) % mod)
n, m = input().split()
n = int(n)
m = int(m)
print((a[n] + c[m]) % mod)
main() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR |
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 \le n, m \le 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] | class ModComb:
def __init__(self, MAX, mod=10**9 + 7):
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, MAX):
fac.append(fac[i - 1] * i % mod)
inv.append(mod - inv[mod % i] * (mod // i) % mod)
finv.append(finv[i - 1] * inv[i] % mod)
self.fac, self.finv, self.mod = fac, finv, mod
def nCk(self, n, k):
if n < k or n < 0 or k < 0:
return 0
fac, finv, mod = self.fac, self.finv, self.mod
return fac[n] * (finv[k] * finv[n - k] % mod) % mod
def main():
mod = 10**9 + 7
mc = ModComb(10**5 + 7)
N, M = map(int, input().split())
ans = 0
for i in range(1, N):
ans += mc.nCk(N - i, i) % mod
for i in range(1, M):
ans += mc.nCk(M - i, i) % mod
print((ans + 1) * 2 % mod)
main() | CLASS_DEF FUNC_DEF BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
mod = 10**9 + 7
if n == 1 and m == 1:
print(2)
exit()
if n == 1 and m == 2 or m == 1 and n == 2:
print(4)
exit()
if n == 2 and m == 2:
print(6)
exit()
add1 = 2
add2 = 4
add = [add1, add2]
for i in range(1, 200000):
add += [(add[i] + add[i - 1]) % mod]
if n > 2 and m == 1:
print(add[n - 1])
exit()
if n > 2 and m == 2:
print((add[n - 1] + 2) % mod)
exit()
if n == 1 and m > 2:
print(add[m - 1])
exit()
if n == 2 and m > 2:
print((add[m - 1] + 2) % mod)
exit()
n1 = 2
n2 = 4
n -= 2
for i in range(n):
nxt = n1 + n2
nxt %= mod
n1 = n2
n2 = nxt
m1 = n2 + 2
m -= 2
for i in range(m):
m1 = (m1 + add[i]) % mod
print(m1 % mod) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR LIST BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
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 \le n, m \le 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] | MOD = int(1000000000.0) + 7
N, M = map(int, input().split())
fib = [(0) for i in range(max(N, M) + 1)]
fib[0] = 1
fib[1] = 1
for i in range(2, max(N, M) + 1):
fib[i] = (fib[i - 1] + fib[i - 2]) % MOD
print(2 * (fib[N] + fib[M] - 1) % MOD) | ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR |
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 \le n, m \le 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] | a = input().split(" ")
x = int(a[0])
y = int(a[1])
n = 2
m = 2
A = 1000000000 + 7
while x > 1:
m = (m % A + n % A) % A
n = (m % A - n % A) % A
x -= 1
r1 = m
m = 2
n = 2
while y > 1:
m = (m % A + n % A) % A
n = (m % A - n % A) % A
y -= 1
r2 = m
print((r1 + r2 - 2) % A) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR |
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 \le n, m \le 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] | import sys
n, m = map(int, sys.stdin.readline().split())
f = [1, 1]
mod = 1000000007
for i in range(100000):
f.append(f[-1] + f[-2])
res = 2 * (f[n] + f[m] - 1)
res %= mod
print(res) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | MOD = 1000000007
n, m = list(map(int, input().split()))
mx = max(n, m)
dp = [0] * mx
dp[0] = 2
if mx >= 2:
dp[1] = 4
for i in range(2, mx):
dp[i] = (dp[i - 1] + dp[i - 2]) % MOD
ans = (dp[n - 1] + dp[m - 1] - 2) % MOD
print(int(ans)) | ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | from sys import stdin, stdout
for i in stdin:
n, m = list(map(int, i.strip().split()))
break
A = [1, 2]
B = [2, 4]
i, j = 0, 0
while 1:
if i and j:
break
if A[0] == m:
C = A[1]
i = 1
if A[0] == n:
D = A[1]
j = 1
A, B = B, [B[0] + 1, (A[1] + B[1]) % (10**9 + 7)]
stdout.write(str((C + D - 2) % (10**9 + 7))) | FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER IF VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | MOD = int(1000000000.0 + 7)
def f(n):
global MOD
li = [1, 2, 0]
for i in range(2, n):
li[i % 3] = li[(i - 1) % 3] + li[(i - 2) % 3] % MOD
return li[(n - 1) % 3]
n, m = map(int, input().split())
print(2 * (f(n) + f(m) - 1) % MOD) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR RETURN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR |
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 \le n, m \le 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] | R = lambda: list(map(int, input().split()))
n, m = R()
m1 = 100005
a = [0] * m1
a[1] = 1
a[0] = 1
p = 1000000007
for i in range(2, m1):
a[i] = (a[i - 1] + a[i - 2]) % p
print((a[n] - 1 + a[m]) * 2 % p) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
MOD = 10**9 + 7
ans = 2
tmp = [0] * 100010
tmp[1] = 2
tmp[2] = 2
dp = [([0] * 100010) for i in range(2)]
dp[1][1] = 2
dp[1][2] = 2
dp[0][2] = 2
for i in range(2, 100009):
dp[0][i + 1] = dp[1][i]
dp[1][i + 1] = dp[1][i] + dp[0][i]
dp[0][i + 1] %= MOD
dp[1][i + 1] %= MOD
sum_yoko = dp[0][m] + dp[1][m]
ans = sum_yoko - 2
sum_tate = dp[0][n] + dp[1][n]
ans += sum_tate
print(ans % MOD) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
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 \le n, m \le 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] | n, m = list(map(int, input().split()))
mod = 10**9 + 7
p1 = 2
p2 = 0
ans = 2
n -= 1
while n:
ans = (ans + p1) % mod
p1, p2 = (p1 + p2) % mod, p1
n -= 1
p1 = 2
p2 = 0
m -= 1
while m:
ans = (ans + p1) % mod
p1, p2 = (p1 + p2) % mod, p1
m -= 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
if n + m == 2:
print(2)
return
if n > m:
n, m = m, n
a, b, c, d = 1, 1, 1, 1
mod = 10**9 + 7
for i in range(2, m):
a, b, c, d = c, a + c, b + d, b
a %= mod
b %= mod
c %= mod
d %= mod
if n == 1:
print((a + b + c + d) % mod)
return
a1 = b1 = c1 = d1 = 1
for i in range(2, n):
a1, b1, c1, d1 = c1, a1 + c1, b1 + d1, b1
a1 %= mod
b1 %= mod
c1 %= mod
d1 %= mod
print((a + b + c + d + a1 + b1 + c1 + d1 - 2 + mod) % mod) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR |
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 \le n, m \le 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] | mod = 1000000000.0 + 7
n, m = list(map(int, input("").split()))
dp = [[[(-1) for i in range(3)] for j in range(3)] for k in range(100005)]
dp[1] = 2
dp[2] = 4
for i in range(3, max(n, m) + 2):
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
ans = int((dp[n] + dp[m] - 2) % mod)
print(ans) | ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | MOD = 10**9 + 7
def get(t, n):
if n == 1:
return t
a, b = t, 2 * t
for i in range(n - 2):
a, b = b, (a + b) % MOD
return b
n, m = map(int, input().split())
ans = 0
ans += get(2, n)
ans += get(2, m)
ans -= 2
print(ans % MOD) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
dp = [0] * 100001
dp[1], dp[2], mod = 1, 2, 10**9 + 7
if n < m:
n, m = m, n
for i in range(1, n + 1):
if i > 2:
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print((2 * (dp[n] + dp[m]) - 2) % mod) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR NUMBER VAR |
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 \le n, m \le 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] | import sys
def input():
return sys.stdin.readline().rstrip()
MOD = int(1000000000.0 + 7)
def slv():
n, m = map(int, input().split())
DP1 = [0] * (m + n)
DP2 = [([0] * 2) for i in range(m + n)]
DP1[0] = 2
DP2[0] = [0, 0]
for i in range(1, m + n):
DP1[i] = DP1[i - 1]
DP2[i][0] = (DP2[i - 1][0] + DP2[i - 1][1]) % MOD
DP2[i][1] = (DP2[i - 1][0] + DP1[i - 1]) % MOD
ans = sum(DP2[m - 1]) + sum(DP2[n - 1]) + 2
ans %= MOD
print(ans)
return
def main():
t = 1
for i in range(t):
slv()
return
main() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
modulo = 10**9 + 7
combs = 0
r = 1
r_next = 2
for i in range(3, n + 1):
r, r_next = r_next, (r + r_next) % modulo
combs += r_next if n > 1 else 1
c = 1
c_next = 2
for j in range(3, m + 1):
c, c_next = c_next, (c + c_next) % modulo
combs += c_next if m > 1 else 1
combs -= 1
combs *= 2
print(combs % modulo) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
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 \le n, m \le 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] | def fibonacci(n):
a, b = 0, 1
for i in range(n):
a, b = b, a + b
return a
n, m = list(map(int, input().split()))
print(2 * (fibonacci(m + 1) + fibonacci(n + 1) - 1) % 1000000007) | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | m, n = map(int, input().split())
t_1 = 2
t_2 = 4
if m >= 3:
for numbers in range(3, m + 1):
t_2_copy = t_2
t_2 = t_2 + t_1
t_1 = t_2_copy
x_1 = 2
x_2 = 4
if n >= 3:
for numbers in range(3, n + 1):
x_2_copy = x_2
x_2 = x_2 + x_1
x_1 = x_2_copy
if m >= 2 and n >= 2:
print((t_2 + x_2 - 2) % (10**9 + 7))
elif m == 1 and n != 1:
print((t_1 + x_2 - 2) % (10**9 + 7))
elif n == 1 and m != 1:
print((t_2 + x_1 - 2) % (10**9 + 7))
else:
print(2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER |
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 \le n, m \le 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] | m, n = list(map(int, input().split()))
mm = max(m, n)
dp = [0] * (mm + 1)
dp[0] = 1
dp[1] = 1
for i in range(2, mm + 1):
dp[i] = (dp[i - 1] + dp[i - 2]) % (10**9 + 7)
print((dp[m] + dp[n] - 1) * 2 % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | mod = 10**9 + 7
n, m = map(int, input().split())
a1, b1 = 0, 2
for h in range(n):
a1, b1 = b1, (a1 + b1) % mod
ans1 = b1
a1, b1 = 0, 2
for h in range(m):
ans1 = (ans1 + a1) % mod
a1, b1 = b1, (a1 + b1) % mod
print(ans1) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | from sys import stdin, stdout
def scal(typ=int):
return typ(stdin.readline())
def vec(typ=int):
if isinstance(typ, list):
inp = stdin.readline().split()
return [typ[i](inp[i]) for i in range(len(inp))]
else:
return list(map(typ, stdin.readline().split()))
n, m = vec()
p = 1000000007
a, b, res = 0, 1, 0
for i in range(1, max(m, n) + 1):
a, b = b, (a + b) % p
if i == m:
res = (res + b) % p
if i == n:
res = (res + b) % p
res -= 1
if res < 0:
res += p
res = res % p
res = 2 * res % p
print(res) | FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
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 \le n, m \le 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] | n, m = map(int, input().split())
mod = 1000000007
record = {}
a, b = 1, 1
for d in range(max(n, m) + 1):
a, b = b % mod, a + b
record[d + 1] = a
ans = record[n] + record[m] - 1
print(ans * 2 % mod) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR |
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 \le n, m \le 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] | Array = [0, 1]
def fibonacci(n):
a = 0
b = 1
if n == 0:
return a
elif n == 1:
return b
else:
for _ in range(2, n):
c = a + b
a = b
b = c
return b
n, m = list(map(int, input().split()))
print(2 * (fibonacci(n + 2) + fibonacci(m + 2) - 1) % 1000000007) | ASSIGN VAR LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | import sys
n, m = map(int, input().split())
if n < m:
n, m = m, n
if n == 1 and m == 1:
print(2)
elif n == 2 and m == 2:
print(6)
else:
md = 1000000007
def Fn(n):
a, b = 1, 1
for i in range(2, n + 1):
a, b = (a + b) % md, a
return a
print((2 * Fn(n) + 2 * Fn(m) - 2) % md) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER VAR |
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 \le n, m \le 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] | arr = [2, 4]
mod = 10**9 + 7
for i in range(100000):
arr.append((arr[-1] + arr[-2]) % mod)
n, m = list(map(int, input().split()))
print((arr[m - 1] + arr[n - 1] - 2) % mod) | ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR |
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 \le n, m \le 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] | a, b = map(int, input().split())
t = max(a, b)
j = min(a, b)
a, b = t, j
dp = [2, 4]
for i in range(2, a + 1):
dp.append(0)
if a < 3:
row = dp[a - 1]
else:
for i in range(2, a):
dp[i] = dp[i - 1] + dp[i - 2]
row = dp[a - 1]
if b - 2 < 0:
print(row % (10**9 + 7))
else:
print((row + dp[b - 1] - 2) % (10**9 + 7)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER |
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 \le n, m \le 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] | p = 1000000000 + 7
n, m = map(int, input().split())
k = n // 2
ans = 0
dp = [[0, 0] for i in range(max(3, max(m + 1, n + 1)))]
dp[2][0] = 1
dp[2][1] = 1
dp[1][1] = 1
for i in range(3, max(m + 1, n + 1)):
dp[i][0] = (dp[i - 2][0] + dp[i - 2][1]) % p
dp[i][1] = (dp[i - 1][1] + dp[i - 1][0]) % p
ans += 2 * ((dp[n][0] + dp[n][1]) % p) % p
ans += 2 * ((dp[m][0] + dp[m][1]) % p) % p
ans -= 2
print(ans % p) | ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
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 \le n, m \le 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] | m = 10**9 + 7
memo = {(1): 0, (2): 2}
def d(n):
if n not in memo:
memo[n] = (d(n - 1) + d(n - 2) + 2) % m
return memo[n]
for i in range(3, 100000):
d(i)
a, b = map(int, input().split())
i, j = 2, 4
p = 1
while p < a:
p += 1
i, j = j, (i + j) % m
start1 = i
i, j = 4, 6
p = 1
while p < a:
p += 1
i, j = j, (i + j - 2) % m
start2 = i
i, j = start1, start2
p = 1
while p < b:
p += 1
i, j = j, (i + j - d(a)) % m
print((i + m) % m) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR |
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 \le n, m \le 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] | mod = 1000000007
n, m = [int(x) for x in input().split()]
m1 = 2
m2 = 1
for x in range(n):
if x < 2:
pass
else:
m2, m1 = m1, (m2 + m1) % mod
doubles = m1 * 2 - 2
if n == 1:
doubles = 0
m1 = 2
m2 = 1
for col in range(m):
if col < 2:
pass
else:
m2, m1 = m1, (m2 + m1) % mod
singles = m1 * 2
if m == 1:
singles = 2
print((doubles + singles) % mod) | ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR |
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 \le n, m \le 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] | mod = 10**9 + 7
n, m = map(int, input().split())
dp = [[[0, 0] for j in range(2)] for i in range(m)]
dp[0] = [[1, 0], [1, 0]]
for i in range(m - 1):
for j in range(2):
for k in range(2):
if j == 0 and k == 0:
dp[i + 1][j][1] += dp[i][j][k]
dp[i + 1][j + 1][0] += dp[i][j][k]
elif j == 1 and k == 0:
dp[i + 1][j][1] += dp[i][j][k]
dp[i + 1][j - 1][0] += dp[i][j][k]
elif j == 0 and k == 1:
dp[i + 1][j + 1][0] += dp[i][j][k]
else:
dp[i + 1][j - 1][0] += dp[i][j][k]
for j in range(2):
for k in range(2):
dp[i + 1][j][k] %= mod
ans = -2
for j in range(2):
for k in range(2):
ans += dp[m - 1][j][k]
ans %= mod
dp2 = [[[0, 0] for j in range(2)] for i in range(n)]
dp2[0] = [[1, 0], [1, 0]]
for i in range(n - 1):
for j in range(2):
for k in range(2):
if j == 0 and k == 0:
dp2[i + 1][j][1] += dp2[i][j][k]
dp2[i + 1][j + 1][0] += dp2[i][j][k]
elif j == 1 and k == 0:
dp2[i + 1][j][1] += dp2[i][j][k]
dp2[i + 1][j - 1][0] += dp2[i][j][k]
elif j == 0 and k == 1:
dp2[i + 1][j + 1][0] += dp2[i][j][k]
else:
dp2[i + 1][j - 1][0] += dp2[i][j][k]
for j in range(2):
for k in range(2):
dp2[i + 1][j][k] %= mod
for j in range(2):
for k in range(2):
ans += dp2[n - 1][j][k]
ans %= mod
print(ans) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.