description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
from sys import stdin input = stdin.readline for xoxo in range(1): n = int(input()) s = input() a = [] b = [] c = [0] * 26 d = [] for i in range(26): a.append([]) b.append([]) d.append([]) for i in range(n): c[ord(s[i]) - 97] += 1 for i in range(n): ...
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR ...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
class Node: idx = None letter = None color = False def __init__(self, idx, letter): assert idx >= 0 and letter self.dependencies = [] self.dependents = [] self.idx = idx self.letter = letter def __repr__(self): return f"Node<{self.idx, self.letter}>"...
CLASS_DEF ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN STRING VAR VAR STRING FUNC_DEF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() last, last1 = "a", "a" ans = "" flag = 1 for i in s: if i < last and i < last1: flag = 0 break elif i >= last: last = i ans += "0" else: last1 = i ans += "1" if flag: print("YES") print(ans) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRI...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() used = [0] * n col = [-1] * n a = [(c, i) for i, c in enumerate(s)] a.sort() for _, i in a: tmp = -1 for j in range(i): if used[j] or col[j] == -1: continue if tmp == -1: tmp = col[j] if tmp != col[j]: print("NO") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR IF VA...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
import sys f_in = sys.stdin f_out = sys.stdout num = int(f_in.readline()) strings = f_in.readline() grp = [[], [], []] warning = 0 for i in range(0, num): if grp[0] == [] or grp[0][-1] <= strings[i]: grp[0].append(strings[i]) grp[2].append("0") elif grp[1] == [] or grp[1][-1] <= strings[i]: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER LIST VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER STRING IF VAR NUMBER LIST VAR NU...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
from sys import stdin, stdout input = stdin.readline def im(): return map(int, input().split()) def ii(): return int(input()) def il(): return list(map(int, input().split())) def ins(): return input()[:-1] n = ii() st = ins() lis = [0] * (n + 1) lis[1] = st[0] r = 1 ans = [1] for i in st[1:]:...
ASSIGN VAR VAR 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 VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUM...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) l = list(input()) k = [(0) for i in range(n)] z = [(0) for i in range(n)] x = sorted(l) r = "" for t in x: r += t for t in range(1, n): if l[t] < l[t - 1]: k[t] = k[t - 1] ^ 1 z[t] = k[t] i = t while i > 0 and l[i] < l[i - 1]: if k[i] == k[i - 1]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
from sys import stdin, stdout t = 1 for _ in range(t): n = int(input()) s = input() ans = [str(0)] last = s[0] color = 0 for i in s[1:]: if i >= last: last = i ans.append(str(color)) else: ans.append(str(color ^ 1)) val1 = [] val2 = []...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER AS...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = str(input()) ls = [] b_end = False s_out = "" for x in range(0, len(s)): tmp_tab = [s[x], -1] ls.append(tmp_tab) ls[0][1] = 0 for x in range(1, len(ls)): tmp_val = ls[x] tmp_lit = ls[x][0] tmp_num = 0 tmp_war = [] for y in range(x - 1, -1, -1): if ls[y][0] > tmp_...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() col = [-1] * n ans = "YES" inversions = False used = [False] * n def solve(i): global ans global inversions used[i] = True for j in range(n): if (ord(s[j]) - ord(s[i])) * (j - i) < 0: if col[j] != -1: if col[i] == col[j]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR N...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() p = [-1] * n dd = [0] * 26 p[0] = 1 dd[ord(s[0]) - 97] = 1 for i in range(1, n): f = 0 mxj = 0 for j in range(26): if dd[j] != 0 and j > ord(s[i]) - 97: f = 1 mxj = max(mxj, dd[j]) p[i] = mxj + 1 dd[ord(s[i]) - 97] = p[i] print(max(p)) for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VA...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = str(input()) lit = ["Z"] * 26 wyn = "" m = -1 for x in s: for y in range(26): if lit[y] <= x: wyn += str(y + 1) + " " lit[y] = x if y + 1 >= m: m = y + 1 break print(m) print(wyn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) f = input() t = "" a = "a" b = "a" h = 0 for j in f: if ord(a[-1]) <= ord(j): a += j t += "0" elif ord(b[-1]) <= ord(j): b += j t += "1" else: print("NO") h += 1 break if h == 0: print("YES") print(t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER IF VA...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
def hello_nigga(): n = int(input()) s = input() s0 = [] l_s0 = "a" s1 = [] l_s1 = "a" t = 1 for i in range(n): if s[i] >= l_s1: l_s1 = s[i] s1.append(i) elif s[i] >= l_s0: l_s0 = s[i] else: t = 0 print("N...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) a = list(input()) max_color = 0 colors = [(0) for _ in range(n)] color_to_max = [-1] for i in range(n): max_ok_color = -1 for color in range(max_color + 1): if ord(a[i]) >= color_to_max[color]: if max_ok_color == -1 or color_to_max[color] > color_to_max[max_ok_color]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() a = [] for i in range(n): a.append(ord(s[i])) visit = [(0) for i in range(n)] i, flag = 1, 0 rama = [(0) for i in range(n)] while i < n: if a[i] < a[i - 1]: visit[i] = 1 rama[i] = visit[i] temp = a[i] tempu = visit[i] j = i while j > 0: if tem...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NU...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() alpha = [0] * 26 col = [] for i in range(0, len(s)): c = 0 for j in range(ord(s[i]) - 97 + 1, 26): c = max(c, alpha[j]) col.append(c + 1) alpha[ord(s[i]) - 97] = c + 1 print(max(col)) print(*col)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
def main(): n = int(input()) s = list(input()) colors = [-1] * n for i in range(len(s)): if colors[i] == -1: colors[i] = 0 for j in range(i + 1, n): if s[j] < s[i]: if colors[j] == colors[i]: print("NO") retu...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) ok = True string = input() seq1 = "a" seq2 = "a" ans = "0" for i in string: if i >= seq1: seq1 = i ans += "0" continue if i >= seq2: seq2 = i ans += "1" else: ok = False if ok == True: print("YES") print(ans[1:]) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR STRING IF VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) c = list(input()) for i in range(n): c[i] = [c[i], -1] i = 0 flag = True while flag and i < n: j = i + 1 while j < n and c[i][1] == -1: if c[j][0] < c[i][0]: if c[j][1] != -1: c[i][1] = (c[j][1] + 1) % 2 j = n + 1 j += 1 if c[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER NUMBER ASSI...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
def main(): n = int(input()) s = input() fst_lst = [s[0]] snd_lst = [] ans = "1" for i in range(1, len(s)): if fst_lst[-1] <= s[i]: fst_lst.append(s[i]) ans += "1" else: snd_lst.append(s[i]) ans += "0" if sorted(snd_lst) == snd_...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
from itertools import tee def line(): return map(int, input().split()) def num(): return int(input()) def pairwise(it): a, b = tee(it) next(b, None) return zip(a, b) n = num() s = input() qq = [] ans = [] for c in s: for j, q in enumerate(qq): if c >= q: qq[j] = c ...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NONE RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR FUNC_CALL VAR...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
def hello_nigga(): n = int(input()) s = input() LAST = {(1): "a"} COLORS = {(1): []} cnum = 1 for i in range(n): nice = 0 for j in range(1, cnum + 1): if s[i] >= LAST[j]: LAST[j] = s[i] COLORS[j].append(i) nice = 1 ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER STRING ASSIGN VAR DICT NUMBER LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR ...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
def r(t=int): return list(map(t, input().split())) def ri(t=int): return t(input()) def cd(it): ret_val = dict() for v in it: ret_val[v] = ret_val.get(v, 0) + 1 return ret_val n = ri() ans = [0] * n alphabet = "abcdefghijklmnopqrstuvwxyz" a = [alphabet.index(ai) for ai in input()] pa =...
FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR STRING ASSIGN V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) a = list(input()) colors = [(0) for _ in range(n)] flag_yes = True last0, last1 = -1, -1 for i in range(n): if ord(a[i]) >= last0: if ord(a[i]) >= last1: if last0 >= last1: last0 = ord(a[i]) colors[i] = 0 else: last1 = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIG...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) letters = list(input()) flag = True flagarr = [0] * n binarr = {x: [0, 0] for x in range(26)} for i in range(n): for k in range(i + 1, n): if ord(letters[k]) % 97 < ord(letters[i]) % 97: flagarr[k] = 1 if flagarr[i]: flag = False break...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
import sys reader = (line.rstrip() for line in sys.stdin) input = reader.__next__ def ceil(tails, L, R, key): while L + 1 < R: m = (L + R) // 2 if key < tails[m]: L = m else: R = m return R def LIS(a, n): tails = [0] * (n + 1) tails[0] = a[0] seq_...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s2 = input() k = 0 s = [] l = {} for i in range(n): s.append(i) l[i] = -1 for i in range(n): m = "zz" index = -1 for j in range(k, n): if index == -1: index = j m = s2[j] if s2[j] < m: index = j m = s2[j] col = -1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
def binSearch(a, n): i, j = 0, len(a) - 1 while i != j: if (j - i) % 2 == 1: if a[i + (j - i) // 2] > n: i = i + (j - i) // 2 + 1 else: j = i + (j - i) // 2 elif a[i + (j - i) // 2] > n: i = i + (j - i) // 2 else: ...
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP BIN_OP VAR V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() kol = [-1] * n cur = 1 ind = 0 while ind < n: if kol[ind] != -1: ind += 1 else: kol[ind] = cur best = s[ind] for i in range(ind + 1, n): if kol[i] != -1: continue elif s[i] >= best: kol[i] = cur ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VA...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() arr = ["a" for i in range(n)] l = [] for i in s: for j in range(n): if i >= arr[j]: arr[j] = i l.append(j + 1) break print(max(l)) print(*l)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
import sys input = sys.stdin.readline class SegmentTree: def __init__(self, a): self.op = lambda a, b: max(a, b) self.e = 0 self.n = len(a) self.lv = (self.n - 1).bit_length() self.size = 2**self.lv self.data = [self.e] * (2 * self.size - 1) self._check = ...
IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VA...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
import sys class SegmentTree: def __init__(self, n, op, e): self.n = n self.op = op self.e = e self.size = 2 ** (n - 1).bit_length() self.node = [self.e] * (2 * self.size) def built(self, array): for i in range(self.n): self.node[self.size + i] = a...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
while True: try: n = int(input()) s = input() a = "" b = "" a += s[0] ans = "0" for i in range(1, n): if s[i] >= a[-1]: a += s[i] ans += "0" elif b == "" or s[i] >= b[-1]: b += s[i] ...
WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR STRING IF VAR STRING VAR VAR VAR NUMBER VAR VAR VAR VAR STRING ASSIGN VAR STRING IF VAR STRING EXPR FUN...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
class RangeMinimumQuery: def __init__(self, n, func=min, inf=float("inf")): self.n0 = 2 ** (n - 1).bit_length() self.op = func self.inf = inf self.data = [self.inf] * (2 * self.n0) def query(self, l, r): l += self.n0 r += self.n0 res = self.inf w...
CLASS_DEF FUNC_DEF VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP NUMBER VAR FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = list(input()) color = [-1] * n feasible = True for i in range(n): for j in range(0, i): if s[j] > s[i]: if color[i] == -1: color[i] = 1 - color[j] elif color[i] == color[j]: feasible = False if color[i] == -1: color[i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER AS...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
def main(): n = int(input()) s = input() lst = ["a"] * n ans = [] m = 0 for i in range(n): for j in range(n): if lst[j] <= s[i]: lst[j] = s[i] ans.append(j + 1) m = max(m, j + 1) break print(m) print(*ans...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER E...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() najm = [0] * n najm[n - 1] = s[n - 1] for i in range(n - 1): j = n - i - 2 najm[j] = min(najm[j + 1], s[j + 1]) can_sort = True for i in range(n): for j in range(i + 1, n - 1): if s[i] > s[j] and s[j] > najm[j]: can_sort = False break if not can_s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) a = list(input()) a1 = [i for i in range(n)] new = {i: set() for i in range(n)} flag = False while not flag: flag = True for i in range(n - 1): if a[i] > a[i + 1]: a[i], a[i + 1] = a[i + 1], a[i] new.setdefault(a1[i], set()).add(a1[i + 1]) a1[i], a1[i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBE...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
def solution(): n = int(input()) s = list(input()) s1, s2 = ["a"], ["a"] ans = [] for i in range(n): if s[i] >= s1[-1]: s1.append(s[i]) ans.append("0") elif s[i] >= s2[-1]: s2.append(s[i]) ans.append("1") else: print...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST STRING LIST STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EX...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): n = ri() s = input().strip() codes = [-1] * n highest = {i: (0) for i in range(ord("a"), ord("z") + 1)} for p, c in enumerate(s): max_before = 0 for i in range(ord(c) + 1, ord("z")...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER FOR V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input().strip() CONTRADICT = False color = [(-1) for i in range(len(s))] color[-1] = 1 for i in range(n - 1, -1, -1): for j in range(i - 1, -1, -1): if s[i] < s[j]: if color[j] == -1: color[j] = 1 if color[i] == 0 else 0 elif color[i] == -1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSI...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
import sys input = sys.stdin.readline n = int(input()) S = input().strip() ANS = [-1] * n for i in range(n): flag = 0 for j in range(i): if S[j] > S[i]: flag = 1 if ANS[j] != -1: if ANS[j] == ANS[i]: print("NO") sys.exit() ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR A...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
import sys input = lambda: sys.stdin.readline().strip() n = int(input()) s = input() adj = [[] for i in range(n)] for i in range(n): for j in range(i + 1, n): if s[i] > s[j]: adj[i].append(j) adj[j].append(i) color = [(0) for i in range(n)] seen = [(False) for i in range(n)] def b...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) arr = list(input()) for i in reversed(range(1, n)): cc = arr[i] cl = 0 for j in reversed(range(i)): if arr[j] > cc: cc = arr[j] cl += 1 if cl == 2: print("NO") exit(0) elif arr[j] > arr[i]: cc = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR ...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n, s = int(input()), input() x = y = "a" d = "" for c in s: if c >= x: d += "0" x = c elif c >= y: d += "1" y = c else: print("NO") exit() print("YES", d)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING VAR
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() s0 = "" s1 = "" k = "" s0 += s[0] k += "0" cont = True for x in range(1, n): if s1 == "": if s[x] >= s0[len(s0) - 1]: s0 += s[x] k += "0" else: s1 += s[x] k += "1" elif s[x] >= s0[len(s0) - 1]: s0 += s[x] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING VAR VAR NUMBER VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR STRING IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR STRING VAR VAR VAR VAR STRING IF VAR VAR VAR BIN...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
import sys def main(): n = int(input()) s = input() subsequences = [] for i, c in enumerate(s): ok = False for subseq in subsequences: if s[subseq[-1]] <= c: subseq.append(i) ok = True break if not ok: subs...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
import sys def main(): n = int(sys.stdin.readline().split()[0]) s = sys.stdin.readline().split()[0] color = [None] * n color[0] = 0 for i in range(n): if color[i] == None: color[i] = 0 for j in range(i + 1, n): if ord(s[j]) < ord(s[i]): if co...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VA...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() ans = [0] * n for i in range(n - 1): for j in range(i + 1, n): if s[i] > s[j]: if ans[i] == 0: ans[j] = 1 else: ans[j] = 0 flag = True for i in range(n - 1): for j in range(i + 1, n): if s[i] > s[j]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) x = input() s = [""] * n for i in range(0, n, 1): s[i] = x[i] ok = True color = [-1] * n ocolor = [-1] * n def swap(i, j): global color, s, ocolor for index in range(j, i, -1): tmpx = s[index] tmpc = color[index] s[index] = s[index - 1] color[index] = color...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() r = [] q = 0 f = ["a"] for i in range(n): z = 0 while s[i] < f[z]: z = z + 1 if z == len(f): f.append(s[i]) break f[z] = s[i] r.append(z + 1) print(max(r)) print(*r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n, s, a, b, ans = int(input()), input(), "a", "a", "" check = True for i in s: if i >= a: ans += "0" a = i elif i >= b: ans += "1" b = i else: print("NO") check = False break if check: print("YES") print(ans)
ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = input() color = [(0) for _ in range(n)] f = 0 for i in range(n): for j in range(i + 1, n): if s[j] < s[i]: color[j] = 1 - color[i] for i in range(n): for j in range(i + 1, n): if color[i] == color[j] and s[i] > s[j]: f = 1 print("NO") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
from sys import stdin, stdout def main(): n = int(stdin.readline()) s = stdin.readline().rstrip() h1 = "A" h2 = "B" res = [] for i, x in enumerate(s): if i == 0: res.append("0") h1 = s[i] continue if s[i] < h2: stdout.write("NO") ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
n = int(input()) s = [(ord(i) - ord("a") + 1) for i in input()] clr = ["0"] * n x = s[0] bad = [] flag = 1 for i in range(n): if s[i] >= x: x = s[i] else: clr[i] = "1" bad.append(s[i]) if any([(s[i] < j) for j in bad]): print("NO") flag = 0 bre...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR V...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
N = int(input()) s = input() a = "a" b = "a" t = "" flag = 0 for i in s: if a < b: if b <= i: b = i t += "1" elif a <= i: a = i t += "0" else: flag = 1 break elif b < a: if a <= i: a = i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR STRING IF VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR STRING IF VAR VAR ASSIGN VAR...
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercase Latin letters. You have to color all its characters one of the ...
a = int(input("")) s = input("") def recurse(s, m): if len(s) == 0: return "" char = min(s) i = s.index(char) if i < m and i != 0: return -1 elif i < m and i == 0: return recurse(s[0:i] + s[i + 1 : len(s)], m - 1) else: add = "" for l in range(i - m): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FUNC_CALL ...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() b = [0] for i in range(k - 1, -1, -1): b.append(a[i]) c = [0] * (k + 1) for i in range(1, k + 1): c[i] += b[i] + c[i - 1] s = [0] * (k + 1) for _ in range(m): x, y = map(int, input().split...
IMPORT ASSIGN VAR VAR ASSIGN VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
import sys def main(): global visited, adj, sets n, m, k = get_list() li = get_list() li.sort() offers = [[10**10, 0]] for _ in range(m): offers.append(get_list()) offers.sort() best_y = [0] ptr = -1 for i in range(k): best_y.append(best_y[-1]) while off...
IMPORT FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST LIST BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER WHI...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
n, m, k = map(int, input().split()) arr = list(map(int, input().split())) offer = [list(map(int, input().split())) for _ in range(m)] arr = sorted(arr) arr = arr[:k] arr = arr[::-1] acum = [0] for i in range(k): acum.append(acum[-1] + arr[i]) dp = [acum[i] for i in range(k + 1)] for x, y in offer: if x > k: ...
ASSIGN VAR 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 VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FU...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
from sys import stdin, stdout n, m, k = tuple(map(lambda x: int(x), stdin.readline().split())) a = stdin.readline().split() for i in range(len(a)): a[i] = int(a[i]) prefix_sum = [] a = sorted(a, key=lambda x: x) for x in a: if prefix_sum: prefix_sum.append(prefix_sum[-1] + x) else: prefix_s...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
n, m, k = map(int, input().split()) ai = list(map(int, input().split())) ar = [0] * k for i in range(m): x, y = list(map(int, input().split())) x -= 1 if x < k: ar[x] = max(ar[x], y) ai.sort() big = 10**9 ar2 = [big] * (k + 1) ar3 = [0] * (k + 1) ar3[0] = 0 for i in range(1, k + 1): ar3[i] = ar3...
ASSIGN VAR 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VA...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
IN = input rint = lambda: int(IN()) rmint = lambda: list(map(int, IN().split())) rlist = lambda: list(rmint()) n, m, k = rmint() a = rlist() t = [] for i in range(m): x, y = rmint() t.append((x, y)) t.sort() a.sort() pr = [0] for i in a: pr.append(pr[-1] + i) f = 4096 * [0] def s(l, r): if l > r: ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
N, M, K = map(int, input().split()) A = sorted([int(a) for a in input().split()])[:K][::-1] B = [0] for a in A: B.append(B[-1] + a) X = [0] * (K + 1) for _ in range(M): x, y = map(int, input().split()) if x <= K: X[x] = max(X[x], y) Y = [0] * (K + 1) for i in range(1, K + 1): mi = 10**100 fo...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VA...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
import sys dp = [] sum = [] INF = sys.maxsize / 2 def sum_range(a, b): if a == 0: return sum[b] return sum[b] - sum[a - 1] def rec(pos, sale, n, k): if k == 0: return 0 if dp[k] != -1: return dp[k] res = INF for x in range(1, k + 1): if sale[x] != -1: ...
IMPORT ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR VAR RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) a = sorted(a) a = a[:k] d = [(1, 0)] for i in range(m): x, y = list(map(int, input().split())) if x > k: continue d.append((x, y)) d = sorted(d) s = [0] * (k + 1) s[1] = a[0] for i in range(1, k + 1): s[i] = s[i - 1] +...
ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF ...
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
n, m, k = (int(i) for i in input().split()) cost = sorted([int(i) for i in input().split()])[:k] + [0] discount = [0] * n for i in range(m): a, b = (int(j) for j in input().split()) discount[a - 1] = max(discount[a - 1], b) S = [0] * (k + 1) for i in range(k): S[i] = cost[i] + S[i - 1] cost[i] += cost[i...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL V...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
n = int(input()) while n > 0: a, x = map(int, input().split()) arr = list(map(int, input().split())) i = 0 count = 0 while i < len(arr): if sorted(arr) == arr: break if arr[i] > x: x, arr[i] = arr[i], x count += 1 i += 1 if sorted(arr) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR N...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
t = int(input()) for i in range(t): n, x = map(int, input().split()) arr = list(map(int, input().split())) if arr == sorted(arr): print(0) else: res = 0 for i in range(n): if arr[i] > x: temp = x x = arr[i] arr[i] = temp...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def f(l): last = l[0] bool = True for i in l[1:]: if last > i: bool = False break last = i return bool for _ in range(int(input())): n, x = map(int, input().split()) l = list(map(int, input().split())) bool = False ans = 0 if f(l): pr...
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR RETURN VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIG...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
test = int(input()) for t in range(0, test): n, x = input().split() n = int(n) x = int(x) a = [int(i) for i in input().split(" ")] ans = 0 while 1: if a == sorted(a): print(ans) break f = 0 for i in range(0, len(a)): if a[i] > x: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN V...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
import sys from sys import maxsize def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) def get_list_string(): return list(map(str, sys.stdin.readline().strip().split())) def get_string(): return sys.std...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL F...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
for u in range(int(input())): n, x = map(int, input().split()) a = list(map(int, input().split())) i = 0 ans = 0 while i < n: k = list(a) k.sort() if k == a: break if a[i] > x: a[i], x = x, a[i] ans += 1 if x > max(a): ...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
t = int(input()) for _ in range(t): n, x = tuple(map(int, input().split(" "))) ans = -1 a = list(map(int, input().split(" "))) for i in range(0, n): if a[i] > x and sorted(a) != a: a[i], x = x, a[i] ans = ans + 1 if sorted(a) != a: ans = -1 print(ans) ...
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 STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def check(a): if sorted(a) == a: return 1 return 0 t = int(input()) for _ in range(t): kt = 0 cnt = 0 n, x = map(int, input().split()) a = list(map(int, input().split())) if check(a): print(0) continue for i in range(n): if x < a[i]: a[i] = a...
FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 IF FUNC_CALL VAR VAR EXPR FUNC_CA...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def sol(): for _ in range(int(input())): n, x = map(int, input().split()) arr = list(map(int, input().split())) if arr == sorted(arr): print(0) else: count = 0 flag = False for i in range(n): if arr[i] > x: ...
FUNC_DEF 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VA...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def notsorted(l, n): for i in range(0, n - 1): if l[i] > l[i + 1]: return True return False for _ in range(int(input())): n, x = map(int, input().split()) l = list(map(int, input().split())) ans = 0 i = 0 flag = True while notsorted(l, n): ans += 1 w...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR ...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def func(x, l1): num = 0 x0 = 0 repeat = 0 for i in range(len(l1) - 1): if l1[i] <= x: x0 = i + 1 if x0 < i: if l1[i] == l1[i - 1]: repeat += 1 if l1[i] > l1[i + 1]: if x > l1[i + 1] or i > 0 and l1[i - 1] > l1[i + 1]: ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_O...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
import sys input = sys.stdin.readline def solve(): n, x = map(int, input().split()) arr = list(map(int, input().split())) B = sorted(arr) if arr == B: return 0 b = n - 1 while b >= 0 and arr[b] == B[b]: b -= 1 A = arr + [x] A.sort() cnt = 0 prev = x for i i...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR EXPR FU...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
import sys input = sys.stdin.buffer.readline t = int(input()) INF = 10**18 for _ in range(t): n, x = map(int, input().split()) a = list(map(int, input().split())) if sorted(a) == a: print(0) continue cnt = 0 for i in range(n): if a[i] > x: a[i], x = x, a[i] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL 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 IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR ...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
t = int(input()) for _ in range(t): n, x = map(int, input().split()) s = 0 a = list(map(int, input().split())) for i in range(n - 1): if a[i] > a[i + 1]: s = 1 if s == 0: print(0) else: c = 0 for i in range(n - 1): if a[i] > x: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUN...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
Inp = input for _ in range(int(Inp())): n, k = map(int, Inp().split()) l = [*map(int, Inp().split())] b = 0 for i in range(n): if sorted(l) == l: break if l[i] > k: l[i], k = k, l[i] b += 1 print([-1, b][sorted(l) == l])
ASSIGN VAR VAR 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 LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def ans(A, x): if A == sorted(A): return 0 i = 0 ret = 0 while i < len(A) and A != sorted(A): if x < A[i]: ret += 1 x, A[i] = A[i], x i += 1 else: i += 1 continue if A == sorted(A): return ret return -1 ...
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL ...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
t = int(input()) for i in range(t): n, x = map(int, input().split()) array = [int(num) for num in input().split()] ans = 0 j = 0 found = False if array == sorted(array): print(0) continue for i in range(n): if array[i] > x: temp = array[i] arra...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def check(arr): for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True for _ in range(int(input())): n, x = map(int, input().split()) arr = list(map(int, input().split())) if check(arr): print(0) else: asn = 0 for j in range(n...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR E...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def solve(l, x): count = 0 for i in range(len(l)): if sorted(l) == l: break if l[i] > x: l[i], x = x, l[i] count += 1 if sorted(l) == l: return count else: return -1 for _ in range(int(input())): n, x = map(int, input().split()) ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR RETURN NUMBER 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 FUN...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
t = int(input()) all = [] x_arr = [] for i in range(t): k = input() k = [int(m) for m in k.split()] l, x = k x_arr.append(x) h = input() a = [int(z) for z in h.split()] all.append(a) for i in range(t): x = x_arr[i] arr = all[i] sorted_ = sorted(arr) if sorted_ == arr: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_C...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def not_sorted(n, a): for i in range(1, n): if a[i] < a[i - 1]: return -1 return 0 def solve(n, x, a): cnt = 0 while not_sorted(n, a): cnt += 1 i = 0 while i < n and a[i] <= x: i += 1 if i == n: return -1 a[i], x = x, ...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
for i in range(int(input())): n, x = [int(_) for _ in input().split()] arr = [int(_) for _ in input().split()] c = 0 for i in range(n): if sorted(arr) == arr: break if arr[i] > x: x, arr[i] = arr[i], x c += 1 if sorted(arr) == arr: print(c)...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR E...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
from sys import stdin nii = lambda: map(int, stdin.readline().split()) lnii = lambda: list(map(int, stdin.readline().split())) t = int(input()) for tt in range(t): n, x = nii() a = lnii() if a == sorted(a): print(0) continue ans = 0 for i in range(n): if a[i] > x: ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
for _ in range(int(input())): n, x = map(int, input().split()) a = [int(i) for i in input().split()] ans = 0 temp = 0 x1 = x for i in range(n - 1): if a[i] > a[i + 1]: if a[i] <= x: ans = -1 break elif x > a[i + 1]: ...
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
for i in range(int(input())): a = list(map(int, input().split())) b = list(map(int, input().split())) n = a[0] x = a[1] if n == 1: print(0) continue i = 0 count = 0 f = 0 flag = 0 while i < n: ans = 0 for j in range(i, n): if j == 0: ...
FOR VAR FUNC_CALL 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 VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBE...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def swap(l, r, x): temp = arr[r] for o in range(r, l, -1): arr[o] = arr[o - 1] arr[l] = x return temp t = int(input()) for z in range(t): n, x = map(int, input().split()) arr = list(map(int, input().split())) count = 0 ok = 0 for i in range(n - 1): if arr[i] > arr[i...
FUNC_DEF ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
t = int(input()) ans = "" def is_sorted(lst, key=lambda x: x): for i, el in enumerate(lst[1:]): if key(el) < key(lst[i]): return False return True for j in range(t): n, x = list(map(int, input().split())) a = list(map(int, input().split())) cnt = 0 if is_sorted(a) == Fals...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FUNC_DEF VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FU...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
I = lambda: map(int, input().split()) s = sorted (T,) = I() for _ in range(T): n, k = I() l = [*I()] a = 0 for i in range(n): if s(l) == l: break if l[i] > k: l[i], k = k, l[i] a += 1 print([a, -1][s(l) < l])
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL V...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def ans(arr, x): if len(arr) == 1: return 0 elif arr == sorted(arr): return 0 else: cnt = 0 for i in range(len(arr)): if arr[i] > x: arr[i], x = x, arr[i] cnt += 1 if arr == sorted(arr): return cnt ...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def check(ll): for i in range(len(l) - 1): if l[i] <= l[i + 1]: continue else: return False return True for i in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) c = 0 if len(l) == 1: print(0) cont...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF F...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
def calc_swaps(nums, x): if nums == sorted(nums): return 0 swaps = 0 for ind in range(len(nums)): if nums[ind] > x: x, nums[ind] = nums[ind], x swaps += 1 if nums == sorted(nums): return swaps return -1 data_count = int(input()) ans = [] for ...
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL V...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
import sys input = sys.stdin.readline (T,) = map(int, input().split()) for _ in range(T): N, x = map(int, input().split()) A = list(map(int, input().split())) f = 0 for i in range(N - 1): if A[i] > A[i + 1]: f = 1 break if not f: print(0) continue ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSI...