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()) v = list(map(int, input().split())) a = [0] * (n + 1) a[0] = 1 for i in range(1, n): if v[i] <= v[i - 1]: a[i] = 1 else: a[i] = a[i - 1] + 1 ans = [1] i = 1 while i < n - 1: if a[i] == 1: if v[i - 1] < v[i + 1]: j = a[i - 1] k = i + 1 while a[k] > 1: j = j + 1 i = k k = k + 1 if k == n: break ans.append(j) elif i > 1: if v[i - 2] < v[i]: j = a[i - 2] + 1 k = i if k < n - 1: while v[k] < v[k + 1]: j = j + 1 i = k k = k + 1 if k >= n - 1: break ans.append(j) i = i + 1 if i >= n: break f = [max(ans), max(a)] print(max(f))
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR 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$.
def seq_len(arr, n): seqs = [] seq_b = 0 seq_e = 0 longest = -1 for i in range(0, n - 1): if arr[i + 1] > arr[i]: seq_e = i + 1 else: longest = max(longest, seq_e - seq_b + 1) seqs.append((seq_b, seq_e)) seq_b = i + 1 seq_e = i + 1 longest = max(longest, seq_e - seq_b + 1) seqs.append((seq_b, seq_e)) if len(seqs) > 1: for i in range(0, len(seqs) - 1): if seqs[i][1] - 1 >= 0: if arr[seqs[i][1] - 1] < arr[seqs[i + 1][0]]: longest = max( longest, seqs[i][1] - seqs[i][0] + 1 + seqs[i + 1][1] - seqs[i + 1][0], ) if seqs[i + 1][0] + 1 < n: if arr[seqs[i][1]] < arr[seqs[i + 1][0] + 1]: longest = max( longest, seqs[i][1] - seqs[i][0] + 1 + seqs[i + 1][1] - seqs[i + 1][0], ) return longest else: return n n = int(input()) arr = [int(x) for x in input().split()] print(seq_len(arr, n))
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR 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 BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR 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 BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN VAR 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 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()) els = list(map(int, input().strip().split())) dp = [([0] * len(els)) for _ in range(2)] dp[0][0] = 1 dp[1][0] = 1 for i in range(1, len(els)): if els[i] > els[i - 1]: dp[0][i] = 1 + dp[0][i - 1] else: dp[0][i] = 1 for i in range(1, len(els)): if els[i] > els[i - 1]: prvi = dp[1][i - 1] + 1 else: prvi = 1 if i >= 2 and els[i] > els[i - 2]: drugi = 1 + dp[0][i - 2] else: drugi = 1 dp[1][i] = max(prvi, drugi) print(max(max(dp)))
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 VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR 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()] d = [] actual = [a[0]] for i in range(1, n): if a[i] > a[i - 1]: actual.append(a[i]) else: d.append([len(actual), actual]) actual = [a[i]] d.append([len(actual), actual]) maxi = 0 if len(d) == 1: print(n) else: n = len(d) for i in range(n): maxi = max(maxi, d[i][0]) for i in range(n - 1): if d[i][0] > 1 and d[i + 1][0] > 1: if d[i][1][-2] < d[i + 1][1][0] or d[i][1][-1] < d[i + 1][1][1]: maxi = max(maxi, d[i][0] + d[i + 1][0] - 1) for i in range(n - 2): if d[i + 1][0] == 1: if d[i][1][-1] < d[i + 2][1][0]: maxi = max(maxi, d[i][0] + d[i + 2][0]) print(maxi)
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 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 LIST FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR 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()) a = list(map(int, input().split())) dp = [([1] * 2) for i in range(N)] ans = 0 for i in range(N): if i == 0: continue else: if a[i - 1] < a[i]: dp[i][0] = max(dp[i][0], dp[i - 1][0] + 1) dp[i][1] = max(dp[i][1], dp[i - 1][1] + 1) if i > 1 and a[i - 2] < a[i]: dp[i][1] = max(dp[i][1], dp[i - 2][0] + 1) ans = max(ans, dp[i][0], 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 FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF 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 VAR NUMBER FUNC_CALL VAR 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 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 class Input: stdin_input = [] def get_next_token(self): if not self.stdin_input or len(self.stdin_input) == 0: self.stdin_input = sys.stdin.readline().split(" ") result = self.stdin_input[0] self.stdin_input = self.stdin_input[1:] return result def get_next_line(self): return sys.stdin.readline() def read_str(self): return self.get_next_token() def read_int(self): return int(self.get_next_token()) read = Input() size = read.read_int() left = [1] * size right = [1] * size stdin_input = sys.stdin.readline().split(" ") t = list(map(lambda a: int(a), stdin_input)) res = 1 for i in range(1, size): if t[i - 1] < t[i]: left[i] = left[i - 1] + 1 for i in range(size - 2, -1, -1): if t[i] < t[i + 1]: right[i] = right[i + 1] + 1 for i in range(0, size - 2): if t[i] < t[i + 2]: res = max(res, left[i] + right[i + 2]) for i in range(0, size - 1): if t[i] < t[i + 1]: res = max(res, left[i] + right[i + 1]) print(res)
IMPORT CLASS_DEF ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN 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 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 VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 = list(map(int, input().split())) dpright = [(1) for i in range(n)] for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: dpright[i] = dpright[i + 1] + 1 dpleft = [(1) for i in range(n)] for i in range(1, n): if a[i] > a[i - 1]: dpleft[i] = dpleft[i - 1] + 1 m = max(dpright[0], dpright[1], dpleft[n - 2]) if a[0] < a[1]: m = max(m, 1 + dpright[1]) if a[-2] < a[-1]: m = max(m, 1 + dpleft[-2]) for i in range(1, n - 1): if a[i - 1] < a[i + 1]: m = max(m, dpleft[i - 1] + dpright[i + 1]) if a[i] < a[i + 1]: m = max(m, dpleft[i] + dpright[i + 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 NUMBER VAR FUNC_CALL 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 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 FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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 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 n = int(stdin.readline()) arr = [int(x) for x in stdin.readline().split()] flag = True for i in range(n - 1): if not arr[i] < arr[i + 1]: flag = False break if flag: print(n) quit() ans = 1 possible = [] prev, ptr = n - 1, n - 1 while ptr > 0: while ptr > 0 and arr[ptr - 1] < arr[ptr]: ptr -= 1 ans = max(ans, prev - ptr + 1) possible.append([ptr, prev]) while ptr > 0 and not arr[ptr - 1] < arr[ptr]: ptr -= 1 prev = ptr for i in range(len(possible) - 1, 0, -1): start1, end1, start2, end2 = ( possible[i][0], possible[i][1], possible[i - 1][0], possible[i - 1][1], ) if end1 + 2 == start2: if arr[end1] < arr[start2]: ans = max(ans, end1 - start1 + 1 + end2 - start2 + 1) elif end1 + 1 == start2: if start1 != end1 and start2 != end2: if arr[end1 - 1] < arr[start2] or arr[end1] < arr[start2 + 1]: ans = max(ans, end1 - start1 + end2 - start2 + 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR IF 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 IF BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER 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 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())) m = 1 l = 1 fw = [1] * n bw = [1] * n for i in range(1, n): if arr[i] > arr[i - 1]: l = l + 1 m = max(m, l) else: l = 1 fw[i] = l l = 1 for i in range(n - 2, -1, -1): if arr[i] < arr[i + 1]: l = l + 1 m = max(m, l) else: l = 1 bw[i] = l ans = m for i in range(1, n - 1): if arr[i - 1] < arr[i + 1]: ans = max(ans, fw[i - 1] + bw[i + 1]) else: ans = max(ans, fw[i - 1], bw[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 NUMBER 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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR 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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN 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 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()) a = list(map(int, input().split())) + [0] max_len = 0 lr = [] cnt = left = right = 0 for i in range(n - 1): if a[i] < a[i + 1]: right += 1 else: lr.append([left, right]) left = right = i + 1 lr.append([left, right]) for i in range(len(lr) - 1): if lr[i][1] - lr[i][0] + 1 > max_len: max_len = lr[i][1] - lr[i][0] + 1 if a[lr[i][1]] < a[lr[i + 1][0] + 1] or a[lr[i][1] - 1] < a[lr[i + 1][0]]: ls = lr[i + 1][1] - lr[i][0] if ls > max_len: max_len = ls if lr[-1][1] - lr[-1][0] + 1 > max_len: max_len = lr[-1][1] - lr[-1][0] + 1 print(max_len)
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 NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR 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 VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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$.
from sys import stdin n = int(stdin.readline().strip()) arr = list(map(int, stdin.readline().split())) dp1 = [0] * n for i in range(n - 1, -1, -1): if i == n - 1: dp1[i] = 1 continue if arr[i] < arr[i + 1]: dp1[i] = dp1[i + 1] + 1 else: dp1[i] = 1 dp2 = [0] * n for i in range(n): if i == 0: dp2[i] = 1 if arr[i] > arr[i - 1]: dp2[i] = dp2[i - 1] + 1 else: dp2[i] = 1 ans = 1 for i in range(len(arr)): if i == 0: pass elif i + 1 < n and arr[i - 1] < arr[i + 1]: ans = max(ans, dp2[i - 1] + dp1[i + 1]) else: ans = max(ans, dp2[i]) 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 VAR 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 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 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER 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 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$.
def play(arr): n = len(arr) if n == 1: return 1 l = [0] * n r = [0] * n s = 0 for i in range(1, n): if arr[i] > arr[i - 1]: s += 1 l[i] = s else: s += 1 l[i] = s s = 0 s = 0 for i in range(n - 2, -1, -1): if arr[i + 1] > arr[i]: s += 1 r[i] = s else: s += 1 r[i] = s s = 0 m = 1 for i in range(0, n): if i > 0: if i < n - 1: if arr[i - 1] >= arr[i + 1]: if arr[i] > arr[i - 1]: m = max(m, l[i] + 1) if arr[i] < arr[i + 1]: m = max(m, r[i] + 1) m = max(m, l[i], r[i]) elif arr[i] > arr[i - 1] and arr[i] < arr[i + 1]: m = max(m, l[i] + r[i] + 1) else: m = max(m, l[i] + r[i]) elif arr[i] > arr[i - 1]: m = max(m, l[i] + 1) else: m = max(m, l[i]) elif arr[i] < arr[i + 1]: m = max(m, r[i] + 1) else: m = max(m, r[i]) return m def main(): n = list(map(int, input().split()))[0] arr = list(map(int, input().split())) print(play(arr)) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER 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 VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR 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()] pre = [0] * n pos = [0] * n pre[0] = 1 pos[n - 1] = 1 for i in range(1, n): if arr[i] > arr[i - 1]: pre[i] = pre[i - 1] + 1 else: pre[i] = 1 for i in range(n - 2, -1, -1): if arr[i + 1] > arr[i]: pos[i] = pos[i + 1] + 1 else: pos[i] = 1 l = 1 ans = 0 for i in range(1, n): if arr[i] > arr[i - 1]: l += 1 else: l = 1 ans = max(ans, l) for i in range(1, n - 1): if arr[i - 1] < arr[i + 1]: ans = max(pre[i - 1] + pos[i + 1], ans) print(ans)
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 NUMBER ASSIGN VAR BIN_OP 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 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL 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 BIN_OP VAR BIN_OP VAR NUMBER 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 n = int(sys.stdin.readline()) arr = list(map(int, sys.stdin.readline().split())) skip = [-1] * n noskip = [-1] * n noskip[0] = 1 prevskip = [-1] * n ans = 1 z = True for i in range(1, n): if arr[i] > arr[i - 1]: noskip[i] = noskip[i - 1] + 1 if z: skip[i] = skip[i - 1] + 1 else: if arr[i] > arr[i - 2]: skip[i] = skip[i - 1] + 1 else: skip[i] = 0 z = True prevskip[i] = prevskip[i - 1] + 1 elif i == 1: skip[i] = 1 noskip[i] = 1 prevskip[i] = 1 else: if arr[i] > arr[i - 2]: prevskip[i] = noskip[i - 2] + 1 noskip[i] = 1 skip[i] = noskip[i - 1] z = False ans = max(ans, skip[i], noskip[i], prevskip[i]) print(ans)
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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER 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 IF VAR ASSIGN VAR VAR BIN_OP 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 NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN 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 VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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()) b = [0] a = list(map(int, input().split())) a = b + a a1 = [0] * (n + 1) a2 = [0] * (n + 1) a1[1] = 1 for i in range(2, n + 1): if a[i] > a[i - 1]: a1[i] = a1[i - 1] + 1 a2[i] = a2[i - 1] + 1 else: a1[i] = 1 if a[i] > a[i - 2]: a2[i] = max(a2[i], a1[i - 2] + 1) print(max(max(a1), max(a2)))
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 BIN_OP VAR 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP 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 NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER 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$.
n = int(input()) l = [int(i) for i in input().split()] dp = [] for i in range(n): dp.insert(len(dp), 1) ma = 1 for i in range(1, n): if l[i] > l[i - 1]: dp[i] += dp[i - 1] ma = max(ma, dp[i]) else: j = i - 1 while j > 0 and l[j] > l[j - 1]: dp[j - 1] = dp[j] j -= 1 j = n - 1 k = 0 while j > 0 and l[j] > l[j - 1]: dp[j - 1] = dp[j] j -= 1 for i in range(2, n): if l[i - 2] < l[i] and (l[i - 1] >= l[i] or l[i - 2] > l[i - 1]): ma = max(ma, dp[i] + dp[i - 2] - 1) print(ma)
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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR 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 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())) res = [] temp = [l[0]] for j in range(1, n + 1): if j != n and l[j] > l[j - 1]: temp.append(l[j]) else: res.append(temp) temp = [l[j]] if j != n else 0 max_length = 0 for j in range(len(res)): max_length = max(max_length, len(res[j])) for j in range(1, len(res)): if ( len(res[j - 1]) > 1 and res[j][0] > res[j - 1][-2] or len(res[j]) > 1 and res[j][1] > res[j - 1][-1] ): max_length = max(max_length, len(res[j]) + len(res[j - 1]) - 1) print(max_length)
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER 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()) l = [int(x) for x in input().split()] l.append(0) l.insert(0, 987654321) m = [] idx = 0 max = 0 for x in range(1, n + 2): if l[x - 1] >= l[x]: m.append([idx, x - 1, x - 1 - idx + 1]) if x - 1 - idx + 1 > max: max = x - 1 - idx + 1 idx = x m.append([n + 1, n + 1, 1]) nm = len(m) for x in range(1, nm - 1): if m[x][2] == 1: if l[m[x - 1][1]] < l[m[x + 1][0]]: if m[x - 1][2] + m[x + 1][2] > max: max = m[x - 1][2] + m[x + 1][2] else: if l[m[x - 1][1]] < l[m[x][0] + 1]: if m[x - 1][2] + m[x][2] - 1 > max: max = m[x - 1][2] + m[x][2] - 1 if l[m[x][1] - 1] < l[m[x + 1][0]]: if m[x][2] + m[x + 1][2] - 1 > max: max = m[x][2] + m[x + 1][2] - 1 print(max)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN 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()) arr = list(map(int, input().split(" "))) counts = set() last = -1 for n in range(N): count = 1 delite = False delited = -1 i = n j = i + 1 if n < last: continue while True: if j < N: if arr[i] < arr[j]: count += 1 if not delite: last = i - 1 elif not delite: if arr[i - 1] < arr[j] and i > 1: delited = i count -= 1 i -= 2 j -= 1 delite = True elif j + 1 < N: if arr[i] < arr[j + 1]: delited = j i -= 1 delite = True else: counts.add(count) break else: counts.add(count) break else: counts.add(count) break i += 1 j += 1 if i == delited: i += 1 if j == delited: j += 1 else: counts.add(count) break print(max(counts))
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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR WHILE NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR 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$.
import sys fast_reader = sys.stdin.readline fast_writer = sys.stdout.write def input(): return fast_reader().strip() def print(*argv): fast_writer(" ".join(str(i) for i in argv)) fast_writer("\n") def list_input(): return list(map(int, input().split())) def sep_input(): return map(int, input().split()) n = int(input()) l = list_input() ans = 1 back = [(1) for i in range(n)] for i in range(n - 2, 0, -1): if l[i + 1] > l[i]: back[i] = back[i + 1] + 1 ans = max(ans, back[i]) up = [(1) for i in range(n)] for i in range(1, n): if l[i] > l[i - 1]: up[i] = up[i - 1] + 1 ans = max(ans, up[i]) for i in range(0, n - 2): if l[i] < l[i + 2]: ans = max(ans, up[i] + back[i + 2]) print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR 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 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 FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 = list(map(int, input().split())) d = [0] * n d[0] = 1 seg = [] for i in range(1, n): if a[i] > a[i - 1]: d[i] = d[i - 1] + 1 else: d[i] = 1 seg.append((d[i - 1], i - 1)) seg.append((d[n - 1], n - 1)) max_dist = seg[0][0] for i in range(1, len(seg)): dist_old, ind_old = seg[i - 1] dist_new, ind_new = seg[i] if ( ind_old - 1 >= 0 and a[ind_old - 1] < a[ind_old + 1] or ind_old + 2 <= n - 1 and a[ind_old] < a[ind_old + 2] ): max_dist = max(max_dist, dist_old + dist_new - 1) max_dist = max(max_dist, dist_new) print(max_dist)
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 LIST 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 EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP 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$.
q = int(input()) a = list(map(int, input().split())) path = [1] start = [0] end = [0] max_len = [1] for i in range(1, len(a)): if a[i] > a[i - 1]: path.append(path[-1] + 1) max_len[-1] += 1 else: path.append(1) start.append(i) max_len.append(1) ans = max(max_len) for i in range(len(start) - 1): if start[i] + max_len[i] - 2 >= 0 and max_len[i + 1] > 1: if a[start[i] + max_len[i] - 2] < a[start[i + 1]]: ans = max(ans, max_len[i] + max_len[i + 1] - 1) elif a[start[i] + max_len[i] - 1] < a[start[i + 1] + 1]: ans = max(ans, max_len[i] + max_len[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 ASSIGN VAR LIST NUMBER 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 EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR 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 BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER 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()) s = [int(x) for x in input().split()] ptr = 0 c = 1 L = [0] * len(s) L[0] = 1 P = [0] * len(s) for i in range(1, len(s)): if s[i] <= s[i - 1]: for j in range(ptr, i): P[j] = c c = 1 ptr = i else: c += 1 L[i] = c for j in range(ptr, len(s)): P[j] = c ans = max(P) for i in range(1, len(s) - 1): if s[i - 1] < s[i + 1]: ans = max(ans, L[i - 1] + P[i + 1] - L[i + 1] + 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER 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 FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 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$.
n = int(input()) a = [int(x) for x in input().split()] c, b, x, d = 1, 0, 0, 0 e, f, g, y = 0, 0, 0, 0 for i in range(1, n): if a[i - 1] < a[i]: c = c + 1 else: x = max(x, b + c - d) if a[i - 2] >= a[i]: b, d = 0, 0 else: d, b = 1, c c = 1 i = 0 x = max(x, b + c - d) for i in range(0, n - 1): if a[i] < a[i + 1]: e = e + 1 else: y = max(y, e + f + 1 - g) if i + 2 >= n: e, f, g = -1, -1, 1 elif a[i] < a[i + 2]: g = 1 f = e + 1 else: g = 0 f = 0 e = 0 y = max(y, e + f + 1 - g) print(max(x, y))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER 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()) l = list(map(int, input().split(" "))) lefts = [] leftsc = [] rights = [] rightsc = [] b = 0 for i in range(0, n - 1): if b == 0: if l[i] < l[i + 1]: b = 1 lefts.append(l[i]) leftsc.append(i) else: lefts.append(l[i]) leftsc.append(i) rights.append(l[i]) rightsc.append(i) if l[i] >= l[i + 1] and b == 1: b = 0 rights.append(l[i]) rightsc.append(i) if l[n - 2] < l[n - 1]: rights.append(l[n - 1]) rightsc.append(n - 1) else: lefts.append(l[n - 1]) leftsc.append(n - 1) rights.append(l[n - 1]) rightsc.append(n - 1) maxl = 0 for i in range(len(lefts)): maxl = max(maxl, rightsc[i] - leftsc[i] + 1) if len(lefts) == 1: print(rightsc[0] - leftsc[0] + 1) exit(0) for i in range(len(lefts) - 1): if rights[i] >= lefts[i + 1]: if rightsc[i] - 1 >= 0: if l[rightsc[i] - 1] < lefts[i + 1]: if maxl < rightsc[i + 1] - leftsc[i]: maxl = rightsc[i + 1] - leftsc[i] if rightsc[i] + 1 < n: if leftsc[i + 1] + 1 < n: if l[rightsc[i]] < l[leftsc[i + 1] + 1]: if maxl < rightsc[i + 1] - leftsc[i]: maxl = rightsc[i + 1] - leftsc[i] print(maxl)
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 ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR 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$.
n = int(input()) a = list(map(int, input().split())) b = list(reversed(a)) dp = [1] * n dp1 = [1] * n for i in range(n - 1): dp[-i - 2] += dp[-i - 1] * int(b[i] > b[i + 1]) for i in range(n - 1): dp1[i + 1] += dp1[i] * int(a[i] < a[i + 1]) ans = max(dp1) for i in range(n - 2): ans = max(ans, (dp1[i] + dp[i + 2]) * int(a[i] < a[i + 2])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER 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$.
n = input() s = input().split() s = [int(x) for x in s] maxis = [1] maxirs = [-1] maxit = 1 for i in range(1, len(s)): maxis.append(1) maxirs.append(-1) if s[i - 1] < s[i]: maxis[i] = maxis[i - 1] + 1 if maxirs[i - 1] != -1: maxirs[i] = maxirs[i - 1] + 1 if i > 1 and s[i - 2] < s[i]: maxirs[i] = max(maxis[i - 2] + 1, maxirs[i]) if maxis[i] > maxit: maxit = maxis[i] if maxirs[i] > maxit: maxit = maxirs[i] print(maxit)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN 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 = input().split() b = [] for i in a: b.append(int(i)) last = b[0] section = [b[0]] sections = [] for i in b[1:]: if i > last: section.append(i) else: sections.append(section) section = [i] last = i sections.append(section) ans = 0 for i in sections: ans = max(ans, len(i)) Last_section = sections[0] for i in sections[1:]: if len(i) > 1 and len(Last_section) > 1: if Last_section[-2] < i[0] or Last_section[-1] < i[1]: ans = max(ans, len(i) + len(Last_section) - 1) Last_section = i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER 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 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$.
input() arr = list(map(int, input().split())) m_arr = [(1, 1), (2 if arr[-2] < arr[-1] else 1, 1)] for n in range(len(arr) - 3, -1, -1): t0 = m_arr[-1][0] + 1 if arr[n] < arr[n + 1] else 1 t1 = m_arr[-2][0] + 1 if arr[n] < arr[n + 2] else 1 m_arr.append((t0, t1)) idx = 0 while idx < len(m_arr): elem = m_arr[idx] if elem[1] > elem[0]: m_arr[idx] = elem[1], elem[1] while idx + 1 < len(m_arr) and m_arr[idx + 1][0] > 1: idx += 1 m_arr[idx] = m_arr[idx - 1][0] + 1, 0 idx += 1 print(max(map(max, m_arr)))
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR 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$.
n = int(input()) arr = list(map(int, input().strip().split())) maxi = 1 cont = 1 for i in range(n - 1): if arr[i] < arr[i + 1]: cont += 1 else: maxi = max(cont, maxi) cont = 1 maxi = max(cont, maxi) a_inc = [(1) for i in range(n)] a_dec = [(1) for i in range(n)] cont = 1 for i in range(1, n): if arr[i] > arr[i - 1]: cont += 1 else: cont = 1 a_inc[i] = cont cont = 1 for i in range(n - 2, -1, -1): if arr[i] < arr[i + 1]: cont += 1 else: cont = 1 a_dec[i] = cont for i in range(1, n - 1): if arr[i - 1] < arr[i + 1]: maxi = max(a_inc[i - 1] + a_dec[i + 1], maxi) print(maxi)
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR 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 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 BIN_OP VAR BIN_OP VAR NUMBER 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$.
def remove(n, a): i = 0 l = [] maxx = 0 while i < n: st = i end = i + 1 while end < n and a[end - 1] < a[end]: end += 1 l.append((st, end - 1)) diff = end - st if diff > maxx: maxx = diff i = end i = 1 while i < len(l): summ = 0 if i != len(l) - 1 and l[i][0] == l[i][1]: if a[l[i + 1][0]] > a[l[i - 1][1]]: summ = l[i - 1][1] - l[i - 1][0] + 1 + l[i + 1][1] - l[i + 1][0] + 1 i += 1 elif ( a[l[i][0]] > a[l[i - 1][1] - 1] or l[i][0] != l[i][1] and a[l[i][0] + 1] > a[l[i - 1][1]] ): summ = l[i - 1][1] - l[i - 1][0] + l[i][1] - l[i][0] + 1 if summ > maxx: maxx = summ i += 1 return maxx n = int(input()) a = [int(i) for i in input().split()] print(remove(n, a))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN 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 VAR ASSIGN VAR 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 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 def INI(): return int(stdin.readline()) def INL(): return [int(_) for _ in stdin.readline().split()] def INS(): return stdin.readline() def MOD(): return pow(10, 9) + 7 def OPS(ans): stdout.write(str(ans) + "\n") def OPL(ans): [stdout.write(str(_) + " ") for _ in ans] stdout.write("\n") n = INI() X = INL() x = 1 D = [] for _ in range(n - 1): if X[_] < X[_ + 1]: x += 1 else: D.append([x, _]) x = 1 D.append([x, _]) d = len(D) ans = D[0][0] if n == 2: if X[0] < X[1]: OPS(2) else: OPS(1) else: for _ in range(d - 1): i = D[_][1] if i == 0: if X[i] < X[i + 2]: ans = max(ans, D[_][0] + D[_ + 1][0] - 1) else: ans = max(ans, D[_][0]) elif i == n - 2 or i == n - 1: ans = max(ans, D[_][0]) elif X[i] < X[i + 2] or X[i - 1] < X[i + 1]: ans = max(ans, D[_][0] + D[_ + 1][0] - 1) else: ans = max(ans, D[_][0]) OPS(max(ans, D[-1][0]))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST 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 NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR 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 IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR 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 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 FUNC_CALL VAR VAR VAR NUMBER 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()) l = list(map(int, input().split())) mass = [] p = [l[0]] le = [] for i in range(1, n): if l[i] > l[i - 1]: p += [l[i]] else: mass += [p] le += [len(p)] p = [l[i]] if len(p) > 0: le += [len(p)] mass += [p] res = max(le) for i2 in range(1, len(mass)): p = mass[i2] p2 = mass[i2 - 1] if le[i2] == 1 and i2 < len(mass) - 1: if mass[i2 + 1][0] > p2[-1]: res = max(res, len(mass[i2 + 1]) + len(p2)) continue if le[i2 - 1] > 1 and le[i2] > 1: if p[1] > p2[-1]: res = max(res, le[i2] + le[i2 - 1] - 1) if p2[-2] < p[0]: res = max(res, le[i2] + le[i2 - 1] - 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 LIST ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR LIST VAR VAR VAR LIST VAR VAR LIST FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR LIST FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR 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()) arr = list(map(int, input().split())) index = -1 temp = 1 lis = [] ind = [] for i in range(n - 1): if arr[i + 1] > arr[i]: temp += 1 else: lis.append(temp) ind.append(i) temp = 1 index = i if index != n - 2: lis.append(temp) l = len(ind) p = len(lis) for j in range(l): if ind[j] > 0 and arr[ind[j] - 1] < arr[ind[j] + 1] and j < p - 1: lis.append(lis[j] + lis[j + 1] - 1) for j in range(l): if ind[j] < n - 2 and arr[ind[j]] < arr[ind[j] + 2] and j < p - 1: lis.append(lis[j] + lis[j + 1] - 1) print(max(lis))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR 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$.
MOD = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n = ii() l = il() l1 = [1] * n l2 = [1] * n for i in range(1, n): if l[i - 1] < l[i]: l1[i] += l1[i - 1] for i in range(n - 2, -1, -1): if l[i + 1] > l[i]: l2[i] += l2[i + 1] mx = max(l1) for i in range(n - 2): if l[i + 2] > l[i]: mx = max(mx, l1[i] + l2[i + 2]) print(mx)
ASSIGN VAR NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 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 NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR 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()) a = list(map(int, input().split())) a.append end = [1] * n start = [1] * n tot = 0 for i in range(1, n): if a[i] > a[i - 1]: end[i] = end[i - 1] + 1 tot = max(tot, end[i]) else: end[i] = 1 i = n - 2 while i >= 0: if a[i] < a[i + 1]: start[i] = start[i + 1] + 1 else: start[i] = 1 i = i - 1 i = n - 2 while i > 0: if a[i + 1] - a[i - 1] >= 1: tot = max(tot, end[i - 1] + start[i + 1]) i = i - 1 print(max(tot, start[0]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR 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 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 ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE 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 VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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()) l = list(map(int, input().split())) ll = [] dum = [0, l[0]] i = 1 mxx = -1 while i < n: if l[i] > l[i - 1]: dum.append(l[i]) else: dum.append(i - 1) ll.append(dum) mxx = max(mxx, len(dum) - 2) dum = [i, l[i]] i += 1 if len(dum) >= 2: dum.append(n - 1) ll.append(dum) mxx = max(mxx, len(dum) - 2) mx = -1 for i in range(1, len(ll)): if ll[i - 1][-1] + 1 == ll[i][0] and len(ll[i]) > 3 and len(ll[i - 1]) > 3: if ll[i - 1][-2] < ll[i][2]: if len(ll[i - 1]) + len(ll[i]) - 4 > mx: mx = len(ll[i - 1]) + len(ll[i]) - 4 elif ll[i - 1][-3] < ll[i][1]: if len(ll[i - 1]) + len(ll[i]) - 4 > mx: mx = len(ll[i - 1]) + len(ll[i]) - 4 print(max(mxx, mx - 1))
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 NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP 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()) arr = list(map(int, input().split())) start = 0 prev = arr[0] subarrays = [] for i, v in enumerate(arr): if i == 0: continue if v <= prev: if i - start > 1: subarrays.append((start, i - 1)) start = i prev = v i += 1 if i - start > 1: subarrays.append((start, i - 1)) start = i c_max = 1 for subarray in subarrays: c_max = max(c_max, subarray[1] - subarray[0] + 1) for j in range(len(subarrays) - 1): left = subarrays[j] right = subarrays[j + 1] if right[0] == left[1] + 1 and arr[right[0] + 1] > arr[left[1]]: c_max = max(c_max, left[1] - left[0] + 1 + right[1] - right[0]) if right[0] == left[1] + 1 and arr[right[0]] > arr[left[1] - 1]: c_max = max(c_max, left[1] - left[0] + 1 + right[1] - right[0]) print(c_max)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN 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 BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER 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())) p = [0] * n z = [0] * n i = 0 d = 1 while i < len(l): cnt = 1 pi = i pj = i + 1 while pj < len(l): if l[pj] > l[pi]: cnt += 1 else: break pj += 1 pi += 1 j = i k1 = 1 k2 = cnt while k1 <= cnt: p[j] = k1, k2 z[j] = d k1 += 1 k2 -= 1 j += 1 i = j d += 1 m = 0 for i in range(n): if i < 2: x = p[i][1] else: e1 = p[i][1] e2 = -1 if l[i] > l[i - 2] and z[i - 2] != z[i]: e2 = e1 + p[i - 2][0] x = max(e1, e2) if x > m: m = x 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL 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())) b = [1] * n tab = [] for i in range(n - 1): if a[i] < a[i + 1]: b[i + 1] = b[i] + 1 else: b[i + 1] = 1 tab.append((i - b[i] + 1, i, b[i])) tab.append((n - b[-1], n - 1, b[-1])) res = 0 for i in range(len(tab) - 1): res = max(res, tab[i][2]) if min(tab[i][2], tab[i + 1][2]) > 1 and ( a[tab[i][1]] < a[tab[i + 1][0] + 1] or a[tab[i][1] - 1] < a[tab[i + 1][0]] ): res = max(res, tab[i][2] + tab[i + 1][2] - 1) res = max(res, tab[-1][2]) for i in range(1, len(tab) - 1): if tab[i][2] == 1 and a[tab[i - 1][1]] < a[tab[i + 1][0]]: res = max(res, tab[i - 1][2] + tab[i + 1][2]) 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 BIN_OP LIST NUMBER VAR ASSIGN VAR LIST 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 EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER 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 NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER 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 n = int(sys.stdin.readline().strip()) a = [int(i) for i in sys.stdin.readline().strip().split()] a.append(-2000000000.0) dp = [0] * (n + 1) dp[0] = 1 bg = 0 for i in range(1, n + 1): if a[i] > a[i - 1]: dp[i] = dp[i - 1] + 1 else: for j in range(bg, i): dp[j] = dp[i - 1] dp[i] = 1 bg = i cnt = 0 for i in range(1, n): cnt = max(cnt, dp[i]) if a[i - 1] >= a[i] and a[i] < a[i + 1] and a[i - 1] < a[i + 1]: cnt = max(cnt, dp[i - 1] + dp[i + 1] - 1) if a[i - 1] <= a[i] and a[i] > a[i + 1] and a[i - 1] < a[i + 1]: cnt = max(cnt, dp[i - 1] + dp[i + 1] - 1) sys.stdout.write(str(cnt))
IMPORT 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR 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 IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR 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 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()] l = [0] * n r = [0] * n l[0] = 1 for i in range(1, n): if a[i] > a[i - 1]: l[i] = l[i - 1] + 1 else: l[i] = 1 r[n - 1] = 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: r[i] = r[i + 1] + 1 else: r[i] = 1 final = 0 s = 0 for i in range(1, n - 1): if a[i - 1] < a[i + 1]: s = l[i - 1] + r[i + 1] if s > final: final = s if final < max(l): final = max(l) print(final)
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 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 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 NUMBER ASSIGN 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 BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN 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 = list(map(int, input().split())) subarray = [] cur_length = 1 for i in range(n - 1): if a[i] < a[i + 1]: cur_length += 1 else: subarray.append(cur_length) cur_length = 1 subarray.append(cur_length) result = max(subarray) index_acc = 0 for i in range(len(subarray) - 1): index_acc += subarray[i] if subarray[i] >= 2 and subarray[i + 1] >= 2: leftmost = index_acc - 2 rightmost = index_acc + 1 if a[leftmost] < a[rightmost - 1] or a[leftmost + 1] < a[rightmost]: result = max(result, subarray[i] + subarray[i + 1] - 1) print(result)
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 BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER 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 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()] a += [0] dp = [0] * (n + 5) i = n - 2 dp[n - 1] = 1 while i >= 0: if a[i] < a[i + 1]: dp[i] = dp[i + 1] + 1 else: dp[i] = 1 i -= 1 temp = 1 ans = 1 for i in range(1, n): if a[i + 1] > a[i - 1]: ans = max(ans, temp + dp[i + 1]) if a[i] > a[i - 1]: temp += 1 else: temp = 1 ans = max(ans, temp) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER WHILE 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN 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$.
n = int(input()) L = list(map(int, input().split())) dp = [1] * n cnt = [1] * n dp[1], cnt[1] = (2, 2) if L[1] > L[0] else (1, 1) for idx in range(2, len(L)): cnt[idx] = cnt[idx - 1] + 1 if L[idx] > L[idx - 1] else 1 for idx in range(2, len(L)): dp[idx] = max( dp[idx - 1] + 1 if L[idx] > L[idx - 1] else 1, cnt[idx - 2] + 1 if L[idx] > L[idx - 2] else 1, ) print(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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR 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 NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER 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$.
n = int(input()) nums = list(map(int, input().strip().split())) curUsed = [(0) for i in range(n)] curUnused = [(0) for i in range(n)] curUnused[0] = 1 ans = 1 for i in range(1, n): if nums[i] > nums[i - 1]: curUnused[i] = curUnused[i - 1] + 1 curUsed[i] = curUsed[i - 1] + 1 else: curUnused[i] = 1 curUsed[i] = 1 if i >= 2 and nums[i] > nums[i - 2]: curUsed[i] = max(curUnused[i - 2] + 1, curUsed[i]) ans = max(curUsed[i], ans) ans = max(ans, curUnused[i]) print(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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR 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 VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR 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$.
def numbersListInput(): aux = list(map(int, input().strip().split())) return aux n = int(input()) a = numbersListInput() auxA = [1] * n auxB = [1] * n for i in range(1, n): if a[i] > a[i - 1]: auxA[i] = auxA[i - 1] + 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: auxB[i] = auxB[i + 1] + 1 res = max(auxA) for i in range(1, n - 1): if a[i - 1] < a[i + 1]: res = max(res, auxA[i - 1] + auxB[i + 1]) print(res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 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$.
def main(): buf = input() n = int(buf) buf = input() buflist = buf.split() a = list(map(int, buflist)) sublen_inc = [] sublen_dec = [] for i in range(n): sublen_inc.append(None) sublen_dec.append(None) c = 1 sublen_inc[0] = c for i in range(1, n): if a[i - 1] < a[i]: c += 1 else: c = 1 sublen_inc[i] = c c = 1 sublen_dec[n - 1] = c for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: c += 1 else: c = 1 sublen_dec[i] = c best = max(sublen_inc) for i in range(1, n - 1): if a[i - 1] < a[i + 1]: new_sublen = sublen_inc[i - 1] + sublen_dec[i + 1] if new_sublen > best: best = new_sublen print(best) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NONE EXPR FUNC_CALL VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER 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 BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN 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$.
n = int(input()) line = input().split(" ") A = [] for e in line: A.append(int(e)) ans = 1 left = [1] * n right = [1] * n for i in range(1, n): if A[i] > A[i - 1]: left[i] = 1 + left[i - 1] if A[n - 1 - i] < A[n - i]: right[n - 1 - i] = 1 + right[n - i] ans = 1 for i in range(n): ans = max(ans, left[i]) ans = max(ans, right[i]) if i > 0 and i < n - 1 and A[i - 1] < A[i + 1]: ans = max(ans, left[i - 1] + right[i + 1]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN 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 VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR 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$.
import sys input = sys.stdin.readline n = int(input()) A = list(map(int, input().split())) ANS = [0] * n count = 1 ANS[0] = 1 ANS2 = [0] * n ucount = 0 for i in range(1, n): if A[i] > A[i - 1]: count += 1 ANS[i] = count if ucount > 0: ucount += 1 ANS2[i] = ucount else: count = 1 ANS[i] = count ucount = 0 if i >= 2 and A[i - 2] < A[i]: ucount = max(ucount, ANS[i - 2] + 1) ANS2[i] = ucount print(max(max(ANS), max(ANS2)))
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 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 NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN 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()) l = list(map(int, input().split())) ans = 1 count = 1 t = 1 ind = -1 for i in range(n - 1): if l[i] < l[i + 1]: count += 1 else: if ind == -1: ans = max(ans, count) elif l[ind - 1] < l[ind + 1] or l[ind] < l[ind + 2]: ans = max(ans, t + count - 1) else: ans = max(ans, t, count) t = count count = 1 ind = i if ind == -1: print(n) else: if count != 1: if l[ind - 1] < l[ind + 1] or l[ind] < l[ind + 2]: ans = max(ans, t + count - 1) else: ans = max(ans, t, count) 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 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 IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF 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 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$.
R = lambda: map(int, input().split()) n = int(input()) arr = list(R()) + [0] left, right = [0] * (n + 1), [0] * (n + 1) for i in range(n): left[i] = left[i - 1] + 1 if arr[i] > arr[i - 1] else 1 for i in range(n - 1, -1, -1): right[i] = right[i + 1] + 1 if arr[i] < arr[i + 1] else 1 res = max(left + right) for i in range(1, n - 1): res = max(res, left[i - 1] + right[i + 1] if arr[i - 1] < arr[i + 1] else 0) print(res)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR 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 BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP 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()) arr = list(map(int, input().split())) a = [] temp = [arr[0]] for i in range(1, n): if arr[i] > arr[i - 1]: temp.append(arr[i]) else: a.append(temp) temp = [arr[i]] a.append(temp) c = 0 ans = [] for i in range(len(a) - 1): x = a[i] y = a[i + 1] m = 0 n = 0 if len(x) > 1: if y[0] > x[-2]: m = len(x) - 1 + len(y) if len(y) > 1: if y[1] > x[-1]: n = len(x) + len(y) - 1 if m == 0 and n == 0: ans.append(len(x)) ans.append(len(y)) else: ans.append(max(m, n)) if ans: print(max(ans)) 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 ASSIGN VAR LIST VAR NUMBER 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 ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL 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 NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL 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()) l = list(map(int, input().split())) end = [1] for i in range(1, n): if l[i] > l[i - 1]: end.append(end[-1] + 1) else: end.append(1) strt = [1] * n for i in range(n - 2, -1, -1): if l[i] < l[i + 1]: strt[i] = strt[i + 1] + 1 else: strt[i] = 1 ans = max(max(end), max(strt)) for i in range(1, n - 1): if l[i + 1] > l[i - 1]: ans = max(ans, end[i - 1] + strt[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 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 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 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()) seq = list(map(int, input().split())) best = [None] * n best[0] = 1, 0 for i in range(1, n): if seq[i] > seq[i - 1]: a, b = best[i - 1][0] + 1, best[i - 1][1] + 1 if i >= 2 and seq[i] > seq[i - 2]: b = max(b, best[i - 2][0] + 1) best[i] = a, b else: a, b = 1, 0 if i >= 2 and seq[i] > seq[i - 2]: b = max(b, best[i - 2][0] + 1) best[i] = a, b maxes = [max(i) for i in best] print(max(maxes))
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 NONE VAR ASSIGN VAR NUMBER 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 NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL 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()) ar = list(map(int, input().split())) l = [1] * n r = [1] * n ans = 0 for i in range(n - 1): if ar[i] < ar[i + 1]: l[i + 1] = l[i] + 1 for j in range(n - 1, 0, -1): if ar[j] > ar[j - 1]: r[j - 1] = r[j] + 1 for k in range(n - 2): if ar[k] < ar[k + 2]: ans = max(ans, l[k] + r[k + 2]) for m in range(n): ans = max(ans, l[m]) 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 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER 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 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$.
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) pre = -1 P = [] tmp = 0 for i, a in enumerate(A): if a > pre: P.append(tmp) else: tmp = i P.append(i) pre = a Q = [-1] * N tmp = N - 1 pre = N - 1 for i in reversed(range(N)): a = A[i] if a < pre: Q[i] = tmp else: tmp = i Q[i] = tmp pre = a ans = max(Q[0] + 1, N - P[N - 1]) for i in range(1, N - 1): ans = max(ans, Q[i] - P[i] + 1) if A[i - 1] < A[i + 1]: ans = max(ans, Q[i + 1] - P[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 NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR 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()) lis = [-1] + list(map(int, input().split())) + [0] ans = [0] + [1] * n + [1] prev = 0 for i in range(1, n + 1): if lis[i - 1] < lis[i]: ans[i] += ans[i - 1] k = max(ans) prev = 0 d = 0 ind = 0 for i in range(1, n + 2): if ans[i] == 1: if lis[ind + 2] > lis[ind]: d = max(d, ans[i - 1] + prev) if lis[ind + 1] > lis[ind - 1]: d = max(d, prev + ans[i - 1]) prev = ans[i - 1] ind = i - 1 d -= 1 print(max(k, d))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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()) l = list(map(int, input().split())) ans = [] v = [] x = [] for t in range(len(l)): if len(v) == 0: v.append(l[t]) elif l[t] > l[t - 1]: v.append(l[t]) else: ans.append(v) v = [l[t]] if t == len(l) - 1: ans.append(v) x.append(len(ans[-1])) for i in range(len(ans) - 1): x.append(len(ans[i])) if len(ans[i]) > 1 and ans[i][-2] < ans[i + 1][0]: x.append(len(ans[i]) + len(ans[i + 1]) - 1) if len(ans[i + 1]) > 1 and ans[i + 1][1] > ans[i][-1]: x.append(len(ans[i]) + len(ans[i + 1]) - 1) print(max(x))
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 LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER 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 BIN_OP VAR NUMBER NUMBER VAR VAR 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$.
n = int(input()) a = list(map(int, input().split())) dp = [[0, 0] for i in range(n + 1)] dp[1][0] = 1 dp[1][1] = 1 for i in range(2, n + 1): if a[i - 1] > a[i - 2]: dp[i][0] = dp[i - 1][0] + 1 dp[i][1] = dp[i - 1][1] + 1 else: dp[i][0] = 1 dp[i][1] = 1 if i - 3 >= 0 and a[i - 1] > a[i - 3]: dp[i][1] = max(dp[i][1], dp[i - 2][0] + 1) ans = 0 for i in range(n + 1): ans = max(ans, dp[i][0], 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 LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER 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 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 BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER 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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 maxIncSubarr(a, n): pre = [0] * n pos = [0] * n pre[0] = 1 pos[n - 1] = 1 l = 0 for i in range(1, n): if a[i] > a[i - 1]: pre[i] = pre[i - 1] + 1 else: pre[i] = 1 l = 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: pos[i] = pos[i + 1] + 1 else: pos[i] = 1 ans = 0 l = 1 for i in range(1, n): if a[i] > a[i - 1]: l += 1 else: l = 1 ans = max(ans, l) for i in range(1, n - 1): if a[i - 1] < a[i + 1]: ans = max(pre[i - 1] + pos[i + 1], ans) return ans n = int(input()) l = list(map(int, input().split())) print(maxIncSubarr(l, n))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER 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 ASSIGN VAR VAR 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 VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR 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 ASSIGN VAR FUNC_CALL 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 BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER 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$.
import sys def solve(): n = int(sys.stdin.readline()) arr = list(map(int, sys.stdin.readline().split())) arr.append(0) subarr = list() sappend = subarr.append start = 0 prev = arr[start] index = 1 mx = 0 while index <= n: cur = arr[index] if cur <= prev: sappend((start, index - 1)) mx = max(mx, index - 1 - start + 1) start = index prev = arr[index] index += 1 for i in range(1, len(subarr), 1): cur_start, cur_end = subarr[i] prev_start, prev_end = subarr[i - 1] cur_le = cur_end - cur_start + 1 prev_le = prev_end - prev_start + 1 if cur_le > 1: if ( prev_le > 1 and arr[prev_end - 1] < arr[cur_start] or arr[prev_end] < arr[cur_start + 1] ): mx = max(mx, cur_le + prev_le - 1) print(mx) solve()
IMPORT 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 NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR 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 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())) ls = [] i = 0 while i < len(a): b = [] b.append(a[i]) i += 1 while i < len(a): if b[-1] < a[i]: b.append(a[i]) else: break i += 1 ls.append(b) mx = len(ls[0]) for i in range(len(ls) - 1): val = 1 if len(ls[i + 1]) > 1: if ls[i][-1] < ls[i + 1][1]: val = len(ls[i] + ls[i + 1]) - 1 if len(ls[i]) > 1: if ls[i][-2] < ls[i + 1][0]: val = len(ls[i] + ls[i + 1]) - 1 val = max(val, len(ls[i]), len(ls[i + 1])) if val > mx: mx = val 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 LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL 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 FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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())) sub = [1] for i in range(1, n): if a[i] > a[i - 1]: sub.append(sub[-1] + 1) else: sub.append(1) val = sub[n - 1] aa = [0] * n aa[n - 1] = 1 ans1 = max(sub) for i in range(n - 2, -1, -1): if sub[i] < sub[i + 1]: aa[i] = val - sub[i] + 1 else: val = sub[i] aa[i] = 1 ans = [0] for i in range(2, n - 1): if a[i - 1] < a[i + 1]: ans.append(sub[i - 1] + aa[i + 1]) print(max(max(ans), 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 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 ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL 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 BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR 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$.
n = int(input()) a = [1e20] + list(map(int, input().split())) + [0] b = [0] * (n + 2) x = 0 for i in range(1, n + 1): if a[i] > a[i - 1]: x += 1 else: x = 1 b[i] = x x = 0 c = max(b) for i in range(n, 0, -1): if a[i - 1] < a[i + 1]: c = max(c, b[i - 1] + x) if a[i] < a[i + 1]: x += 1 else: x = 1 print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER 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 IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Panda is fond of numbers. Given a number, he subtracts it with squares of any one particular digit of that number to get new numbers. This operation can be applied any number of times (possibly zero) till he obtains a pandatic number. If he is able to reach to a pandatic number then he wins. A pandatic number is a number which can be expressed in the form A^A, where A is a positive integer. Input Format: The first line will contain T, the number of test cases. Then T lines follow, each containing an integer N. Output Format: For each test case, output whether it's possible for panda to reach a pandatic number by doing the operations as described. If it's possible print "Yes" (without quotes), otherwise print "No" (without quotes). Constraints: Subtask 1: (10 points) 1 ≀ T ≀ 10^3 1 ≀ N ≀ 10^3 Subtask 2: (90 points) 1 ≀ T ≀ 10^5 1 ≀ N ≀ 10^6 SAMPLE INPUT 3 1 3 13 SAMPLE OUTPUT Yes No Yes Explanation Case 1: 1 is a pandatic number, hence the answer is "Yes". Case 2: 3 is not a pandatic number, the answer for this is "No". 3 - 3^3 = -6 is also not a "pandatic number". Hence the final answer is "No". Case 3: 13 is not a pandatic number. 13 - 1^2 = 12 is not a pandatic number. 13 - 3^2 = 4 is a pandatic number. . . . Hence the final answer is "Yes".
rr = raw_input panda = set([(k**k) for k in range(1, 8)]) dp = {} for i in range(10**6 + 1): dp[i] = None for i in panda: dp[i] = True def dpp(x): if dp[x] is not None: return dp[x] for d in str(x): cand = x - int(d) ** 2 if cand > 0 and dp[cand]: return True return False for i in range(10**6 + 1): z = dpp(i) dp[i] = z for tc in range(int(rr())): N = int(rr()) if dp[N]: print("Yes") else: print("No")
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NONE FOR VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF IF VAR VAR NONE RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Panda is fond of numbers. Given a number, he subtracts it with squares of any one particular digit of that number to get new numbers. This operation can be applied any number of times (possibly zero) till he obtains a pandatic number. If he is able to reach to a pandatic number then he wins. A pandatic number is a number which can be expressed in the form A^A, where A is a positive integer. Input Format: The first line will contain T, the number of test cases. Then T lines follow, each containing an integer N. Output Format: For each test case, output whether it's possible for panda to reach a pandatic number by doing the operations as described. If it's possible print "Yes" (without quotes), otherwise print "No" (without quotes). Constraints: Subtask 1: (10 points) 1 ≀ T ≀ 10^3 1 ≀ N ≀ 10^3 Subtask 2: (90 points) 1 ≀ T ≀ 10^5 1 ≀ N ≀ 10^6 SAMPLE INPUT 3 1 3 13 SAMPLE OUTPUT Yes No Yes Explanation Case 1: 1 is a pandatic number, hence the answer is "Yes". Case 2: 3 is not a pandatic number, the answer for this is "No". 3 - 3^3 = -6 is also not a "pandatic number". Hence the final answer is "No". Case 3: 13 is not a pandatic number. 13 - 1^2 = 12 is not a pandatic number. 13 - 3^2 = 4 is a pandatic number. . . . Hence the final answer is "Yes".
""" pandatic_num = [] maxlimit = 10**6 + 1 for num in range(1, 10): numpow = num ** num if numpow <= maxlimit: val = 1 nextnum = (num + 1) ** (num + 1) pandatic_num.append(numpow) tempnum = numpow while tempnum <= (nextnum): tempnum = numpow + val**2 if str(val) in str(tempnum): pandatic_num.append(tempnum) val += 1 else: break this works if only substract the digits and not recursively reduce the number down to zero """ for _ in range(eval(input())): val = eval(input()) if val == 90 or val == 91: print("No") elif val < 13: if val == 1 or val == 4: print("Yes") else: print("No") else: print("Yes")
EXPR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Panda is fond of numbers. Given a number, he subtracts it with squares of any one particular digit of that number to get new numbers. This operation can be applied any number of times (possibly zero) till he obtains a pandatic number. If he is able to reach to a pandatic number then he wins. A pandatic number is a number which can be expressed in the form A^A, where A is a positive integer. Input Format: The first line will contain T, the number of test cases. Then T lines follow, each containing an integer N. Output Format: For each test case, output whether it's possible for panda to reach a pandatic number by doing the operations as described. If it's possible print "Yes" (without quotes), otherwise print "No" (without quotes). Constraints: Subtask 1: (10 points) 1 ≀ T ≀ 10^3 1 ≀ N ≀ 10^3 Subtask 2: (90 points) 1 ≀ T ≀ 10^5 1 ≀ N ≀ 10^6 SAMPLE INPUT 3 1 3 13 SAMPLE OUTPUT Yes No Yes Explanation Case 1: 1 is a pandatic number, hence the answer is "Yes". Case 2: 3 is not a pandatic number, the answer for this is "No". 3 - 3^3 = -6 is also not a "pandatic number". Hence the final answer is "No". Case 3: 13 is not a pandatic number. 13 - 1^2 = 12 is not a pandatic number. 13 - 3^2 = 4 is a pandatic number. . . . Hence the final answer is "Yes".
tc = int(input()) while tc: n = int(input()) if n == 90 or n == 91: print("No") elif n < 13: if n == 1 or n == 4: print("Yes") else: print("No") else: print("Yes") tc = tc - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER
Panda is fond of numbers. Given a number, he subtracts it with squares of any one particular digit of that number to get new numbers. This operation can be applied any number of times (possibly zero) till he obtains a pandatic number. If he is able to reach to a pandatic number then he wins. A pandatic number is a number which can be expressed in the form A^A, where A is a positive integer. Input Format: The first line will contain T, the number of test cases. Then T lines follow, each containing an integer N. Output Format: For each test case, output whether it's possible for panda to reach a pandatic number by doing the operations as described. If it's possible print "Yes" (without quotes), otherwise print "No" (without quotes). Constraints: Subtask 1: (10 points) 1 ≀ T ≀ 10^3 1 ≀ N ≀ 10^3 Subtask 2: (90 points) 1 ≀ T ≀ 10^5 1 ≀ N ≀ 10^6 SAMPLE INPUT 3 1 3 13 SAMPLE OUTPUT Yes No Yes Explanation Case 1: 1 is a pandatic number, hence the answer is "Yes". Case 2: 3 is not a pandatic number, the answer for this is "No". 3 - 3^3 = -6 is also not a "pandatic number". Hence the final answer is "No". Case 3: 13 is not a pandatic number. 13 - 1^2 = 12 is not a pandatic number. 13 - 3^2 = 4 is a pandatic number. . . . Hence the final answer is "Yes".
t = int(eval(input())) for _ in range(t): n = int(eval(input())) if n == 90 or n == 91: print("No") elif n < 13: if n == 1 or n == 4: print("Yes") else: print("No") else: print("Yes")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
It is the hard version of the problem. The difference is that in this version, there are nodes with already chosen colors. Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem? You have a perfect binary tree of $2^k - 1$ nodes β€” a binary tree where all vertices $i$ from $1$ to $2^{k - 1} - 1$ have exactly two children: vertices $2i$ and $2i + 1$. Vertices from $2^{k - 1}$ to $2^k - 1$ don't have any children. You want to color its vertices with the $6$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow). Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube. A picture of Rubik's cube and its 2D map. More formally: a white node can not be neighboring with white and yellow nodes; a yellow node can not be neighboring with white and yellow nodes; a green node can not be neighboring with green and blue nodes; a blue node can not be neighboring with green and blue nodes; a red node can not be neighboring with red and orange nodes; an orange node can not be neighboring with red and orange nodes; However, there are $n$ special nodes in the tree, colors of which are already chosen. You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color. The answer may be too large, so output the answer modulo $10^9+7$. -----Input----- The first line contains the integers $k$ ($1 \le k \le 60$) β€” the number of levels in the perfect binary tree you need to color. The second line contains the integer $n$ ($1 \le n \le \min(2^k - 1, 2000)$) β€” the number of nodes, colors of which are already chosen. The next $n$ lines contains integer $v$ ($1 \le v \le 2^k - 1$) and string $s$ β€” the index of the node and the color of the node ($s$ is one of the white, yellow, green, blue, red and orange). It is guaranteed that each node $v$ appears in the input at most once. -----Output----- Print one integer β€” the number of the different colorings modulo $10^9+7$. -----Examples----- Input 3 2 5 orange 2 white Output 1024 Input 2 2 1 white 2 white Output 0 Input 10 3 1 blue 4 red 5 orange Output 328925088 -----Note----- In the picture below, you can see one of the correct colorings of the first test example.
MOD = 10**9 + 7 color = {"white": 0, "yellow": 5, "green": 2, "blue": 3, "red": 4, "orange": 1} special = {} marked = set() k = int(input()) n = int(input()) dp = {} def solve(i, j): if special.get(i, -1) != -1 and special[i] != j: return 0 if dp[i][j] != -1: return dp[i][j] nodel = 2 * i noder = 2 * i + 1 suml = 0 sumr = 0 for col in range(6): if col != 5 - j and col != j: if nodel in marked: suml += solve(nodel, col) else: suml = 1 if noder in marked: sumr += solve(noder, col) else: sumr = 1 dp[i][j] = suml * sumr % MOD return dp[i][j] for _ in range(n): v, s = input().split(" ") v = int(v) special[v] = color[s] while v not in marked and v >= 1: marked.add(v) dp[v] = [-1] * 6 v //= 2 res = 0 for col in range(6): res += solve(1, col) unmarked_node = 2**k - 1 - len(marked) ability_unmarked = pow(4, unmarked_node, MOD) res %= MOD res = res * ability_unmarked % MOD print(res)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
It is the hard version of the problem. The difference is that in this version, there are nodes with already chosen colors. Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem? You have a perfect binary tree of $2^k - 1$ nodes β€” a binary tree where all vertices $i$ from $1$ to $2^{k - 1} - 1$ have exactly two children: vertices $2i$ and $2i + 1$. Vertices from $2^{k - 1}$ to $2^k - 1$ don't have any children. You want to color its vertices with the $6$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow). Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube. A picture of Rubik's cube and its 2D map. More formally: a white node can not be neighboring with white and yellow nodes; a yellow node can not be neighboring with white and yellow nodes; a green node can not be neighboring with green and blue nodes; a blue node can not be neighboring with green and blue nodes; a red node can not be neighboring with red and orange nodes; an orange node can not be neighboring with red and orange nodes; However, there are $n$ special nodes in the tree, colors of which are already chosen. You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color. The answer may be too large, so output the answer modulo $10^9+7$. -----Input----- The first line contains the integers $k$ ($1 \le k \le 60$) β€” the number of levels in the perfect binary tree you need to color. The second line contains the integer $n$ ($1 \le n \le \min(2^k - 1, 2000)$) β€” the number of nodes, colors of which are already chosen. The next $n$ lines contains integer $v$ ($1 \le v \le 2^k - 1$) and string $s$ β€” the index of the node and the color of the node ($s$ is one of the white, yellow, green, blue, red and orange). It is guaranteed that each node $v$ appears in the input at most once. -----Output----- Print one integer β€” the number of the different colorings modulo $10^9+7$. -----Examples----- Input 3 2 5 orange 2 white Output 1024 Input 2 2 1 white 2 white Output 0 Input 10 3 1 blue 4 red 5 orange Output 328925088 -----Note----- In the picture below, you can see one of the correct colorings of the first test example.
k = int(input()) n = int(input()) l = [1] m = 10**9 + 7 for i in range(k - 1): l.append(16 * l[-1] ** 2 % m) counts = {} ind = {"white": 0, "green": 1, "red": 2, "yellow": 3, "blue": 4, "orange": 5} given = {} for i in range(n): v, c = input().split() v = int(v) c = ind[c] given[v] = c def count(k, i, counts, color=None): if i in counts: return None m = 10**9 + 7 if 2 * i not in counts and 2 * i + 1 not in counts: layer = len(bin(i)) - 2 if color is None: counts[i] = [l[k - layer]] * 6 else: counts[i] = [0] * 6 counts[i][color] = l[k - layer] elif 2 * i in counts and 2 * i + 1 in counts: left = counts[2 * i] right = counts[2 * i + 1] new = [0] * 6 for _ in range(6): totleft = sum(left) - left[_] - left[(_ + 3) % 6] totright = sum(right) - right[_] - right[(_ + 3) % 6] if color is None or _ == color: new[_] = totleft * totright % m counts[i] = new else: layer = len(bin(i)) - 2 if 2 * i in counts: left = counts[2 * i] right = [l[k - layer - 1]] * 6 else: left = counts[2 * i + 1] right = [l[k - layer - 1]] * 6 new = [0] * 6 for _ in range(6): totleft = sum(left) - left[_] - left[(_ + 3) % 6] totright = sum(right) - right[_] - right[(_ + 3) % 6] if color is None or _ == color: new[_] = totleft * totright % m counts[i] = new bits = k while bits > 0: for guy in list(counts.keys()): if len(bin(guy)) == bits + 3: color = given[guy // 2] if guy // 2 in given else None count(k, guy // 2, counts, color) for guy in given: if len(bin(guy)) == bits + 2: count(k, guy, counts, given[guy]) bits -= 1 print(sum(counts[1]) % m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR DICT ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF NONE IF VAR VAR RETURN NONE ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR BIN_OP LIST VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NONE VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NONE VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NONE EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR
It is the hard version of the problem. The difference is that in this version, there are nodes with already chosen colors. Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem? You have a perfect binary tree of $2^k - 1$ nodes β€” a binary tree where all vertices $i$ from $1$ to $2^{k - 1} - 1$ have exactly two children: vertices $2i$ and $2i + 1$. Vertices from $2^{k - 1}$ to $2^k - 1$ don't have any children. You want to color its vertices with the $6$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow). Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube. A picture of Rubik's cube and its 2D map. More formally: a white node can not be neighboring with white and yellow nodes; a yellow node can not be neighboring with white and yellow nodes; a green node can not be neighboring with green and blue nodes; a blue node can not be neighboring with green and blue nodes; a red node can not be neighboring with red and orange nodes; an orange node can not be neighboring with red and orange nodes; However, there are $n$ special nodes in the tree, colors of which are already chosen. You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color. The answer may be too large, so output the answer modulo $10^9+7$. -----Input----- The first line contains the integers $k$ ($1 \le k \le 60$) β€” the number of levels in the perfect binary tree you need to color. The second line contains the integer $n$ ($1 \le n \le \min(2^k - 1, 2000)$) β€” the number of nodes, colors of which are already chosen. The next $n$ lines contains integer $v$ ($1 \le v \le 2^k - 1$) and string $s$ β€” the index of the node and the color of the node ($s$ is one of the white, yellow, green, blue, red and orange). It is guaranteed that each node $v$ appears in the input at most once. -----Output----- Print one integer β€” the number of the different colorings modulo $10^9+7$. -----Examples----- Input 3 2 5 orange 2 white Output 1024 Input 2 2 1 white 2 white Output 0 Input 10 3 1 blue 4 red 5 orange Output 328925088 -----Note----- In the picture below, you can see one of the correct colorings of the first test example.
import sys from sys import stdin cdic = {} cdic["white"] = 0 cdic["yellow"] = 0 cdic["green"] = 1 cdic["blue"] = 1 cdic["red"] = 2 cdic["orange"] = 2 mod = 10**9 + 7 k = int(stdin.readline()) n = int(stdin.readline()) dp = {} dplis = [] vtos = {} for i in range(n): v, s = stdin.readline()[:-1].split() v = int(v) vtos[v] = s while v != 0: if v not in dp: dp[v] = [0, 0, 0] dplis.append(v) v //= 2 dplis.sort() dplis.reverse() def getans(v, c): if v in dp: return dp[v][c] else: height = v.bit_length() remh = k - height + 1 chnum = 2**remh - 1 return pow(2, chnum - 1, mod) for v in dplis: if 2 ** (k - 1) <= v: ncolor = cdic[vtos[v]] dp[v][ncolor] = 1 else: for x in range(3): for y in range(3): for z in range(3): if x != y and x != z: dp[v][x] += getans(2 * v, y) * getans(2 * v + 1, z) dp[v][x] %= mod if v in vtos: ncolor = cdic[vtos[v]] for x in range(3): if x != ncolor: dp[v][x] = 0 ans = pow(2, 2**k - 1 - n, mod) * sum(dp[1]) print(ans % mod)
IMPORT ASSIGN VAR DICT ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR VAR IF BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
It is the hard version of the problem. The difference is that in this version, there are nodes with already chosen colors. Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem? You have a perfect binary tree of $2^k - 1$ nodes β€” a binary tree where all vertices $i$ from $1$ to $2^{k - 1} - 1$ have exactly two children: vertices $2i$ and $2i + 1$. Vertices from $2^{k - 1}$ to $2^k - 1$ don't have any children. You want to color its vertices with the $6$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow). Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube. A picture of Rubik's cube and its 2D map. More formally: a white node can not be neighboring with white and yellow nodes; a yellow node can not be neighboring with white and yellow nodes; a green node can not be neighboring with green and blue nodes; a blue node can not be neighboring with green and blue nodes; a red node can not be neighboring with red and orange nodes; an orange node can not be neighboring with red and orange nodes; However, there are $n$ special nodes in the tree, colors of which are already chosen. You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color. The answer may be too large, so output the answer modulo $10^9+7$. -----Input----- The first line contains the integers $k$ ($1 \le k \le 60$) β€” the number of levels in the perfect binary tree you need to color. The second line contains the integer $n$ ($1 \le n \le \min(2^k - 1, 2000)$) β€” the number of nodes, colors of which are already chosen. The next $n$ lines contains integer $v$ ($1 \le v \le 2^k - 1$) and string $s$ β€” the index of the node and the color of the node ($s$ is one of the white, yellow, green, blue, red and orange). It is guaranteed that each node $v$ appears in the input at most once. -----Output----- Print one integer β€” the number of the different colorings modulo $10^9+7$. -----Examples----- Input 3 2 5 orange 2 white Output 1024 Input 2 2 1 white 2 white Output 0 Input 10 3 1 blue 4 red 5 orange Output 328925088 -----Note----- In the picture below, you can see one of the correct colorings of the first test example.
import sys MOD = int(1000000000.0 + 7) colors_matrix = [ [2, 4, 3, 5], [2, 4, 3, 5], [0, 1, 4, 5], [0, 1, 4, 5], [0, 1, 2, 3], [0, 1, 2, 3], ] def rec(tree, vertex, level): global dp if vertex not in tree: return [dp[level]] * 6 vertex_color_restriction = tree[vertex] if level == 0: if vertex_color_restriction >= 0: res = [0] * 6 res[vertex_color_restriction] = 1 return res else: return [1] * 6 left = rec(tree, vertex * 2, level - 1) right = rec(tree, vertex * 2 + 1, level - 1) res = [0] * 6 for vertex_color in range(6): if vertex_color_restriction >= 0 and vertex_color_restriction != vertex_color: continue left_options = 0 for color_left in colors_matrix[vertex_color]: left_options += left[color_left] right_options = 0 for color_right in colors_matrix[vertex_color]: right_options += right[color_right] res[vertex_color] = left_options * right_options % MOD return res def solve(): global dp inp = sys.stdin.readline k = int(inp()) n = int(inp()) dp = [0] * k dp[0] = 1 for i in range(1, k): dp[i] = dp[i - 1] * 4 * dp[i - 1] * 4 % MOD tree = {} color_to_id = { "white": 0, "yellow": 1, "green": 2, "blue": 3, "red": 4, "orange": 5, } for i in range(n): v, s = inp().split() v = int(v) tree[v] = color_to_id[s] v //= 2 while v > 0: if v not in tree: tree[v] = -1 v //= 2 print(sum(rec(tree, 1, k - 1)) % MOD) def main(): solve() main()
IMPORT ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN BIN_OP LIST VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER RETURN VAR RETURN BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR DICT ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input() arr1 = [0] * 26 arr2 = [[(0) for k in range(26)] for i in range(26)] for i in s: c = ord(i) - ord("a") for j in range(26): arr2[j][c] += arr1[j] arr1[c] += 1 maxi = 0 for i in arr1: maxi = max(maxi, i) for i in arr2: maxi = max(maxi, max(i)) print(maxi)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
from sys import gettrace, stdin if not gettrace(): def input(): return next(stdin)[:-1] def main(): ss = [(ord(s) - ord("a")) for s in list(input())] lcount = [0] * 26 tlcount = [([0] * 26) for _ in range(26)] for s in ss: for i in range(26): tlcount[s][i] += lcount[i] lcount[s] += 1 m1 = max(lcount) m2 = max(map(max, tlcount)) print(max(m1, m2)) main()
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
import sys RI = lambda: [int(x) for x in sys.stdin.readline().split()] ri = lambda: sys.stdin.readline().strip() mod = 10**7 + 1 st = ri() cnt = [0] * 26 cnt2 = [[(0) for i in range(26)] for j in range(26)] ans = 0 for i in range(len(st)): c = ord(st[i]) - ord("a") for j in range(26): cnt2[j][c] += cnt[j] ans = max(ans, cnt2[j][c]) cnt[c] += 1 ans = max(ans, cnt[c]) 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 ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = list(input()) list1 = [0] * 26 list2 = list() for i in range(26): p = [0] * 26 list2.append(p) for i in range(len(s)): t = ord(s[i]) - ord("a") for j in range(26): list2[j][t] += list1[j] list1[t] += 1 ans1 = 0 for i in range(26): ans1 = max(ans1, list1[i]) for i in range(26): for j in range(26): ans1 = max(ans1, list2[i][j]) print(ans1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
dp = [[(0) for i in range(26)] for j in range(26)] s = input() ans = [(0) for i in range(26)] ans[ord(s[0]) - ord("a")] = 1 for i in range(1, len(s)): for j in range(26): dp[j][ord(s[i]) - ord("a")] += ans[j] ans[ord(s[i]) - ord("a")] += 1 an = 0 for i in range(26): for j in range(26): an = max(dp[i][j], an) print(max(an, max(ans)))
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
def solve(s, a, b): cnt = 0 res = 0 for ch in s: if ch == b: res += cnt if ch == a: cnt += 1 return res s = input() res = 0 for i in range(26): res = max(res, len([x for x in s if x == chr(i + 97)])) for j in range(26): res = max(res, solve(s, chr(97 + i), chr(97 + j))) print(res)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = str(input()) num = [0] * 30 a = [[(0) for x in range(26)] for y in range(26)] res = 0 for i in range(0, len(s)): val = ord(s[i]) - ord("a") for j in range(26): a[j][val] += num[j] num[val] += 1 for i in range(26): for j in range(26): res = max(res, a[i][j]) res = max(res, max(num)) print(int(res))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input() n = len(s) arr = [(-1) for _ in range(n)] for i in range(n): arr[i] = ord(s[i]) - ord("a") ans = 0 cnt = [(0) for _ in range(26)] for i in range(n): cnt[arr[i]] += 1 ans = max(cnt) cntPrev = [(0) for _ in range(26)] cnt2 = [[(0) for _ in range(26)] for __ in range(26)] for i in range(n): for j in range(26): cnt2[j][arr[i]] += cntPrev[j] cntPrev[arr[i]] += 1 for i in range(26): for j in range(26): ans = max(ans, cnt2[i][j]) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
A = [(ord(a) - 97) for a in input()] N = len(A) X = [0] * 26 Y = [([0] * 26) for _ in range(26)] for a in A: for k in range(26): Y[k][a] += X[k] X[a] += 1 print(max([max(y) for y in Y] + X))
ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
a = input() s_map = {x: (0) for x in "abcdefghijklmnopqrstuvwxyz"} another_map = {} for i in range(0, len(a)): for x in s_map: if x + a[i] not in another_map: another_map[x + a[i]] = 0 another_map[x + a[i]] += s_map[x] s_map[a[i]] += 1 print(max(list(another_map.items()) + list(s_map.items()), key=lambda x: x[1])[1])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
import sys message = sys.stdin.readline().strip() positions = {} for pos in range(len(message)): sym = message[pos] try: positions[sym].append(pos) except: positions[sym] = [pos] answer = 0 for sym in positions: answer = max(answer, len(positions[sym])) for sym1 in positions: for sym2 in positions: lenPositions1 = len(positions[sym1]) lenPositions2 = len(positions[sym2]) pos1 = 0 pos2 = 0 tmpAnswer = 0 while pos1 < lenPositions1 and pos2 < lenPositions2: while ( pos1 < lenPositions1 and positions[sym1][pos1] < positions[sym2][pos2] ): tmpAnswer += lenPositions2 - pos2 pos1 += 1 pos2 += 1 answer = max(answer, tmpAnswer) pos1 = 0 pos2 = 0 tmpAnswer = 0 while pos2 < lenPositions2 and pos1 < lenPositions1: while ( pos2 < lenPositions2 and positions[sym1][pos1] > positions[sym2][pos2] ): tmpAnswer += lenPositions1 - pos1 pos2 += 1 pos1 += 1 answer = max(answer, tmpAnswer) print(answer)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
def solve(s): count = [0] * 26 count_pair = [([0] * 26) for _ in range(26)] res = -float("INF") for i in s: a = ord(i) - ord("a") for j in range(26): if count[j] == 0: continue count_pair[j][a] += count[j] res = max(count_pair[j][a], res) count[a] += 1 res = max(res, count[a]) print(res) def main(): s = input() solve(s) main()
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input() arr1 = [] arr2 = [] for i in range(26): lst = [] for j in range(26): lst.append(0) arr2.append(lst) arr1.append(0) for ch in s: ind = ord(ch) - ord("a") for j in range(26): arr2[j][ind] += arr1[j] arr1[ind] += 1 ans = 0 for i in range(26): ans = max(ans, arr1[i]) for i in range(26): for j in range(26): ans = max(ans, arr2[i][j]) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = str(input()) cml = [[(0) for i in range(len(s) + 1)] for j in range(26)] c = 1 for i in s: k = ord(i) - ord("a") cml[k][c] = cml[k][c - 1] + 1 for j in range(26): if j != k: cml[j][c] = cml[j][c - 1] c += 1 ab = [[(0) for i in range(26)] for j in range(26)] c = 1 for k in s: i = ord(k) - ord("a") for j in range(26): ab[i][j] += cml[j][-1] - cml[j][c] c += 1 ans = 0 res = 0 for i in range(26): res = max(res, cml[i][-1]) for j in range(26): ans = max(ans, ab[i][j]) print(max(ans, res))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input().strip() prev = [[(0) for i in range(len(s))] for i in range(26)] prev[ord(s[0]) - ord("a")][0] = 1 for index in range(1, len(s)): cmp = ord(s[index]) - ord("a") for letter in range(26): prev[letter][index] = prev[letter][index - 1] prev[cmp][index] = prev[cmp][index - 1] + 1 dp1 = [[(0) for i in range(26)] for i in range(26)] dp2 = [[(0) for i in range(len(s))] for i in range(26)] for index in range(1, len(s)): cur = ord(s[index]) - ord("a") cmp = ord(s[index - 1]) - ord("a") for letter in range(26): dp1[letter][cur] += prev[letter][index - 1] ans = max(max([max(i) for i in dp1]), max([prev[i][len(s) - 1] for i in range(26)])) print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input() co = [0] * 26 co2 = [0] * (26 * 26) for a in s: a = ord(a) - ord("a") for b in range(26): r = a + 26 * b co2[r] += co[b] co[a] += 1 print(max(max(co), max(co2)))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = list(input()) n = len(s) t = [[(0) for i in range(26)] for i in range(26)] o = [(0) for i in range(26)] ans = 0 for i in range(n): for j in range(26): t[j][ord(s[i]) - 97] += o[j] o[ord(s[i]) - 97] += 1 ans = max(ans, max(o)) for i in range(26): for j in range(26): ans = max(ans, t[i][j]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input() n = len(s) count1 = [(0) for _ in range(26)] count2 = [[(0) for _ in range(26)] for _ in range(26)] for i in range(n): curr = ord(s[i]) - 97 for j in range(26): count2[j][curr] += count1[j] count1[curr] += 1 ans = 0 for i in range(26): ans = max(ans, count1[i]) for j in range(26): ans = max(ans, count2[i][j]) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input().strip() alph = "abcdefghijklmnopqrstuvwxyz" mx = max(s.count(i) for i in alph) for first in alph: for second in alph: count = 0 sc = s.count(second) for i in s: if i == second: sc -= 1 if i == first: count += sc mx = max(mx, count) print(mx)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
q = 1 for i in range(q): s = list(input()) a = [0] * 26 arr = [([0] * 26) for i in range(26)] for i in range(len(s)): for j in range(26): arr[j][ord(s[i]) - 97] += a[j] a[ord(s[i]) - 97] += 1 ans = max(a) for i in range(26): for j in range(26): ans = max(ans, arr[i][j]) print(ans)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input() dp = [] n = len(s) dp1 = {} for _ in range(n): dp.append(list([0] * 26)) dp[0][ord(s[0]) - ord("a")] += 1 ans = 1 for i in range(1, len(s)): vl = ord(s[i]) - ord("a") for j in range(26): dp[i][j] = dp[i - 1][j] if dp[i - 1][j]: vl1 = chr(ord("a") + j) + s[i] if dp1.get(vl1) == None: dp1[vl1] = dp[i - 1][j] else: dp1[vl1] += dp[i - 1][j] if j == vl: dp[i][j] += 1 for i in range(26): ans = max(dp[n - 1][i], ans) if len(dp1): ans = max(ans, max(dp1.values())) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
a, b = {}, {} for x in input(): for y in a: b[x, y] = b.get((x, y), 0) + a.get(y, 0) a[x] = a.get(x, 0) + 1 print(max(0, 0, *a.values(), *b.values()))
ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
F = [[(0) for i in range(26)] for j in range(26)] t = [0] * 26 s = input() ans = 0 for k in s: number = ord(k) - 97 for m in range(26): F[number][m] += t[m] ans = max(ans, F[number][m]) t[number] += 1 ans = max(ans, t[number]) print(ans)
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = list(input()) al = [] als = [] for i in s: if i in al: als[al.index(i)] += 1 else: al.append(i) als.append(1) ans1 = max(als) for i in al: for j in al: if i != j: f = 0 ans2 = 0 for k in range(len(s)): if s[k] == i: f += 1 continue if s[k] == j: ans2 += f ans1 = max(ans1, ans2) for i in als: ans1 = max(ans1, i * (i - 1) // 2) print(ans1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input() instant_count = {} dict = {} a = set(s) a = "".join(a) for q in a: instant_count[q] = 0 for i in s: for j in a: x = j + i if x not in dict: dict[x] = instant_count[j] else: dict[x] += instant_count[j] instant_count[i] += 1 print(max(max(instant_count.values()), max(dict.values())))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input() n = len(s) dp = [[(0) for i in range(26)] for j in range(n + 1)] for i in range(n): for j in range(26): if ord(s[i]) - ord("a") == j: dp[i + 1][j] = dp[i][j] + 1 else: dp[i + 1][j] = dp[i][j] m1 = 0 for i in range(26): p = dp[n][i] m1 = max(m1, p * (p - 1) // 2) m2 = 0 ma = [0] * (n + 1) for i in range(n + 1): ma[i] = max(dp[i]) d = {} m2 = ma[n] for i in range(n, 1, -1): ind = i - 1 c = s[ind] for j in range(26): d[chr(ord("a") + j) + c] = d.get(chr(ord("a") + j) + c, 0) + dp[i - 1][j] for i in d: m2 = max(m2, d[i]) print(max(m1, m2))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$. -----Input----- The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) β€” the text that Bessie intercepted. -----Output----- Output a single integer Β β€” the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at $(1)$, $(2)$, $(3)$ b occurs at $(4)$, $(5)$ ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$ aa occurs at $(1,2)$, $(1,3)$, $(2,3)$ bb occurs at $(4,5)$ aab occurs at $(1,3,5)$, $(2,3,4)$ aaa occurs at $(1,2,3)$ abb occurs at $(3,4,5)$ aaab occurs at $(1,2,3,4)$ aabb occurs at $(2,3,4,5)$ aaabb occurs at $(1,2,3,4,5)$ Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l.
s = input() ss = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split() d1 = {} d2 = {} for ssi in ss: d1[ssi] = 0 for i in ss: for k in ss: d2[i + k] = 0 for si in s: for ki in d1.keys(): d2[ki + si] += d1[ki] d1[si] += 1 print(max(max(d1.values()), max(d2.values())))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR