description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) A = list(map(int, input().strip().split())) L = [1] * len(A) R = [1] * len(A) Ans = [1] * len(A) for i in range(1, len(A)): if A[i] > A[i - 1]: L[i] = L[i] + L[i - 1] for i in range(len(A) - 1, 0, -1): if A[i - 1] < A[i]: R[i - 1] = R[i - 1] + R[i] Ans[-1] = L[-1] for i in range(1, len(A) - 1): if A[i - 1] < A[i + 1]: Ans[i] = max([L[i], L[i - 1] + R[i + 1]]) else: Ans[i] = L[i] print(max(Ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST 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 BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) f = input().split(" ") a = [int(f[i]) for i in range(0, n)] pred = [0] * n suc = [0] * n ans = 0 pred[0] = 1 for i in range(1, n): if a[i] > a[i - 1]: pred[i] = pred[i - 1] + 1 else: pred[i] = 1 ans = max(ans, pred[i]) suc[n - 1] = 1 i = n - 2 while i >= 0: if a[i + 1] > a[i]: suc[i] = suc[i + 1] + 1 else: suc[i] = 1 i -= 1 for i in range(1, n - 1): if a[i - 1] < a[i + 1]: ans = max(ans, pred[i - 1] + suc[i + 1]) print(ans, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL 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 FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) segs = [[a[0]]] for i in range(1, n): if segs[-1][-1] < a[i]: segs[-1].append(a[i]) else: segs.append([a[i]]) ret = len(segs[0]) for i in range(1, len(segs)): prev, cur = segs[i - 1], segs[i] ret = max(ret, len(cur)) if len(cur) > 1 and prev[-1] < cur[1] or len(prev) > 1 and prev[-2] < cur[0]: ret = max(ret, len(cur) + len(prev) - 1) print(ret)
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 LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [int(x) for x in input().split()] i = 1 d = [] maxi = 0 while i < n: c = 1 j = i while i < n and a[i] > a[i - 1]: i += 1 c += 1 d.append([c, j, i]) i += 1 maxi = max(maxi, d[-1][0]) for i in range(len(d) - 1): if ( a[d[i][2] - 2] < a[d[i + 1][1] - 1] or d[i + 1][1] != n and a[d[i][2] - 1] < a[d[i + 1][1]] ): maxi = max(maxi, d[i][0] + d[i + 1][0] - 1) print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [int(x) for x in input().split()] end = [0] * n beg = [0] * n for i in range(n): if i > 0 and a[i] > a[i - 1]: end[i] = end[i - 1] + 1 else: end[i] = 1 for i in reversed(range(n)): if i < n - 1 and a[i] < a[i + 1]: beg[i] = beg[i + 1] + 1 else: beg[i] = 1 best = max(beg) for i in range(n): if i == 0 or i == n - 1 or a[i - 1] < a[i + 1]: x = end[i - 1] if i > 0 else 0 y = beg[i + 1] if i < n - 1 else 0 if x + y > best: best = x + y print(best)
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 FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
N = int(input()) a = list(map(int, input().split())) dp_l = [0] * N dp_r = [0] * N for i in range(N): if a[i] > a[i - 1]: dp_l[i] = dp_l[i - 1] + 1 else: dp_l[i] = 1 dp_r[-1] = 1 for i in range(N - 2, -1, -1): if a[i] < a[i + 1]: dp_r[i] = dp_r[i + 1] + 1 else: dp_r[i] = 1 if dp_l[-1] == N: print(N) exit() ans = max(dp_l[-2], dp_r[1]) for i in range(1, N - 1): if a[i - 1] < a[i + 1]: ans = max(ans, dp_l[i - 1] + dp_r[i + 1]) else: ans = max(ans, dp_l[i - 1], dp_r[i + 1]) 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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR 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 NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = [int(i) for i in input().split()] def maxsub(a): inc = [[a[0]]] for x in a[1:]: if x > inc[-1][-1]: inc[-1].append(x) else: inc.append([x]) l = len(inc) for i in range(l - 1): if len(inc[i + 1]) == 1: if i + 2 < l: if inc[i][-1] < inc[i + 2][0]: inc[i] = inc[i] + inc[i + 2] else: can, can2 = inc[i], inc[i] if inc[i][-1] < inc[i + 1][1]: can = inc[i] + inc[i + 1][1:] if len(inc[i]) > 1: if inc[i][-2] < inc[i + 1][0]: can2 = inc[i][:-1] + inc[i + 1] if len(can) > len(can2): inc[i] = can else: inc[i] = can2 for i in range(len(inc)): inc[i] = len(inc[i]) return max(inc) print(maxsub(arr))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST LIST VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
d0 = [0] * 200010 d1 = [0] * 200010 d2 = [0] * 200010 n = int(input()) v = list(map(int, input().split())) d0[0] = 1 d1[0] = 0 d2[0] = 1 ans = 1 for i in range(1, n): d0[i] = 1 if v[i] > v[i - 1]: d0[i] = d0[i - 1] + 1 d2[i] = d2[i - 1] + 1 d1[i] = d0[i - 1] if i > 1 and v[i] > v[i - 2]: d2[i] = max(d2[i], d1[i - 1] + 1) ans = max(ans, max(max(d0[i], d1[i]), d2[i])) print(str(ans))
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER 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 NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys def rl(): return sys.stdin.readline() def compute(A, N): A.append(0) st = 0 n = A[0] l = [] for i, v in enumerate(A[1:]): if v <= n: l.append((st, i)) st = i + 1 n = v max1 = l[0][1] - l[0][0] + 1 for i in range(1, len(l)): if l[i][0] - l[i - 1][1] == 1: if ( l[i][1] - l[i][0] + 1 > 1 and A[l[i][0] + 1] > A[l[i - 1][1]] or l[i - 1][1] - l[i - 1][0] + 1 > 1 and A[l[i][0]] > A[l[i - 1][1] - 1] ): c = l[i][1] - l[i - 1][0] else: c = l[i][1] - l[i][0] + 1 else: c = l[i][1] - l[i][0] + 1 max1 = max(max1, c) print(max1) def main(): N = int(rl()) A = list(map(int, rl().split())) compute(A, N) main()
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF 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 VAR VAR EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) b = [] now = [] prev = 0 ans = 0 for i in range(n): if prev < a[i]: now.append(a[i]) else: b.append(now) ans = max(ans, len(now)) now = [a[i]] prev = a[i] if len(now) != 0: ans = max(ans, len(now)) b.append(now) for i in range(1, len(b)): if len(b[i - 1]) >= 2: if b[i - 1][-2] < b[i][0]: ans = max(ans, len(b[i]) + len(b[i - 1]) - 1) if len(b[i]) >= 2: if b[i][1] > b[i - 1][-1]: ans = max(ans, len(b[i]) + len(b[i - 1]) - 1) 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 LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split(" "))) listas = [[a[0]]] j = 0 for i in range(0, len(a) - 1): if a[i + 1] > a[i]: listas[j].append(a[i + 1]) else: j += 1 listas.append([]) listas[j].append(a[i + 1]) long = [] for i in range(0, len(listas)): long.append(len(listas[i])) for i in range(0, len(listas) - 1): if listas[i][len(listas[i]) - 2] < listas[i + 1][0]: long.append(len(listas[i]) + len(listas[i + 1]) - 1) elif len(listas[i + 1]) >= 2 and listas[i][len(listas[i]) - 1] < listas[i + 1][1]: long.append(len(listas[i]) + len(listas[i + 1]) - 1) print(max(long))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys RI = lambda: [int(x) for x in sys.stdin.readline().split()] ri = lambda: sys.stdin.readline().strip() mod = 10**7 + 1 n = int(ri()) a = RI() l = [1] * len(a) r = [1] * len(a) ans = -1 for i in range(1, len(a)): if a[i] > a[i - 1]: l[i] = l[i - 1] + 1 ans = max(ans, l[i]) for i in range(len(a) - 2, -1, -1): if a[i] < a[i + 1]: r[i] = 1 + r[i + 1] ans = max(ans, r[i]) for i in range(0, len(a) - 2): if a[i + 2] > a[i]: ans = max(ans, l[i] + r[i + 2]) print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = list(map(int, input().split())) l = [(1) for i in range(n)] r = [(1) for i in range(n)] for i in range(1, n): if arr[i] > arr[i - 1]: l[i] = l[i - 1] + 1 else: l[i] = 1 for i in range(n - 2, -1, -1): if arr[i] < arr[i + 1]: r[i] = r[i + 1] + 1 else: r[i] = 1 count = max(l) for i in range(n): if i == 0: leng = r[i + 1] if leng > count: count = leng elif i == n - 1: leng = l[i - 1] if leng > count: count = leng elif arr[i - 1] < arr[i + 1]: leng = l[i - 1] + r[i + 1] if leng > count: count = leng print(count)
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 ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER 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 FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) i = 0 b = [] while i < n: j = i + 1 l = 1 while j < n: if a[j] > a[j - 1]: l += 1 j += 1 else: break while i < j: b.append(l) i += 1 c = [] for i in range(1, n - 1): if a[i] <= a[i - 1] and a[i] <= a[i + 1]: c.append(i) if a[i] >= a[i - 1] and a[i] >= a[i + 1]: c.append(i) d = [] d.append(max(b)) for i in c: if a[i] <= a[i - 1] and a[i] <= a[i + 1]: if a[i + 1] > a[i - 1]: d.append(b[i - 1] + b[i + 1] - 1) if a[i] >= a[i - 1] and a[i] >= a[i + 1]: if a[i + 1] > a[i - 1]: d.append(b[i - 1] - 1 + b[i + 1]) print(max(d))
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 LIST WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST 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 IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().strip().split())) b = [[(1) for i in range(n)] for j in range(2)] if a[0] < a[1]: b[0][1] = 2 for i in range(2, n): d = 0 if a[i - 1] < a[i]: b[0][i] = b[0][i - 1] + 1 d = b[1][i - 1] + 1 c = 0 if a[i - 2] < a[i]: c = b[0][i - 2] + 1 b[1][i] = max(c, d) print(max(max(b[0]), max(b[1])))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
def process(A): answer = 1 n = len(A) current = [[A[0], A[0], 0, 0]] for i in range(1, n): if A[i] <= current[-1][1]: answer = max(answer, current[-1][3] - current[-1][2] + 1) current.append([A[i], A[i], i, i]) else: current[-1][1] = A[i] current[-1][3] = i answer = max(answer, current[-1][3] - current[-1][2] + 1) m = len(current) for i in range(m - 1): s1, e1, i1, i2 = current[i] s2, e2, j1, j2 = current[i + 1] if i2 > 0 and A[i2 - 1] < A[j1]: answer = max(answer, j2 - j1 + i2 - i1 + 1) if j1 < j2 and A[i2] < A[j1 + 1]: answer = max(answer, j2 - j1 + i2 - i1 + 1) for i in range(m - 2): s1, e1, i1, i2 = current[i] s2, e2, j1, j2 = current[i + 1] s3, e3, k1, k2 = current[i + 2] if j1 == j2 and A[i2] < A[k1]: answer = max(answer, k2 - k1 + 1 + i2 - i1 + 1) return answer n = int(input()) A = [int(x) for x in input().split()] print(process(A))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) inc = [] curinc = 1 curincmax = [] gap = 0 gaps = [] maxinc = 1 for i in range(1, n): if a[i] > a[i - 1]: if gap > 0: if gap == 1 and a[i - 1] > a[i - 3]: gaps.append(len(inc)) gap = 0 curinc += 1 else: gap += 1 inc.append(curinc) maxinc = max(curinc, maxinc) curinc = 1 inc.append(curinc) maxinc = max(curinc, maxinc) total = 0 special = 0 for e in range(len(inc)): each = inc[e] total += each if total + 1 < n and a[total - 1] < a[total + 1]: special = max(special, inc[e] + inc[e + 1] - 1) elif total - 2 >= 0 and total < n and a[total - 2] < a[total]: special = max(special, inc[e] + inc[e + 1] - 1) print(max(special, maxinc))
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 ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) l = [int(x) for x in input().split()] a = [] b = [] j = 0 last = 0 for i in l: if j < i: a.append(last + 1) last += 1 else: a.append(1) last = 1 j = i j = 10**10 last = 0 for i in range(n - 1, -1, -1): if l[i] < j: b.append(last + 1) last += 1 else: b.append(1) last = 1 j = l[i] b = b[::-1] end = a start = b m = max(max(end), max(start)) for i in range(1, n - 1): if l[i - 1] < l[i + 1]: m = max(m, end[i - 1] + start[i + 1]) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [int(i) for i in input().split()] ind = [0] * n temp = [] cnt = 0 count = 1 for i in range(1, n): if a[i] > a[i - 1]: count += 1 ind[i] = cnt else: temp.append(count) count = 1 cnt += 1 ind[i] = cnt temp.append(count) maxi = max(temp) for i in range(1, n - 2): if ind[i] != ind[i + 1]: if a[i - 1] < a[i + 1]: curr = temp[ind[i]] + temp[ind[i + 1]] - 1 maxi = max(curr, maxi) elif a[i] < a[i + 2]: curr = temp[ind[i]] + temp[ind[i + 1]] - 1 maxi = max(curr, maxi) print(maxi)
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 LIST 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 VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = list(map(int, input().split())) incLen = list() incS = list() tempAns = 1 last = arr[0] currS = 0 currLen = 1 for i in range(1, n): curr = arr[i] if curr > last: last = curr currLen += 1 else: tempAns = max(tempAns, currLen) incLen.append(currLen) incS.append(currS) last = arr[i] currS = i currLen = 1 tempAns = max(tempAns, currLen) incLen.append(currLen) incS.append(currS) for i in range(0, len(incLen) - 1): prevLast = arr[incS[i] + incLen[i] - 1] nextFirst = arr[incS[i + 1]] if incS[i] + incLen[i] - 2 >= 0 and incLen[i] >= 2: prevLLast = arr[incS[i] + incLen[i] - 2] if nextFirst > prevLLast: tempAns = max(tempAns, incLen[i] - 1 + incLen[i + 1]) if incLen[i + 1] >= 2: nextFFirst = arr[incS[i + 1] + 1] if nextFFirst > prevLast: tempAns = max(tempAns, incLen[i] + incLen[i + 1] - 1) print(tempAns)
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 ASSIGN 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 VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
N = int(input()) L = list(map(int, input().split())) dp = [([0] * 2) for _ in range(N)] dp[0][0] = 1 ans = 1 for i in range(1, N): if L[i - 1] < L[i]: dp[i][0] = dp[i - 1][0] + 1 dp[i][1] = dp[i - 1][1] + 1 if i >= 2 and L[i - 2] < L[i]: dp[i][1] = max(dp[i][1], dp[i - 2][0] + 1) ans = max(ans, dp[i][0], dp[i][1]) else: dp[i][0] = 1 dp[i][1] = dp[i - 2][0] + 1 if i >= 2 and L[i - 2] < L[i] else 0 ans = max(ans, dp[i][1]) 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 BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR 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 IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
def rint(): return int(input()) def rints(): return list(map(int, input().split())) n = rint() a = rints() rng = [] l = 0 for i in range(1, len(a)): if a[i] <= a[i - 1]: rng.append((l, i)) l = i rng.append((l, n)) mx = max(r - l for l, r in rng) for i in range(len(rng) - 1): l1, r1 = rng[i] l2, r2 = rng[i + 1] if r1 - l1 == 1 or r2 - l2 == 1: continue if a[r1 - 2] < a[l2] or a[r1 - 1] < a[l2 + 1]: mx = max(mx, r2 - l1 - 1) print(mx)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [int(i) for i in input().split()] left = [(0) for _ in range(n)] right = [(0) for _ in range(n)] for i in range(n): val = 0 if i - 1 >= 0 and a[i - 1] < a[i]: val = max(val, left[i - 1]) left[i] = 1 + val for i in range(n - 1, -1, -1): val = 0 if i + 1 < n and a[i] < a[i + 1]: val = max(val, right[i + 1]) right[i] = 1 + val val = 0 for i in range(1, n - 1): if a[i - 1] < a[i + 1]: val = max(val, left[i - 1] + right[i + 1]) for i in range(n): val = max(val, left[i]) print(val)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) dp = [[a[0]]] for i in range(1, n): if a[i] > a[i - 1]: dp[-1].append(a[i]) else: dp.append([a[i]]) maxm = 1 for x in dp: maxm = max(maxm, len(x)) m = len(dp) for i in range(m): if len(dp[i]) == 1: if i + 1 < m and i - 1 >= 0 and dp[i + 1][0] > dp[i - 1][-1]: maxm = max(len(dp[i - 1] + dp[i + 1], maxm)) else: if i > 0 and dp[i - 1][-1] < dp[i][1]: maxm = max(maxm, len(dp[i - 1]) + len(dp[i]) - 1) if i + 1 < m and dp[i][-2] < dp[i + 1][0]: maxm = max(maxm, len(dp[i]) + len(dp[i + 1]) - 1) print(maxm)
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 LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
def solve(): n = int(input()) a = list(map(int, input().split(" "))) l, r = [1] * n, [1] * n for i, v in enumerate(reversed(a)): if i > 0: l[i] = l[i - 1] + 1 if v < a[-i] else 1 l = list(reversed(l)) for i, v in enumerate(a): if i > 0: r[i] = r[i - 1] + 1 if v > a[i - 1] else 1 ans = max(l) for i in range(1, n - 1): if a[i - 1] < a[i + 1]: ans = max(ans, l[i + 1] + r[i - 1]) print(ans) solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) inc_seq = [] last = 0 for i in range(len(a)): if i == 0 or a[i] > a[i - 1]: continue else: inc_seq.append((last, i - 1, a[i - 1])) last = i inc_seq.append((last, len(a) - 1, a[-1])) maxList = list(map(lambda x: x[1] - x[0] + 1, inc_seq)) i = 0 j = 1 while j < len(inc_seq): try: if ( inc_seq[i][1] + 1 == inc_seq[j][0] and a[inc_seq[i][1] - 1] < a[inc_seq[j][0]] ): maxList.append(inc_seq[j][1] - inc_seq[i][0]) elif ( inc_seq[i][1] + 1 == inc_seq[j][0] and a[inc_seq[i][1]] < a[inc_seq[j][0] + 1] ): maxList.append(inc_seq[j][1] - inc_seq[i][0]) except: pass i += 1 j += 1 print(max(maxList))
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) b = [0] * n c = [0] * n cnt = 1 b[0] = 1 for i in range(1, n): if a[i - 1] < a[i]: cnt += 1 b[i] = cnt else: cnt = 1 b[i] = cnt cnt = 1 c[n - 1] = 1 for i in range(0, n - 1)[::-1]: if a[i] < a[i + 1]: cnt += 1 c[i] = cnt else: cnt = 1 c[i] = cnt ans = max(b) for i in range(1, n - 1): if a[i - 1] < a[i + 1]: ans = max(ans, b[i - 1] + c[i + 1]) 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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) f = [[1, 0] for i in range(200002)] use = [(False) for i in range(200002)] ans = 1 if a[1] > a[0]: f[1][0] = 2 ans = 2 for i in range(2, len(a)): u1 = 0 u2 = 0 v1 = 0 if a[i] > a[i - 1]: u1 = f[i - 1][0] u2 = f[i - 1][1] if a[i] > a[i - 2]: v1 = f[i - 2][0] f[i][0] += u1 f[i][1] = 1 + max(u2, v1) if f[i][1] == 1: f[i][1] = 0 ans = max(f[i][0], f[i][1], ans) 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 LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) A = list(map(int, input().split())) R = [1] * n L = [1] * n for i in reversed(range(n - 1)): if A[i] < A[i + 1]: R[i] = R[i + 1] + 1 for i in range(1, n): if A[i - 1] < A[i]: L[i] = L[i - 1] + 1 ans = max(L) for i in range(1, n - 1): if A[i - 1] < A[i + 1]: ans = max(ans, L[i - 1] + R[i + 1]) 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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) arr = [0] * n arr[0] = 1 temp = [-1] * n m = 1 for i in range(1, n): if a[i] > a[i - 1]: arr[i] += arr[i - 1] + 1 m = max(m, arr[i]) else: arr[i] = 1 if arr[n - 1] == 1: temp[n - 1] = n - 1 for i in range(n - 2, -1, -1): if arr[i] == 1: temp[i] = i else: temp[i] = temp[i + 1] if m == n: print(m) else: for i in range(1, n - 1): if a[i - 1] < a[i + 1]: p = n - 1 if i + 2 < n: if temp[i + 2] != -1: p = temp[i + 2] - 1 m = max(m, arr[i - 1] + (arr[p] - arr[i + 1] + 1)) print(m)
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 LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = [int(x) for x in input().split()] if n is 2: print(2 if arr[1] > arr[0] else 1) exit() l = [0] * (n + 1) r = [0] * (n + 1) l[0] = 1 r[n - 1] = 1 for i in range(1, n): l[i] = l[i - 1] + 1 if arr[i] > arr[i - 1] else 1 for i in range(n - 2, -1, -1): r[i] = r[i + 1] + 1 if arr[i] < arr[i + 1] else 1 ans = max(max(l), max(r)) for i in range(1, n - 1): if arr[i - 1] < arr[i + 1]: ans = max(ans, l[i - 1] + r[i + 1]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = list(map(int, input().split())) inc = [] count = 1 start = 0 if len(arr) == 1: print(1) else: for i in range(1, len(arr)): if arr[i] > arr[i - 1]: count += 1 else: if i - start != 1: inc.append([start, i - 1, i - start]) start = i count = 0 if i - start + 1 > 1: inc.append([start, i, i - start + 1]) if inc: m = inc[0][2] else: m = 1 for i in range(1, len(inc)): if inc[i][0] - inc[i - 1][1] - 1 == 1: if arr[inc[i][0]] > arr[inc[i - 1][1]]: m = max(m, inc[i][2] + inc[i - 1][2]) elif inc[i][0] - inc[i - 1][1] - 1 == 0: if arr[inc[i][0]] > arr[inc[i - 1][1] - 1]: m = max(m, inc[i][2] + inc[i - 1][2] - 1) elif arr[inc[i][0] + 1] > arr[inc[i - 1][1]]: m = max(m, inc[i][2] + inc[i - 1][2] - 1) m = max(m, inc[i][2]) print(m)
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) A = list(map(int, input().split())) I = [(0) for _ in range(n)] D = [(0) for _ in range(n)] for i in range(n): if i == 0: I[i] = 1 elif A[i] > A[i - 1]: I[i] = I[i - 1] + 1 else: I[i] = 1 for i in range(n - 1, -1, -1): if i == n - 1: D[i] = 1 elif A[i] < A[i + 1]: D[i] = D[i + 1] + 1 else: D[i] = 1 res = max(D) for i in range(1, n - 1): if A[i - 1] < A[i + 1]: res = max(res, I[i - 1] + D[i + 1]) print(res)
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 VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER 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 FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) hehe = [(1) for i in range(n)] lol = [(1) for i in range(n)] for i in range(1, n): if a[i] > a[i - 1]: hehe[i] = 1 + hehe[i - 1] for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: lol[i] = 1 + lol[i + 1] mx = 0 for i in range(1, n - 1): if a[i - 1] < a[i + 1]: mx = max(mx, hehe[i - 1] + lol[i + 1]) else: mx = max(mx, hehe[i - 1], lol[i + 1]) xx = max(hehe) print(max(mx, xx))
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 ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) list1 = list(map(int, input().split())) left = [] right = [] for i in range(n): left.append(1) right.append(1) for i in range(1, n): if list1[i] > list1[i - 1]: left[i] = left[i - 1] + 1 for i in range(n - 2, -1, -1): if list1[i] < list1[i + 1]: right[i] = right[i + 1] + 1 maxi = 0 if max(left) > max(right): maxi = max(left) else: maxi = max(right) for i in range(n - 2): if list1[i] < list1[i + 2]: maxi = max(maxi, left[i] + right[i + 2]) print(maxi)
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [-1] + list(map(int, input().split())) cur = 0 l = [0] * n m = [0] * n for i in range(1, n + 1): if a[i] > a[i - 1]: cur += 1 else: cur = 1 l[i - 1] = cur cur = n - 1 num = l[cur] while cur >= 0: m[cur] = num if l[cur] == 1: num = l[cur - 1] cur -= 1 res = max(m) a = a[1:] for i in range(1, n - 1): if l[i - 1] + 2 != l[i + 1] and a[i - 1] < a[i + 1]: res = max(res, m[i - 1] + m[i + 1] - 1) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) mass = list(map(int, input().split())) left = [1] * n right = [1] * n for i in range(1, n): if mass[i] > mass[i - 1]: left[i] = left[i - 1] + 1 for i in range(n - 2, -1, -1): if mass[i] < mass[i + 1]: right[i] = right[i + 1] + 1 mx = 1 for i in range(n): if i == 0: mx = max(right[0], mx) elif i == n - 1: mx = max(mx, left[n - 1]) elif mass[i + 1] > mass[i - 1]: mx = max(mx, left[i - 1] + right[i + 1]) mx = max(mx, left[i]) mx = max(mx, right[i]) print(mx)
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 LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
class X: def __init__(self, d): self.start = d self.end = d self.before_end = d self.after_start = d self.size = 1 def add(self, d): self.before_end = self.end if self.after_start == self.start: self.after_start = d self.end = d self.size += 1 def compare(a, b): res = [a.size, b.size] if a.before_end < b.start or a.end < b.after_start: res.append(a.size + b.size - 1) return max(res) n = int(input()) arr = [int(x) for x in input().split()] l = [X(arr[0])] l_index = 0 for i in range(1, n): if arr[i] > l[l_index].end: l[l_index].add(arr[i]) else: l_index += 1 l.append(X(arr[i])) res = l[0].size for i in range(len(l) - 1): res = max(res, compare(l[i], l[i + 1])) print(res)
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN 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 LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
from sys import stdin, stdout cin = stdin.readline cout = stdout.write n = int(cin()) a = list(map(int, cin().split())) length = i = 1 k = 0 x = [1] while i < n: j = i while j < n: if a[j] > a[j - 1]: j += 1 x.append(j - i + 1) else: x.append(1) break i = j + 1 x.append(1) length = max(x) lst = [] for i in range(1, n + 1): if x[i] == 1: lst.append(i) for i in range(len(lst) - 1): if lst[i] >= n - 1: break if a[lst[i] + 1] > a[lst[i] - 1]: length = max(length, x[lst[i + 1] - 1] + x[lst[i] - 1] - 1) if lst[i] - 2 >= 0 and a[lst[i]] > a[lst[i] - 2]: length = max(length, x[lst[i + 1] - 1] + x[lst[i] - 2]) cout(str(length))
ASSIGN VAR VAR ASSIGN VAR 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER WHILE VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [int(o) for o in input().split()] arr = [1] * n upto = [1] * n c = 1 for i in range(1, n): flag = 0 if a[i - 1] < a[i]: c += 1 else: flag = 1 for j in range(i - c, i): arr[j] = c c -= 1 c = 1 upto[i] = c if i == n - 1 and flag == 0: for j in range(i - c + 1, i): arr[j] = c c -= 1 ca = max(arr) for i in range(1, n - 1): if a[i - 1] < a[i + 1]: ca = max(ca, upto[i - 1] + arr[i + 1]) print(ca)
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) + [0] seq = [] cur_start = 0 prev = 0 for i, x in enumerate(a): if prev < x: pass else: seq.append((cur_start, i)) cur_start = i prev = x best = max([(r - l) for l, r in seq]) for (l1, r1), (l2, r2) in zip(seq, seq[1:]): if a[l2 - 1] < a[l2 + 1]: best = max(best, r2 - l1 - 1) if a[l2 - 2] < a[l2]: best = max(best, r2 - l1 - 1) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
def solve(n, ar): r = [1] * n l = [1] * n ans = 0 for i in range(n - 2, -1, -1): if ar[i] < ar[i + 1]: r[i] = r[i + 1] + 1 ans = max(ans, r[i]) for i in range(1, n): if ar[i] > ar[i - 1]: l[i] = l[i - 1] + 1 ans = max(ans, l[i]) for i in range(n - 2): if ar[i] < ar[i + 2]: ans = max(ans, l[i] + r[i + 2]) print(ans) n = int(input()) ar = list(map(int, input().split())) solve(n, ar)
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR 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 EXPR FUNC_CALL VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) lr = [0] * n lr[-1] = 1 for i in range(n - 1)[::-1]: if a[i] < a[i + 1]: lr[i] = lr[i + 1] + 1 else: lr[i] = 1 rl = [0] * n rl[0] = 1 for i in range(n - 1): if a[i] < a[i + 1]: rl[i + 1] = rl[i] + 1 else: rl[i + 1] = 1 ans = max(max(lr), max(rl)) for i in range(1, n - 1): left = rl[i - 1] right = lr[i + 1] if a[i - 1] < a[i + 1]: ans = max(left + right, ans) print(ans)
IMPORT ASSIGN VAR 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 LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = list(map(int, input().split())) dp = [1] * n for i in range(1, n): if arr[i] > arr[i - 1]: dp[i] = dp[i - 1] + 1 ds = [1] * n for i in range(n - 2, -1, -1): if arr[i] < arr[i + 1]: ds[i] = ds[i + 1] + 1 ys = 0 for i in range(1, n - 1): if arr[i - 1] < arr[i + 1]: xs = dp[i - 1] + ds[i + 1] ys = max(ys, xs) print(max(ys, max(dp)))
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 LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) A = [int(x) for x in input().split()] B = [0] * n k = 0 K = [1] for i in range(1, n): if A[i - 1] >= A[i]: k += 1 K.append(0) K[k] += 1 B[i] = k m = max(K) if n > 2: for i in range(1, n - 1): mm = K[B[i - 1]] + K[B[i + 1]] if K[B[i]] == 1: if A[i - 1] < A[i + 1]: mm = K[B[i - 1]] + K[B[i + 1]] m = max(mm, m) elif B[i - 1] < B[i + 1] and A[i - 1] < A[i + 1]: m = max(mm - 1, m) print(m)
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 NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) dp = [1] for i in range(1, n): if a[i - 1] < a[i]: dp.append(dp[i - 1] + 1) else: dp.append(1) dp2 = [1] * n for i in range(n - 2, -1, -1): if a[i + 1] > a[i]: dp2[i] = dp2[i + 1] + 1 ans = max(dp) for i in range(n - 2): if a[i] < a[i + 2]: ans = max(ans, dp[i] + dp2[i + 2]) print(ans)
IMPORT ASSIGN VAR 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) s = input() l = list(map(int, s.split())) records = [] current = 1 for i in range(1, len(l)): if l[i - 1] < l[i]: current += 1 if l[i - 1] >= l[i]: records.append(current) append0 = False if i > 1 and l[i] <= l[i - 2]: append0 = True if i < len(l) - 1 and l[i - 1] < l[i + 1]: append0 = False if append0: records.append(0) current = 1 records.append(current) mx = records[0] for i in range(1, len(records)): mx = max(mx, records[i] + records[i - 1] - 1, records[i]) print(mx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
x = input() a = list(map(int, input().split())) m, clast, cnow = 1, 0, 1 last = 1 for i in range(1, len(a)): if a[i] > a[i - 1]: cnow += 1 m = max(m, cnow) else: if clast > 1 and cnow > 1: if a[last - 1] < a[last + 1] or a[last] < a[last + 2]: m = max(m, clast + cnow - 1) if cnow > 1: last = i - 1 clast = cnow else: clast = 0 cnow = 1 if clast > 1 and cnow > 1: if a[last - 1] < a[last + 1] or a[last] < a[last + 2]: m = max(m, clast + cnow - 1) print(m)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input().strip()) a = [int(j) for j in input().strip().split()] a.append(0) b = [a[0]] r = [] for i in range(len(a) - 1): left = a[i] right = a[i + 1] if right > left: b.append(right) else: r.append(b) b = [a[i + 1]] def find_len(list1, list2, list3): max_len = max(len(list1), len(list2), len(list3)) if len(list2) == 1: if list1[-1] < list3[0]: max_len = len(list1) + len(list3) else: if list2[1] > list1[-1]: m_len = len(list1) + len(list2) - 1 if m_len > max_len: max_len = m_len if len(list1) >= 2: if list1[-2] < list2[0]: m_len = len(list1) + len(list2) - 1 if m_len > max_len: max_len = m_len if list2[-2] < list3[0]: m_len = len(list3) + len(list2) - 1 if m_len > max_len: max_len = m_len if len(list3) >= 2: if list3[1] > list2[-1]: m_len = len(list3) + len(list2) - 1 if m_len > max_len: max_len = m_len return max_len res = 0 if len(r) < 3: r.extend([[0], [0]]) for mi in range(len(r) - 2): l1 = r[mi] l2 = r[mi + 1] l3 = r[mi + 2] mr = find_len(l1, l2, l3) if mr > res: res = mr print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) l = [] c = 0 c1 = 0 for i in range(1, n): if a[i] > a[i - 1]: c1 += 1 else: l.append([c, c1]) c = c1 + 1 c1 += 1 l.append([c, c1]) m = 1 for i in l: m = max(m, i[1] - i[0] + 1) for i in range(1, len(l)): if l[i][0] != l[i][1] and l[i - 1][0] != l[i - 1][1]: if a[l[i - 1][1] - 1] < a[l[i][0]]: m = max(m, l[i - 1][1] - l[i - 1][0] + l[i][1] - l[i][0] + 1) elif a[l[i][0] + 1] > a[l[i - 1][1]]: m = max(m, l[i - 1][1] - l[i - 1][0] + l[i][1] - l[i][0] + 1) print(m)
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [int(_) for _ in input().split()] l1 = [] l2 = [a[0]] l3 = [] for i in range(1, n): if a[i] > a[i - 1]: l2.append(a[i]) else: l1.append(l2[:]) l2.clear() l2.append(a[i]) l1.append(l2) for i in l1: l3.append(len(i)) max_ = max(l3) for i in range(1, len(l3) - 1): if l3[i] == 1 and l1[i - 1][-1] < l1[i + 1][0] and l3[i - 1] + l3[i + 1] > max_: max_ = l3[i - 1] + l3[i + 1] for i in range(len(l3) - 1): shit = 0 if l3[i] > 1 and l3[i + 1] > 1: if l1[i][-2] < l1[i + 1][0]: shit = l3[i] + l3[i + 1] - 1 elif l1[i][-1] < l1[i + 1][1]: shit = l3[i] + l3[i + 1] - 1 if shit > max_: max_ = shit print(max_)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) pref = [0] * n suff = [0] * n pref[0] = 1 suff[-1] = 1 l = 0 r = n - 1 for i in range(1, n): if a[i] > a[i - 1]: pref[i] = i - l + 1 else: l = i pref[i] = 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: suff[i] = r - i + 1 else: r = i suff[i] = 1 ans = max(pref) for i in range(n): if i == 0: ans = max(ans, suff[1]) elif i == n - 1: ans = max(ans, pref[n - 2]) elif a[i - 1] < a[i + 1]: ans = max(ans, pref[i - 1] + suff[i + 1]) 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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) max_length = 0 curr_length = 0 prev_length = 0 curr_first, curr_second = None, None curr_last, curr_prelast = None, None prev_last, prev_prelast = None, None prev = 0 seq = list(map(int, input().split())) for i in range(n): curr = seq[i] if curr > prev: curr_length += 1 if curr_length == 1: curr_first = curr elif curr_length == 2: curr_second = curr curr_prelast, curr_last = curr_last, curr if curr <= prev or i == n - 1: if prev_length <= 1 or curr_length <= 1: max_length = max(max_length, curr_length, prev_length) elif curr_first > prev_prelast or curr_second > prev_last: max_length = max(max_length, curr_length + prev_length - 1) else: max_length = max(max_length, curr_length, prev_length) prev_length, curr_length = curr_length, 1 prev_last, prev_prelast = curr_last, curr_prelast curr_first, curr_second = curr, None curr_last, curr_prelast = curr, None prev = curr print(max_length)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NONE NONE ASSIGN VAR VAR NONE NONE ASSIGN VAR VAR NONE NONE ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NONE ASSIGN VAR VAR VAR NONE ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys reader = (line.rstrip() for line in sys.stdin) input = reader.__next__ n = int(input()) a = list(map(int, input().split())) segm = [] st = 0 for i in range(1, n): if a[i - 1] >= a[i]: if i - 1 > st: segm.append((st, i - 1)) st = i if n - 1 > st: segm.append((st, n - 1)) if not segm: print(1) sys.exit() elif len(segm) == 1: print(segm[0][1] - segm[0][0] + 1) sys.exit() maxSegm = max(segm, key=lambda x: x[1] - x[0]) currMax = maxSegm[1] - maxSegm[0] + 1 for i in range(len(segm)): st0, en0 = segm[i - 1] st1, en1 = segm[i] if en0 + 2 == st1 and a[en0] < a[st1]: currMax = max(currMax, en1 - st0) elif en0 + 1 == st1 and (a[en0] < a[st1 + 1] or a[en0 - 1] < a[st1]): currMax = max(currMax, en1 - st0) print(currMax)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
input() nums = list(map(int, input().split())) n = len(nums) pure = [0] * n skipped = [0] * n pure[0] = 1 skipped[0] = 1 pure[1] = 2 if nums[0] < nums[1] else 1 skipped[1] = 1 for i in range(2, n): if nums[i] > nums[i - 1]: pure[i] = 1 + pure[i - 1] skipped[i] = 1 + skipped[i - 1] if nums[i] > nums[i - 2]: skipped[i] = max(skipped[i], 1 + pure[i - 2]) else: pure[i] = 1 if nums[i] > nums[i - 2]: skipped[i] = 1 + pure[i - 2] else: skipped[i] = 1 print(max(max(pure), max(skipped)))
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys input = sys.stdin.readline def main(): N = int(input()) A = [int(x) for x in input().split()] AX = [] for i in range(N): if i == 0: AX.append(1) elif A[i] > A[i - 1]: AX.append(AX[i - 1] + 1) else: AX.append(1) BX = [1] * N for i in range(N - 1, -1, -1): if i == N - 1: BX[i] = 1 elif A[i + 1] > A[i]: BX[i] = BX[i + 1] + 1 else: BX[i] = 1 ans = max(AX) for i in range(N): if i == 0 or i == N - 1: continue if A[i - 1] < A[i + 1]: ans = max(ans, AX[i - 1] + BX[i + 1]) print(ans) main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
from sys import stdin, stdout outputs = [] n = int(stdin.readline().strip()) arr = [int(num) for num in stdin.readline().strip().split()] req = [] l, r = 0, 0 for i in range(n - 1): if arr[i] < arr[i + 1]: r += 1 else: req.append([l, r]) l = i + 1 r = i + 1 if l == n - 1: req.append([n - 1, n - 1]) else: req.append([l, r]) res = 1 for i in range(len(req)): res = max(res, req[i][1] - req[i][0] + 1) prev1, next1 = None, None prev2, next2 = None, None tot1, tot2 = 0, 0 for i in range(len(req)): prev1, next1 = req[i][0] - 1, req[i][0] + 1 prev2, next2 = req[i][1] - 1, req[i][1] + 1 tot1, tot2 = 0, 0 if prev1 == -1 or next1 == n: pass elif arr[prev1] < arr[next1]: tot1 += req[i - 1][1] - req[i - 1][0] + 1 if next1 > req[i][1]: tot1 += req[i + 1][1] - req[i + 1][0] + 1 else: tot1 += req[i][1] - req[i][0] res = max(res, tot1) else: pass if prev2 == -1 or next2 == n: pass elif arr[prev2] < arr[next2]: tot2 += req[i + 1][1] - req[i + 1][0] + 1 if prev2 < req[i][0]: tot2 += req[i - 1][1] - req[i - 1][0] + 1 else: tot2 += req[i][1] - req[i][0] res = max(res, tot2) else: pass print(res)
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NONE NONE ASSIGN VAR VAR NONE NONE ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
def solve(arr, n): if n == 1: return 1 if n == 2: if arr[1] > arr[0]: return 2 else: return 1 dp = list() org = list() curr = 1 org.append(1) for i in range(1, n): if arr[i] > arr[i - 1]: curr += 1 org.append(curr) else: curr = 1 org.append(curr) dp.append(org[0]) dp.append(org[1]) for i in range(2, n): if arr[i] > arr[i - 2]: if arr[i] > arr[i - 1]: dp.append(max(dp[i - 1] + 1, org[i - 2] + 1)) else: dp.append(max(org[i], org[i - 2] + 1)) elif arr[i] > arr[i - 1]: dp.append(dp[i - 1] + 1) else: dp.append(org[i]) return max(dp) n = int(input()) arr = list(map(int, input().split())) print(solve(arr, n))
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
input() A, B, C = [int(_) for _ in input().split()], [1], [1] for i in range(1, len(A)): if A[i] > A[i - 1]: B.append(B[-1] + 1) C.append(C[-1] + 1) else: B.append(1) C.append(1) if i >= 2 and A[i] > A[i - 2]: C[-1] = max(C[-1], B[i - 2] + 1) print(max(*B, *C))
EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = list(map(int, input().split())) incs = [1] decs = [1] inc = 1 dec = 1 ans = 0 for i in range(1, n): if arr[i] > arr[i - 1]: inc += 1 else: inc = 1 incs.append(inc) ans = max(ans, inc) if arr[n - i] > arr[n - i - 1]: dec += 1 else: dec = 1 decs.append(dec) decs.reverse() for i in range(1, n - 1): if arr[i - 1] < arr[i + 1]: ans = max(ans, incs[i - 1] + decs[i + 1]) else: ans = max(ans, incs[i - 1], decs[i + 1]) 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 LIST NUMBER ASSIGN VAR LIST NUMBER 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 EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) incseq = [0] seq = list(map(int, input().split())) incseq[0] = [seq[0]] for i in range(1, len(seq)): if seq[i] > seq[i - 1]: incseq[-1].append(seq[i]) else: incseq.append([seq[i]]) seqLen = max(len(k) for k in incseq) for i in range(1, len(incseq) - 1): if len(incseq[i]) == 1: if incseq[i - 1][-1] < incseq[i + 1][0]: seqLen = max(seqLen, len(incseq[i - 1]) + len(incseq[i + 1])) else: if incseq[i - 1][-1] < incseq[i][1]: seqLen = max(seqLen, len(incseq[i - 1]) + len(incseq[i]) - 1) if incseq[i][-2] < incseq[i + 1][0]: seqLen = max(seqLen, len(incseq[i + 1]) + len(incseq[i]) - 1) if len(incseq) >= 2: if len(incseq[0]) != 1: if incseq[0][-2] < incseq[1][0]: seqLen = max(seqLen, len(incseq[1]) + len(incseq[0]) - 1) if len(incseq[-1]) != 1: if incseq[-2][-1] < incseq[-1][1]: seqLen = max(seqLen, len(incseq[-2]) + len(incseq[-1]) - 1) print(seqLen)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
def solve(lst): dp = [[1, 1] for _ in range(len(lst))] val = 0 for i in range(1, len(lst)): if lst[i] > lst[i - 1]: dp[i][0] = max(dp[i - 1][0] + 1, dp[i][0]) dp[i][1] = max(dp[i - 1][1] + 1, dp[i][1]) if i > 1 and lst[i] > lst[i - 2]: dp[i][1] = max(dp[i - 2][0] + 1, dp[i][1]) val = max(val, dp[i][0], dp[i][1]) return val n = input() lst = list(map(int, list(input().split()))) print(solve(lst))
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) l = list(map(int, input().split())) x = 1 l1 = [1] * n l1[0] = 1 ans = 1 temp = 1 for i in range(1, n): if l[i] > l[i - 1]: ans += 1 temp = max(temp, ans) else: ans = 1 ans = temp for i in range(1, n): if l[i] > l[i - 1]: l1[i] = l1[i - 1] + 1 else: l1[i] = x l2 = [1] * n l2[n - 1] = 1 for i in range(n - 2, -1, -1): if l[i] < l[i + 1]: l2[i] = l2[i + 1] + 1 else: l2[i] = x for i in range(1, n - 1): if l[i + 1] > l[i - 1]: ans = max(ans, l1[i - 1] + l2[i + 1]) 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN 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 ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL 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 VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) ai = list(map(int, input().split())) ans = [([0] * n) for i in range(4)] ans[0][0] = 1 ans[1][0] = ai[0] for i in range(1, n): if ans[1][i - 1] < ai[i] and ans[3][i - 1] < ai[i]: ans[0][i] = ans[0][i - 1] + 1 ans[1][i] = ai[i] ans[2][i] = ans[2][i - 1] + 1 ans[3][i] = ai[i] elif ans[1][i - 1] < ai[i]: ans[0][i] = ans[0][i - 1] + 1 ans[1][i] = ai[i] ans[2][i] = ans[0][i] - 1 ans[3][i] = ai[i] else: if i > 1 and ans[1][i - 2] < ai[i]: ans[3][i] = ai[i] else: ans[3][i] = ans[1][i - 1] ans[2][i] = ans[0][i - 1] ans[0][i] = 1 ans[1][i] = ai[i] print(max(max(ans[2]), max(ans[0])))
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 LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) dp1 = [(0) for i in range(n + 1)] dp2 = [(0) for i in range(n + 1)] dp1[1] = 1 for i in range(2, n + 1): if a[i - 1] > a[i - 2]: dp1[i] = dp1[i - 1] + 1 else: dp1[i] = 1 dp2[n] = 1 for i in range(n - 1, 0, -1): if a[i - 1] < a[i]: dp2[i] = dp2[i + 1] + 1 else: dp2[i] = 1 ans = 0 for i in range(2, n): if a[i] > a[i - 2]: ans = max(ans, dp1[i - 1] + dp2[i + 1]) for i in range(1, n + 1): ans = max(ans, dp1[i], dp2[i]) 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) s = list(map(int, input().split())) def increasing_subsquence_end(L): DP = [(1) for i in L] for i in range(1, len(L)): if L[i] > L[i - 1]: DP[i] = DP[i - 1] + 1 return DP def increasing_subsquence_begin(L): DP = [(1) for i in L] for i in range(len(L) - 2, -1, -1): if L[i] < L[i + 1]: DP[i] = DP[i + 1] + 1 return DP end = increasing_subsquence_end(s) begin = increasing_subsquence_begin(s) curr_max = max(end) for i in range(1, len(s) - 1): curr_max = max(curr_max, end[i - 1] + begin[i + 1] if s[i - 1] < s[i + 1] else 0) print(curr_max)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) num = [int(x) for x in input().split()] f = [] for i in range(n): f.append([1, 0, 0]) for i in range(1, n): if num[i] > num[i - 1]: f[i][0] = f[i - 1][0] + 1 f[i][1] = f[i - 1][0] f[i][2] = f[i - 1][2] + 1 if i >= 2 and num[i] > num[i - 2]: f[i][2] = max(f[i][2], f[i - 1][1] + 1) else: f[i][0] = 1 f[i][1] = f[i - 1][0] if i >= 2 and num[i] > num[i - 2]: f[i][2] = max(f[i][2], f[i - 1][1] + 1) ans = 0 for i in range(0, n): ans = max(ans, max(f[i][0], max(f[i][1], f[i][2]))) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
def answer(n, A): l = [1] * n for i in range(1, n): if A[i] > A[i - 1]: l[i] = l[i - 1] + 1 r = [1] * n for i in range(n - 2, -1, -1): if A[i] < A[i + 1]: r[i] = r[i + 1] + 1 ans = 0 for i in range(0, n): if i <= n - 3 and A[i + 2] > A[i]: ans = max(ans, l[i] + r[i + 2]) else: ans = max(ans, l[i]) return ans n = int(input()) arr = list(map(int, input().split())) print(answer(n, arr))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN 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
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
from sys import stdin, stdout n = int(stdin.readline().strip()) s = list(map(int, stdin.readline().strip().split())) dp = [(0) for i in range(n)] dp[0] = 1 for i in range(1, n): if s[i] > s[i - 1]: dp[i] = dp[i - 1] + 1 else: dp[i] = 1 aux = [(0) for i in range(n)] aux[-1] = dp[-1] for i in range(n - 2, -1, -1): if dp[i + 1] != 1: aux[i] = aux[i + 1] else: aux[i] = dp[i] ans = max(dp) for i in range(1, n - 1): if s[i - 1] < s[i + 1]: ans = max(ans, dp[i - 1] + aux[i + 1] - dp[i + 1] + 1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL 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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys input = sys.stdin.buffer.readline n = int(input()) data = [int(i) for i in input().split()] l = [1] idx = [0] for i in range(1, len(data)): if data[i] > data[i - 1]: l[-1] += 1 else: l.append(1) idx.append(i) max_length = 0 for i in range(1, len(idx)): index = idx[i] if l[i] > 1 and ( data[index - 2] < data[index] or data[index - 1] < data[index + 1] ): max_length = max(max_length, l[i] + l[i - 1] - 1) print(max(max(l), max_length))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys def read_ints(): return [int(x) for x in sys.stdin.readline().strip().split()] def main(): N = read_ints()[0] nums = read_ints() pref = [0] * N suf = [0] * N pref[0] = 1 ans = 1 for ix in range(1, N): pref[ix] = 1 + (pref[ix - 1] if nums[ix] > nums[ix - 1] else 0) ans = max(ans, pref[ix]) suf[N - 1] = 1 for ix in range(N - 2, -1, -1): suf[ix] = 1 + (suf[ix + 1] if nums[ix] < nums[ix + 1] else 0) for to_delete in range(1, N - 1): if nums[to_delete - 1] < nums[to_delete + 1]: ans = max(pref[to_delete - 1] + suf[to_delete + 1], ans) print(ans) main()
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = [int(x) for x in input().split()] ending = [1] starting = [1] for x in range(1, n): if arr[x] > arr[x - 1]: ending.append(ending[-1] + 1) else: ending.append(1) for x in range(n - 2, -1, -1): if arr[x] < arr[x + 1]: starting.append(starting[-1] + 1) else: starting.append(1) starting = starting[::-1] ans = max(ending) for x in range(1, n - 1): if arr[x + 1] > arr[x - 1]: ans = max(ans, ending[x - 1] + starting[x + 1]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
ii = lambda: int(input()) kk = lambda: map(int, input().split()) ll = lambda: list(kk()) n = ii() ls = ll() l, r = [1] * n, [1] * n m = 0 for i in range(1, n): if ls[i] > ls[i - 1]: l[i] = l[i - 1] + 1 for i in range(n - 2, -1, -1): if ls[i] < ls[i + 1]: r[i] = r[i + 1] + 1 for i in range(1, n - 1): if ls[i - 1] < ls[i + 1]: m = max(m, l[i - 1] + r[i + 1]) m = max(m, l[i], r[i]) m = max(m, r[0], r[n - 1], l[0], l[n - 1]) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys n = int(sys.stdin.readline()) a = [int(i) for i in sys.stdin.readline().split()] if n == 1: print(1) elif n == 2: if a[0] < a[1]: print(2) else: print(1) else: arr = [0] * n par = [-1] * n ctr = 1 ans = 1 ind = 0 for g in range(n - 1): if a[g] < a[g + 1]: ctr += 1 else: arr[ind] = ctr par[ind] = ind ans = max(ans, ctr) ctr = 1 ind = g + 1 arr[ind] = ctr par[ind] = ind ans = max(ans, ctr) for h in range(n - 1): if arr[h + 1] == 0: arr[h + 1] = arr[h] if par[h + 1] == -1: par[h + 1] = par[h] for p in range(n - 2): if a[p] < a[p + 2] and par[p] != par[p + 2]: val = arr[p] + arr[p + 2] if a[p] < a[p + 1] or a[p + 1] < a[p + 2]: val -= 1 ans = max(ans, val) print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
from sys import exit def iis(): return map(int, input().split()) def ii(): return int(input()) def liis(): return list(map(int, input().split())) n = ii() a = liis() fim = [0] * n fim[0] = 1 tam = 1 for i in range(1, n): if a[i] <= a[i - 1]: tam = 1 fim[i] = tam else: fim[i] = tam + 1 tam += 1 cont = [0] * n cont[n - 1] = 1 tam = 1 for i in range(n - 2, -1, -1): if a[i] >= a[i + 1]: tam = 1 cont[i] = tam else: cont[i] = tam + 1 tam += 1 ans = 0 for i in range(n): ans = max(ans, cont[i]) for i in range(1, n - 1): if a[i - 1] < a[i + 1]: ans = max(ans, fim[i - 1] + cont[i + 1]) print(ans)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
from sys import stdin read = stdin.readline def main(): n = int(read()) nums = list(map(int, read().strip().split())) inclass, ac, edges, cnt = dict(), 1, list(), 0 for num in nums: inclass[num] = 0 for i in range(len(nums) - 1): if nums[i + 1] > nums[i]: ac += 1 else: ac_temp = ac - 1 inclass[nums[i]] = ac, cnt j = i - 1 while ac_temp > 0: inclass[nums[j]] = ac, cnt j -= 1 ac_temp -= 1 ac = 1 edges.append(i + 1) cnt += 1 i = len(nums) - 1 ac_temp = ac - 1 inclass[nums[i]] = ac, cnt j = i - 1 while ac_temp > 0: inclass[nums[j]] = ac, cnt j -= 1 ac_temp -= 1 ac = 1 ans = 0 for key in inclass: ans = max(ans, inclass[key][0]) for i in range(1, len(nums) - 1): if ( nums[i - 1] < nums[i + 1] and inclass[nums[i - 1]][1] != inclass[nums[i + 1]][1] ): ans = max(ans, inclass[nums[i - 1]][0] + inclass[nums[i + 1]][0] - 1) print(ans) main()
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = list(map(int, input().split())) ind = 0 dp = [] co = 0 maxi = 1 for i in range(0, n - 1): if arr[i] >= arr[i + 1]: if ind == i: dp.append([ind]) ind += 1 else: if (len(dp) > 0 and len(dp[-1]) > 1) and ( arr[dp[-1][1] - 1] < arr[ind] or arr[dp[-1][1]] < arr[ind + 1] ): if maxi < dp[-1][1] - dp[-1][0] + i - ind + 1: maxi = dp[-1][1] - dp[-1][0] + i - ind + 1 elif maxi < i - ind + 1: maxi = i - ind + 1 dp.append([ind, i]) ind = i + 1 i = n - 1 if ind == n - 1: dp.append([ind]) ind += 1 else: if (len(dp) > 0 and len(dp[-1]) > 1) and ( arr[dp[-1][1] - 1] < arr[ind] or arr[dp[-1][1]] < arr[ind + 1] ): if maxi < dp[-1][1] - dp[-1][0] + i - ind + 1: maxi = dp[-1][1] - dp[-1][0] + i - ind + 1 elif maxi < i - ind + 1: maxi = i - ind + 1 dp.append([ind, n - 1]) print(maxi)
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 LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [1e18] + [int(i) for i in input().split()] + [-1] l, r = [0] * (n + 1), [0] * (n + 1) cnt = 0 for i in range(1, n + 1): if a[i] <= a[i - 1]: cnt = 0 cnt += 1 l[i] = cnt for i in reversed(range(1, n + 1)): if a[i] >= a[i + 1]: cnt = 0 cnt += 1 r[i] = cnt ans = max(l) for i in range(1, n + 1): if a[i - 1] < a[i + 1]: ans = max(ans, l[i - 1] + r[i + 1]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER 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 NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [int(x) for x in input().split()] l = [(1) for i in range(n)] r = [(1) for i in range(n)] for i in range(1, n): if a[i] > a[i - 1]: l[i] = l[i - 1] + 1 for i in range(n - 2, 0, -1): if a[i] < a[i + 1]: r[i] = r[i + 1] + 1 maxi = -9999999999 p = max(max(l), max(r)) for i in range(n): if i == 0: maxi = max(maxi, r[i + 1]) elif i == n - 1: maxi = max(maxi, l[i - 1]) elif a[i - 1] >= a[i + 1]: maxi = max(maxi, max(l[i - 1], r[i + 1])) else: maxi = max(maxi, l[i - 1] + r[i + 1]) print(max(p, maxi))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) lst = [*map(int, input().split())] d, item, j = {(0): 1}, [[lst[0]]], 0 res = 0 for i, x in enumerate(lst[1:]): if x > lst[i]: d[j] += 1 item[-1].append(x) else: res = max(res, d[j]) j += 1 d[j] = 1 item.append([x]) res = max(res, d[j]) for i, x in enumerate(item[:-1]): if d[i] > 1 and d[i + 1] > 1: y = item[i + 1] if x[-1] < y[1]: res = max(res, d[i] + d[i + 1] - 1) if x[-2] < y[0]: res = max(res, d[i] + d[i + 1] - 1) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR DICT NUMBER NUMBER LIST LIST VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input().strip()) A = list(map(int, input().strip().split())) max_l = 0 fir_sub_max_l = 0 sec_sub_max_l = 1 last = A[0] sec_last = -1000000000000000000000000000000000 remove_type = "other" for i, a in enumerate(A[1:]): if a > last: sec_sub_max_l += 1 sec_last = last last = a elif a > sec_last or i != n - 2 and A[i + 2] > last: max_l = max(max_l, fir_sub_max_l + sec_sub_max_l) fir_sub_max_l = sec_sub_max_l - 1 sec_sub_max_l = 1 sec_last = last last = a else: max_l = max(max_l, fir_sub_max_l + sec_sub_max_l) fir_sub_max_l = 0 sec_sub_max_l = 1 sec_last = last last = a max_l = max(max_l, fir_sub_max_l + sec_sub_max_l) print(max_l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
N = int(input()) A = list(map(int, input().split())) increasing = [1] * N for i in range(1, N): if A[i] > A[i - 1]: increasing[i] = increasing[i - 1] + 1 decreasing = [1] * N for i in range(N - 2, -1, -1): if A[i] < A[i + 1]: decreasing[i] = decreasing[i + 1] + 1 afterRem = [1] * N for i in range(N): try: l = increasing[i - 1] if i == 0: raise IndexError except IndexError: l = 0 try: r = decreasing[i + 1] except IndexError: r = 0 try: if i > 0 and A[i - 1] < A[i + 1]: afterRem[i] = l + r else: afterRem[i] = max(l, r) except IndexError: afterRem[i] = max(l, r) print(max(max(increasing), max(afterRem)))
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 LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) x = [int(i) for i in input().split()] y = x[::-1] lst1 = [1] * n lst2 = [1] * n for i in range(1, n): if x[i - 1] < x[i]: lst1[i] += lst1[i - 1] for i in range(n - 1): if y[i] > y[i + 1]: lst2[-i - 2] += lst2[-i - 1] res = max(lst1) for i in range(n - 2): if x[i + 2] > x[i]: res = max(res, lst1[i] + lst2[i + 2]) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) arr = list(map(int, input().split())) dp = [[1, 1] for i in range(n)] for i in range(1, n): if arr[i] > arr[i - 1]: dp[i][1] = dp[i - 1][1] + 1 dp[i][0] = dp[i - 1][0] + 1 if i > 1 and arr[i] > arr[i - 2]: dp[i][1] = max(dp[i][1], dp[i - 2][0] + 1) print(max(max(dp[i]) for i in range(n)))
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 NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) dpl = [0] * n dpl[0] = 1 for i in range(1, n): if a[i - 1] < a[i]: dpl[i] = dpl[i - 1] + 1 else: dpl[i] = 1 dpr = [0] * n dpr[-1] = 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: dpr[i] = dpr[i + 1] + 1 else: dpr[i] = 1 ans = 0 for i in range(n): ans = max(ans, dpl[i] + dpr[i] - 1) if 1 <= i <= n - 2 and a[i - 1] < a[i + 1]: ans = max(ans, dpl[i - 1] + dpr[i + 1]) print(ans)
IMPORT ASSIGN VAR 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 LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) l = list(map(int, input().split())) ll = [1] for i in range(1, n): if l[i] > l[i - 1]: ll[-1] += 1 else: ll.append(1) t = 0 ans = max(ll) for i in range(len(ll) - 1): t += ll[i] if ll[i] != 1: end = t - 1 bb = l[end - 1] kk = l[end + 1] if bb < kk: ans = max(ans, ll[i] + ll[i + 1] - 1) if ll[i + 1] != 1: end = t bb = l[end - 1] kk = l[end + 1] if bb < kk: ans = max(ans, ll[i] + ll[i + 1] - 1) 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 LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input().strip()) A = list(map(int, input().strip().split())) max_l = 0 dp = 0, 0 last = -10000000000000000000000 for i, a in enumerate(A): if a > last: dp = dp[0] + 1, dp[1] + 1 elif i > 1 and a > A[i - 2] or i < n - 1 and A[i + 1] > A[i - 1]: dp = 1, dp[0] else: dp = 1, 1 max_l = max(max_l, dp[1]) last = a print(max_l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) xs = [int(x) for x in input().split()] dp0 = [(1) for _ in range(n)] dp1 = [(1) for _ in range(n)] for i in range(1, n): dp0[i] = dp0[i - 1] + 1 if xs[i] > xs[i - 1] else 1 if i > 1: left = dp1[i - 1] + 1 if xs[i] > xs[i - 1] else 1 right = dp0[i - 2] + 1 if xs[i] > xs[i - 2] else 1 dp1[i] = max(left, right) best = max(max(dp0), max(dp1)) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) dp = [[0, 0] for i in range(n)] dp[0] = [1, 1] t = list(map(int, input().split())) for j in range(1, n): if t[j] > t[j - 1]: dp[j][0] = dp[j - 1][0] + 1 dp[j][1] = dp[j - 1][1] + 1 else: dp[j][0] = 1 dp[j][1] = 1 if j >= 2 and t[j] > t[j - 2]: dp[j][1] = max(dp[j][1], dp[j - 2][0] + 1) ans = 0 for i in dp: ans = max(ans, max(i)) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [int(x) for x in input().split()] l = [(1) for _ in range(n)] r = [(1) for _ in range(n)] for i in range(1, n): if a[i] > a[i - 1]: l[i] = l[i - 1] + 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: r[i] = r[i + 1] + 1 ans = max(l) for i in range(n - 2): if a[i] < a[i + 2]: ans = max(ans, l[i] + r[i + 2]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
from sys import stdin, stdout n = stdin.readline() n = int(n) total = stdin.readline().split() ar = [] for i in total: ar.append(int(i)) lt = [1] * n rt = [1] * n ans = int(0) for i in range(1, n): if ar[i - 1] < ar[i]: lt[i] = lt[i - 1] + 1 ans = max(ans, lt[i]) for i in range(n - 2, -1, -1): if ar[i] < ar[i + 1]: rt[i] = rt[i + 1] + 1 ans = max(ans, rt[i]) for i in range(1, n - 1): if ar[i - 1] < ar[i + 1]: ans = max(ans, lt[i - 1] + rt[i + 1]) stdout.write(str(ans))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = [int(i) for i in input().split()] b1 = [1] * n b2 = [1] * n for i in range(1, n): if a[i - 1] < a[i]: b1[i] = max(b1[i - 1] + 1, b1[i]) b2[i] = max(b2[i - 1] + 1, b2[i]) if i < n - 1 and a[i - 1] < a[i + 1]: b2[i + 1] = b1[i - 1] + 1 print(max(b2))
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 FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
def solve(): n = int(input()) nums = [int(x) for x in input().split()] dp = [([1] * n) for i in range(2)] flag = [0] * n if n == 0: print(0) return if n == 1: print(1) return if n == 2: if nums[0] < nums[1]: print(2) else: print(1) return dp[0][0] = 1 dp[0][1] = 0 if nums[0] < nums[1]: dp[0][1] = 2 else: dp[0][1] = 1 dp[1][1] = 1 for i in range(2, n): if nums[i] > nums[i - 1]: dp[0][i] = dp[0][i - 1] + 1 dp[1][i] = dp[1][i - 1] + 1 if nums[i] > nums[i - 2]: dp[1][i] = max(dp[1][i], dp[0][i - 2] + 1) ans = 0 for i in range(2): for j in range(n): ans = max(ans, dp[i][j]) print(ans) solve()
FUNC_DEF 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 VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys N = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) list_check = [1] * N list_check.append(0) list_r = [(1) for _ in range(N)] for i in range(1, N): if a[i] > a[i - 1]: list_check[i] += list_check[i - 1] list_check_r = list_check[:] s, e = 0, 1 while s <= e and e < N: if list_check[e] < list_check[e + 1]: e += 1 elif list_check[e] > list_check[e + 1]: for i in range((e - s + 1) // 2): list_check_r[i + s] = list_check[e - i] list_check_r[e - i] = list_check[i + s] s = e + 1 e += 1 else: e += 1 s += 1 res = 0 for i in range(N): res = max(res, list_check[i]) if 0 < i < N - 1: if a[i - 1] < a[i + 1]: res = max(res, list_check[i - 1] + list_check_r[i + 1]) print(res)
IMPORT 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 LIST NUMBER VAR EXPR FUNC_CALL VAR NUMBER 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 ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N = INT() A = LIST() B = [1] * N for i, a in enumerate(A[1:], 1): if A[i - 1] < a: B[i] = B[i - 1] + 1 B2 = [1] * N for i in range(N - 2, -1, -1): if A[i] < A[i + 1]: B2[i] = B2[i + 1] + 1 ans = max(B) for i in range(1, N - 1): if A[i - 1] < A[i + 1]: ans = max(ans, B[i - 1] + B2[i + 1]) print(ans)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) li = list(map(int, input().split())) arr = [] p = 0 b = [] ans = [] for i in range(n - 1): if p == 0: b.append(i) p = 1 if li[i] < li[i + 1]: p += 1 else: b.append(i) arr.append(b) ans.append(p) b = [] p = 0 if p != 0: b.append(i + 1) arr.append(b) ans.append(p) else: b.append(i + 1) b.append(i + 1) arr.append(1) ans1 = max(ans) for i in range(len(ans) - 1): if arr[i + 1][0] - arr[i][1] == 1: if arr[i][1] != 0: if li[arr[i][1] - 1] < li[arr[i + 1][0]]: ans1 = max(ans1, ans[i] - 1 + ans[i + 1]) if arr[i + 1][0] != n - 1: if li[arr[i][1]] < li[arr[i + 1][0] + 1]: ans1 = max(ans1, ans[i] - 1 + ans[i + 1]) print(ans1)
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 ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
def max_length(length, arr): sub_arr_1 = [1] * length sub_arr_2 = [1] * length for j in range(length - 2, -1, -1): if arr[j] < arr[j + 1]: sub_arr_1[j] = sub_arr_1[j + 1] + 1 sub_arr_2[j] = sub_arr_2[j + 1] + 1 if j + 2 < length and arr[j] < arr[j + 2]: sub_arr_2[j] = max(sub_arr_2[j], sub_arr_1[j + 2] + 1) max_1 = max(sub_arr_1) max_2 = max(sub_arr_2) return max(max_1, max_2) n = int(input("")) second_line = input("") a = second_line.split() for i in range(0, n): a[i] = int(a[i]) print(max_length(n, a))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) a = list(map(int, input().split())) d = [] for i in range(0, n - 1): d.append(a[i + 1] - a[i]) i = 0 flag = 0 j = 0 t = [] while i < n - 1: count = 0 while i < n - 1 and d[i] > 0: i = i + 1 count = count + 1 t.append([i, count + 1]) if i == n - 1 and count + 1 == n: flag = 1 i = i + 1 m = 0 k = i i = 0 for i in range(0, len(t) - 1): if d[t[i][0] + 1] > 0 and ( a[t[i][0] + 1] > a[t[i][0] - 1] or a[t[i][0] + 2] > a[t[i][0]] ): c = t[i][1] + t[i + 1][1] - 1 else: c = t[i][1] if c > m: m = c if len(t) != 1: if d[t[i][0] + 1] > 0 and ( a[t[i][0] + 1] > a[t[i][0] - 1] or a[t[i][0] + 2] > a[t[i][0]] ): c = t[i][1] + t[i + 1][1] - 1 else: c = t[i][1] c2 = t[i + 1][1] c = max(c, c2) if c > m: m = c if len(t) == 1: if k == n - 1: m = n - 1 if flag == 0: print(m) else: print(n)
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 EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) l = list(map(int, input().split())) sufinc = [1] * n count = 1 for i in range(n - 2, -1, -1): if l[i] < l[i + 1]: count += 1 sufinc[i] = count else: count = 1 sufinc[i] = count preinc = [1] * n count = 1 for i in range(1, n): if l[i] > l[i - 1]: count += 1 preinc[i] = count else: count = 1 preinc[i] = count ans = 0 ans = max(sufinc[0], preinc[-1]) ans = max(sufinc[1], preinc[-2], ans) for i in range(1, n - 1): if l[i + 1] > l[i - 1]: if preinc[i - 1] + sufinc[i + 1] > ans: ans = preinc[i - 1] + sufinc[i + 1] else: ans = max(ans, preinc[i - 1], sufinc[i + 1]) 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array $a$ consisting of $n$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer β€” the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $4$.
n = int(input()) lis = list(map(int, input().split())) dp = [0] * len(lis) for i in range(len(lis) - 1, -1, -1): if i == len(lis) - 1: dp[i] = 1 continue if lis[i] < lis[i + 1]: dp[i] = dp[i + 1] + 1 else: dp[i] = 1 dp2 = [0] * len(lis) for i in range(len(lis)): if i == 0: dp2[i] = 1 continue if lis[i] > lis[i - 1]: dp2[i] = dp2[i - 1] + 1 else: dp2[i] = 1 output = 0 for i in range(len(dp)): if i == 0: output = max(output, dp[i + 1]) continue if i == len(dp) - 1: output = max(output, dp2[i - 1]) continue if lis[i - 1] < lis[i + 1]: output = max(output, dp2[i - 1] + dp[i + 1]) else: output = max(output, dp[i + 1]) output = max(max(dp), output) print(output)
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 LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER 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 BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR