description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): n = int(input()) if n == 2: print("NO") elif n % 2 == 0: o = [] e = [] print("YES") for i in range(1, n + 1): if i % 2 != 0: o.append(i) else: e.append(i) x = o.pop() ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FU...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) for i in range(t): n = int(input()) if n % 2 == 0: if n < 3: print("NO") elif n == 4: print("YES") ar = [] ar = [2, 1, 4, 3] print(*ar) else: print("YES") ar = [] a = n // 2 -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for i in range(int(input())): n = int(input()) half = n // 2 if n == 2: print("NO") else: print("YES") if n % 2 == 0: ans = [] for i in range(2, half + 1): ans.append(i) ans.append(1) for i in range(n, half, -1): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUM...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): n = int(input()) if n == 2: print("NO") else: print("YES") c = n // 2 d = 1 if n % 2 else 2 for i in range(d, c + 1): print(i, end=" ") if n % 2 == 0: print(1, end=" ") for i in range(n, c, -1): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBE...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): N = int(input()) if N == 1: print("YES") print(1) elif N == 2: print("NO") elif N % 2 != 0: print("YES") print(*(list(range(N, (N + 1) // 2, -1)) + list(range(1, (N + 3) // 2)))) else: print("YES") l = [1] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) for i in range(t): n = int(input()) if n == 2: print("NO") else: print("YES") k = n // 2 if n % 2 != 0: for i in range(1, k + 1): print(i, end=" ") while n != k: print(n, end=" ") n -= 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING WHILE VAR VAR EX...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
def solve(n): if n == 2: return "NO" if n == 3: return "YES\n1 3 2" left = [2, 4] if n % 2 == 0: right = [3, 1] for _ in range(2, n // 2): left.append(left[-1] + 2) right.append(5 if right[-1] == 1 else right[-1] + 2) else: right = [1, ...
FUNC_DEF IF VAR NUMBER RETURN STRING IF VAR NUMBER RETURN STRING ASSIGN VAR LIST NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN ...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
from sys import stdin, stdout nmbr = lambda: int(input()) lst = lambda: list(map(int, input().split())) for _ in range(nmbr()): n = nmbr() if n == 2: print("NO") else: a = [i for i in range(1, n + 1)] pos = n // 2 a = a[:pos] + a[pos:][::-1] if n & 1 == 0: ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): n = int(input()) if n <= 2: print("NO") elif n % 2 != 0: even = [] odd = [] for i in range(1, n + 1): if i % 2 == 0: even.append(i) else: odd.append(i) print("YES") print(*od...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): n = int(input()) if n == 2: print("NO") elif n == 4: print("YES") print(3, 1, 4, 2, sep=" ") elif n % 2 == 0: print("YES") print(1, end=" ") print(n - 1, n, sep=" ", end=" ") s1, s2 = 2, n - 2 while s1 <= n // ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) for zz in range(t): n = int(input()) p = n // 2 l = [] l1 = [] if n == 2: print("NO") continue if n % 2 == 0: x = n // 2 print("YES") print(x, end=" ") for j in range(1, x): print(j, end=" ") for j in range(n, x...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING FO...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
def solve(): n = int(input()) l = [] if n <= 2: print("NO") return print("YES") if n & 1: for i in range(1, n // 2 + 1): l.append(i) for i in range(n, n // 2, -1): l.append(i) print(*l) return for i in range(2, n // 2 + 1): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
def front(j, strng): for i in range(1, j): strng += str(i) + " " return strng def back(n, j, strng): for i in range(n, j - 1, -1): strng += str(i) + " " return strng for _ in range(int(input())): n = int(input()) if n == 2: print("NO") continue print("YES"...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR STRING RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR STRING RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR ST...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
def xxx(N): if N % 2 == 0: k = N // 2 for i in range(1, k): print(2 * i + 1, end=" ") print(1, end=" ") for i in range(k, 0, -1): print(2 * i, end=" ") print("") else: k = (N - 1) // 2 print(1, end=" ") for i in range(1, k +...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BI...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): n = int(input()) if n == 1: print("YES") print(1) elif n % 2 != 0: print("YES") l = list(range(1, n + 1)) l = l[: n // 2] + l[-1 : n // 2 - 1 : -1] print(*l) elif n != 2: print("YES") l = list(range(1, n + 1)) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUM...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): m = int(input()) if m % 2: print("YES") for i in range(1, m // 2 + 1): print(i, end=" ") print(m, end=" ") for i in range(m - 1, m // 2, -1): print(i, end=" ") print() elif m != 2: print("YES") prin...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBE...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): k = int(input()) if k == 1: print("YES") print(1) continue if k == 2: print("NO") continue print("YES") if k % 2 == 1: a = [i for i in range(1, k + 1, 2)] b = [i for i in range(2, k, 2)] print(*(a + b[::-1]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): n = int(input()) if n > 2: print("YES") ans3 = [1, 3, 2] ans4 = [2, 1, 4, 3] odd = [] even = [] if n & 1: for i in range(4, n + 1): if i & 1: odd.append(i) else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP ...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) for _ in range(t): n = int(input()) if n % 2: print("YES") l = list( map(str, list(range(1, int(n / 2) + 1)) + list(range(n, int(n / 2), -1))) ) print(" ".join(l)) elif n != 2: print("YES") l = ( [int(n / 2)] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_C...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
T = int(input()) for _ in range(T): n = int(input()) if n == 2: print("NO") elif n % 2 != 0: print("YES") for i in range(1, int(n / 2) + 1): print(i, end=" ") for i in range(n, int(n / 2), -1): print(i, end=" ") print("\n") else: pr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
T = int(input()) for i in range(T): N = int(input()) if N == 2: print("NO") else: if N % 2 == 0: K = N - 1 else: K = N l = list(range(1, K + 1)) a = l[0 : int(K / 2)] b = l[int(K / 2) :] b = b[::-1] c = a + b pri...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) while t > 0: n = int(input()) if n == 2: print("NO") else: print("YES") if n % 2 == 1: ans = [i for i in range(1, n // 2 + 1)] for i in range(n, n // 2, -1): ans.append(i) else: ans = [i for i in range(2, n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUN...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) for i in range(t): n = int(input()) l = [] for i in range(1, n + 1): l.append(i) if n == 2: print("NO") else: if n % 2 != 0: mid = n // 2 + 1 x = l[: mid - 1] + l[mid - 1 :][::-1] elif n % 2 == 0: mid = n // 2 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP V...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) def solve(n): ans = [] if n & 1 == 1: i = 1 while i < n // 2 + 1: ans.append(i) i += 1 i = n while i > n // 2: ans.append(i) i -= 1 else: i = 1 ans.append(n // 2) while i < n // 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER WH...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): n = int(input()) if n == 2: print("NO") elif n == 4: print("YES") ans = [3, 4, 1, 2] print(*ans) elif n % 2: ans = [] for i in range(n // 2 + 1, n + 1): ans.append(i) for i in range(n // 2, 0, -1): ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER ...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): z = int(input()) if z > 2: if z % 2 == 0: m = [] o = [] h = [1] for i in range(2, z + 1): if i % 2 == 0: m.append(i) else: o.append(i) l = m +...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BI...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) for i in range(t): n = int(input()) if n == 2: print("NO") else: print("YES") if n % 2 == 1: for i in range(n // 2): print(i + 1, end=" ") for i in range(n // 2 + 1): print(n - i, end=" ") else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VA...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
try: t = int(input()) foundation = [] while t: n = int(input()) if n > 2: print("YES") g = n g = g - 1 if n % 2 == 0: while g != 3: print(g, end=" ") g = g - 2 print("2 1 4...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ST...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
import sys input = lambda: sys.stdin.readline().rstrip() for _ in range(int(input())): n = int(input()) if n == 2: print("NO") continue print("YES") a = [0] * n if n & 1: i, v = 0, 1 while i < n: a[i] = v v += 1 i += 2 i, v...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR NU...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) def fun(lt, n): temp = [] if n % 2 != 0: for i in range(0, n // 2): temp.append(lt[i]) temp.append(lt.pop()) for i in range(n - 2, n // 2 - 1, -1): temp.append(lt[i]) for j in temp: print(j, end=" ") print(end="\n") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXP...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
def func(): n = int(input()) if n == 2: print("NO") elif n % 2: print("YES") for i in range(1, n // 2 + 1): print(i, end=" ") for i in range(n, n // 2, -1): print(i, end=" ") print() else: print("YES") print(n // 2, end=" ")...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CAL...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
import itertools for _ in range(int(input())): n = int(input()) if n == 2: print("NO") else: print("YES") if n % 2 == 1: ans = [(i + 1) for i in range(n // 2)] ans += [i for i in range(n, n // 2, -1)] print(*ans) elif n == 4: p...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) test = [] for i in range(t): v = int(input()) test.append(v) for i in test: if i == 2: print("NO") continue print("YES") v = i // 2 ls = [] if i % 2 == 1: v += 1 for j in range(v, 0, -1): ls.append(str(j)) for j in range(v + 1, i + 1):...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CA...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) for i in range(t): n = int(input()) if n % 2 == 0: if n == 2: print("NO") elif n == 4: print("YES") print(" ".join(["3", "4", "1", "2"])) else: print("YES") print( " ".join( [...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING LIST STRING STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CAL...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) for test in range(t): n = int(input()) if n == 2: print("NO") continue elif n % 2 == 1: ans = [0] * n i = 1 j = 0 k = n - 1 while j <= k: if j == k: ans[j] = i i += 1 break ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR N...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
t = int(input()) for i in range(t): t1 = t2 = 0 l3 = [1, 3, 2] l4 = [2, 1, 4, 3] n = int(input()) if n == 2: print("NO") elif n % 2 == 0: t1 = n - 4 k1 = 4 l = l4 while t1 > 0: l.append(k1 + 1) l.insert(0, k1 + 2) k1 = k...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBE...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
n = int(input()) for i in range(n): n1 = int(input()) list1 = [] count = 1 if n1 == 2: print("NO") else: print("YES") i = 0 j = n1 - 1 san = True for k in range(n1): list1.insert(k, 0) while i <= j: if san: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NU...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for i in range(int(input())): n = int(input()) if n % 2 == 1: print("YES") l = [i for i in range(1, n + 1)] x = [0] * n a = 0 b = n - 1 f = 0 while f < n: x[a] = l[f] f += 1 if f < n: x[b] = l[f] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): num = int(input()) if num == 2: print("NO") continue if num == 4: print("YES") print(2, 4, 1, 3) continue print("YES") if num % 2 == 0: for i in range(1, num - 1, 2): print(i, end=" ") print(num, num - ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUM...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
try: for _ in range(int(input())): n = int(input()) if n % 2 == 0: array = [k for k in range(n // 2 + 1, n + 1)] for ll in range(n // 2 - 1, 0, -1): array.append(ll) array.append(n // 2) ans = "YES" if n != 2 else "NO" print...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
from sys import stdin, stdout t = int(stdin.readline().rstrip()) while t > 0: n = int(stdin.readline().rstrip()) if n == 2: print("NO") elif n % 2 == 0: print("YES") array_odd = [] for i in range(1, n): if i % 2 == 0: array_odd.append(i) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_C...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for t in range(int(input())): N = int(input()) if N == 2: print("NO") continue print("YES") ArraySoham = [] for i in range(1, N // 2 + 1): ArraySoham.append(i) for i in range(N, N // 2, -1): ArraySoham.append(i) if N % 2 == 0: ArraySoham[(N - 1) // 2],...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
for _ in range(int(input())): n = int(input()) if n <= 2: print("NO") else: print("YES") even_series = [2, 1, 4, 3] odd_series = [1, 3, 2] if n % 2 == 0: for i in range(5, n + 1, 2): even_series.append(i + 1) even_series.ins...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EX...
For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices i_{1} < i_{2} < \ldots < i_{K} such that P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}. Define P^{R} to be the permutation (P_{N}, P_{N-1}, \ld...
T = int(input()) for i in range(T): n = int(input()) if n <= 2: print("NO", end="") else: print("YES") if n % 2 != 0: for x in range(1, n // 2 + 1): print(x, end=" ") for t in range(n, n // 2, -1): print(t, end=" ") else...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VA...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) a = [0] for i in range(n): a.append(list(input())) x = int(input()) b = list(map(int, input().split())) if x == 2: print(2) print(*b) exit() st = [b[0]] st1 = [b[0]] k = b[1] for i in range(1, n + 1): a[i][i - 1] = "1" pr = [] pr.append(b[0]) for j in range(2, x): for l in st1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL V...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
import sys input = sys.stdin.readline def warshall_floyd(d): for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d n = int(input()) A = [input()[:-1] for _ in range(n)] m = int(input()) if m == 2: p = list(map(int...
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_C...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
def warshall_floyd(d): for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d n = int(input()) g = [list(input()) for _ in range(n)] d = [([float("inf")] * n) for _ in range(n)] for i in range(n): for j in range(n): ...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VA...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
def floyd_warshall(graph): n = len(graph) dist = [[float("inf") for _ in range(n)] for _ in range(n)] for i in range(n): for j in range(n): if i == j: dist[i][j] = 0 elif graph[i][j]: dist[i][j] = 1 for thru in range(n): for i in ra...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VA...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
import sys n = int(sys.stdin.readline().strip()) A = [] for i in range(0, n): A.append(sys.stdin.readline().strip()) D = [[(-200) for i in range(0, n)] for j in range(0, n)] L = [] L2 = [] for i in range(0, n): D[i][i] = 0 L.append([i, i]) for i in range(0, n): while len(L) > 0: x, y = L.pop() ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER EXPR ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) G = [[] for _ in range(n)] for i in range(n): l = input() for j in range(n): if l[j] == "1": G[i].append(j) ds = [([-1] * n) for _ in range(n)] for i in range(n): ds[i][i] = 0 l = [i] while len(l) > 0: l2 = [] for j in l: for k in G[j]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LI...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) dist = [] for i in range(n): s = input() tem = [] for j in s: if j == "0": tem.append(101) else: tem.append(1) dist.append(tem) m = int(input()) p = list(map(int, input().split())) for k in range(0, n): for i in range(0, n): for j in r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
import sys def input(): return sys.stdin.readline()[:-1] n = int(sys.stdin.readline()) s = [input() for _ in range(n)] d = [([pow(10, 30)] * n) for i in range(n)] for i in range(n): for j in range(n): if s[i][j] == "1": d[i][j] = 1 for k in range(n): for i in range(n): for j ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) a = [] t = 0 b = 0 for i in range(n): t = input() b = [] for j in range(n): b.append(int(t[j])) if i != j and t[j] == "0": b[j] = 10**9 a.append(b) for k in range(n): for i in range(n): for j in range(n): a[i][j] = min(a[i][j], a[i][k]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FU...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
import sys def main(): def input(): return sys.stdin.readline()[:-1] n = int(input()) G = [""] * n for k in range(n): G[k] = input() D = [([float("inf")] * n) for k in range(n)] for k in range(n): D[k][k] = 0 for k in range(n): for m in range(n): ...
IMPORT FUNC_DEF FUNC_DEF RETURN FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
MOD = 10**9 + 7 I = lambda: list(map(int, list(input()))) n = int(input()) g = [] for i in range(n): g.append(I()) m = int(input()) p = [(int(i) - 1) for i in input().split()] d = g[:] for i in range(n): for j in range(n): if not d[i][j] and i != j: d[i][j] = 1000 for i in range(n): for ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUN...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
def bfs(s): q = [s] visited[s] = True while q: s = q.pop(0) for i in range(n): if adj[s][i] == "1": if not visited[i]: paths[j][i] = paths[j][s] + 1 visited[i] = True q.append(i) n = int(input()) adj = ...
FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
def path(s): s1 = {s} s2 = set() used = [0] * (n + 1) used[s] = 1 ans = 0 while s1: ans += 1 for v in s1: for u in graph[v]: if used[u] == 0: paths[s][u] = ans used[u] = 1 s2.add(u) s1...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER FOR VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN V...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) a = [] for i in range(n): a.append(list(map(int, list(input())))) m = int(input()) b = list(map(int, input().split())) for i in range(n): for j in range(n): if i != j and a[i][j] == 0: a[i][j] = 10**18 for k in range(n): for i in range(n): for j in range(n): ...
ASSIGN VAR FUNC_CALL VAR 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 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 FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
import sys input = sys.stdin.readline def main(): N = int(input()) graph = [[int(a) for a in list(input().rstrip())] for _ in range(N)] M = int(input()) P = list(map(int, input().split())) INF = 10**16 dp = [([None] * N) for _ in range(N)] for i in range(N): for j in range(N): ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR 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 BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP L...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
N = int(input()) E = [([N**2] * N) for i in range(N)] for i in range(N): (*X,) = map(int, input()) for j in range(N): if X[j]: E[i][j] = 1 E[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): E[i][j] = min(E[i][j], E[i][k] + E[k][j]) M = int(input(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) l = [] p = [] ans = [] for i in range(n): l.append(list(map(int, input()))) for i in range(n): for j in range(n): if i != j and l[i][j] == 0: l[i][j] = 9999999 for k in range(n): for i in range(n): for j in range(n): if l[i][j] > l[i][k] + l[k][j]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) distance = [[(1000000) for _ in range(n)] for _ in range(n)] adjMatrix = [[] for _ in range(n)] for i in range(n): adjMatrix[i] = [int(x) for x in input()] length = int(input()) path = [(int(x) - 1) for x in input().split()] for i in range(n): for k in range(n): if adjMatrix[i][k] == 1:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CAL...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
import sys input = sys.stdin.readline INF = 10**12 n = int(input()) edge = [[] for _ in range(n)] for i in range(n): line = input().rstrip() for j, ch in enumerate(line): if i == j: edge[i].append(0) elif ch == "1": edge[i].append(1) else: edge[i].app...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CAL...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) inf = 10**9 matrix = [list(map(lambda x: int(x) or inf, input())) for _ in range(n)] for k in range(n): for i in range(n): for j in range(n): if matrix[i][j] > matrix[i][k] + matrix[k][j]: matrix[i][j] = matrix[i][k] + matrix[k][j] for i in range(n): matrix[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VA...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
from sys import setrecursionlimit as SRL from sys import stdin SRL(10**7) rd = stdin.readline rrd = lambda: map(int, rd().strip().split()) dis = [([1000000000] * 101) for _i in range(101)] n = int(rd()) for i in range(n + 1): dis[i][i] = 0 for i in range(1, n + 1): s = str(rd().strip()) for j in range(n): ...
EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) nei = [] for _ in range(n): s = input() nei.append(list(int(c) for c in s)) m = int(input()) p = list([(int(x) - 1) for x in input().split()]) shortest = [] for i in range(n): vals = [] for j, con in enumerate(nei[i]): if i == j: vals.append(0) elif con: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CA...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
def do(): n = int(input()) graph = [([0] * n) for _ in range(n)] for i in range(n): tmp = [int(c) for c in input()] for j in range(len(tmp)): graph[i][j] = 1 if tmp[j] == 1 else float("inf") n_path = int(input()) path = [(int(c) - 1) for c in input().split(" ")] dis =...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR AS...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
from sys import stdin input = stdin.readline def floyd(a, n): for i in range(n): for j in range(n): if i != j and a[i][j] == 0: a[i][j] = 10**18 for k in range(n): for i in range(n): for j in range(n): a[i][j] = min(a[i][j], a[i][k] + a[...
ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
N = int(1000000.0 + 3) n = int(input()) dis = list([N] * n for _ in range(n)) for i in range(n): for j in range(n): if i == j: dis[i][j] = 0 for i in range(n): s = input() for j in range(n): if s[j] == "1": dis[i][j] = 1 for k in range(n): for i in range(n): ...
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) gr = list() for _ in range(n): gr.append(list(map(lambda x: [10000000000, 1][int(x)], input()))) m = int(input()) p = list(map(lambda x: int(x) - 1, input().split())) for k in range(n): for i in range(n): for j in range(n): gr[i][j] = min(gr[i][j], gr[i][k] + gr[k][j]) skip ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VA...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) d = [] for i in range(n): d += [[int(i) for i in input()]] inf = 200 for i in range(n): for j in range(n): if d[i][j] == 0 and i != j: d[i][j] = inf for k in range(n): for j in range(n): for i in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) m =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL V...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
from sys import setcheckinterval, stdin setcheckinterval(1000) iin = lambda: int(stdin.readline()) lin = lambda: list(map(int, stdin.readline().split())) def BFS(s, adj): level = {s: 0} parent = {s: None} lv = 1 u = [s] while u: nextu = [] for i in u: for v in adj[i]: ...
EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT VAR NUMBER ASSIGN VAR DICT VAR NONE ASSIGN VAR NUMBER ASSIGN VAR LIST VAR WHILE VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIG...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
R = lambda: map(int, input().split()) n = int(input()) L = [] for i in range(n): L.append([int(j) for j in input()]) for i in range(n): for j in range(n): if i != j and L[i][j] == 0: L[i][j] = 10**9 for k in range(n): for i in range(n): for j in range(n): L[i][j] = mi...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER FOR VAR F...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
import sys def main(): INF = int(1000000000.0) n = int(sys.stdin.readline()) g = [[]] * n for i in range(n): s = sys.stdin.readline().strip() sg = list(map(int, list(s))) g[i] = sg m = int(sys.stdin.readline()) p = list(map(lambda x: int(x) - 1, sys.stdin.readline().spl...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) mat = [] for _ in range(n): mat.append([int(i) for i in input()]) short = [] for i in range(n): short.append([-1] * n) for i in range(n): layer = {i} cnt = 1 sht = short[i] sht[i] = 0 while len(layer) > 0: new = set() for v in layer: for j in rang...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
from sys import stdin input = stdin.readline a = [] n = int(input()) for _ in range(n): s = input() a.append(s) m = int(input()) b = list(map(int, input().split())) c = [0] * m k = 0 for i in range(1, m - 1): if k == 1: k = 0 continue if a[b[i - 1] - 1][b[i + 1] - 1] == "0" and b[i - 1]...
ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
import sys MOD = pow(10, 9) + 7 INF = 999999999999999 def IN(f=0): if f == 0: return [int(i) for i in sys.stdin.readline().split()] else: return int(sys.stdin.readline()) def floydWarshall(graph, V): dist = [] for i in range(V): dist.append(graph[i].copy()) for k in rang...
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FU...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) INF = 10**18 g = [[INF for i in range(n)] for _ in range(n)] for i in range(n): s = input().rstrip() for j in range(n): if s[j] == "1": g[i][j] = 1 g[i][i] = 0 for k in range(n): for i in range(n): for j in range(n): g[i][j] = min(g[i][j], g[i][k]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
nodes = int(input()) dist = {} for i in range(1, nodes + 1): for j in range(1, nodes + 1): dist[i, j] = float("inf") for i in range(nodes): lst = input() for j in range(len(lst)): if lst[j] == "1": dist[i + 1, j + 1] = 1 n = input() path = [int(x) for x in input().split()] for n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
import sys input = lambda: sys.stdin.readline().strip() n = int(input()) d = [] for i in range(n + 1): d.append([]) for j in range(n + 1): d[-1].append(0) for i in range(1, n + 1): s = input() for j in range(1, n + 1): if i != j: if s[j - 1] == "0": d[i][j] =...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_C...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
gi = lambda: list(map(int, input().split())) (n,) = gi() g = [list(map(int, list(input()))) for _ in range(n)] (lenp,) = gi() p = gi() ans = p[:] lenans = lenp k = 1 while k < lenp - 1: if g[ans[k - 1] - 1][ans[k + 1] - 1] == 0 and ans[k - 1] != ans[k + 1]: p[k] = -1 ans[k] = ans[k - 1] lena...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BI...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) dis = [] for i in range(n): a = list(map(int, input())) for j in range(n): if a[j] == 0: a[j] = 200 a[i] = 0 dis.append(a) for k in range(n): for i in range(n): for j in range(n): dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]) m = int(input...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL V...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
def floyd(n, dist): for k in range(n): for i in range(n): for j in range(n): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) n = int(input()) graph = [([0] * n) for _ in range(n)] for i in range(n): s = input() for j in range(n): graph[i][j] = int(s[j]) if...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUN...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
def gns(): return list(map(int, input().split())) n = int(input()) mp = [] for i in range(n): mp.append(input()) def bfs(i): nxt = [i] ans = [None] * n ans[i] = 0 v = [False] * n v[i] = True p = 0 while len(nxt) > 0: p += 1 nxt_ = [] for ni in nxt: ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NU...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) edges = [[] for i in range(n)] for i in range(n): s = input() for j in range(n): if s[j] == "1": edges[i].append(j) m = int(input()) path = [(int(i) - 1) for i in input().split()] dist = [[(0) for i in range(n)] for j in range(n)] for i in range(n): visited = [(-1) for j...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) adj = [] for i in range(n): adj.append(str(input())) dist = [[(999999999999999999999999999) for i in range(n)] for j in range(n)] for i in range(n): for j in range(n): if i == j: dist[i][j] = 0 elif adj[i][j] == "1": dist[i][j] = 1 m = int(input()) p = li...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
n = int(input()) g = [] def bfs(src): q = [] dist = [] visited = [] for i in range(n): visited.append(False) dist.append(1e18) dist[src] = 0 visited[src] = True q.append(src) while q: src = q.pop(0) for i in g[src]: if visited[i] == False: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR IF VA...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
from sys import stdin, stdout input = stdin.readline print = stdout.write n = int(input()) dist = [] for i in range(n): dist.append(list(map(lambda x: 1 if x == "1" else 200, input()))) m = int(input()) p = list(map(int, input().split())) def solve(n, dist, m, p): for i in range(n): dist[i][i] = 0 ...
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER NUMBER 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 FUNC_DEF FOR VAR ...
The main characters have been omitted to be short. You are given a directed unweighted graph without loops with $n$ vertexes and a path in it (that path is not necessary simple) given by a sequence $p_1, p_2, \ldots, p_m$ of $m$ vertexes; for each $1 \leq i < m$ there is an arc from $p_i$ to $p_{i+1}$. Define the seq...
def floyd(g): n = len(g) for k in range(n): for i in range(n): if g[i][k] is None: continue for j in range(n): if g[k][j] is None: continue cand = g[i][k] + g[k][j] if g[i][j] is None or g[i][j] >...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NONE FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NONE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR ...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
def myFunc(e): return e[0] + e[1] count, rating = list(map(int, input().split())) goodJob = [] badJob = [] taken = 0 for i in range(count): a, b = list(map(int, input().split())) if b >= 0: goodJob.append([a, b]) else: badJob.append([a, b]) goodJob.sort() badJob.sort(reverse=True, key=...
FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_C...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
import sys input = sys.stdin.readline n, r = map(int, input().split()) l = [] for _ in range(n): l.append(list(map(int, input().split()))) p = 0 ans = 0 while p < n: if l[p][0] <= r and l[p][1] >= 0: r += l[p][1] l = l[:p] + l[p + 1 :] p = 0 n -= 1 ans += 1 else: ...
IMPORT ASSIGN 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 ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR ...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
n, r = map(int, input().split()) pt = [] nt = [] r2 = r result = 0 for _ in range(n): a, b = map(int, input().split()) r2 += b if b >= 0: pt.append((a, b)) else: nt.append((a, b)) pt.sort() nt.sort(key=lambda t: t[1] + t[0], reverse=True) for a, b in pt: if r < a: break r...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR B...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
n, r = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(n)] pos = [] neg = [] ans = 0 for x in a: if x[1] > 0: pos.append(x) else: neg.append(x) pos.sort(key=lambda k: k[0]) flag = True for x in pos: if r >= x[0]: r += x[1] ans += 1 neg.sort...
ASSIGN VAR VAR FUNC_CALL 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 LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER A...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
inp = str(input()).split() size = int(inp[0]) r = int(inp[1]) pos = [] neg = [] for i in range(size): inp = str(input()).split() a = int(inp[0]) b = int(inp[1]) if b >= 0: pos.append((a, b)) else: neg.append((a, b)) pos = sorted(pos) projects = 0 for ab in pos: a, b = ab if r...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR F...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
from sys import setrecursionlimit as SRL from sys import stdin SRL(10**7) rd = stdin.readline rrd = lambda: list(map(int, rd().strip().split())) n, r = rrd() pos = [] neg = [] for i in range(n): a, b = rrd() if b < 0: neg.append([a, b]) else: pos.append([a, b]) pos.sort(key=lambda x: x[0]) ...
EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VA...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
N, R = [int(x) for x in input().split()] projects = [[int(x) for x in input().split()] for _ in range(N)] pos = [] neg = [] for a, b in projects: if b < 0: neg.append((a, b)) else: pos.append((a, b)) pos.sort() ans = 0 for a, b in pos: if R >= a: R += b ans += 1 neg.sort(key=...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
n, r = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(n)] def solve1(cur, arr): cnt = 0 while len(arr) > 0: max_inc = -9999 choose = None for a, b in arr: if cur >= a and max_inc < b: max_inc = b choose = a ...
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 FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIG...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers asked him to complete some projects for their companies. To complet...
n, r = map(int, input().split()) a = [] cnt = 0 for i in range(n): a.append([int(j) for j in input().split()]) flag = True while flag: flag = False for i in a: if r >= i[0] and i[1] >= 0: flag = True r += i[1] cnt += 1 a.remove(i) break a =...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER VAR NUMBER ...
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices. A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T. You're given a tr...
import sys def minp(): return sys.stdin.readline().strip() n = int(minp()) e = [0] p = [None] * (n + 1) for i in range(n): e.append([]) for i in range(n - 1): a, b = map(int, minp().split()) e[a].append(b) e[b].append(a) v = list(map(int, minp().split())) plus = [0] * (n + 1) minus = [0] * (n + ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR...
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices. A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T. You're given a tr...
n = int(input()) r = [[] for i in range(n + 1)] r[1] = [0] for i in range(n - 1): a, b = map(int, input().split()) r[a].append(b) r[b].append(a) t = list(map(int, input().split())) u, v = [0] * (n + 1), [0] * (n + 1) for i, j in enumerate(t, 1): if j < 0: u[i] = -j else: v[i] = j t, ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_...