description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def solve(inp): n = len(inp) l = [0] * n r = [0] * n ans = 1 l[0] = 1 updateLeft(inp, l, n) updateRight(inp, r, n) for i in range(1, n - 1): if inp[i + 1] - inp[i - 1] >= 2: ans = max(ans, l[i - 1] + r[i + 1] + 1) for i in range(n - 1): ans = max(ans, r[i + 1] + 1) for i in range(1, n): ans = max(ans, l[i - 1] + 1) return ans def updateRight(inp, r, n): p1 = n - 2 p2 = n - 1 r[n - 1] = 1 while p1 >= 0: if inp[p1] >= inp[p1 + 1]: p2 = p1 r[p1] = p2 - p1 + 1 p1 -= 1 def updateLeft(inp, l, n): p1 = 0 p2 = 1 while p2 < n: if inp[p2] <= inp[p2 - 1]: p1 = p2 l[p2] = p2 - p1 + 1 p2 += 1 n = int(input()) lst = list(map(int, input().strip().split())) print(solve(lst))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR 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 ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) nums = list(map(int, input().split())) left = [1] * n right = [1] * n res = 1 for i in range(1, n): if nums[i - 1] < nums[i]: left[i] = left[i - 1] + 1 res = max(res, left[i]) for i in range(n - 2, -1, -1): if nums[i] < nums[i + 1]: right[i] = right[i + 1] + 1 res = max(res, right[i]) if res != n: res += 1 for i in range(1, n - 1): if nums[i - 1] + 1 < nums[i + 1]: res = max(res, left[i - 1] + right[i + 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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
import sys T = 1 for _ in range(T): n = int(input()) l = list(map(int, input().split())) p = [] i = 0 j = 1 kk = 0 while j < n: if l[j] <= l[j - 1]: p.append((i, j - 1)) if j - i > kk: kk = j - i i = j j += 1 p.append((i, j - 1)) if j - i > kk: kk = j - i ans = 0 if len(p) == 1: ans = n else: ans = kk + 1 for i in range(len(p) - 1): t1 = p[i] t2 = p[i + 1] i1, i2 = t1[0], t1[1] j1, j2 = t2[0], t2[1] if i1 == i2 or j1 == j2: q = j2 - i1 + 1 if q > ans: ans = q elif l[j1] - l[i2 - 1] >= 2 or l[j1 + 1] - l[i2] >= 2: q = j2 - i1 + 1 if q > ans: ans = q print(ans)
IMPORT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) a = [-1] + a + [1000000007] maxi = 0 up = [(0) for i in range(n + 2)] down = [(0) for i in range(n + 2)] for i in range(1, n + 1): up[i] = up[i - 1] + 1 if a[i] > a[i - 1] else 1 for i in range(n, 0, -1): down[i] = down[i + 1] + 1 if a[i] < a[i + 1] else 1 for i in range(1, n + 1): maxi = max(maxi, up[i - 1] + (a[i - 1] + 1 < a[i + 1]) * down[i + 1] + 1) maxi = max(maxi, up[i - 1] * (a[i + 1] - 1 > a[i - 1]) + down[i + 1] + 1) print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER 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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def canMerge(seq1, seq2): if len(seq2) == 1: return True last = seq1[-1] second = seq2[1] if second - last > 1: return True if len(seq1) == 1: return True second_last = seq1[-2] first = seq2[0] if first - second_last > 1: return True return False def main(): n = int(input()) arr = list(map(int, input().split())) sequences = [] seq = [arr[0]] for i in range(1, n): if arr[i] > seq[-1]: seq.append(arr[i]) else: sequences.append(seq) seq = [arr[i]] sequences.append(seq) ans = len(sequences[-1]) for i in range(len(sequences) - 1): seq1 = sequences[i] seq2 = sequences[i + 1] ans = max(ans, len(seq1) + 1, len(seq2) + 1) if canMerge(seq1, seq2): ans = max(ans, len(seq1) + len(seq2)) print(ans) main()
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF 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 NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR 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 VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = [int(x) for x in input().split()] res = [[0], []] cur = 1 for i in range(1, n): res[0].append(cur) if a[i - 1] < a[i]: cur += 1 else: cur = 1 cur = 1 for i in range(n - 2, -1, -1): res[1].append(cur) if a[i + 1] > a[i]: cur += 1 else: cur = 1 res[1] = res[1][::-1] + [0] fin = max(max(res[1][0] + 1, res[0][-1] + 1), 2) for i in range(1, n - 1): fin = max(fin, max(res[0][i] + 1, res[1][i] + 1)) if a[i - 1] + 1 < a[i + 1]: fin = max(fin, res[0][i] + res[1][i] + 1) print(min(n, fin))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def fast_dzy_loves_sequence(a): a = [10**9] + a + [0] lens = [] left = [] right = [] c_left = 0 c_right = 0 for i in range(0, len(a)): if i > 0 and a[i - 1] < a[i]: c_left += 1 else: c_left = 1 left.append(c_left) for j in range(len(a) - 1, -1, -1): if j < len(a) - 1 and a[j + 1] > a[j]: c_right += 1 else: c_right = 1 right.append(c_right) right.reverse() left[0] = 0 left[-1] = 0 right[0] = 0 right[-1] = 0 for k in range(1, len(a) - 1): if a[k - 1] + 1 < a[k + 1]: this_len = left[k - 1] + 1 + right[k + 1] else: this_len = max(left[k - 1] + 1, right[k + 1] + 1) lens.append(this_len) return max(lens) n = int(input()) a = [int(x) for x in input().split()] print(fast_dzy_loves_sequence(a))
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP LIST BIN_OP NUMBER NUMBER VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) INF = 10**9 dp = [([-INF] * 3) for i in range(n)] for i in range(n): dp[i][0] = dp[i][2] = 1 if i > 0: dp[i][1] = 2 def upd(i, cr, nx): dp[i + 1][nx] = max(dp[i + 1][nx], dp[i][cr] + 1) for i in range(n - 1): for j in range(3): cur = dp[i][j] if j == 0: if a[i + 1] > a[i]: upd(i, j, 0) upd(i, j, 2) else: upd(i, j, 2) elif j == 1: if a[i + 1] > a[i]: upd(i, j, 1) elif i > 0 and a[i + 1] > a[i - 1] + 1: upd(i, j, 1) ans = 0 for i in range(n): ans = max(ans, max(dp[i])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) A = input() A = A.split() i = 0 while i < n: A[i] = int(A[i]) i = i + 1 opt_solutions_0 = list() opt_solutions_1 = list() i = 0 while i < n: opt_solutions_0.append(0) opt_solutions_1.append(0) i = i + 1 opt_solutions_0[0] = 1 opt_solutions_1[0] = 1 i = 1 while i < n: if A[i] > A[i - 1]: opt_solutions_0[i] = opt_solutions_0[i - 1] + 1 else: opt_solutions_0[i] = 1 if i >= 3: if A[i - 1] < A[i]: if A[i - 2] < A[i - 1]: opt_solutions_1[i] = opt_solutions_1[i - 1] + 1 elif A[i - 2] >= A[i - 1]: case1_1 = None if A[i] - A[i - 2] >= 2: case1_1 = opt_solutions_0[i - 2] + 2 else: case1_1 = 2 case1_2 = None if A[i - 1] - A[i - 3] >= 2: case1_2 = opt_solutions_0[i - 3] + 3 else: case1_2 = 3 if case1_1 >= case1_2: opt_solutions_1[i] = case1_1 else: opt_solutions_1[i] = case1_2 elif A[i] - A[i - 2] >= 2: opt_solutions_1[i] = opt_solutions_0[i - 2] + 2 else: opt_solutions_1[i] = opt_solutions_0[i - 1] + 1 elif i == 2: if A[i - 1] < A[i]: opt_solutions_1[i] = 3 elif A[i] - A[i - 2] >= 2: opt_solutions_1[i] = opt_solutions_0[i - 2] + 2 else: opt_solutions_1[i] = opt_solutions_0[i - 1] + 1 else: opt_solutions_1[i] = 2 i = i + 1 max_l = opt_solutions_1[0] i = 1 while i < n: if opt_solutions_1[i] > max_l: max_l = opt_solutions_1[i] i = i + 1 print(max_l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NONE IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER 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 BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, input().split())) for i in range(1): n = nmbr() a = lst() if n == 1: print(1) continue f = [1] * n b = [1] * (1 + n) for i in range(1, n): if a[i] > a[i - 1]: f[i] = 1 + f[i - 1] for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: b[i] = b[i + 1] + 1 ans = min(n, max(f) + 1) for i in range(n): if i - 1 >= 0 and i + 1 < n and a[i - 1] + 2 <= a[i + 1]: ans = max(ans, f[i - 1] + b[i + 1] + 1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP 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 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 BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = input().split(" ") a = [int(a) for a in a] b = [(-1) for b in range(0, n)] now = 0 while now < n: start = now while now < n - 1 and a[now] < a[now + 1]: now += 1 while start <= now: b[start] = now start += 1 now += 1 start = now ans = 0 for i in range(0, n): if b[i] == n - 1: ans = max(ans, b[i] - i + 1) elif b[i] == n - 2: ans = max(ans, b[i] - i + 2) elif a[b[i] + 2] - a[b[i]] > 1: ans = max(ans, b[b[i] + 2] - i + 1) else: ans = max(ans, b[i] - i + 2) if b[i] == 0 or a[b[i] + 1] - a[b[i] - 1] > 1: ans = max(ans, b[b[i] + 1] - i + 1) if i != 0 and n != 1: ans = max(ans, b[i] - i + 2) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) c = [0] * (n + 2) d = [1] * (n + 2) a = [1] * (n + 2) a[0] = 0 d[-1] = 0 for i, x in enumerate(map(int, input().split()), 1): c[i] = x if c[i] > c[i - 1]: a[i] = a[i - 1] + 1 for i in range(n, 0, -1): if c[i] < c[i + 1]: d[i] = d[i + 1] + 1 m = 0 for i in range(1, n + 1): if c[i + 1] - c[i - 1] > 1: m = max(m, a[i - 1] + d[i + 1] + 1) else: m = max(m, a[i - 1] + 1, d[i + 1] + 1) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR 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 VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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 NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = [int(x) for x in input().split()] vcnt = 1 vpl = [0] vpr = [] for i in range(1, n): if a[i - 1] >= a[i]: vcnt += 1 vpr.append(i - 1) vpl.append(i) if len(vpl) > len(vpr): vpr.append(n - 1) mmax = 0 for i in range(vcnt): if vpr[i] - vpl[i] + 1 > mmax: mmax = vpr[i] - vpl[i] + 1 if mmax < len(a): mmax += 1 mmax1 = 0 for i in range(vcnt - 1): if vpr[i] - vpl[i] > 0 and vpr[i + 1] - vpl[i + 1] > 0: if a[vpr[i] - 1] + 1 < a[vpl[i + 1]] or a[vpr[i]] < a[vpl[i + 1] + 1] - 1: mm = vpr[i] - vpl[i] + vpr[i + 1] - vpl[i + 1] + 2 if mm > mmax1: mmax1 = mm if mmax1 > mmax: print(mmax1) else: print(mmax)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) Ar = [int(0)] * (n + 5) A = [int(0)] * (n + 5) i = 1 res = 0 for x in input().split(): Ar[i] = int(x) A[i] = 1 if Ar[i] > Ar[i - 1]: A[i] = A[i - 1] + 1 i += 1 for i in range(1, n + 1): res = max(res, min(A[i] + 1, n)) if Ar[i - A[i] + 1] > Ar[i - A[i] - 1] + 1: res = max(res, A[i] + A[i - A[i]]) if Ar[i - A[i] + 2] > Ar[i - A[i]] + 1: res = max(res, A[i] + A[i - A[i]]) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) b = [1] for i in range(1, n): if a[i] > a[i - 1]: b.append(b[-1] + 1) else: b.append(1) ans = max(b) if ans != n: ans += 1 c = [0] * n i = n - 1 val = b[-1] while i >= 0: for j in range(val): c[i] = val i -= 1 val = b[i] for i in range(1, n - 1): if a[i + 1] - a[i - 1] >= 2: if b[i] == 1: ans = max(ans, c[i - 1] + c[i]) elif b[i + 1] == 1: ans = max(ans, c[i + 1] + c[i]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) ans = 0 cnt = 1 q = [] for i in range(n - 1): if a[i] < a[i + 1]: cnt += 1 else: q.append([cnt, i]) cnt = 1 q.append([cnt, n - 1]) for i in range(len(q) - 1): c1, idx1 = q[i] c2, idx2 = q[i + 1] if idx1 + 2 < n and a[idx1] + 1 < a[idx1 + 2]: ans = max(ans, c1 + c2) elif 0 <= idx1 - 1 and idx1 + 1 < n and a[idx1 - 1] + 1 < a[idx1 + 1]: ans = max(ans, c1 + c2) else: ans = max(ans, c1) ans = max(ans, q[-1][0]) for i in range(len(q)): c1, idx1 = q[i] if idx1 + 1 < n: ans = max(ans, c1 + 1) for i in range(1, len(q)): c1, idx1 = q[i] if idx1 - 1 >= 0: ans = max(ans, c1 + 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 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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) a = [0] + a + [0] pre = [(0) for i in range(n + 2)] pre[1] = 1 for i in range(2, n + 1): pre[i] = pre[i - 1] + 1 if a[i] > a[i - 1] else 1 suf = [(0) for i in range(n + 2)] suf[n] = 1 for i in range(n - 1, 0, -1): suf[i] = suf[i + 1] + 1 if a[i] < a[i + 1] else 1 sol = 0 for i in range(1, n + 1): curr = max(pre[i - 1], suf[i + 1]) + 1 if a[i - 1] + 1 < a[i + 1]: curr = max(curr, pre[i - 1] + suf[i + 1] + 1) sol = max(sol, curr) print(sol)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) arr = [int(var) for var in input().split()] maxLeft = [(1) for _ in range(n)] maxRight = [(1) for _ in range(n)] ans = 1 for i in range(1, n): if arr[i] > arr[i - 1]: maxLeft[i] = maxLeft[i - 1] + 1 for i in reversed(range(n - 1)): if arr[i] < arr[i + 1]: maxRight[i] = maxRight[i + 1] + 1 for i in range(n): prev, next = arr[i - 1] if i - 1 >= 0 else -float("inf"), ( arr[i + 1] if i + 1 < n else float("inf") ) leftSubArray = maxLeft[i - 1] if i - 1 >= 0 else 0 rightSubArray = maxRight[i + 1] if i + 1 < n else 0 if not prev < arr[i] < next: if next - prev >= 2: ans = max(ans, rightSubArray + leftSubArray + 1) else: ans = max(ans, leftSubArray + 1, 1 + rightSubArray) else: ans = max(ans, rightSubArray + leftSubArray + 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 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 ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) arr = list(map(int, input().split())) pre = [(0) for i in range(n)] pre[-1] = 1 for i in range(n - 2, -1, -1): if arr[i + 1] > arr[i]: pre[i] = pre[i + 1] + 1 else: pre[i] = 1 ans = 0 for i in range(n): last1 = arr[i + pre[i] - 1] ans = max(ans, pre[i]) if pre[i] == 1: if i + 1 < n: ans = max(ans, pre[i + 1] + 1) elif i + pre[i] < n: if arr[i + pre[i]] > last1: ans = max(ans, pre[i] + pre[i + pre[i]]) elif pre[i + pre[i]] == 1: ans = max(ans, pre[i] + 1) else: if arr[i + pre[i] + 1] - last1 >= 2: ans = max(ans, pre[i] + pre[i + pre[i]]) if last1 + 1 >= arr[i + pre[i] + 1]: ans = max(ans, pre[i] + 1) if arr[i + pre[i]] - arr[i + pre[i] - 2] >= 2: ans = max(ans, pre[i] + pre[i + pre[i]]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def main(): n, l, res, a = int(input()), [], [], 0 aa = list(map(int, input().split())) for i, b in enumerate(aa): if a >= b: l.append(i) a = b if not l: print(n) return l.append(n) rapp, a = res.append, 0 for b in l: rapp(b - a) a = b a = b = 0 for c in l: if a + 1 < b < c - 1 and (aa[b] - aa[b - 2] > 1 or aa[b + 1] - aa[b - 1] > 1): rapp(c - a - 1) a, b = b, c print(max(res) + 1) def __starting_point(): main() __starting_point()
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
import sys n = int(input()) s = list(map(int, input().split())) a = [0] * n b = [0] * n a[0] = 1 b[0] = 1 if n == 1: print(1) sys.exit() for i in range(1, n): if s[i] > s[i - 1]: a[i] = a[i - 1] + 1 else: a[i] = 1 s = s[::-1] for i in range(1, n): if s[i] < s[i - 1]: b[i] = b[i - 1] + 1 else: b[i] = 1 s = s[::-1] b = b[::-1] ans = b[1] + 1 for i in range(1, n - 1): if s[i - 1] + 1 < s[i + 1]: ans = max(ans, a[i - 1] + 1 + b[i + 1]) else: ans = max(ans, a[i - 1] + 1, 1 + b[i + 1]) ans = max(ans, a[n - 2] + 1) 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 NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR 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 VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) if n <= 2: print(n) exit() a = list(map(int, input().split())) lower = [(0) for _ in range(n)] higher = [(0) for _ in range(n)] current = 0 e = -1 for x in range(n): if a[x] > e: current += 1 else: for y in range(current): lower[x - 1 - y] = y + 1 higher[x - 1 - y] = current - y current = 1 e = a[x] x = n for y in range(current): lower[x - 1 - y] = y + 1 higher[x - 1 - y] = current - y best = max(lower) x = 1 while x < n - 1: inc = a[x - 1] + 1 dec = a[x + 1] - 1 seq = 1 best = max(best, seq + higher[x - 1]) best = max(best, seq + lower[x + 1]) if inc < a[x + 1] or dec > a[x - 1]: best = max(best, seq + higher[x - 1] + lower[x + 1]) x += 1 if a[-1] <= a[-2]: best = max(best, higher[-2] + 1) if a[0] >= a[1]: best = max(best, lower[1] + 1) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
a = int(input()) z = list(map(int, input().split())) dp = [[(0) for i in range(len(z))] for i in range(2)] ans = [1] for i in range(1, len(z)): if z[i] > z[i - 1]: ans.append(ans[-1] + 1) else: ans.append(1) dp[0][0] = 1 dp[1][0] = 0 maxa = 1 for i in range(1, len(z)): if z[i] > z[i - 1]: if i == 1: dp[0][i] = 2 dp[1][i] = 2 maxa = max(dp[0][i], dp[1][i], maxa) continue dp[1][i] = ans[i - 1] + 1 dp[0][i] = dp[0][i - 1] + 1 if z[i - 2] + 1 < z[i]: dp[0][i] = max(dp[1][i - 1] + 1, dp[0][i]) maxa = max(maxa, dp[0][i], dp[1][i]) else: if i == 1: dp[0][i] = 2 dp[1][i] = 2 maxa = max(dp[0][i], dp[1][i], maxa) continue dp[1][i] = ans[i - 1] + 1 dp[0][i] = 2 if z[i - 2] + 1 < z[i]: dp[0][i] = max(dp[1][i - 1] + 1, dp[0][i]) maxa = max(dp[0][i], dp[1][i], maxa) print(maxa)
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 FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
from sys import stdin, stdout n = int(stdin.readline()) a = [int(s) for s in stdin.readline().split()] left = [(0) for i in range(n)] right = [(0) for i in range(n)] left[0] = 1 for i in range(1, n): if a[i] > a[i - 1]: left[i] = left[i - 1] + 1 else: left[i] = 1 right[n - 1] = 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: right[i] = right[i + 1] + 1 else: right[i] = 1 ans = 0 for i in range(1, n - 1): if a[i + 1] - a[i - 1] > 1: ans = max(ans, left[i - 1] + 1 + right[i + 1]) else: ans = max(ans, left[i - 1] + 1, right[i + 1] + 1) if n > 1: ans = max(ans, 1 + right[1], 1 + left[n - 2]) else: ans = 1 stdout.write(str(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) seq = [int(n) for n in input().split()] dp = [(0) for n in range(n + 1)] for j in range(0, n): if seq[j] > seq[j - 1]: dp[j] = dp[j - 1] + 1 else: dp[j] = 1 seq.append(0) m = 0 x = 0 for i in range(n - 1, -1, -1): m = max(m, dp[i - 1] + 1, x + 1) if i == 0 or i == n - 1 or seq[i - 1] + 1 < seq[i + 1]: m = max(m, dp[i - 1] + x + 1) if seq[i] < seq[i + 1]: x += 1 else: x = 1 print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
import sys input = sys.stdin.buffer.readline def solution(): n = int(input()) l = list(map(int, input().split())) end = [1] * (n + 1) start = [1] * (n + 1) for i in range(1, n): if l[i] > l[i - 1]: end[i] += end[i - 1] for i in range(n - 2, -1, -1): if l[i] < l[i + 1]: start[i] += start[i + 1] ans = max(end) if ans < n: ans += 1 for i in range(1, n - 1): if l[i - 1] + 1 < l[i + 1]: ans = max(ans, end[i - 1] + start[i + 1] + 1) print(ans) solution()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def solve(): size = int(input()) ls = list(map(int, input().rstrip().split())) dp0 = [(1) for i in range(size)] dp1 = [(1) for i in range(size)] for i in range(1, size): dp0[i] = dp0[i - 1] + 1 if ls[i - 1] < ls[i] else 1 for i in range(0, size - 1)[::-1]: dp1[i] = dp1[i + 1] + 1 if ls[i + 1] > ls[i] else 1 best = max(max(dp0), max(dp1)) for i in range(0, size): if i >= 1: best = max(best, dp0[i - 1] + 1) if i <= size - 2: best = max(best, dp1[i + 1] + 1) if i <= size - 2 and i >= 1: if ls[i - 1] + 1 < ls[i + 1]: best = max(best, dp0[i - 1] + dp1[i + 1] + 1) return best print(solve())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER 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 RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
elems = int(input()) data = list(map(int, input().split())) data.append(float("-inf")) def find_seq_breaks(): nonlocal elems nonlocal data seq_spans = [] sequence_idx = 0 longest_span = 0 for i in range(1, elems + 1): if data[i] <= data[i - 1]: seq_range = [sequence_idx, i - 1] seq_spans.append(seq_range) diff = i - sequence_idx if longest_span < diff: longest_span = diff sequence_idx = i return seq_spans, longest_span def parse_seqs(seq_spans, longest_span): nonlocal data nonlocal elems if len(seq_spans) > 1: longest_span += 1 for i in range(1, len(seq_spans)): one_past = seq_spans[i][0] if one_past >= 2 or one_past <= elems - 1: r = data[one_past] - data[one_past - 2] r2 = data[one_past + 1] - data[one_past - 1] candidate = seq_spans[i][1] - seq_spans[i - 1][0] + 1 if r >= r2: if r >= 2: if longest_span < candidate: longest_span = candidate elif r2 >= 2: if r2 >= 2: if longest_span < candidate: longest_span = candidate return longest_span d = find_seq_breaks() print(parse_seqs(d[0], d[1]))
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 STRING FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) pre = [1] * n suf = [1] * n for i in range(1, n): if a[i] > a[i - 1]: pre[i] = pre[i - 1] + 1 for i in range(n - 2, 0, -1): if a[i] < a[i + 1]: suf[i] = suf[i + 1] + 1 ans = max(pre) for i in range(0, n): if i > 0: ans = max(ans, pre[i - 1] + 1) if i < n - 1: ans = max(ans, suf[i + 1] + 1) if i > 0 and i < n - 1 and a[i - 1] <= a[i + 1] - 2: ans = max(ans, pre[i - 1] + suf[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 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 VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) start = [1] * n for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: start[i] += start[i + 1] end = [1] * n for i in range(1, n): if a[i] > a[i - 1]: end[i] += end[i - 1] ret = max(start) for i in range(n): if i + 1 < n: ret = max(ret, start[i + 1] + 1) if i - 1 >= 0: ret = max(ret, end[i - 1] + 1) if 0 < i < n - 1 and a[i + 1] - a[i - 1] > 1: ret = max(ret, end[i - 1] + 1 + start[i + 1]) print(ret)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def main(): n = int(input()) a = [10**10] + list(map(int, input().split())) + [-(10**10)] if n == 1: print(1) return b = [0] * (n + 10) c = [0] * (n + 10) i = 1 while i <= n: for j in range(i, n + 1): if a[j] >= a[j + 1]: break for k in range(i, j + 1): b[k] = i c[k] = j i = j + 1 ans = max(c[2], n - b[n - 1] + 1, c[1], n - b[n] + 1) for i in range(2, n): ans = max(ans, c[i] - i + 2, i - b[i] + 2) if a[i - 1] + 1 < a[i + 1]: ans = max(ans, c[i + 1] - b[i - 1] + 1) print(ans) def __starting_point(): main() __starting_point()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST BIN_OP NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST BIN_OP NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) arr = list(map(int, input().split())) pre, pre1 = [1], [1] for i in range(1, n): if arr[i] > arr[i - 1]: pre.append(pre[-1] + 1) else: pre.append(1) arr.reverse() for i in range(1, n): if arr[i] < arr[i - 1]: pre1.append(pre1[-1] + 1) else: pre1.append(1) pre1.reverse() arr.reverse() ans = 1 for i in range(n): if i > 0 and i < n - 1 and arr[i - 1] < arr[i + 1] - 1: ans = max(ans, pre[i - 1] + pre1[i + 1] + 1) if i > 0: ans = max(ans, pre[i - 1] + 1) if i < n - 1: ans = max(ans, pre1[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 VAR LIST NUMBER 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 EXPR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) arr = list(map(int, input().split())) l = [(1) for i in range(n)] m = [(1) for i in range(n)] f = 1 for i in range(n): if i != n - 1: if arr[i + 1] > arr[i]: l[i + 1] += l[i] for i in range(n - 2, -1, -1): if arr[i + 1] > arr[i]: m[i] += m[i + 1] max1 = max(l) z = max1 for i in range(n - 2): if arr[i + 2] - arr[i] > 1: max1 = max(max1, l[i] + m[i + 2] + 1) if z == max1 and max1 != n: max1 += 1 print(max1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR 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 ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
dp_right, dp_left = [], [] def solve(n, a): a.insert(0, 0) a.append(0) for i in range(1000005): dp_right.append(0) dp_left.append(0) res = 0 for i in range(1, n + 1): if a[i] > a[i - 1]: dp_right[i] = dp_right[i - 1] + 1 else: dp_right[i] = 1 res = max(res, dp_right[i]) for i in range(n, 1 - 1, -1): if a[i] < a[i + 1]: dp_left[i] = dp_left[i + 1] + 1 else: dp_left[i] = 1 for i in range(1, n + 1): res = max(res, max(dp_right[i - 1] + 1, dp_left[i + 1] + 1)) if a[i - 1] + 1 < a[i + 1]: res = max(res, dp_right[i - 1] + 1 + dp_left[i + 1]) return res def dp010_dzy_loves_sequences(n, a): return solve(n, a) n = int(input()) a = list(map(int, input().split())) print(dp010_dzy_loves_sequences(n, a))
ASSIGN VAR VAR LIST LIST FUNC_DEF EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
from sys import stdin input = stdin.readline n = int(input()) a = [-100] + [*map(int, input().split())] + [10**9 + 100] c = 0 ans = [] for i, j in enumerate(a): if 1 <= i <= n: if a[i - 1] < a[i]: c += 1 else: ans.append(c) c = 1 if a[i + 1] - a[i - 1] > 1 or a[i] - a[i - 2] > 1: ans.append(True) else: ans.append(False) if i == n + 1: ans.append(c) k = 0 for i, j in enumerate(ans): if type(j) == bool: if j: k = max(k, ans[i - 1] + ans[i + 1]) else: k = max(k, ans[i - 1] + 1, ans[i + 1] + 1) else: k = max(k, j) print(k)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
ints = int(input()) nums = list(map(int, input().split(" "))) if ints == 1: print(1) elif ints == 2: print(2) else: left = [1] * ints right = [1] * ints for i in range(ints - 1): if nums[i + 1] > nums[i]: left[i + 1] += left[i] nums.reverse() for i in range(ints - 1): if nums[i + 1] < nums[i]: right[i + 1] += right[i] nums.reverse() right.reverse() maximum = 2 for i in range(1, ints - 1): if nums[i - 1] + 1 < nums[i + 1]: maximum = max(maximum, left[i - 1] + right[i + 1] + 1) else: maximum = max(maximum, max(left[i - 1] + 1, right[i + 1] + 1)) maximum = max(maximum, left[ints - 2] + 1, right[1] + 1) print(maximum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def seq(arr): l = [1] * len(arr) r = [1] * len(arr) for i in range(1, len(arr)): if arr[i] > arr[i - 1]: l[i] = l[i - 1] + 1 for i in range(len(arr) - 2, -1, -1): if arr[i] < arr[i + 1]: r[i] = r[i + 1] + 1 m = max(l) if m < len(arr): m += 1 for i in range(1, len(arr) - 1): if arr[i - 1] + 1 < arr[i + 1]: m = max(m, l[i - 1] + r[i + 1] + 1) return m a = input() lst = list(map(int, input().strip().split())) print(seq(lst))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER 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 RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) nums = list(map(int, str(input()).split(" "))) increasing_subs = [] l = 0 r = 0 for i in range(n): if i == 0: continue if nums[i - 1] < nums[i]: r += 1 else: increasing_subs.append((l, r)) l = i r = i if i == n - 1: increasing_subs.append((l, r)) if n > 1: maxi = max([(x[1] - x[0] + 1) for x in increasing_subs]) + ( len(increasing_subs) != 1 ) else: maxi = 1 for i in range(len(increasing_subs)): if i != 0: a = increasing_subs[i - 1] b = increasing_subs[i] if ( a[0] != a[1] and b[0] != b[1] and (nums[b[0] + 1] - nums[a[1]] > 1 or nums[b[0]] - nums[a[1] - 1] > 1) ): maxi = max(maxi, b[1] - a[0] + 1) elif b[0] == b[1]: maxi = max(maxi, a[1] + 1 - a[0] + 1) elif a[0] == a[1]: maxi = max(maxi, b[1] - (b[0] + 1) + 1) print(maxi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) alist = [int(x) for x in input().split()] maximum = 2 l = [1] * n r = l[:] if n < 3: print(n) quit() for i in range(0, n - 1): if alist[i] < alist[i + 1]: l[i + 1] += l[i] if alist[n - 1 - i] > alist[n - 2 - i]: r[n - 2 - i] += r[n - 1 - i] for i in range(1, n - 1): if alist[i - 1] + 1 < alist[i + 1]: maximum = max(maximum, l[i - 1] + r[i + 1] + 1) else: maximum = max(maximum, l[i - 1] + 1, r[i + 1] + 1) maximum = max(maximum, r[1] + 1, l[n - 2] + 1) print(maximum)
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 BIN_OP LIST NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def find_inc_seq(n, nums): max_found = 1 if n else 0 dp = [([1] * 2) for _ in range(n)] dp[0][0] = 0 for i in range(2, n): if nums[i - 1] > nums[i - 2]: dp[i][0] = dp[i - 1][0] + 1 dp[n - 1][1] = 0 for i in range(n - 3, -1, -1): if nums[i + 1] < nums[i + 2]: dp[i][1] = dp[i + 1][1] + 1 for i in range(n): max_found = max(max_found, max(dp[i]) + 1) if i and i < n - 1 and nums[i + 1] - nums[i - 1] > 1: max_found = max(max_found, dp[i][0] + dp[i][1] + 1) return max_found n = int(input()) nums = list(map(int, input().split())) ans = find_inc_seq(n, nums) print(ans)
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR 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 BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER RETURN 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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) b = [] b.append(1) for i in range(1, len(a)): if a[i] > a[i - 1]: b.append(b[i - 1] + 1) else: b.append(1) for i in range(len(a) - 2, -1, -1): if a[i] < a[i + 1]: b[i] = b[i + 1] ans = max(b) + 1 if len(a) > 2: for i in range(len(a) - 2): if a[i] >= a[i + 1]: if a[i + 2] - a[i] > 1 or a[i + 1] - a[i - 1] > 1: ans = max(ans, b[i] + b[i + 1]) print(min(ans, len(a)))
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 EXPR FUNC_CALL VAR 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 BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR 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 BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) l = [1] * n r = [1] * n if n == 1: print(1) exit(0) ans = 1 for i in range(1, len(a)): if a[i] > a[i - 1]: l[i] = l[i - 1] + 1 for i in range(len(a) - 2, -1, -1): if a[i] < a[i + 1]: r[i] = r[i + 1] + 1 ans = max(r[1], l[len(a) - 2]) + 1 for i in range(1, len(a) - 1): ans = max(max(l[i - 1], r[i + 1]) + 1, ans) if a[i + 1] - a[i - 1] > 1: ans = max(ans, l[i - 1] + r[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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
import sys def solve(n, a): t = [0] * (n + 1) a = [0] + a for i in range(1, n + 1): if a[i] > a[i - 1]: t[i] = t[i - 1] + 1 else: t[i] = 1 r = 0 for i in range(1, n + 1): r = max(r, t[i]) cur_max = t[i] if ( a[i - cur_max] >= a[i - cur_max + 1] and a[i - cur_max - 1] < a[i - cur_max + 1] - 1 ): new_max = t[i - cur_max - 1] + 1 + t[i] r = max(r, new_max) elif i - cur_max + 2 <= i and a[i - cur_max] < a[i - cur_max + 2] - 1: new_max = t[i] + t[i - cur_max] r = max(r, new_max) return max(r, min(n, max(t) + 1)) n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().strip().split())) r = solve(n, a) print(r)
IMPORT FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) + [0] s, sb, val = [], 0, 0 for i in range(1, n + 1): if a[i] <= a[i - 1]: s.append((sb, i - 1)) val = max(val, i - sb) sb = i val += len(s) > 1 for i in range(1, len(s)): c = s[i][0] if c in range(2, n - 1) and max(a[c] - a[c - 2], a[c + 1] - a[c - 1]) >= 2: val = max(val, s[i][1] - s[i - 1][0] + 1) print(val)
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 VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
from sys import stdin inFile = stdin tokens = [] tokens_next = 0 def next_str(): global tokens, tokens_next while tokens_next >= len(tokens): tokens = inFile.readline().split() tokens_next = 0 tokens_next += 1 return tokens[tokens_next - 1] def nextInt(): return int(next_str()) def nextIncreasingSeg(a, ind): if ind >= len(a): return None r = ind while r + 1 < len(a) and a[r + 1] > a[r]: r += 1 return ind, r def myLen(s): return s[1] - s[0] + 1 def getBest(a, s0, s1): if not s1: return myLen(s0) if s0[1] - 1 >= s0[0]: if a[s0[1] - 1] < a[s1[0]] - 1: return myLen(s0) + myLen(s1) if s1[0] + 1 <= s1[1]: if a[s1[0] + 1] > a[s0[1]] + 1: return myLen(s0) + myLen(s1) return 1 + max(myLen(s0), myLen(s1)) n = nextInt() a = [nextInt() for i in range(n)] s0 = nextIncreasingSeg(a, 0) s1 = nextIncreasingSeg(a, s0[1] + 1) res = getBest(a, s0, s1) while s1 and s1[1] + 1 < len(a): s0, s1 = s1, nextIncreasingSeg(a, s1[1] + 1) res = max(res, getBest(a, s0, s1)) print(res)
ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NONE ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_DEF IF VAR RETURN FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) vec = list(map(int, input().split())) status = [1] * (n + 1) for i in range(1, n): if vec[i] > vec[i - 1]: status[i] = status[i - 1] + 1 far = [1] * (n + 1) cur = status[n - 1] for i in range(n - 2, -1, -1): if vec[i] < vec[i + 1]: far[i] += cur - status[i] else: cur = status[i] ans = max(status) for i in range(n): if i == 0: if i + 1 < n and vec[i + 1] != 1: ans = max(ans, far[i + 1] + 1) elif i == n - 1: ans = max(ans, status[i - 1] + 1) elif vec[i + 1] - vec[i - 1] > 1: if far[i] == 1: ans = max(ans, status[i - 1] + far[i + 1] + 1) else: ans = max(ans, status[i - 1] + far[i]) else: ans = max(ans, status[i] + 1) if vec[i + 1] != 1: ans = max(ans, far[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 BIN_OP 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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 VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) l = list(map(int, input().split(" "))) a = [1] * n b = [1] * n for i in range(1, n): if l[i] > l[i - 1]: a[i] = a[i - 1] + 1 i = n - 2 while i >= 0: if l[i + 1] > l[i]: b[i] = b[i + 1] + 1 i = i - 1 total = max(a) if total < n: total = total + 1 for i in range(1, n - 1): if l[i - 1] + 1 < l[i + 1]: total = max(total, a[i - 1] + 1 + b[i + 1]) else: total = max(total, a[i - 1] + 1) print(total)
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 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 ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) ls = [] temp = [a[0]] for i in range(1, n): if a[i] > a[i - 1]: temp.append(a[i]) else: ls.append(temp) temp = [a[i]] if len(temp): ls.append(temp) ans = 0 for i in range(len(ls) - 1): ans = max(ans, len(ls[i]) + 1) if len(ls[i + 1]) > 1 and ls[i + 1][1] - ls[i][-1] > 1: ans = max(ans, len(ls[i]) + len(ls[i + 1])) if len(ls[i]) > 1 and ls[i + 1][0] - ls[i][-2] > 1: ans = max(ans, len(ls[i]) + len(ls[i + 1])) ans = max(ans, len(ls[-1]) + 1) print(min(ans, 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 IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) if n == 1: print(1) else: right = [1] * n left = [1] * n for i in range(1, n): if a[i] > a[i - 1]: right[i] = right[i - 1] + 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: left[i] = left[i + 1] + 1 mx = max(max(right), max(left)) for i in range(n): if i == 0: if a[i] >= a[i + 1]: mx = max(mx, left[i + 1] + 1) else: mx = max(mx, left[i]) elif i == n - 1: if a[i] <= a[i - 1]: mx = max(mx, right[i - 1] + 1) else: mx = max(mx, right[i]) elif not a[i - 1] < a[i] < a[i + 1]: if a[i - 1] < a[i + 1] - 1: mx = max(mx, left[i + 1] + right[i - 1] + 1) else: mx = max(mx, right[i - 1] + 1, left[i + 1] + 1) print(mx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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 NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = [0] + list(map(int, input().split())) start = [0] * (n + 1) end = [0] * (n + 1) s, e = 1, 1 for i in range(2, n + 1): e += 1 if a[i] <= a[i - 1]: start[s:e] = [s] * (e - s) end[s:e] = [e - 1] * (e - s) s = e start[s:] = [s] * (n - s + 1) end[s:] = [n] * (n - s + 1) best = 1 for i in range(2, n): if a[i - 1] + 1 < a[i + 1]: best = max(best, end[i + 1] - start[i - 1] + 1) else: best = max(best, i - start[i - 1] + 1, end[i + 1] - i + 1) if n != 1: best = max(best, n - start[n - 1] + 1, end[2]) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP LIST VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP LIST VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP LIST VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def ii(): return int(input()) def si(): return input() def mi(): return map(int, input().split()) def msi(): return map(str, input().split()) def li(): return list(mi()) n = ii() a = li() pre, suf = [1] * n, [1] * n for i in range(1, n): if a[i] > a[i - 1]: pre[i] += pre[i - 1] for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: suf[i] += suf[i + 1] ans = max(pre) if ans < n: ans += 1 for i in range(1, n - 1): if a[i + 1] > a[i - 1] + 1: ans = max(ans, pre[i - 1] + suf[i + 1] + 1) print(ans)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) s = list(map(int, input().split())) B = [1] E = [1] ans = 0 if n < 3: print(n) else: for i in range(1, n): if s[i] > s[i - 1]: B.append(B[-1] + 1) else: B.append(1) for i in range(n - 1, 0, -1): if s[i] > s[i - 1]: E.append(E[-1] + 1) else: E.append(1) for i in range(-1, n - 1): if i == n - 2: ans = max(ans, B[i] + 1) elif i == -1: ans = max(ans, E[n - 2] + 1) elif s[i + 2] - s[i] > 1: ans = max(ans, B[i] + E[n - i - 3] + 1) else: ans = max(ans, B[i] + 1, E[n - i - 3] + 1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) s = input() s1 = s.split() l = [int(i) for i in s1] dp1 = [(1) for i in range(len(l))] for i in range(1, len(l)): if l[i] > l[i - 1]: dp1[i] = dp1[i - 1] + 1 dp2 = [(1) for i in range(len(l))] for i in range(len(l) - 2, -1, -1): if l[i] < l[i + 1]: dp2[i] = dp2[i + 1] + 1 maxlen = max(dp1) for i in range(0, len(l)): if i + 1 < len(l) and i - 1 >= 0 and l[i + 1] > l[i - 1] + 1: maxlen = max(dp1[i - 1] + dp2[i + 1] + 1, maxlen) if i - 1 >= 0 and l[i] <= l[i - 1]: maxlen = max(maxlen, dp1[i - 1] + 1) if i + 1 < len(l) and l[i] >= l[i + 1]: maxlen = max(maxlen, dp2[i + 1] + 1) print(maxlen)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
arg = int(input()) list1 = list(map(int, input().strip().split())) origarr = [a for a in list1] res = 1 if arg == 1: print(1) else: global_maximum = 0 if list1[1] <= list1[0]: orig_i = 0 orig = list1[0] list1[0] = list1[1] - 1 counter = 1 maximum = 2 current = list1[1] index = 2 else: maximum = 1 counter = 0 current = list1[0] index = 1 while True: if index == arg: global_maximum = max(global_maximum, res, maximum) break if list1[index] > current: maximum += 1 elif counter == 0: orig_i = index orig = list1[index] list1[index] = current + 1 counter += 1 maximum += 1 else: counter = 0 if maximum > res: res = maximum maximum = 1 list1[orig_i] = orig index = orig_i current = list1[index] index += 1 list1 = [a for a in origarr] list1.reverse() res = 1 if list1[1] >= list1[0]: orig_i = 0 orig = list1[0] list1[0] = list1[1] + 1 counter = 1 maximum = 2 current = list1[1] index = 2 else: maximum = 1 counter = 0 current = list1[0] index = 1 while True: if index == arg: global_maximum = max(global_maximum, res, maximum) break if list1[index] < current: maximum += 1 elif counter == 0: orig_i = index orig = list1[index] list1[index] = current - 1 counter += 1 maximum += 1 else: counter = 0 if maximum > res: res = maximum maximum = 1 list1[orig_i] = orig index = orig_i current = list1[index] index += 1 print(global_maximum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) l = [*map(int, input().split())] res = [[0, 0]] for i in range(1, n): if l[i] <= l[res[-1][-1]]: res.append([i, i]) else: res[-1][-1] = i f = lambda p: p[-1] - p[0] + 1 ans = f(res[0]) for i, p in enumerate(res): if i < len(res) - 1: v = f(p) if f(res[i + 1]) > 1 and l[p[-1]] + 1 < l[res[i + 1][0] + 1]: v += f(res[i + 1]) else: v += 1 ans = max(ans, v) if i > 0: v = f(p) if f(res[i - 1]) > 1 and l[res[i - 1][1] - 1] + 1 < l[p[0]]: v += f(res[i - 1]) else: v += 1 ans = max(ans, v) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
length = int(input()) nums = [int(num) for num in input().split()] + [float("inf"), float("-inf")] ans = 0 small = 0 big = 0 for i in range(length): if nums[i] > nums[i - 1]: small += 1 big += 1 else: ans = max(ans, small + 1, big) big = ( small + 1 if nums[i + 1] > nums[i - 1] + 1 or nums[i] > nums[i - 2] + 1 else 2 ) small = 1 if nums[i + 1] > nums[i] else 0 ans = max(ans, big) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
import sys def answer(n, a): if n == 1: return 1 if n == 2: return 2 lord = [(0) for _ in range(n)] lord[0] = 1 for i in range(1, n): if a[i] > a[i - 1]: lord[i] = lord[i - 1] + 1 else: lord[i] = 1 rord = [(0) for _ in range(n)] rord[n - 1] = 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: rord[i] = rord[i + 1] + 1 else: rord[i] = 1 rep = [(0) for _ in range(n)] rep[0] = rord[1] + 1 rep[n - 1] = lord[n - 2] + 1 for i in range(1, n - 1): rep[i] = max(lord[i - 1] + 1, rord[i + 1] + 1) if a[i - 1] + 1 < a[i + 1]: rep[i] = max(rep[i], lord[i - 1] + rord[i + 1] + 1) return max(rep) def main(): n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) print(answer(n, a)) return main()
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR 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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().strip().split())) inc = [(0) for i in range(n)] inc[0] = 1 for i in range(1, n): if a[i] > a[i - 1]: inc[i] = inc[i - 1] + 1 else: inc[i] = inc[0] dec = [(0) for i in range(n)] dec[-1] = 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: dec[i] = dec[i + 1] + 1 else: dec[i] = dec[-1] maxi = 1 for i in range(1, n - 1): if a[i - 1] - a[i + 1] < -1: maxi = max(maxi, inc[i - 1] + dec[i + 1] + 1) maxi = max(maxi, inc[i] + 1, dec[i] + 1) if n == 2: print(2) else: 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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
N = int(input()) if N > 1: a = list(map(int, input().split())) b = a[::-1] a.append(10**20) b.append(0) r = 0 dp = [(0) for i in range(N)] for l in range(N): while r < N and a[r] < a[r + 1]: r += 1 if l == r: dp[l] = 1 r += 1 elif l < r: if r != N: dp[l] = r - l + 1 else: dp[l] = r - l r = 0 dpr = [(0) for i in range(N)] for l in range(N): while r < N and b[r] > b[r + 1]: r += 1 if l == r: dpr[l] = 1 r += 1 elif l < r: if r != N: dpr[l] = r - l + 1 else: dpr[l] = r - l ans = 0 for i in range(N): if i == 0: ans = max(ans, dp[1] + 1) elif i == N - 1: ans = max(ans, dpr[1] + 1) elif a[i - 1] + 1 < a[i + 1]: ans = max(ans, dp[i + 1] + dpr[N - i] + 1) elif a[i - 1] + 1 >= a[i + 1]: ans = max(ans, dp[i + 1] + 1, dpr[N - i] + 1) print(ans) else: print(1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER 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 VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = [0] + list(map(int, input().split())) + [0] l = [] st = 1 for i in range(2, n + 2): if a[i] <= a[i - 1]: l.append([st, i - 1]) st = i if len(l) == 1: print(n) exit() mx = 0 for i in range(1, len(l)): lf = l[i - 1][1] rt = l[i][0] ln1 = l[i][1] - l[i][0] + 1 ln2 = l[i - 1][1] - l[i - 1][0] + 1 if a[rt + 1] - a[lf] > 1 or a[rt] - a[lf - 1] > 1: tm = ln1 + ln2 else: tm = max(ln1, ln2) + 1 mx = max(mx, tm) print(mx)
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 LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) l = list(map(int, input().split())) + [-(99**9)] t = 1 p = [] for i in range(1, n + 1): if l[i] > l[i - 1]: t += 1 else: p.append((t, i - 1)) t = 1 best = p[0][0] for i in range(len(p) - 1): uz = p[i][0] end = p[i][1] uz2 = p[i + 1][0] end2 = p[i + 1][1] if uz == 1 or uz2 == 1: best = max(best, uz2 + 1, uz + 1) else: k1 = end k2 = end2 - uz2 + 1 el1 = l[k2] - 1 el2 = l[k1] + 1 if el1 > l[k1 - 1] or el2 < l[k2 + 1]: best = max(best, uz2 + uz, uz2 + 1, uz + 1) else: best = max(best, uz2 + 1, uz + 1) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) if n == 1: print(1) else: a = [int(i) for i in input().split()] good = [[(0) for j in range(2)] for i in range(n)] good[0][1] = 1 for i in range(n): if a[i] > a[i - 1]: good[i][1] = good[i - 1][1] + 1 else: good[i][1] = 1 good[n - 1][0] = 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: good[i][0] = good[i + 1][0] + 1 else: good[i][0] = 1 mx = max(good[1][0] + 1, good[n - 2][1] + 1) for i in range(1, n - 1): if a[i + 1] - a[i - 1] > 1: mx = max(mx, good[i - 1][1] + good[i + 1][0] + 1) mx = max(mx, good[i - 1][1] + 1, good[i + 1][0] + 1) print(mx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
N = eval(input()) Data = [10**9 + 5] + list(map(int, input().split())) + [0] l, r, ans = [0] + [1] * N + [0], [0] + [1] * N + [0], 1 for i in range(1, N + 2): if Data[i - 1] < Data[i]: l[i] += l[i - 1] for i in range(N, 0, -1): if Data[i] < Data[i + 1]: r[i] += r[i + 1] for i in range(1, N + 1): if Data[i - 1] + 1 < Data[i + 1]: ans = max(ans, l[i - 1] + 1 + r[i + 1]) else: ans = max(ans, max(l[i - 1] + 1, 1 + r[i + 1])) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR LIST NUMBER BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR LIST NUMBER 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 FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
import sys sequenceLength = int(sys.stdin.readline()) sequence = list(map(int, sys.stdin.readline().split())) ans = 0 leftList = [1] * sequenceLength rightlist = [1] * sequenceLength for i in range(1, sequenceLength): if sequence[i - 1] < sequence[i]: leftList[i] += leftList[i - 1] ans = max(ans, leftList[i]) if ans < sequenceLength: ans += 1 for i in range(sequenceLength - 2, 0, -1): if sequence[i + 1] > sequence[i]: rightlist[i] += rightlist[i + 1] for i in range(1, sequenceLength - 1): if sequence[i + 1] - sequence[i - 1] >= 2: ans = max(ans, leftList[i - 1] + 1 + rightlist[i + 1]) 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) t = list(map(int, input().split())) t.append(0) p = [0] * (n + 1) for i in range(n - 1): p[i + 1] = p[i] + 1 if t[i + 1] > t[i] else 0 s = max(p) + 2 if s >= n: print(n) else: i = 1 if p[i] == 0: if t[i + 1] > t[i - 1] + 1: d = p[i - 1] - 1 i += 1 while p[i]: i += 1 s = max(s, d + p[i - 1] + 3) else: i += 1 else: i += 1 while i < n - 1: if p[i] == 0: if t[i] > t[i - 2] + 1: d = p[i - 2] elif t[i + 1] > t[i - 1] + 1: d = p[i - 1] - 1 else: i += 1 continue i += 1 while p[i]: i += 1 s = max(s, d + p[i - 1] + 3) else: i += 1 print(s)
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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
num_nums = int(input()) nums = list(map(int, input().split(" "))) increasing_subseqs = [] current_l = [] current_n = None for i in range(len(nums)): if len(current_l) == 0: current_l.append(nums[i]) current_n = nums[i] elif nums[i] > current_n: current_l.append(nums[i]) current_n = nums[i] else: increasing_subseqs.append(current_l) current_l = [nums[i]] current_n = nums[i] if len(current_l) > 0: increasing_subseqs.append(current_l) longest = len(increasing_subseqs[0]) for i in range(len(increasing_subseqs) - 1): curr_ = increasing_subseqs[i] next_ = increasing_subseqs[i + 1] if len(curr_) > 1 and len(next_) > 1: if next_[1] > curr_[-1] + 1 or next_[0] > curr_[-2] + 1: longest = max(len(curr_) + len(next_), longest) longest = max(longest, len(curr_) + 1, len(next_) + 1) print(longest)
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 NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL 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 VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n, b, i, ma = int(input()), [], 0, 0 a = list(map(int, input().split())) while i < n: j = i while j < n - 1 and a[j] < a[j + 1]: j += 1 b.append([i, j]) ma, i = max(j - i + 1 + (i != 0 or j != n - 1), ma), j + 1 for i in range(len(b) - 1): if b[i + 1][0] - b[i][1] == 2 and a[b[i + 1][0]] > a[b[i][1]] + 1: ma = max(ma, b[i + 1][1] - b[i][0] + 1) elif b[i + 1][0] - b[i][1] == 1: if ( b[i + 1][0] + 1 < n and a[b[i + 1][0] + 1] > a[b[i][1]] + 1 or b[i][1] - 1 >= 0 and a[b[i][1] - 1] + 1 < a[b[i + 1][0]] ): ma = max(ma, b[i + 1][1] - b[i][0] + 1) print(ma)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) arr = [int(i) for i in input().split(" ")] a = [] last = 0 running_length = 0 for i in arr: if i > last: running_length += 1 else: a.append(running_length) running_length = 1 last = i if running_length > 0: a.append(running_length) def canjoin(en, begin): if begin == len(a) - 1: return True return arr[en - 1] < arr[begin] - 1 or arr[en] < arr[begin + 1] - 1 best = max(a) + 1 if max(a) != len(arr) else len(arr) start = 0 for i in range(len(a) - 1): end = start + a[i] - 1 if end == len(arr) - 1: best = max(best, a[i]) else: if a[i + 1] == 1 and end + 1 != len(arr) - 1: if arr[end] < arr[end + 2] - 1: best = max(best, a[i] + a[i + 2]) if a[i] == 1 or a[i + 1] == 1 or canjoin(end, end + 1): best = max(best, a[i] + a[i + 1]) start = end + 1 print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
from sys import stdin n = int(input()) s = list(map(int, stdin.readline().strip().split())) dp = [(1) for i in range(n)] x = 1 for i in range(n - 2, -1, -1): if s[i] < s[i + 1]: x += 1 else: x = 1 dp[i] = x ans = 1 for i in range(n): ans = max(ans, min(n, dp[i] + 1)) aux = i + dp[i] if aux + 1 < n and abs(s[aux - 1] - s[aux + 1]) > 1 and s[aux - 1] < s[aux + 1]: ans = max(ans, dp[i] + 1 + dp[aux + 1]) aux -= 1 if ( aux > 0 and aux + 1 < n and abs(s[aux - 1] - s[aux + 1]) > 1 and s[aux - 1] < s[aux + 1] ): ans = max(ans, dp[i] + dp[aux + 1]) 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 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER 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 VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER 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
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) vec = list(map(int, input().split())) al = [] otrez = [] for x in vec: if len(al) == 0: al.append(x) elif x <= al[-1]: otrez.append(al) al = [x] else: al.append(x) otrez.append(al) maxx = 0 if len(otrez) != 1: for i in range(0, len(otrez) - 1): if len(otrez[i]) == 1 or len(otrez[i + 1]) == 1: maxot = len(otrez[i]) + len(otrez[i + 1]) elif otrez[i + 1][0] - otrez[i][-2] > 1 or otrez[i + 1][1] - otrez[i][-1] > 1: maxot = len(otrez[i]) + len(otrez[i + 1]) else: maxot = max([len(otrez[i]), len(otrez[i + 1])]) + 1 if maxot > maxx: maxx = maxot print(maxx) else: print(len(otrez[0]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) if n <= 2: print(n) else: al = list(map(int, input().split())) sta = 0 nextsta = sta + 1 l = 0 while sta < n: count = 0 last = al[sta] nextsta = sta + 1 for end in range(nextsta, n): if al[end] > last: last = al[end] elif count == 0: if end - sta >= 2 and al[end] - al[end - 2] >= 2: last = al[end] else: last += 1 count += 1 nextsta = end else: l = max(l, end - sta) if nextsta > sta + 1: nextend = max(nextsta + 1, end - 1) else: nextend = nextsta + 1 break if end == n - 1: if count == 0 and sta >= 1: l = max(l, n + 1 - sta) else: l = max(l, n - sta) nextsta = n sta = nextsta print(l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) A = [int(ele) for ele in input().split(" ")] if n <= 2: print(n) else: LISend = [1] * n LISbegin = [1] * n for i in range(1, n): if A[i] > A[i - 1]: LISend[i] = LISend[i - 1] + 1 for i in range(n - 2, -1, -1): if A[i] < A[i + 1]: LISbegin[i] = LISbegin[i + 1] + 1 maxLength = 0 for i in range(1, n - 1): if A[i + 1] - A[i - 1] >= 2: maxLength = max(LISend[i - 1] + 1 + LISbegin[i + 1], maxLength) maxLength = max(LISbegin[1] + 1, maxLength) maxLength = max(LISend[n - 2] + 1, maxLength) maxLength = max(min(n, max(LISbegin) + 1), maxLength) print(maxLength)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) arr = list(map(int, input().split())) left, right = [1] * n, [1] * n left[0] = 0 for i in range(2, n): if arr[i - 1] > arr[i - 2]: left[i] += left[i - 1] right[-1] = 0 for i in range(n - 3, -1, -1): if arr[i + 1] < arr[i + 2]: right[i] += right[i + 1] ans = 1 for i in range(n): if i - 1 >= 0 and i + 1 <= n - 1: if arr[i + 1] - arr[i - 1] >= 2: ans = max(ans, left[i] + 1 + right[i]) ans = max(ans, left[i] + 1, right[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 VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) sequence = [float("-inf")] + [int(i) for i in input().split()] + [float("inf")] f1 = [0] * n f2 = [0] * n f3 = [ (True if sequence[i + 1] - sequence[i - 1] > 1 else False) for i in range(1, len(sequence) - 1) ] len_1 = 0 len_2 = 0 l = len(sequence) - 1 for i in range(1, len(sequence) - 1): f1[i - 1] = len_1 f2[i - 1] = len_2 if sequence[i] > sequence[i - 1]: len_1 += 1 else: len_1 = 1 if sequence[l - i] < sequence[l - i + 1]: len_2 += 1 else: len_2 = 1 f2 = f2[::-1] f = [(f1[i] + f2[i] + 1 if f3[i] else max(f1[i], f2[i]) + 1) for i in range(0, n)] max_len = max(f) print(max_len)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR LIST FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) pre = [(1) for i in range(n)] suf = [(1) for i in range(n)] for i in range(1, n): if a[i] > a[i - 1]: pre[i] = pre[i - 1] + 1 for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: suf[i] = suf[i + 1] + 1 ans = 0 for i in range(n): if i == 0: ans = max(ans, min(n, suf[i] + 1)) elif i == n - 1: ans = max(ans, min(n, pre[i] + 1)) else: ans = max(ans, min(n, 1 + pre[i]), min(1 + suf[i], n)) if a[i - 1] + 1 < a[i + 1]: ans = max(ans, pre[i - 1] + 1 + suf[i + 1]) if n == 1: ans = 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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = [int(x) for x in input().split()] l, r = 0, 0 c = None mx = 1 while r < n - 1: r += 1 if a[r] <= (a[r - 1] if r - 1 != c else a[r - 2] + 1): if c is not None and r - 1 == c and a[r - 1] < a[r]: if a[c] < a[c + 1]: l = c = c - 1 else: l = c else: if c is not None: if a[c] < a[c + 1]: l = c else: l = c + 1 if r - 1 == l or a[r] - a[r - 2] > 1: c = r - 1 else: c = r mx = max(mx, r - l + 1) print(mx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NONE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NONE IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) a = list(map(int, input().split())) dp = [1] * n for i in range(1, n): if a[i] > a[i - 1]: dp[i] = dp[i - 1] + 1 ans = 1 l = dp[-1] for j in range(n - 1, 0, -1): ans = max(ans, dp[j]) if dp[j - 1] >= dp[j]: if j + 1 < n: if ( a[j + 1] - a[j - 1] > 1 or j - 1 == 0 or j - 2 >= 0 and a[j] - a[j - 2] > 1 ): ans = max(ans, l + dp[j - 1]) ans = max(ans, dp[j - 1] + 1, l + 1) l = dp[j - 1] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR 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 NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
R = lambda: map(int, input().split()) n = int(input()) a = list(R()) dp = [1] * n res = min(2, n) for i in range(n - 2, -1, -1): dp[i] = dp[i + 1] + 1 if a[i] < a[i + 1] else 1 cnt = 0 for i in range(n): if 0 < i < n - 1 and a[i + 1] > a[i - 1] + 1: res = max(res, cnt + dp[i + 1] + 1) else: res = max(res, cnt + 1, dp[i + 1] + 1 if i < n - 1 else 1) cnt = cnt + 1 if i > 0 and a[i] > a[i - 1] else 1 print(res)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 FUNC_CALL VAR NUMBER VAR 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 NUMBER FOR VAR FUNC_CALL VAR VAR IF NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def find_longest_streak(n, nums): if n < 2: return n rights = [0] * n lefts = [0] * n rights[0] = 1 lefts[n - 1] = 1 for i in range(1, n): if nums[i] > nums[i - 1]: rights[i] = rights[i - 1] + 1 else: rights[i] = 1 for i in range(n - 2, -1, -1): if nums[i] < nums[i + 1]: lefts[i] = lefts[i + 1] + 1 else: lefts[i] = 1 highest = 0 for i in range(n): highest = max(highest, change_value(n, nums, i, rights, lefts)) return highest def change_value(n, nums, index, rights, lefts): if index - 1 < 0: return lefts[index + 1] + 1 if index + 1 == n: return rights[index - 1] + 1 if nums[index - 1] < nums[index + 1] - 1: return 1 + rights[index - 1] + lefts[index + 1] else: return max(rights[index - 1], lefts[index + 1]) + 1 n = int(input()) nums = [int(i) for i in input().split(" ")] print(find_longest_streak(n, nums))
FUNC_DEF IF VAR NUMBER RETURN 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 VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
N = int(input()) A = list(map(int, input().split())) subseg = [] start = 0 for i in range(N - 1): if A[i] >= A[i + 1]: subseg.append((A[start], A[i], i - start, start, i)) start = i + 1 else: if N - 1 == 0: subseg.append((A[start], A[start], N - start - 1, start, start)) else: subseg.append((A[start], A[i + 1], N - start - 1, start, i + 1)) l = len(subseg) ans = max(subseg, key=lambda x: x[2])[2] + 1 for i in range(l): if i + 1 < l and subseg[i + 1][2] == 0: if i + 2 < l and subseg[i][1] + 2 <= subseg[i + 2][0]: ans = max(ans, subseg[i][2] + subseg[i + 2][2] + 3) if ( i + 1 < l and subseg[i + 1][3] + 1 < N and subseg[i][1] + 1 < A[subseg[i + 1][3] + 1] ): ans = max(ans, subseg[i][2] + subseg[i + 1][2] + 2) if ( i + 1 < l and 0 <= subseg[i][4] - 1 and A[subseg[i][4] - 1] + 1 < subseg[i + 1][0] ): ans = max(ans, subseg[i][2] + subseg[i + 1][2] + 2) if i != 0 or i != l - 1: ans = max(ans, subseg[i][2] + 2) else: ans = max(ans, subseg[i][2] + 1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER 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 IF BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER 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 IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
n = int(input()) arr = [int(x) for x in input().split(" ")] af = [0] * n ab = [0] * n for i in range(n): if i == 0 or arr[i] <= arr[i - 1]: af[i] = 1 else: af[i] = af[i - 1] + 1 for i in range(n - 1, -1, -1): if i == n - 1 or arr[i] >= arr[i + 1]: ab[i] = 1 else: ab[i] = ab[i + 1] + 1 ans = 0 for i in range(n): if i == 0: left = 0 else: left = af[i - 1] if i == n - 1: right = 0 else: right = ab[i + 1] if left and right and arr[i - 1] + 2 <= arr[i + 1]: ans = max(ans, left + right + 1) else: ans = max(ans, max(left, right) + 1) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR 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 BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
DZY has a sequence a, consisting of n integers. We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≀ i ≀ j ≀ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. -----Input----- The first line contains integer nΒ (1 ≀ n ≀ 10^5). The next line contains n integers a_1, a_2, ..., a_{n}Β (1 ≀ a_{i} ≀ 10^9). -----Output----- In a single line print the answer to the problem β€” the maximum length of the required subsegment. -----Examples----- Input 6 7 2 3 1 5 6 Output 5 -----Note----- You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
def main(): n = int(input()) a = list(map(int, input().split())) if n <= 2: print(n) return left = [(0) for _ in range(n)] right = [(0) for _ in range(n)] left[0] = 1 right[-1] = 1 ans = 0 for i in range(1, n): if a[i] > a[i - 1]: left[i] = left[i - 1] + 1 else: left[i] = 1 ans = max(ans, left[i - 1] + 1) for i in range(n - 2, -1, -1): if a[i] < a[i + 1]: right[i] = right[i + 1] + 1 else: right[i] = 1 ans = max(ans, right[i + 1] + 1) for i in range(1, n - 1): if a[i + 1] - a[i - 1] >= 2: ans = max(left[i - 1] + right[i + 1] + 1, ans) print(ans) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER 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 NUMBER ASSIGN VAR FUNC_CALL 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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given two bracket sequences (not necessarily regular) s and t consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). Recall what is the regular bracket sequence: * () is the regular bracket sequence; * if S is the regular bracket sequence, then (S) is a regular bracket sequence; * if S and T regular bracket sequences, then ST (concatenation of S and T) is a regular bracket sequence. Recall that the subsequence of the string s is such string t that can be obtained from s by removing some (possibly, zero) amount of characters. For example, "coder", "force", "cf" and "cores" are subsequences of "codeforces", but "fed" and "z" are not. Input The first line of the input contains one bracket sequence s consisting of no more than 200 characters '(' and ')'. The second line of the input contains one bracket sequence t consisting of no more than 200 characters '(' and ')'. Output Print one line β€” the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). If there are several answers, you can print any. Examples Input (())(() ()))() Output (())()() Input ) (( Output (()) Input ) ))) Output ((())) Input ()) (()(()(()( Output (()()()(()()))
S, T = input(), input() s1 = [(1 if c == "(" else -1) for c in S] s2 = [(1 if c == "(" else -1) for c in T] len1, len2 = len(s1), len(s2) inf = 10**9 dp = [[([inf] * (len1 + len2 + 1)) for _ in range(len2 + 1)] for _ in range(len1 + 1)] dp[0][0][0] = 0 for i in range(len1 + 1): for j in range(len2 + 1): for k in range(len1 + len2): if i < len1: k1 = k + s1[i] if k1 < 0: dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k] + 2) else: dp[i + 1][j][k1] = min(dp[i + 1][j][k1], dp[i][j][k] + 1) if j < len2: k2 = k + s2[j] if k2 < 0: dp[i][j + 1][k] = min(dp[i][j + 1][k], dp[i][j][k] + 2) else: dp[i][j + 1][k2] = min(dp[i][j + 1][k2], dp[i][j][k] + 1) if i < len1 and j < len2: if s1[i] == s2[j]: if k1 < 0: dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + 2) else: dp[i + 1][j + 1][k1] = min( dp[i + 1][j + 1][k1], dp[i][j][k] + 1 ) k = 0 length = inf for i in range(len1 + len2 + 1): if dp[len1][len2][i] + i < length: length = dp[len1][len2][i] + 1 k = i i, j = len1, len2 ans = [")"] * k while i > 0 or j > 0: if i > 0 and j > 0 and s1[i - 1] == s2[j - 1]: if dp[i - 1][j - 1][k - s1[i - 1]] + 1 == dp[i][j][k]: ans.append(S[i - 1]) k -= s1[i - 1] i -= 1 j -= 1 continue elif k == 0 and s1[i - 1] == -1 and dp[i - 1][j - 1][k] + 2 == dp[i][j][k]: ans.extend((S[i - 1], "(")) i -= 1 j -= 1 continue if i > 0: if dp[i - 1][j][k - s1[i - 1]] + 1 == dp[i][j][k]: ans.append(S[i - 1]) k -= s1[i - 1] i -= 1 continue elif k == 0 and s1[i - 1] == -1 and dp[i - 1][j][k] + 2 == dp[i][j][k]: ans.extend((S[i - 1], "(")) i -= 1 continue if j > 0: if dp[i][j - 1][k - s2[j - 1]] + 1 == dp[i][j][k]: ans.append(T[j - 1]) k -= s2[j - 1] j -= 1 continue elif k == 0 and s2[j - 1] == -1 and dp[i][j - 1][k] + 2 == dp[i][j][k]: ans.extend((T[j - 1], "(")) j -= 1 continue raise Exception(i, j, k, S[i - 1], T[j - 1]) print(*ans[::-1], sep="")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING NUMBER NUMBER VAR VAR ASSIGN VAR VAR STRING NUMBER NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING
You are given two bracket sequences (not necessarily regular) s and t consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). Recall what is the regular bracket sequence: * () is the regular bracket sequence; * if S is the regular bracket sequence, then (S) is a regular bracket sequence; * if S and T regular bracket sequences, then ST (concatenation of S and T) is a regular bracket sequence. Recall that the subsequence of the string s is such string t that can be obtained from s by removing some (possibly, zero) amount of characters. For example, "coder", "force", "cf" and "cores" are subsequences of "codeforces", but "fed" and "z" are not. Input The first line of the input contains one bracket sequence s consisting of no more than 200 characters '(' and ')'. The second line of the input contains one bracket sequence t consisting of no more than 200 characters '(' and ')'. Output Print one line β€” the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). If there are several answers, you can print any. Examples Input (())(() ()))() Output (())()() Input ) (( Output (()) Input ) ))) Output ((())) Input ()) (()(()(()( Output (()()()(()()))
def limitbal(a, b): min_level = 0 level = 0 for aa in a: if aa == "(": level += 1 else: level -= 1 if level < min_level: min_level = level for aa in b: if aa == "(": level += 1 else: level -= 1 if level < min_level: min_level = level return -min_level + len(a) + len(b) + (level - min_level) def go(): a = input() b = input() lena = len(a) lenb = len(b) a += "X" b += "X" bal_lim = limitbal(a, b) // 2 + 3 tab = [[([None] * (bal_lim + 2)) for _ in range(lenb + 1)] for _ in range(lena + 1)] par = [[([None] * (bal_lim + 2)) for _ in range(lenb + 1)] for _ in range(lena + 1)] tab[0][0][0] = 0 que = [(0, 0, 0)] index = 0 while tab[lena][lenb][0] is None: i, j, bal = que[index] ai = a[i] bj = b[j] if bal < bal_lim and (bal == 0 or not ai == bj == ")"): ii = i jj = j if ai == "(": ii = i + 1 if bj == "(": jj = j + 1 if tab[ii][jj][bal + 1] is None: tab[ii][jj][bal + 1] = tab[i][j][bal] + 1 par[ii][jj][bal + 1] = i, j, bal, "(" que.append((ii, jj, bal + 1)) if bal > 0 and not ai == bj == "(": ii = i jj = j if ai == ")": ii = i + 1 if bj == ")": jj = j + 1 if tab[ii][jj][bal - 1] is None: tab[ii][jj][bal - 1] = tab[i][j][bal] + 1 par[ii][jj][bal - 1] = i, j, bal, ")" que.append((ii, jj, bal - 1)) index += 1 i = lena j = lenb bal = 0 answer = [] while (i, j, bal) != (0, 0, 0): i, j, bal, symb = par[i][j][bal] answer.append(symb) print("".join(reversed(answer))) go()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER NONE ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NONE ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NONE ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given two bracket sequences (not necessarily regular) s and t consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). Recall what is the regular bracket sequence: * () is the regular bracket sequence; * if S is the regular bracket sequence, then (S) is a regular bracket sequence; * if S and T regular bracket sequences, then ST (concatenation of S and T) is a regular bracket sequence. Recall that the subsequence of the string s is such string t that can be obtained from s by removing some (possibly, zero) amount of characters. For example, "coder", "force", "cf" and "cores" are subsequences of "codeforces", but "fed" and "z" are not. Input The first line of the input contains one bracket sequence s consisting of no more than 200 characters '(' and ')'. The second line of the input contains one bracket sequence t consisting of no more than 200 characters '(' and ')'. Output Print one line β€” the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). If there are several answers, you can print any. Examples Input (())(() ()))() Output (())()() Input ) (( Output (()) Input ) ))) Output ((())) Input ()) (()(()(()( Output (()()()(()()))
def scs(str1, str2): INF = 10**9 dp = [[([INF] * 210) for _ in range(210)] for _ in range(210)] dp[0][0][0] = 0 prv = [[([None] * 210) for _ in range(210)] for _ in range(210)] len_str1 = len(str1) len_str2 = len(str2) str1 += "#" str2 += "#" for i in range(len_str1 + 1): for j in range(len_str2 + 1): for k in range(201): k2 = k + 1 i2 = i + (str1[i] == "(") j2 = j + (str2[j] == "(") if dp[i2][j2][k2] > dp[i][j][k] + 1: dp[i2][j2][k2] = dp[i][j][k] + 1 prv[i2][j2][k2] = i, j, k for k in range(1, 201): k2 = k - 1 i2 = i + (str1[i] == ")") j2 = j + (str2[j] == ")") if dp[i2][j2][k2] > dp[i][j][k] + 1: dp[i2][j2][k2] = dp[i][j][k] + 1 prv[i2][j2][k2] = i, j, k ans = INF cnt = 0 for c, val in enumerate(dp[len_str1][len_str2]): if c + val < ans + cnt: ans = val cnt = c res = [] i, j, k = len_str1, len_str2, cnt while i > 0 or j > 0 or k > 0: prv_i, prv_j, prv_k = prv[i][j][k] if prv_k < k: res.append("(") else: res.append(")") i, j, k = prv_i, prv_j, prv_k return "(" * (ans - len(res) - cnt) + "".join(res[::-1]) + ")" * cnt s = input() t = input() print(scs(s, t))
FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR STRING VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL STRING VAR NUMBER BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given two bracket sequences (not necessarily regular) s and t consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). Recall what is the regular bracket sequence: * () is the regular bracket sequence; * if S is the regular bracket sequence, then (S) is a regular bracket sequence; * if S and T regular bracket sequences, then ST (concatenation of S and T) is a regular bracket sequence. Recall that the subsequence of the string s is such string t that can be obtained from s by removing some (possibly, zero) amount of characters. For example, "coder", "force", "cf" and "cores" are subsequences of "codeforces", but "fed" and "z" are not. Input The first line of the input contains one bracket sequence s consisting of no more than 200 characters '(' and ')'. The second line of the input contains one bracket sequence t consisting of no more than 200 characters '(' and ')'. Output Print one line β€” the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). If there are several answers, you can print any. Examples Input (())(() ()))() Output (())()() Input ) (( Output (()) Input ) ))) Output ((())) Input ()) (()(()(()( Output (()()()(()()))
import sys import time def play(s1, s2): n = len(s1) m = len(s2) maxBalance = 200 dp = [] p = [] for i in range(0, n + 1): dp.append([]) p.append([]) for j in range(0, m + 1): dp[i].append([]) p[i].append([]) for a in range(0, maxBalance + 1): dp[i][j].append(sys.maxsize) p[i][j].append(None) dp[0][0][0] = 0 for i in range(0, n + 1): for j in range(0, m + 1): for a in range(0, maxBalance + 1): if dp[i][j][a] == sys.maxsize: continue next_i = i + (i < n and s1[i] == "(") next_j = j + (j < m and s2[j] == "(") if a < maxBalance and dp[next_i][next_j][a + 1] > dp[i][j][a] + 1: dp[next_i][next_j][a + 1] = dp[i][j][a] + 1 p[next_i][next_j][a + 1] = i, j, a, "(" next_i = i + (i < n and s1[i] == ")") next_j = j + (j < m and s2[j] == ")") if a > 0 and dp[next_i][next_j][a - 1] > dp[i][j][a] + 1: dp[next_i][next_j][a - 1] = dp[i][j][a] + 1 p[next_i][next_j][a - 1] = i, j, a, ")" aa = 0 nn = n mm = m for a in range(0, maxBalance + 1): if dp[n][m][a] + a < dp[n][m][aa] + aa: aa = a ret = ")" * aa while nn > 0 or mm > 0 or aa > 0: d = p[nn][mm][aa] nn = d[0] mm = d[1] aa = d[2] ret += d[3] return ret[::-1] def main(): print(play(input(), input())) main()
IMPORT IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NONE ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR STRING IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR STRING IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP STRING VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given two bracket sequences (not necessarily regular) s and t consisting only of characters '(' and ')'. You want to construct the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). Recall what is the regular bracket sequence: * () is the regular bracket sequence; * if S is the regular bracket sequence, then (S) is a regular bracket sequence; * if S and T regular bracket sequences, then ST (concatenation of S and T) is a regular bracket sequence. Recall that the subsequence of the string s is such string t that can be obtained from s by removing some (possibly, zero) amount of characters. For example, "coder", "force", "cf" and "cores" are subsequences of "codeforces", but "fed" and "z" are not. Input The first line of the input contains one bracket sequence s consisting of no more than 200 characters '(' and ')'. The second line of the input contains one bracket sequence t consisting of no more than 200 characters '(' and ')'. Output Print one line β€” the shortest regular bracket sequence that contains both given bracket sequences as subsequences (not necessarily contiguous). If there are several answers, you can print any. Examples Input (())(() ()))() Output (())()() Input ) (( Output (()) Input ) ))) Output ((())) Input ()) (()(()(()( Output (()()()(()()))
s1 = input() s2 = input() inf = 10**8 n = len(s1) m = len(s2) d = [[[inf for x in range(n + m + 10)] for y in range(m + 10)] for z in range(n + 10)] tata = [ [[(0) for x in range(n + m + 10)] for y in range(m + 10)] for z in range(n + 10) ] d[0][0][0] = 0 for i in range(n + 1): for j in range(m + 1): i1 = i + (i < n and s1[i] == "(") j1 = j + (j < m and s2[j] == "(") for k in range(n + m + 1): if d[i][j][k] == inf: continue if d[i][j][k] + 1 < d[i1][j1][k + 1]: d[i1][j1][k + 1] = d[i][j][k] + 1 tata[i1][j1][k + 1] = 1 i1 = i + (i < n and s1[i] == ")") j1 = j + (j < m and s2[j] == ")") for k in reversed(range(1, n + m + 1)): if d[i][j][k] == inf: continue if d[i][j][k] + 1 < d[i1][j1][k - 1]: d[i1][j1][k - 1] = d[i][j][k] + 1 tata[i1][j1][k - 1] = -1 lmin = inf pz = 0 for i in range(n + m + 1): if d[n][m][i] + i < lmin: lmin = d[n][m][i] + i pz = i ans = "" for i in range(pz): ans += ")" i = n j = m k = pz while i > 0 or j > 0 or k > 0: val = d[i][j][k] - 1 if tata[i][j][k] == 1: c = "(" k -= 1 else: c = ")" k += 1 ans += c i1 = i > 0 and s1[i - 1] == c j1 = j > 0 and s2[j - 1] == c if d[i][j][k] == val: continue elif i1 > 0 and d[i - 1][j][k] == val: i -= 1 elif j1 > 0 and d[i][j - 1][k] == val: j -= 1 else: i -= 1 j -= 1 ans = ans[::-1] print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR STRING VAR NUMBER ASSIGN VAR STRING VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
import sys from sys import stdin ans = 0 n, m = map(int, stdin.readline().split()) mod = 998244353 a = [list(map(int, stdin.readline().split())) for i in range(n)] fac = 1 for i in range(1, n + 1): fac *= i inv = pow(fac, mod - 2, mod) for j in range(m): na = [a[i][j] for i in range(n)] na.sort() now = 1 able = 0 for i in range(n): while len(na) > 0 and na[-1] > n - i: del na[-1] able += 1 now *= able able -= 1 ans += now * inv ans %= mod print((m - ans) % mod)
IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
import sys input = sys.stdin.readline fact, inv_fact = [0] * 21, [0] * 21 fact[0] = 1 mod = 998244353 def make_nCr_mod(max_n=20, mod=998244353): global fact global inv_fact for i in range(max_n): fact[i + 1] = fact[i] * (i + 1) % mod inv_fact[-1] = pow(fact[-1], mod - 2, mod) for i in reversed(range(max_n)): inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod make_nCr_mod() def nCr_mod(n, r): global fact global inv_fact res = 1 while n or r: a, b = n % mod, r % mod if a < b: return 0 res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod n //= mod r //= mod return res n, m = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] freq = [[(0) for j in range(n + 2)] for i in range(m)] for j in range(m): for i in range(n): freq[j][a[i][j]] += 1 ans = 0 for i in range(m): counted = 0 bad = 1 for j in range(1, n + 2): if freq[i][j] == 0: continue if freq[i][j] >= j - counted: bad = 0 break bad *= nCr_mod(j - 1 - counted, freq[i][j]) * fact[freq[i][j]] counted += freq[i][j] ans += (fact[n] - bad) % mod print(ans * pow(fact[n], mod - 2, mod) % mod)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
import sys input = sys.stdin.buffer.readline mod = 998244353 ans = 0 n, m = map(int, input().split()) fact = 1 for i in range(2, n + 1): fact = fact * i % mod inv_fact = pow(fact, mod - 2, mod) dist = [list(map(int, input().split())) for i in range(n)] for point in range(m): time = [(n + 1 - dist[city][point] + 1) for city in range(n)] add = [0] * (n + 2) for i in time: add[i] += 1 dp = [([0] * (n + 1)) for i in range(n + 2)] dp[0][0] = 1 for t in range(n + 1): for to_place in range(n + 1): if dp[t][to_place]: dp[t + 1][to_place + add[t + 1]] = ( dp[t + 1][to_place + add[t + 1]] + dp[t][to_place] ) % mod if to_place: dp[t + 1][to_place - 1 + add[t + 1]] = ( dp[t + 1][to_place - 1 + add[t + 1]] + to_place * dp[t][to_place] ) % mod ans = (ans + (fact - dp[n + 1][0]) * inv_fact) % mod print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
def get_one(ns, m): n = len(ns) ans = 1 for i in range(n): t = ns[i] - i if t <= 0: return 0 ans = ans * t % m return ans def get_one_pre(ns: list): ans = [0] * len(ns) ns.sort() l = 0 for i in range(len(ns)): for j in range(l, len(ns)): if i + 1 < ns[j]: l = j ans[i] = len(ns) - l break else: l = j ans[i] = 0 return list(reversed(ans)) def pow(a, b, m): tb = [a] for i in range(35): tb.append(tb[-1] * tb[-1] % m) ans = 1 for i in range(35): if b >> i & 1 == 1: ans = ans * tb[i] % m return ans def inv(a, m): return pow(a, m - 2, m) def functoria(x, m): ans = 1 for i in range(1, x + 1): ans = ans * i % m return ans def gns(): return list(map(int, input().split())) def gn(): return int(input()) n, m = gns() md = 998244353 ms = [[] for i in range(m)] for i in range(n): ns = gns() for i in range(m): ms[i].append(ns[i]) sm = 0 for i in range(m): x = get_one_pre(ms[i]) y = get_one(x, md) sm = (sm + y) % md f = functoria(n, md) fv = inv(f, md) ans = (f * m - sm + md) * fv % md print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
import sys input = sys.stdin.readline MOD = 998244353 def main(): n, m = map(int, input().split()) dlst = [list(map(int, input().split())) for _ in range(n)] ans = 0 fact = 1 for i in range(2, n + 1): fact *= i fact %= MOD for i in range(m): lst = [dlst[j][i] for j in range(n)] lst.sort(reverse=True) lst += [0] ret = 1 s = 0 pos = 0 for j in range(n, 0, -1): while lst[pos] > j: s += 1 pos += 1 ret *= s s -= 1 ans += fact - ret ans %= MOD print(ans * pow(fact, MOD - 2, MOD) % MOD) for _ in range(1): main()
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
mod = 998244353 def gcd(a, b): if a == 0 or b == 0: return 1 while b: a, b = b, a % b return a def gcdExtended(a, b): if a == 0: return b, 0, 1 gcd, x1, y1 = gcdExtended(b % a, a) x = y1 - b // a * x1 y = x1 return gcd, x, y def simpl(a): gecd = gcd(a[0], a[1]) return a[0] // gecd, a[1] // gecd def mulmod(a, b): a = summod(a, 0) b = summod(b, 0) return a % mod * (b % mod) % mod def summod(a, b): return (a % mod + b % mod + mod) % mod def addfrac(a, b): a = summod(a[0], 0), summod(a[1], 0) b = summod(b[0], 0), summod(b[1], 0) gecd = gcd(a[1], b[1]) lcm = a[1] // gecd * b[1] x = mulmod(a[0], b[1] // gecd) y = mulmod(b[0], a[1] // gecd) return simpl((summod(x, y), lcm)) def mulfrac(a, b): return simpl((mulmod(a[0], b[0]), mulmod(a[1], b[1]))) n, m = map(int, input().split()) dists = [[(0) for j in range(n)] for i in range(m)] out = 0, 1 for i in range(n): dist = list(map(int, input().split())) for j in range(m): dists[j][i] = dist[j] for i in range(m): dists[i].sort() out = 0 nfac = 1 for i in range(2, n + 1): nfac = mulmod(nfac, i) for i in range(m): cur = 1 for j in range(n): cur = mulmod(cur, max(0, dists[i][j] - (j + 1))) out = summod(out, cur) out = mulfrac((-1, 1), (out, nfac)) out = addfrac((m, 1), out) out = mulmod(out[0], (gcdExtended(out[1], mod)[1] + mod) % mod) print(out)
ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
from sys import stdin mod = 998244353 n, m = map(int, input().split()) arr = [] for i in range(m): arr.append([]) for i in range(n): temp = list(map(int, stdin.readline().split())) for j in range(m): arr[j].append(temp[j]) for i in range(m): arr[i].sort() ans = 1 for i in range(1, n + 1): ans *= i den = ans ans *= m ans %= mod for i in range(m): temp = 1 for j in range(n): temp *= arr[i][j] - (j + 1) ans -= temp ans %= mod ans *= pow(den, mod - 2, mod) ans %= mod print(ans)
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
n, m = map(int, input().split()) mod = 998244353 dis = [([0] * (m + 1)) for i in range(n + 1)] jc = 1 ans = 0 def ksm(a, b, p): a = a % p b = b % (p - 1) cheng = a ret = 1 while b > 0: if b % 2: ret = ret * cheng % p cheng = cheng * cheng % p b //= 2 return ret def inv(a, p=mod): return ksm(a, p - 2, p) for i in range(n): jc = jc * (i + 1) % mod for i in range(n): t = list(map(int, input().split())) for j in range(m): dis[i][j] = t[j] for i in range(m): c = [0] * n for j in range(n): c[j] = dis[j][i] - 1 c.sort() ret = 1 for index, j in enumerate(c): ret = ret * max(0, j - index) ret = ret * inv(jc) % mod ret = ((1 - ret) % mod + mod) % mod ans = (ans + ret) % mod print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
import sys input = sys.stdin.readline n, m = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(n)] mod = 998244353 invF = 1 for i in range(1, n + 1): invF = invF * i % mod invF = pow(invF, mod - 2, mod) ans = 0 for j in range(m): cnt = [0] * (n + 1) for i in range(n): cnt[n + 1 - A[i][j]] += 1 tot = 0 cur = 1 for i in range(n): tot += cnt[i] cur = cur * tot % mod tot = max(0, tot - 1) ans = (ans + 1 - cur * invF) % mod print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
import sys input = sys.stdin.readline get_int = lambda: int(input().rstrip()) get_arr = lambda: [int(w) for w in input().split()] get_str = lambda: input().rstrip() n, m = get_arr() d = [get_arr() for _ in range(n)] mod = 998244353 inv = 1 for t in range(1, n + 1): inv *= pow(t, -1, mod) inv %= mod ans = 0 for j in range(m): arr = sorted(d[i][j] - 1 for i in range(n)) p = 1 for k in range(n): val = arr[k] - k if val <= 0: p = 0 break p *= val ans += (1 - p * inv) % mod ans %= mod print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
p = 998244353 def f(x, y): r = 1 x = x % p if x == 0: return 0 while y > 0: if y % 2 == 1: r = r * x % p y = y >> 1 x = x * x % p return r n, m = map(int, input().split()) l = [] for _ in range(n): l.append(list(map(int, input().split()))) a = 1 for i in range(1, n + 1): a = a * i % p q = 0 for i in range(m): v = [0] * n for j in range(n): v[j] = l[j][i] v.sort() x = 1 for j in range(n): x = x * (min(v[j] - 1, n) - j) % p q = (q + a - x) % p print(q * f(a, p - 2) % p)
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
def power(a, n, mod): answer = 1 while n > 0: if n % 2 == 0: n //= 2 a = a * a % mod else: answer *= a answer %= mod n -= 1 return answer def putin(): return map(int, input().split()) def main(): n, m = putin() mod = 998244353 fac = 1 for i in range(1, n + 1): fac *= i fac %= mod inv = power(fac, mod - 2, mod) assert inv * fac % mod == 1 A = [] for i in range(n): A.append(list(putin())) bad_sum = 0 for i in range(m): B = [] for j in range(n): B.append(A[j][i]) B.sort(reverse=True) cnt = 0 bad = 1 for j in range(n, 0, -1): while cnt < len(B) and B[cnt] > j: cnt += 1 bad *= cnt + j - n bad_sum += bad print((fac * m - bad_sum) * inv % mod) main()
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands. Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn. Monocarp has $m$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $1$ to this city. Next turn, the Monument controls all points at distance at most $2$, the turn after β€” at distance at most $3$, and so on. Monocarp will build $n$ Monuments in $n$ turns and his empire will conquer all points that are controlled by at least one Monument. Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $m$ of them) he will conquer at the end of turn number $n$. Help him to calculate the expected number of conquered points! -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 20$; $1 \le m \le 5 \cdot 10^4$) β€” the number of cities and the number of points. Next $n$ lines contains $m$ integers each: the $j$-th integer of the $i$-th line $d_{i, j}$ ($1 \le d_{i, j} \le n + 1$) is the distance between the $i$-th city and the $j$-th point. -----Output----- It can be shown that the expected number of points Monocarp conquers at the end of the $n$-th turn can be represented as an irreducible fraction $\frac{x}{y}$. Print this fraction modulo $998\,244\,353$, i. e. value $x \cdot y^{-1} mod 998244353$ where $y^{-1}$ is such number that $y \cdot y^{-1} mod 998244353 = 1$. -----Examples----- Input 3 5 1 4 4 3 4 1 4 1 4 2 1 4 4 4 3 Output 166374062 -----Note----- Let's look at all possible orders of cities Monuments will be build in: $[1, 2, 3]$: the first city controls all points at distance at most $3$, in other words, points $1$ and $4$; the second city controls all points at distance at most $2$, or points $1$, $3$ and $5$; the third city controls all points at distance at most $1$, or point $1$. In total, $4$ points are controlled. $[1, 3, 2]$: the first city controls points $1$ and $4$; the second city β€” points $1$ and $3$; the third city β€” point $1$. In total, $3$ points. $[2, 1, 3]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[2, 3, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” point $1$. In total, $3$ points. $[3, 1, 2]$: the first city controls point $1$; the second city β€” points $1$ and $3$; the third city β€” points $1$ and $5$. In total, $3$ points. $[3, 2, 1]$: the first city controls point $1$; the second city β€” points $1$, $3$ and $5$; the third city β€” points $1$ and $5$. In total, $3$ points. The expected number of controlled points is $\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$ $=$ $\frac{19}{6}$ or $19 \cdot 6^{-1}$ $\equiv$ $19 \cdot 166374059$ $\equiv$ $166374062$ $\pmod{998244353}$
MOD = 998244353 def inv_f(x): return pow(x, MOD - 2, MOD) inv = [0] * 50 for i in range(1, 50): inv[i] = inv_f(i) n, m = map(int, input().split()) board = [] for i in range(n): board.append(list(map(int, input().split()))) out = 0 for j in range(m): count = [0] * (n + 1) for i in range(n): count[board[i][j] - 1] += 1 p = 0 tot = n for i in range(n): tot -= count[~i] pp = tot * inv[n - i] % MOD p = (p + (1 - p) * pp) % MOD out += p out %= MOD print(out)
ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR