description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
def solve(n, a, b): if n % 2: if a[n // 2] != b[n // 2]: return "no" def get_pairs(a): ret = [] for i in range(len(a) // 2): x, y = a[i], a[n - i - 1] if x > y: x, y = y, x ret.append((x, y)) return sorted(ret) ...
FUNC_DEF IF BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN STRING FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN V...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
test = int(input()) number = [] col_a = [] col_b = [] for i in range(test): number.append(int(input())) col_a.append(list(map(int, input().split()))) col_b.append(list(map(int, input().split()))) for i in range(test): if number[i] % 2 == 1: if col_a[i][int((number[i] - 1) / 2)] != col_b[i][int((...
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 EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FU...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
for _ in range(int(input())): n = int(input()) k = n // 2 a = list(map(int, input().split())) b = list(map(int, input().split())) dicA = {} dicB = {} for i in range(k): p, q = a[i], a[-i - 1] if p > q: if (q, p) not in dicA: dicA[q, p] = 0 ...
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 ASSIGN 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 ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) d = {} f = True if n % 2 != 0 and a[n // 2] != b[n // 2]: f = False for i in range(n // 2): mn = min(a[i], a[n - i - 1]) mx = max(a[i], a[n - i - 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VA...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
t = int(input()) for i in range(t): l = int(input()) if l <= 1: g = int(input()) f = int(input()) if g == f: print("Yes") else: print("No") else: a = [] b = [] a = list(map(int, input().split())) b = list(map(int, input(...
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if sorted(a) != sorted(b): print("NO") continue c = {} for i in range(n): if a[i] not in c: c[a[i]] = [a[n - i - 1]] else: ...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CAL...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
def is_equal(a1, a2, n): if n % 2 == 1 and a1[n // 2] != a2[n // 2]: return False arr1 = create(a1) arr2 = create(a2) for u, v in zip(arr1, arr2): if u != v: return False return True def create(a): arr = [] n = len(a) for i in range(n // 2): if a[i] ...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
n = int(input()) inp = lambda: list(map(int, input().split(" "))) pairs = lambda x: sorted(zip(x, x[::-1])) for _ in range(n): inp() print(["no", "yes"][pairs(inp()) == pairs(inp())])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST STRING STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
def solve(n, a, b): if a[n // 2] != b[n // 2] and n % 2 != 0: return "NO" i = 0 seta = sorted([[a[i], a[n - 1 - i]] for i in range(n)]) setb = sorted([[b[i], b[n - i - 1]] for i in range(n)]) for i in range(n): if seta[i] != setb[i]: return "NO" return "YES" for _ i...
FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
t = int(input()) for i in range(t): n = int(input()) fail = False a = [int(j) for j in input().split()] b = [int(j) for j in input().split()] if n % 2 != 0: if a[int((n - 1) / 2)] != b[int((n - 1) / 2)]: print("no") continue counter = {} for j in range(int(n /...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
t = int(input()) for o in range(t): n = int(input()) a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split())) aPairs = [] bPairs = [] oddBreaker = False if n % 2: if a[n // 2] != b[n // 2]: oddBreaker = True for i in range(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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER IF BIN_OP VA...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
case = int(input()) for o in range(case): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ok = True if n % 2 == 1: if a[n // 2] != b[n // 2]: ok = False pa = [] pb = [] for i in range(n // 2): x = a[i] y = a[n -...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP ...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) paira = [] for i in range((n + 1) // 2): paira.append(tuple(sorted([a[i], a[~i]]))) pairb = [] for i in range((n + 1) // 2): pairb.append(tuple(sorted(...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CA...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
T = int(input()) X = [] for i in range(0, T): C = [] D = [] n = int(input()) A = [int(x) for x in input().split(" ")] B = [int(x) for x in input().split(" ")] for i in range(0, len(A) // 2): a = [A[i], A[len(A) - 1 - i]] b = [B[i], B[len(A) - 1 - i]] a.sort() b.so...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [] D = [] if n % 2 == 1: if A[n // 2] != B[n // 2]: print("No") continue for i in range(...
IMPORT ASSIGN VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER ...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
from sys import stdin, stdout def swaps_again(n, a, b): if n % 2 == 1 and a[n // 2] != b[n // 2]: return "No" dica = {} for i in range(0, n // 2): al = a[i] ar = a[n - 1 - i] if al not in dica: dica[al] = {} if ar not in dica: dica[ar] = {} ...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR DICT IF VAR VAR ASSIGN VAR VAR DICT IF VAR VAR VAR ASSIGN VAR VAR VAR NUM...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
def result(a, b, n): set1 = {} set2 = {} for i in range(n // 2): if (max(a[i], a[n - 1 - i]), min(a[i], a[n - 1 - i])) in set1: set1[max(a[i], a[n - 1 - i]), min(a[i], a[n - 1 - i])] += 1 else: set1[max(a[i], a[n - 1 - i]), min(a[i], a[n - 1 - i])] = 1 if (max...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER A...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
from itertools import count def get_repr(items): size = len(items) result = [] for i in count(): if size <= 2 * i: break first, second = items[i], items[-(i + 1)] if first > second: first, second = second, first result.append((first, second)) res...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL ...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
t = int(input()) def solve(): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n % 2 == 1 and a[n // 2] != b[n // 2]: return "no" sa = {} i = 0 j = n - 1 while i < j: u = a[i] v = a[j] if u > v: u, v...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR DI...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) pair = dict() possible = 1 if n % 2 == 1: if a[n // 2] != b[n // 2]: possible = 0 for i in range(n // 2): M, m = max(a[i], a[n - i - 1]), m...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
from sys import stdin input = stdin.buffer.readline for _ in range(int(input())): n = int(input()) (*a,) = map(int, input().split()) (*b,) = map(int, input().split()) if n & 1 and a[n // 2] != b[n // 2]: print("no") continue a = sorted([sorted([a[i], a[n - i - 1]]) for i in range(n ...
ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CAL...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
t = int(input()) for i in range(t): n = int(input()) lis1 = [int(x) for x in input().split()] lis2 = [int(x) for x in input().split()] if n % 2 == 1: if lis1[n // 2] != lis2[n // 2]: print("No") continue dict1 = dict() for i in range(n // 2): str1 = str(li...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING A...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
t = int(input()) for _ in range(t): q, f = lambda: list(map(int, input().split())), lambda x: sorted( zip(x, reversed(x)) ) q(), print(["no", "yes"][f(q()) == f(q())])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST STRING STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
def solve(): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n % 2 == 1: if a[n // 2] != b[n // 2]: print("No") return u, v = list(), list() def add(s, p, q): if p > q: p, q = q, p s.append((...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR FUNC_CALL VAR F...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
import sys def ii(): return sys.stdin.readline().strip() def idata(): return [int(x) for x in ii().split()] def solve_of_problem(): n = int(ii()) data = idata() data1 = idata() if n == 1: if data1 == data: print("Yes") else: print("No") retur...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR FUNC_CAL...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
cases = int(input()) answers = [] * 0 for problems in range(cases): n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] s1 = sorted(a) s2 = sorted(b) pairs = [] * 0 for i in range(n // 2): pairs.append(sorted([a[i], a[-1 - i]])) if s1 != s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
from sys import stdin, stdout t = int(stdin.readline().strip()) for _ in range(t): n = int(stdin.readline().strip()) a = list(map(int, stdin.readline().split())) b = list(map(int, stdin.readline().split())) pairs = {} i, j = 0, n - 1 while i < (n - 1) / 2: pairs[a[i], a[j]] = pairs.get(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE ...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
import sys t = int(input()) while t != 0: t -= 1 n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] aa = [] bb = [] k = int(n / 2) if n & 1 and a[k] != b[k]: print("NO") continue for i in range(k): aa.append((a[i], a[...
IMPORT 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMB...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
for _ in range(int(input())): n = int(input()) a = [int(c) for c in input().split()] b = [int(c) for c in input().split()] ad = sorted(a) bd = sorted(b) if ad != bd: print("No") continue if n % 2 == 1: if a[n // 2] != b[n // 2]: print("No") con...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER N...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
from sys import gettrace, stdin if gettrace(): inputi = input else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def main(): def solve(): n = int(inputi()) aa = [int(a) for a in inputi().split()] bb = [int(a) for a in inp...
IF FUNC_CALL VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF FUNC_DEF 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 VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUM...
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
q, f = lambda: list(map(int, input().split())), lambda x: sorted(zip(x, x[::-1])) for _ in range(q()[0]): q(), print("yneos"[f(q()) != f(q()) :: 2])
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer $n$ and two arrays $a$ and $b$, of size $n$. If after some (possibly zero) operations described below, array $a$ can be transformed into arr...
from sys import stdin tt = int(stdin.readline()) for loop in range(tt): n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) b = list(map(int, stdin.readline().split())) if n % 2 == 1 and a[n // 2] != b[n // 2]: print("no") continue dic = {} for i in range(n //...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_...
Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n). Now Dima wants to count the number of distinct sequences of points of length 2Β·n that can be assembled from these sequences, such that the x-coordinates of points in th...
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1): n = nmbr() a = lst() b = lst() M = nmbr() tot = {} ans = 1 mp = {} for v, v1 in zip(a, b): tot[v] = tot.get(v, 0) + 1 tot[v1] = to...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR VAR A...
Consider a grid A with dimensions N \times M, such that all elements of the grid are distinct. A remote controlled car is present at cell (1,1). Chef and Chefina will alternatively move the car with Chef starting first. If it is Chef's turn, he will move the car to either right or down by 1 cell. He moves the car to ...
import sys t = int(input()) while t: n, m = map(int, input().split()) h = n p = m n = min(h, p) m = max(h, p) b = [int(x) for x in input().split()] b.sort() x = min(n, m) - 1 ch = (x + 1) // 2 che = x // 2 ans = sys.maxsize pos = -1 for i in range(ch, n * m - che - n...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR...
Consider a grid A with dimensions N \times M, such that all elements of the grid are distinct. A remote controlled car is present at cell (1,1). Chef and Chefina will alternatively move the car with Chef starting first. If it is Chef's turn, he will move the car to either right or down by 1 cell. He moves the car to ...
for i in range(int(input())): n, m = map(int, input().split()) lst = [int(x) for x in input().split()] lst.sort() h, p = n, m n = min(h, p) m = max(h, p) x = min(n, m) - 1 temp = (x + 1) // 2 t2 = x // 2 maxv = 999999999999999 start = -1 for i in range(temp, n * m - t2 - ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER A...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
import sys def get_arr(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) a = get_arr() s = input() b = [] for i in range(n):...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR 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 ASSIGN VA...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split(" "))) s = input() if sorted(arr) == arr: print(0) elif s.count("N") == n or s.count("N") == 0: print(-1) else: a = sorted(arr) b = arr start = 2147483647 last = -2147...
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 STRING ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def isSorted(nums): for i in range(1, len(nums)): if nums[i - 1] > nums[i]: return False return True def solve(n, s, nums): if isSorted(nums): return 0 if "N" not in s or "S" not in s: return -1 temp = nums.copy() i = s.find("N") j = s.rfind("S") if ...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR RETURN NUMBER IF STRING VAR STRING VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR BIN_O...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) nums = list(map(int, input().split())) pole = input() o = sorted(nums) pre = [] for i, item in enumerate(pole): k = 0 if item == "N": k = 1 if i: k += pre[i - 1] pre.append(k) index = [] ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
a = int(input()) for i in range(a): N = int(input()) A = list(map(int, input().split())) S = input() if sorted(A) == A: print(0) elif S[0] != S[N - 1]: print(1) elif S.count(S[0]) == N: print(-1) elif S[0] == "N": k = S.index("S") r = S.rfind("S") ...
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 FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CAL...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def solve(n, arr, p): sorted_arr = sorted(arr) if arr == sorted_arr: return 0 first_s = -1 last_s = -1 first_n = -1 last_n = -1 for i in range(n): if p[i] == "S": if first_s == -1: first_s = i last_s = i else: if fir...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR N...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) def solve(ar, pol): ref = sorted(ar) if ar == ref: return 0 if len(set(pol)) == 1: return -1 n = len(ar) for i in range(n): if ar[i] != ref[i]: break for j in range(n - 1, -1, -1): if ar[j] != ref[j]: break for k in r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR FOR VAR FUNC_CA...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
import sys def check(A, first, last): A[first : last + 1] = sorted(A[first : last + 1]) if A == sorted(A): return 1 return 0 def solve(A, S): arr = sorted(A) if arr == A: return 0 n_count = S.count("N") s_count = S.count("S") if n_count == 0 or s_count == 0: r...
IMPORT FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR D...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def disturbance(l, p, n): st, en = -1, 0 for i in range(n): if l[i] != p[i]: if st == -1: st = i else: en = i return st, en for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) s = str(input()) p ...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR 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 ASSIGN VAR FUNC_CALL V...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for i in range(int(input())): n = int(input()) A = [int(k) for k in input().split()] s = input() S = 0 N = 0 for k in s: if k == "N": N += 1 else: S += 1 if S == n and A != sorted(A) or N == n and A != sorted(A): print(-1) elif A == sorted(...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EX...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) s = input() b = a.copy() b.sort() if a == b: print(0) elif len(set(s)) == 1: print(-1) else: b1 = 0 for j in range(0, n - 1): if s[-1] == "S": ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER E...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
T = int(input()) for _ in range(T): n = int(input()) lo = list(map(int, input().split())) s = sorted(lo) c = list(input()) r = -1 if lo == s: r = 0 if "N" in c and "S" in c: if lo == s: r = 0 elif c[0] != c[-1]: r = 1 else: ...
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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR IF VAR VA...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) s = input() if sorted(arr) == arr: print(0) elif "N" not in s or "S" not in s: print(-1) else: begin = -1 end = -1 temp = sorted(arr) for i in range(n): ...
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 FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER A...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) s = list(input()) if all(a[i - 1] <= a[i] for i in range(1, n)): print(0) continue n_ct = s.count("N") if n_ct == n or n_ct == 0: print(-1) continue left, right = n + 1, -...
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 FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN V...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def check(A, first, last): A[first : last + 1] = sorted(A[first : last + 1]) if A == sorted(A): return 1 return 0 def solve(A, S, N): if A == sorted(A): print(0) return countN = 0 for ch in S: if ch == "N": countN += 1 if countN == 0 or countN ==...
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN V...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
from sys import stdin input = stdin.readline for _ in range(int(input())): n = int(input()) li = list(map(int, input().split())) s = input().strip() res = sorted(li[:]) if res == li: print(0) elif s.count("S") == 0 or s.count("N") == 0: print(-1) elif s[0] + s[-1] == "NS" or...
ASSIGN VAR 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 ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STR...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) while t: t -= 1 n = int(input()) a = list(map(int, input().split())) temparr = sorted(a) s = input() if temparr == a: print(0) continue if s.count("S") == n or s.count("N") == n: print(-1) continue d = {"leftN": 0, "leftS": 0, "rightN": 0,...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR EXPR FUNC_...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
n_test_cases = int(input()) results = [] for _ in range(n_test_cases): n_ints = int(input()) A = [int(x) for x in input().split()] polarity = input() A_sorted = sorted(A) if len(A) == 1: results.append(0) continue if A == A_sorted: results.append(0) continue i...
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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBE...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = input() c = sorted(a) d = 0 e = f = 0 if a != c: if "N" not in b or "S" not in b: print(-1) continue if b[0] != b[-1]: print(1) continue ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER IF VAR N...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for _ in range(t): ct, n = 0, int(input()) a = list(map(int, input().split())) pre, s, f = 0, input(), True for i in a: if i < pre: f = False break pre = i if f: print(0) continue for i in s: if i == "S": ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER FO...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) string = input() cnt_s = string.count("S") cnt_n = string.count("N") sorted_a = list(sorted(a)) if a == sorted_a: print(0) elif cnt_s == 0 or cnt_n == 0: print(-1) else: f...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR F...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) while t: n = int(input()) li = list(map(int, input().strip().split())) s = input() lii = li.copy() lii.sort() ans = 2 if lii == li: ans = 0 elif len(set(s)) == 1: ans = -1 elif s[0] == s[n - 1] and len(set(s)) > 1: lis = list(s) for j ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMB...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) s = input() arr1 = [] arr1 = arr.copy() arr1.sort() t1 = 0 t2 = 0 for i in range(n): if arr[n - 1 - i] != arr1[n - 1 - i] and t2 == 0: tester2 = n - 1 - i t2 = 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def res1(n, arr, stri): cnt1 = 0 cnt2 = 0 for i in range(n): if stri[i] == "N": cnt1 += 1 else: cnt2 += 1 sarr = sorted(arr) if cnt1 == n and sarr != arr or cnt2 == n and sarr != arr: return -1 if sarr == arr: return 0 if stri[0] != str...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NU...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
try: for t in range(int(input())): number = int(input()) ant = list(map(int, input().split())) starting = input() sorts = sorted(ant) if ant == sorts: print(0) else: fin = 0 last = number - 1 for i in range(number): ...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for _ in range(t): n = int(input()) nums = list(map(int, input().split())) chars = [x for x in input()] num_north = sum([(1 if x == "N" else 0) for x in chars]) if all(nums[x] <= nums[x + 1] for x in range(n - 1)): print(0) elif num_north == 0 or num_north == n: ...
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 VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CA...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = sorted(a) d = list(input()) if a == b: print(0) continue if d.count("N") == n or d.count("N") == 0: print("-1") continue start = -1 end = -1 for i in range(n):...
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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING VAR FUNC_CALL VAR ST...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def arraySortedOrNot(arr, N): if N == 0 or N == 1: return True for i in range(1, N): if arr[i - 1] > arr[i]: return False return True T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) polarityStr = input() boolSort = arrayS...
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER 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 ...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def solve(n, s, nums): if sorted(nums) == nums: return 0 if "N" not in s or "S" not in s: return -1 temp = nums.copy() if s[0] == "N": idx = -1 for i in range(n): if s[i] == "S": idx = i temp[: idx + 1] = sorted(temp[: idx + 1]) els...
FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF STRING VAR STRING VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR I...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): N = int(input()) A = [int(x) for x in input().split()] P = input() SA = sorted(A) if A == SA: print(0) continue elif not (P.count("N") and P.count("S")): print(-1) continue elif P[0] != P[-1]: print(1) continue ...
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 ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBE...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) polarity = input() if sorted(a) == a: print(0) elif len(set(polarity)) == 1: print(-1) elif polarity[0] != polarity[-1]: print(1) else: f = 0 i = 0 p1 = 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NU...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = input() opp = {"S": "N", "N": "S"} temp = sorted(a) if a == temp: print(0) elif s[0] != s[-1]: print(1) elif opp[s[0]] not in s: print(-1) else: for i in range(n): ...
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 FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def getCount(): for k in range(num): if arr1[k] != sorted[k]: break pol = arr2[k] if pol == "N": for l in range(num - 1, k, -1): if arr1[l] != sorted[l] and arr2[l] == "N": break if (arr1[l] != sorted[l] or arr1[l] == sorted[l]) and arr2[l]...
FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR STRING IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR STRING RETURN NUMBER IF VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = input().strip() if a == sorted(a) or n == 1: print(0) continue if s.count("N") == n or s.count("S") == n: print(-1) continue if s[0] == "N" and s[-1] == "S" or s[0] == "S" and s...
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 FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def mi(): return map(int, input().split()) def li(): return list(mi()) def ni(): return int(input()) def si(): return str(input()) def isSorted(A): if not A: return True temp = list(A) temp.sort() return temp == A for t in range(ni()): N = ni() A = li() S = ...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR A...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def solve(n, a, s): b = sorted(a) i = 0 while i < n and a[i] == b[i]: i += 1 if i == n: return 0 if s == "S" * n or s == "N" * n: return -1 j = n - 1 while j >= 0 and a[j] == b[j]: j -= 1 s = s[: i + 1] + s[j:] if s == "S" * (i + 1 + n - j) or s == "N"...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR BIN_OP STRING VAR VAR BIN_OP STRING VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP ST...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for i in range(t): n = int(input()) lst = list(map(int, input().split())) s = input() ele = s[0] c = 0 lst1 = lst.copy() lst1.sort() if lst1 == lst: print(0) else: for j in range(1, n): if s[j] != ele: c += 1 ...
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 FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) def solve(): N = int(input()) A = [int(x) for x in input().split(" ")] S = input().strip("\n") sA = list(sorted(A)) if sA == A: print("0") return firsts, firstn, lasts, lastn, firstw, lastw = [-1] * 6 for i in range(N): if S[i] == "S": i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP LI...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) ai = list(map(int, input().split())) s = input() s1 = -1 s2 = -1 n1 = -1 n2 = -1 for i in range(n): if s[i] == "S": s2 = i else: n2 = i if s[n - i - 1] == "S": s1 = n - i - 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN V...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def solve(A, S): arr = sorted(A) if arr == A: return 0 n_count = S.count("N") s_count = S.count("S") if n_count == 0 or s_count == 0: return -1 l = float("inf") r = 0 left_N = False right_N = False left_S = False right_S = False for i in range(len(A)): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL ...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) while t != 0: n = int(input()) A = list(map(int, input().split())) s = input() B = sorted(A) k = set(s) if A == B: print(0) t -= 1 continue if "N" not in k or "S" not in k: print(-1) t -= 1 continue i = 0 while i < n an...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF STRING VAR STRING VAR EX...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
_ = int(input()) while _: _ -= 1 n = int(input()) l = list(map(int, input().split())) s = input() nl = sorted(l) if l == nl: print(0) elif "N" not in s or "S" not in s: print(-1) elif s[0] != s[-1]: print(1) else: fn = s.index("N") fs = s.index...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBE...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) st = list(input()) f = [] res = sorted(arr) for i in range(0, n): if arr[i] != res[i]: f.append(i) com = st[0] flag = 0 for i in st: if i != com: flag = 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIG...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def solve(n, arr, s): a = list(sorted(arr)) if arr == a or n == 1: return 0 if len(set(s)) == 1: return -1 i, j = 0, n - 1 while arr[i] == a[i]: i += 1 while arr[j] == a[j]: j -= 1 lefts = "S" in s[: i + 1] leftn = "N" in s[: i + 1] rights = "S" in s[j...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR STRING VAR BIN_OP V...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = input() if a == sorted(a): print(0) continue if not s.count("N") or not s.count("S"): print(-1) continue firstN, firstS, lastN, lastS = -1, -1, -1, -1 for i in range(n): ...
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 FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VA...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
T = int(input()) while T: T -= 1 N = int(input()) arr = list(map(int, input().split())) polar = input() sorted_arr = sorted(arr) if arr == sorted_arr: print(0) continue if polar[0] != polar[-1]: print(1) continue if polar.count("N") == len(polar) or polar....
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = input() arr = [] for j in a: arr.append(j) arr.sort() c = c1 = c2 = d = e = 0 for j in range(n - 1): if a[j] > a[j + 1]: c = 1 break if c == 0: print...
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 FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NU...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def solve(a, p, s): if a == s: return 0 elif p[0] != p[-1]: return 1 elif ("N" in p) == False or ("S" in p) == False: return -1 if p[0] == p[-1]: start = 2147483647 last = -2147483648 for i in range(n): if s[i] != a[i]: start = ...
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF STRING VAR NUMBER STRING VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSI...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): N = input() x = list(map(int, input().split())) weights = input() sx = sorted([(a, b, weights[a]) for a, b in enumerate(x)], key=lambda x: x[1]) first_N = last_N = first_S = last_S = -1 fS = fN = fX = True fu = lu = -1 m = [float("inf"), -1] for i in ran...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMB...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) lst = list(map(int, input().split())) s = input() sorted_lst = sorted(lst) if n == 1: print(0) elif lst != sorted_lst: if s[0] != s[-1]: print(1) elif s == "N" * n or s == "S" * n: print(-1) el...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR B...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) s = input().strip() b = sorted(a) if b == a or len(a) == 1: print(0) else: st = 0 for i in range(n): if a[i] == b[i]: pass else: ...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR V...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
def MostMisplaced(arr, arrSorted): for x in range(len(arr)): if arr[x] != arrSorted[x]: return x return None def insideRange(val, myRange): if val >= myRange[0] and val <= myRange[1]: return True else: return False def areIn(leftMost, rightMost, givenRange): i...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN VAR RETURN NONE FUNC_DEF IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = input().strip() if a == sorted(a) or n == 1: print(0) continue if s.count("N") == n or s.count("S") == n: print(-1) continue if s[0] == "N" and s[-1] == "S" or s[0] == "S" and s...
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 FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for t in range(int(input())): n = int(input()) lst = list(map(int, input().split(" "))) dirc = input() if lst == sorted(lst): print(0) elif dirc[0] != dirc[n - 1]: print(1) elif "N" in dirc and "S" in dirc: i = n - 1 while dirc[0] == dirc[i]: i -= 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 STRING ASSIGN VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRIN...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) p = str(input()) f = a.copy() f.sort() if f == a: print(0) elif p.count("S") == 0 or p.count("N") == 0: print(-1) elif p[0] != p[-1]: print(1) elif p[0] == p[-1]: ...
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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING NUMBE...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
try: t = int(input()) for q in range(t): n = int(input()) l = list(map(int, input().split())) s = input() a = [] flag = 0 left = 0 right = n - 1 for v in range(n - 1): if s[v] != s[v + 1]: flag += 1 for j in l: ...
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 FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF ...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) s = input() k = l.copy() k.sort() if k == l: print(0) elif len(set(s)) == 1: print(-1) elif s[0] != s[-1]: print(1) else: c = s[-1] ind = 0 for i i...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER E...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) s = input() c = sorted(a) if c == a: print(0) continue if 0 in [s.count("N"), s.count("S")]: print(-1) continue l = None r = None for j in range(n): if c[j...
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF NUMBER LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING E...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) s = input() if "N" in s and "S" in s: if l == sorted(l): print("0") else: a = 0 b = n - 1 if s[a] != s[b]: print("1") else: ...
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 FUNC_CALL VAR IF STRING VAR STRING VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR V...
There is an array A with N elements. Each element of A has a fixed *polarity*: either north or south. Chef is allowed to perform some (possibly zero) operations on the array A. In one operation, Chef can: Pick some subarray of array A, such that, the first and last elements of the subarray have different polarities,...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = input() d = a.copy() d.sort() flag = 1 for i in range(n): if d[i] != a[i]: flag = 0 break if flag == 1: print(0) else: countn = 0 counts = 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ...
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into bl...
import sys input = sys.stdin.readline n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) MOD = 10**9 + 7 ans = 1 for ai, bi in zip(a, b): if bi == 0: h = 10 ** (k - 1) - 1 cnt = h // ai + 1 else: h = bi * 10 ** (k - 1) + 10 ** (k - 1...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NU...
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into bl...
n1 = input() q, w = n1.split() n = int(q) k = int(w) n2 = input() A1 = n2.split() n3 = input() B1 = n3.split() x = "" y = "" A = [] B = [] for i in range(0, n // k): A.append(int(A1[i])) B.append(int(B1[i])) for i in range(0, k - 1): x += "0" y += "9" fin = 0 for i in range(0, n // k): ans = int("9"...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR ...
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into bl...
def get_multypler(k, a, b): res = (10**k - 1) // a + 1 bad_residue = (a - 10 ** (k - 1) * b % a) % a suf = 10 ** (k - 1) - 1 minus = suf // a + (1 if bad_residue <= suf % a else 0) return res - minus n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().spl...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR ...
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into bl...
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = n // k ans = 1 for i in range(c): t_ans = ( (10**k - 1) // a[i] + 1 + b[i] * 10 ** (k - 1) // a[i] - (b[i] + 1) * 10 ** (k - 1) // a[i] ) if b[i] * 10 ** (k - 1) % a[i...
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER...
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into bl...
s = input() ast = s.split(" ") n, k = int(ast[0]), int(ast[1]) s = input() a = [int(i) for i in s.split(" ")] s = input() b = [int(i) for i in s.split(" ")] L = n // k p = 10**k r = 10 ** (k - 1) rez = 1 for i in range(L): cnt = 0 if b[i] > 0: cnt += (b[i] * r - 1) // a[i] cnt += (p - 1) // a[i]...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN...