description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) inp = [int(x) for x in input().split()] l = {} ans = 0 for i in range(n): x = inp[i] ans += x * (2 * i - n + 1) if x - 1 in l: ans -= l[x - 1] if x + 1 in l: ans += l[x + 1] l[x] = l[x] + 1 if x in l else 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 DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
cnt = {} n = int(input()) s = 0 an = 0 a = list(map(int, input().split())) for i in range(n): if a[i] not in cnt.keys(): cnt[a[i]] = 0 if a[i] - 1 not in cnt.keys(): cnt[a[i] - 1] = 0 if a[i] + 1 not in cnt.keys(): cnt[a[i] + 1] = 0 s += a[i] cnt[a[i]] += 1 num = i + 1 - ...
ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF BIN...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) a = list(map(int, input().split())) ps = a[0] ans = 0 h = {a[0]: 1} hv = {a[0]: a[0]} def gv(h, k): if k in h: return h[k] else: return 0 for i in range(1, n): c = i - gv(h, a[i]) - gv(h, a[i] - 1) - gv(h, a[i] + 1) cps = ps - gv(hv, a[i]) - gv(hv, a[i] - 1) - gv(hv,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER NUMBER ASSIGN VAR DICT VAR NUMBER VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BI...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) arr = list(map(int, input().split())) summ = sum(arr) ans = 0 for i in range(n - 1): ans += summ - arr[i] - (n - i - 1) * arr[i] summ -= arr[i] d = {} for i in range(n): if arr[i] in d.keys(): d[arr[i]] += 1 else: d[arr[i]] = 1 for i in range(n): if arr[i] - 1 in d.k...
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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) a = list(map(int, input().split())) d1 = dict() s = 0 for i in range(n): d1[a[i]] = d1.get(a[i], 0) + 1 s += a[i] p = 0 ans = 0 d2 = dict() for i in range(n): d2[a[i]] = d2.get(a[i], 0) + 1 p += a[i] k1 = d1.get(a[i] - 1, 0) - d2.get(a[i] - 1, 0) k2 = d1.get(a[i], 0) - d2.get(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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FU...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
import sys N = int(input()) a = [] b = {} ans = 0 a = input().split() for i in range(N): b[int(a[i])] = 0 b[int(a[i]) - 1] = 0 b[int(a[i]) + 1] = 0 for i in range(N): ans += int(a[i]) * (i - (N - 1 - i)) - (b[int(a[i]) - 1] - b[int(a[i]) + 1]) b[int(a[i])] = b[int(a[i])] + 1 print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CA...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
def main(): n = int(input()) array = list(map(int, input().split())) counts = dict() for elem in array: counts[elem - 1], counts[elem], counts[elem + 1] = 0, 0, 0 answer, l, r = 0, 0, n - 1 for elem in array: counts[elem] += 1 answer += (l - r) * elem l += 1 ...
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 FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR BIN_OP...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) a = list(map(int, input().split())) sum0 = 0 ans = 0 sum1 = 0 m = {} for i in range(0, n): m[a[i]] = 0 m[a[i] + 1] = 0 m[a[i] - 1] = 0 sum0 += a[i] for i in range(0, n): m[a[i]] += 1 for i in range(n - 1, -1, -1): sum1 = sum0 - a[i] - m[a[i] - 1] * (a[i] - 1) - m[a[i] + 1] * (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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR V...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) arr = [int(e) for e in input().split()] m = {} pref = 0 ans = 0 for i in arr: m[i] = 0 m[i + 1] = 0 m[i - 1] = 0 for i in range(len(arr)): ans += i * arr[i] - pref ans -= m[arr[i] - 1] - m[arr[i] + 1] pref += arr[i] m[arr[i]] += 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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR ...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) a = list(map(int, input().split())) d = {} ans = 0 s = 0 for z in range(n): i = a[z] if i not in d: d[i] = 0 d[i] += 1 count = d[i] + (d[i - 1] if i - 1 in d else 0) + (d[i + 1] if i + 1 in d else 0) tot = ( d[i] * i + (d[i - 1] if i - 1 in d else 0) * (i - 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) ans = 0 s = {} for i, a in enumerate(map(int, input().split())): ans += a * i - a * (n - 1 - i) + s.get(a + 1, 0) - s.get(a - 1, 0) s[a] = s.get(a, 0) + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n_elements = int(input()) elements = [int(x) for x in input().split()] res = 0 for i, x in enumerate(elements): res -= (n_elements - 1 - i) * x for i, y in enumerate(elements): res += i * y m = dict() m[elements[0]] = 1 for num in elements[1:]: if num + 1 in m: res += m[num + 1] if num - 1 in m:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER IF BIN_OP ...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) a = input().split(" ") for i in range(n): a[i] = int(a[i]) ans = 0 sum = 0 m = dict() for i in range(n): m[a[i]] = m.get(a[i], 0) + 1 sum += a[i] ans += (i + 1) * a[i] - sum ans -= m.get(a[i] + 1, 0) * -1 ans -= m.get(a[i] - 1, 0) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP BIN_...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) l = list(map(int, input().split())) d = {} ans = 0 curr = 0 for i in range(len(l) - 1, -1, -1): curr += l[i] z = 0 z1 = 0 if l[i] - 1 in d: z = d[l[i] - 1] else: z = 0 if l[i] + 1 in d: z1 = d[l[i] + 1] else: z1 = 0 ans += curr - (len(l) -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BI...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) l = input().split() l = [int(i) for i in l] cnt = {} for i in l: cnt[i - 1] = 0 cnt[i + 1] = 0 cnt[i] = 0 ans = 0 pre = 0 for i in range(0, n): ans += l[i] * i - pre pre += l[i] ans -= cnt[l[i] - 1] ans += cnt[l[i] + 1] cnt[l[i]] += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP ...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) res = 0 sum = 0 qua = 0 m = dict() a = list(map(int, input().split())) for i in range(0, n): if m.get(a[i] - 1) == None: m[a[i] - 1] = 0 if m.get(a[i] + 1) == None: m[a[i] + 1] = 0 if m.get(a[i]) == None: m[a[i]] = 0 res += a[i] * (qua - m[a[i] - 1] - m[a[i]] - m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER NONE ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR B...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
tcase = int(input().strip()) li = list(map(lambda x: int(x), input().split())) ans = 0 sum = li[0] di = {} di[sum] = 1 i = 1 for x in li[1:]: if x + 1 in di: df = di[x + 1] else: df = 0 if x - 1 in di: da = di[x - 1] else: da = 0 ans += i * x - sum + df - da sum +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) arr = [int(e) for e in input().split()] m = {} f = {} for i in arr: m[i] = 0 m[i - 1] = 0 m[i + 1] = 0 f[i] = 0 f[i - 1] = 0 f[i + 1] = 0 for i in arr: m[i] += 1 ans = 0 for i in range(n): tot = n left = i right = n - i - 1 left -= f[arr[i]] left -= f[arr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) M = {} F = [0] * 200005 P = [0] * 200005 F = list(map(int, input().split())) P[0] = F[0] for i in range(n): val = M.get(F[i]) if val == None: val = 0 M[F[i]] = val + 1 P[i] = P[i - 1] + F[i] ans = 0 for i in range(n): val = M.get(F[i]) M[F[i]] = val - 1 ans += P[n - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE ASSIGN VAR NUMBER ASSIGN...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) all = list(input().split(" ")) qtd = 0 cur = 0 ans = 0 cnt = dict() for num in all: x = int(num) qtd = qtd + 1 ans = ans + (qtd - 1) * x - cur if x - 1 in cnt: ans = ans - cnt[x - 1] if x + 1 in cnt: ans = ans + cnt[x + 1] cur = cur + x if x in cnt: c...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR ...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = input() ar = list(map(int, input().split())) sum = 0 pref = {} for i in ar: pref[i] = 0 pref[i - 1] = 0 pref[i + 1] = 0 ans = 0 k = 0 for i in ar: ans += k * i - sum - pref[i - 1] + pref[i + 1] pref[i] += 1 sum += i k += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR ...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
from sys import stdin, stdout n = int(stdin.readline()) a = [int(i) for i in stdin.readline().split()] d = dict() ans, sm = 0, 0 for i in range(n): if a[i] not in d.keys(): d[a[i]] = 0 d[a[i]] += 1 ans += i * a[i] - sm if a[i] + 1 in d.keys(): ans += 1 * d[a[i] + 1] if a[i] - 1 in d...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER FUNC_CALL VAR V...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
inp = [] d = {} n = int(input()) tot = 0 ans = 0 temp = input() temp = temp.split() inp = [int(i) for i in temp] for i in range(n): val = inp[i] tot = tot + val if val not in d: d[val] = 1 else: d[val] += 1 for i in range(n - 1, 0, -1): prev = 0 nxt = 0 if inp[i] + 1 in d: ...
ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
n = int(input()) v = list(map(int, input().split())) m = {} res = 0 for i in v: if not i in m: m[i] = 0 m[i] += 1 k = v.copy() for i in range(n - 1, 0, -1): k[i - 1] = k[i] + k[i - 1] for i in range(0, n - 1): res += -(n - i - 1) * v[i] + k[i + 1] m[v[i]] -= 1 if v[i] + 1 in m: r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR V...
Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. -----Input----- The ...
t = int(input()) a = input().split(" ") sum = [] curr = 0 dic = {} sum.append(0) for i in a: curr = curr + int(i) sum.append(curr) if i in dic: p = dic[i] p = p + 1 dic[i] = p else: dic[i] = 1 ans = 0 for i in range(1, t + 1): ans = ans + sum[t] - sum[i] - int(t - int...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR DICT EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR...
Given a matrix containing lower alphabetical characters only of size n*m. We need to count the number of palindromic paths in the given matrix. A path is defined as a sequence of cells starting from top-left cell and ending at bottom-right cell. We are allowed to move to right and down only from current cell. Example...
class Solution: def countOfPalindromicPaths(self, matrix): mp = {} M = 1000000007 def findP(arr, i, j, p, q, n, m): n = len(arr) m = len(arr[0]) if i >= n or j >= m or p < 0 or q < 0: return 0 if arr[i][j] != arr[p][q]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBE...
Given a matrix containing lower alphabetical characters only of size n*m. We need to count the number of palindromic paths in the given matrix. A path is defined as a sequence of cells starting from top-left cell and ending at bottom-right cell. We are allowed to move to right and down only from current cell. Example...
class Solution: def __init__(self): self.mod = 10**9 + 7 self.dp = {} def countOfPalindromicPaths(self, matrix): return self.path(matrix, 0, 0, len(matrix) - 1, len(matrix[0]) - 1) % self.mod def path(self, matrix, i, j, x, y): if ( i >= len(matrix) ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR DICT FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR ...
Given a matrix containing lower alphabetical characters only of size n*m. We need to count the number of palindromic paths in the given matrix. A path is defined as a sequence of cells starting from top-left cell and ending at bottom-right cell. We are allowed to move to right and down only from current cell. Example...
class Solution: def countOfPalindromicPaths(self, arr): n = len(arr) m = len(arr[0]) memo = {} def pali(s, e): global count x1, y1 = s x2, y2 = e if x1 > x2 or y1 > y2: return 0 if x1 == x2 and y1 == y2: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN ...
Given a matrix containing lower alphabetical characters only of size n*m. We need to count the number of palindromic paths in the given matrix. A path is defined as a sequence of cells starting from top-left cell and ending at bottom-right cell. We are allowed to move to right and down only from current cell. Example...
class Solution: def countOfPalindromicPaths(self, matrix): m = len(matrix) n = len(matrix[0]) memo = {} count = self.helper(matrix, 0, 0, m - 1, n - 1, m, n, memo) return count def helper(self, matrix, t_i, t_j, d_i, d_j, m, n, memo): if t_i < 0 or t_i > m - 1 o...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR BIN_OP V...
Given a matrix containing lower alphabetical characters only of size n*m. We need to count the number of palindromic paths in the given matrix. A path is defined as a sequence of cells starting from top-left cell and ending at bottom-right cell. We are allowed to move to right and down only from current cell. Example...
class Solution: def solve(self, ma, i1, j1, i2, j2, dp): n = len(ma) m = len(ma[0]) if ( i1 >= n or j1 >= m or i2 < 0 or j2 < 0 or i1 > i2 or j1 > j2 or ma[i1][j1] != ma[i2][j2] ): return...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR ...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) for tt in range(t): n = int(input()) nlist = list(map(int, input().split())) count = 0 for i in range(len(nlist)): if i >= nlist[i] - 1: count += n - i print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
def solve(arr): result = 0 for i, val in enumerate(arr, 1): if val > i: continue result += len(arr) - i + 1 return result def main(): for _ in range(int(input())): N = int(input()) arr = [int(val) for val in input().split()] result = solve(arr) ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXP...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
T = int(input()) for o in range(T): n = int(input()) l = list(map(int, input().split())) c = 0 for j in range(n): if l[j] == j + 1: c = c + n - j elif l[j] < j + 1: c = c + n - j print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
try: for i in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] c = 0 for i in range(n): if a[i] in range(1, i + 2): c += n - i print(c) except EOFError: print(0)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
for t in range(int(input())): n = int(input()) sm = 0 liz = list(map(int, input().split())) for i in range(0, n): if i + 1 >= liz[i]: sm = sm + 1 sm = sm + (n - (i + 1)) print(sm)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) for i in range(0, t): n = int(input()) count = 0 l = [int(i) for i in input().split()] l_2 = [] for i in range(0, n): l_2.append([l[i], i + 1]) for i in range(0, n): if l_2[i][0] <= l_2[i][1]: count += n - i print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
for _ in range(int(input())): n = int(input()) c = 0 A = list(map(int, input().split())) for i in range(n): if i + 1 >= A[i]: c += n - i print(c)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
def fun(n, l): c = 0 for i in range(n): k = i + 1 if k >= l[i]: c += n - k + 1 return c for t in range(int(input())): n = int(input()) l = list(map(int, input().split())) print(fun(n, l))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) for z in range(t): count = 0 n = int(input()) l = list(map(int, input().split())) for i in range(n): if l[i] in range(1, i + 2): count += n - i print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
def main(): for _ in range(int(input())): input() ans = 0 arr = [int(i) for i in input().split()] for n in range(len(arr)): if n + 1 >= arr[n]: ans += len(arr) - (n + 1) + 1 print(ans) main()
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(N): if A[i] == i + 1: ans += N - i if A[i] <= i: ans += N - i print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) while t > 0: n = int(input()) ar = list(map(int, input().split())) dp = [0] * n if ar[0] == 1: dp[0] = 1 for i in range(1, n): if ar[i] <= i + 1: dp[i] += dp[i - 1] + 1 else: dp[i] = dp[i - 1] s = 0 for i in dp: s += i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP V...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) for _ in range(0, t): n = int(input()) count = 0 arr = list(map(int, input().split())) for i in range(0, n): if arr[i] == 1: count += n - i continue if arr[i] <= i + 1: count += n - i print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR F...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
try: test_cases = int(input()) for i in range(0, test_cases): count = 0 l = int(input()) A = input().split() for i in range(0, l): number = int(A[i]) index = i + 1 if index >= number: count = count + l - index + 1 print(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) while t: n = int(input()) l = list(map(int, input().split())) c = 0 for i in range(1, n + 1): if i == l[i - 1]: c += n - i + 1 elif i - l[i - 1] > 0: c += n - i + 1 print(c) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER NU...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(1): b = a[i:n] for j in range(len(b)): if b[j] == j + 1: ans += 1 * (len(b) - j) elif b[j] <= j + 1: ans += 1 * (len(b) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) while t > 0: t -= 1 n = int(input()) a = [int(x) for x in input().split()] ans = 0 for i in range(n): if a[i] > i + 1: continue else: ans += n - i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
T = int(input()) for i in range(T): N = int(input()) arr = map(int, input().split()) ss = 0 for idx, n in enumerate(arr): if idx + 1 >= n: ss += N - (idx + 1) + 1 print(ss)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
import sys input = sys.stdin.readline t = int(input()) while t > 0: n = int(input()) arr = list(map(int, input().split())) count = 0 for i in range(0, n): if arr[i] <= i + 1: count += n - i print(count) t -= 1
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) for _ in range(t): n = int(input()) arr = input() arr = arr.split(" ") ans = 0 for i in range(1, len(arr) + 1): val = int(arr[i - 1]) if i - val + 1 > 0: ans += n - i + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER N...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
def main(): for t in range(int(input())): n = int(input()) arr = list(map(int, input().split())) total = 0 new = [] for i, j in enumerate(arr, start=1): if i >= j: new.append(total + 1) total += 1 else: n...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EX...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
try: t = int(input()) for i in range(0, t): n = int(input()) g = input() arr = list(map(int, g.split())) fp = 0 p = 0 for i in range(1, n + 1): if i == arr[i - 1]: p = n - i + 1 fp = fp + p if i > arr[i - 1]:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) print(sum([(n - k) for k, v in enumerate(l) if v <= k + 1]))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
for _ in range(int(input())): a = int(input()) b = [int(i) for i in input().split()] sum = 0 for i in range(1, 1 + a): if i >= b[i - 1]: sum += a - i + 1 print(sum)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
for _ in range(int(input())): n = int(input()) l = [0] l.extend(map(int, input().split())) ref = list(map(int, "0" * (n + 1))) sum = 0 for i in range(1, n + 1): sum += (i - l[i] + 1 > 0) * (n - i + 1) print(sum)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN...
Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point if A_{i} = i, where 1≤ i ≤ N. For example, in the array A = [1, ...
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) count = 0 for i in range(0, n): if i + 1 == a[i]: count += n - i elif a[i] < i + 1: count += n - i print(count) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_C...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) if n == 1: print("1") print("1") if n == 2: print("1 2") print("2 1") if n == 3: print("1 3 2") print("3 1 2") if n == 4: print("2 1 4 3") print("4 1 2 3") if n == 5: print("2 1 4 5 3") print("5 1 2 3 4") if n == 6: print("2 3 1 5 6 4") print("6 1 2 3 4 5...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXP...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
N = int(input()) mn = [N] for i in range(1, N): mn.append(i) mx = [1] for i in range(2, N + 1): mx.append(i) mid = int(N / 2) mx[0], mx[mid] = mx[mid], mx[0] for i in range(N - 1): if i != mid or i + 1 != mid: mx[i], mx[i + 1] = mx[i + 1], mx[i] MX = "" MN = "" for i in range(N): MX = MX + " " +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BI...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) if n == 1: print(1) print(1) exit() elif n == 3: print(2, 3, 1) print(3, 1, 2) exit() for i in range(2, n // 2 + 1): print(i, end=" ") print(1, end=" ") for i in range(n // 2 + 2, n + 1): print(i, end=" ") print(n // 2 + 1) print(n, end=" ") for i in range(1, n): pri...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) b = [I for I in range(1, n + 1)] r1 = b[-1:] + b[0:-1] c = n // 2 + n % 2 l1 = b[:c] l2 = b[c:] r2 = l1[1:] + l1[0:1] + l2[1:] + l2[0:1] for i in range(len(r2)): print(r2[i], end=" ") for i in range(len(r1)): print(r1[i], end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER N...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
def rotate(l): return l[1:] + l[:1] n = int(input()) p2 = [n] + list(range(1, n)) c = n // 2 p1 = list(range(1, n + 1)) ans = rotate(p1[:c]) + rotate(p1[c:]) print(*ans) print(*p2)
FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL ...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) if n == 2: print(1, 2) print(1, 2) elif n == 3: print(1, 3, 2) print(3, 2, 1) elif n == 4: print(2, 1, 4, 3) print(4, 2, 3, 1) elif n == 5: print(2, 1, 4, 5, 3) print(5, 1, 2, 3, 4) elif n == 7: print(2, 3, 1, 5, 6, 7, 4) print(7, 1, 2, 3, 4, 5, 6) elif n == 10: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) if n == 1: print(1) print(1) else: k = [] for i in range(2, n // 2 + 1): k.append(i) k.append(1) for i in range(n // 2 + 2, n + 1): k.append(i) k.append(n // 2 + 1) k1 = [] k1.append(n) for i in range(1, n): k1.append(i) print(*k) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VA...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) if n == 1: print(1) print(1) elif n % 2 == 0: print( " ".join( [ str(x) for x in list(range(2, n // 2 + 1)) + [1] + list(range(n // 2 + 2, n + 1)) + list([n // 2 + 1]) ] )...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL STRING FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER LIST NUMBER FUNC_CALL VAR FUNC_...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) a = [(i + 1) for i in range(n)] if n == 3: a = [1, 3, 2] elif n == 4: a = [2, 1, 4, 3] if n > 4: if n < 7: a = [2, 3, 1] for i in range(5, n + 1): a.append(i) a.append(4) elif n < 9: a = [2, 3, 4, 1] for i in range(6, n + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
def swap(arr, a, b): arr[a], arr[b] = arr[b], arr[a] n = int(input()) arr = [x for x in range(1, n + 1)] if n % 2 == 0: p1 = n // 2 - 1 else: p1 = n // 2 p2 = p1 + 1 for i in range(p1): swap(arr, i, i + 1) for i in range(p2, n - 1): swap(arr, i, i + 1) for j in arr: print(j, "", end="") print(...
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR V...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) ma = ( [i for i in range(2, 2 + (n - 1) // 2)] + [1] + [j for j in range(3 + (n - 1) // 2, n + 1)] + [2 + (n - 1) // 2] ) mi = [n] + [i for i in range(1, n)] print(*ma) print(*mi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER LIST NUMBER VAR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER LIST BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST VA...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) def shuffle(ordre): ls = [(i + 1) for i in range(len(ordre))] for i in range(len(ordre)): swap(ls, i, ordre[i]) return ls def swap(ls, i, j): ls[i], ls[j] = ls[j], ls[i] return ls def f_maxi(n): if n != 1: l = [(i + 1) for i in range(n)] l1 = l[0 : ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_C...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) l = [] for i in range(1, n + 1): l.append(i) if n % 2 == 0: d = l[: n // 2] v = l[n // 2 :] for j in range(1, len(d)): print(d[j], end=" ") print(d[0], end=" ") for k in range(1, len(v)): print(v[k], end=" ") print(v[0]) else: c = (n - 1) // 2 d = l[:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR V...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) m = n // 2 for i in range(2, m + 1): print(i, end=" ") print(1, end=" ") for i in range(m + 2, n + 1): print(i, end=" ") print(m + 1) print(n, end=" ") for i in range(1, n): print(i, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VA...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) max = [1, 12, 231, 2143, 21453, 214563, 2315674, 23416785, 234167895] min = [1, 21, 123, 4123, 51234, 612345, 7123456, 81234567, 912345678] if n < 10: opmin = " ".join(list(str(min[n - 1]))) opmax = " ".join(list(str(max[n - 1]))) print(opmax) print(opmin) elif n == 10: print("2 3 4...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUN...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) if n > 1: minli = [n] + [i for i in range(1, n)] maxli = [i for i in range(1, n + 1)] for i in range(0, n // 2 - 1): maxli[i], maxli[i + 1] = maxli[i + 1], maxli[i] for i in range(n // 2, n - 1): maxli[i], maxli[i + 1] = maxli[i + 1], maxli[i] for i in maxli: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) a = [] if n == 1: a.append(1) elif n % 2 == 0: for i in range(2, n // 2 + 1): a.append(i) a.append(1) for i in range(n // 2 + 2, n + 1): a.append(i) a.append(n // 2 + 1) else: for i in range(2, n // 2 + 2): a.append(i) a.append(1) for i in range(n...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL ...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
a = int(input()) c = [] f = 1 for y in range(a): c.append(f) f += 1 if a == 1: print(1) print(1) else: b = a % 2 if b != 0: f = (a + 1) // 2 else: f = a // 2 for x in range(1, f): print(c[x], end=" ") print(c[0], end=" ") for x in range(f + 1, a): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VA...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
p = [ None, [1], [2, 1], [1, 3, 2], [2, 1, 4, 3], [2, 1, 4, 5, 3], [2, 3, 1, 5, 6, 4], [2, 3, 1, 5, 6, 7, 4], [2, 3, 4, 1, 6, 7, 8, 5], [2, 3, 4, 1, 6, 7, 8, 9, 5], [2, 3, 4, 5, 1, 7, 8, 9, 10, 6], [2, 3, 4, 5, 1, 7, 8, 9, 10, 11, 6], [2, 3, 4, 5, 6, 1, 8, 9, 10, 11, ...
ASSIGN VAR LIST NONE LIST NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NU...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
def printmin(n): print(n, end=" ") for i in range(1, n): print(i, end=" ") n = int(input()) if n == 1: print("1") elif n == 2: print("1 2") elif n == 3: print("1 3 2") elif n == 4: print("2 1 4 3") else: for i in range(2, n // 2 + 1): print(i, end=" ") print("1", end=" ...
FUNC_DEF EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL V...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
def shift(l, n): return l[n:] + l[:n] t = int(input()) l = [] for i in range(1, t + 1): l.append(i) n = t // 2 x = [] y = [] for i in range(1, n + 1): x.append(i) for j in range(n + 1, t + 1): y.append(j) x = shift(x, 1) y = shift(y, 1) x.extend(y) for i in range(t): print(x[i], end=" ") print(" "...
FUNC_DEF RETURN BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
N = int(input()) for i in range(2, N // 2 + 1): print(i, end=" ") if N is not 1: print(1, end=" ") for i in range(N // 2 + 2, N + 1): print(i, end=" ") print(N // 2 + 1) print(N, end=" ") for i in range(1, N): print(i, end=" ") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMB...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) l = [ "1", "1 2", "2 1 3", "2 1 4 3", "2 3 1 5 4", "2 3 1 5 6 4", "2 3 4 1 6 7 5", "2 3 4 1 6 7 8 5", "2 3 4 5 1 7 8 9 6", "2 3 4 5 1 7 8 9 10 6", "2 3 4 5 6 1 8 9 10 11 7", "2 3 4 5 6 1 8 9 10 11 12 7", "2 3 4 5 6 7 1 9 10 11 12 13 8", "2 3 4 5 6...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) if n == 1: print(1) print(1) exit() A = [] i = 2 j = 0 if n % 2 == 0: a = n // 2 - 1 else: a = n // 2 while j < a: A.append(i) i += 1 j += 1 A.append(1) a = i i += 1 while i <= n: A.append(i) i += 1 A.append(a) for i in A: print(i, end=" ") print() print(n, e...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUM...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) a = [] for i in range(n): a.append(i + 1) for i in range(int(n / 2)): a[i + 1], a[i] = a[i], a[i + 1] for j in range(i, n - 1): a[j], a[j + 1] = a[j + 1], a[j] for i in range(n): print(a[i], end=" ") print() print(n, end=" ") for i in range(1, n): print(i, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) mxi = [] mni = [] for i in range(1, n + 1): mni.append(i) for i in range(1, n): mxi.append(i + 1) mxi.append(1) for i in range(n): mni[i], mni[n - 1] = mni[n - 1], mni[i] if n % 2 == 0: mxi[n // 2 - 1], mxi[n - 1] = mxi[n - 1], mxi[n // 2 - 1] else: mxi[n // 2], mxi[n - 1] = mxi[n -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBE...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) p = [x for x in range(1, n + 1)] q = [x for x in range(n + 1)] p.append(1) if n % 2 == 0: p[n // 2], p[n] = p[n], p[n // 2] else: p[n // 2 + 1], p[n] = p[n], p[n // 2 + 1] print(*p[1:]) q = q[n:] + q[1:n] print(*q)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) s = "" if n == 1: print("1\n1\n") else: mid = n // 2 for i in range(1, mid): s += str(i + 1) + " " s += "1" + " " for j in range(mid + 1, n): s += str(j + 1) + " " s += str(mid + 1) p = "" p += str(n) for i in range(1, n): p += " " + str(i) pr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR BIN_OP STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) print1 = [] print2 = [n] add = n // 2 for i in range(2, n + 1): print1.append(i) print1.append(1) mid = n // 2 if n % 2 == 0: mid = mid - 1 print1[mid], print1[n - 1] = print1[n - 1], print1[mid] for i in range(1, n): print2.append(i) print(*print1) print(*print2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMB...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) a = [] b = [] c = [] d = [] for i in range(1, n + 1): a.append(i) c = a.copy() if n % 2 == 0: p = n // 2 for i in range(1, p): b.append(c[i]) b.append(c[0]) for i in range(p + 1, n): b.append(c[i]) b.append(c[p]) print(*b) else: p = n // 2 + 1 for i i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR ...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) a = [i for i in range(1, n + 1)] if n == 2: print(1, 2) print(2, 1) elif n == 3: print(1, 3, 2) print(1, 2, 3) else: min_a = [] min_a.append(n) for i in range(1, n): min_a.append(i) max_a = [] mid = (1 + n) // 2 for i in range(2, mid + 1): max_a.a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR FU...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) p = [i for i in range(1, n + 1)] p1 = p[1 : n // 2] + [p[0]] + p[n // 2 + 1 :] + [p[n // 2]] p2 = [p[-1]] + p[: n - 1] for i in p1: print(i, end=" ") print() for i in p2: print(i, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL ...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) temp = [] for i in range(n): temp.append(i + 1) if n == 1: print(temp[0]) print(temp[0]) if n > 1 and n % 2 == 0: max_ans = [] if n <= 4: for i in range(len(temp)): if i % 2 == 0: max_ans.append(temp[i] + 1) else: max_a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBE...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) print( *range(2, n // 2 + 1 + n % 2), 1, *range(n // 2 + 2 + n % 2, n + 1), n // 2 + 1 + n % 2, "\r" + str(n), *range(1, n) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP STRING FUNC_CALL VAR VAR...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) s = [] if n == 3: s = [2, 1, 3] elif n == 1: s = [1] else: for i in range(2, int(n / 2) + 1): s.append(i) s.append(1) for i in range(int(n / 2) + 2, n + 1): s.append(i) s.append(int(n / 2) + 1) print(" ".join(str(i) for i in s)) s = [] s.append(n) for i in range(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) t = n // 2 arr = [0] * n if n == 1: for i in range(2): print(n) elif n == 2: print("1 2") print("2 1") else: arr[t - 1] = 1 if t - 1 != 0: arr[0] = 2 e = 3 for m in range(1, t - 1): arr[m] = e e += 1 arr[t] = t + 2 arr[-1] = t + 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMB...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) if n == 1: print(n) print(n) elif n == 2: print("1 2") print("2 1") else: b = [n] for i in range(n): if i > 0: b.append(i) if n == 3: print("1 3 2") elif n == 4: print("2 1 4 3") elif n == 5: print("2 1 4 5 3") elif n =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input().strip()) if n == 2: min_list = [1, 2] max_list = [2, 1] else: mid_elem = n // 2 max_list = list(range(2, mid_elem + 1)) max_list.append(1) max_list.extend(list(range(mid_elem + 2, n + 1))) max_list.append(mid_elem + 1) min_list = [n] min_list.extend(list(range(1, n)))...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NU...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) for i in range(1, n + 1): if i < n // 2: print(i + 1, end=" ") elif i == n // 2: print(1, end=" ") elif i == n: print(n // 2 + 1) else: print(i + 1, end=" ") print(n, end=" ") for i in range(1, n - 1): print(i, end=" ") print(n - 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING E...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
def get_all_substrings(string): length = len(string) for i in xrange(length): for j in xrange(i + 1, length + 1): yield string[i:j] def eulers_gcd(russia, argentina): if russia == 0: return argentina return eulers_gcd(argentina % russia, russia) def pretty(pre, n): fo...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CAL...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) if n == 1: print("1\n1") elif n == 2: print("1 2\n2 1") elif n == 3: print("1 3 2\n1 2 3") elif n == 4: print("2 1 4 3\n4 1 2 3") elif n == 5: print("2 1 4 5 3\n5 1 2 3 4") elif n == 6: print("2 3 1 5 6 4\n6 1 2 3 4 5") elif n == 7: print("2 3 1 5 6 7 4\n7 1 2 3 4 5 6") elif...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING I...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) m = n // 2 buffer = [] for i in range(1, m): buffer.append(str(i + 1)) buffer.append(str(1)) for i in range(m + 1, n): buffer.append(str(i + 1)) buffer.append(str(m + 1)) print(" ".join(buffer)) buffer = [] buffer.append(str(n)) for i in range(0, n - 1): buffer.append(str(i + 1)) print(" "....
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VA...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) arr = [] for i in range(1, n + 1): arr.append(i) arr2 = arr.copy() if n % 2 != 0: i = 0 while i < n // 2: temp = arr2[i] arr2[i] = arr2[i + 1] arr2[i + 1] = temp i += 1 i = n // 2 + 1 while i < n - 1: temp = arr2[i] arr2[i] = arr2[i + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUM...
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] for i in 1..N do j := rand(1, N) swap(P[i], P[j]) Here, rand(1, N) ...
n = int(input()) p = [] q = [] if n == 1: p = [1] q = [1] elif n == 2: p = [1, 2] q = [2, 1] elif n == 3: p = [1, 3, 2] q = [3, 2, 1] elif n == 4: p = [2, 1, 4, 3] q = [4, 1, 2, 3] elif n == 5: p = [2, 3, 1, 5, 4] q = [5, 1, 2, 3, 4] elif n == 6: p = [2, 3, 1, 5, 6, 4] q ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LI...