description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
for _ in range(int(input())): s = input() t = input() for c in t[::-1]: i = len(s) - 1 while i >= 0: if s[i] != c: i -= 2 else: s = s[:i] break else: print("NO") break else: pr...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
rint = lambda: int(input()) rli = lambda: list(map(int, input().split())) rl = lambda: input().split() def strm(m): s = "" for i in range(len(m)): for j in range(len(m[0])): s += str(m[i][j]) s += "\n" return s def solve(): s = input() t = input() if len(s) < len(...
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 FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR STRING RETURN VAR FUNC_DEF ASSI...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
import sys input = sys.stdin.buffer.readline def solve(): si = len(S) - 1 ti = len(T) - 1 while si >= 0 and ti >= 0: if S[si] != T[ti]: si -= 2 continue ti -= 1 si -= 1 return "YES" if ti == -1 else "NO" test_cases = int(input()) for test_case in rang...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR A...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
import sys input = sys.stdin.readline for _ in range(int(input())): s = input().strip("\n") t = input().strip("\n") i = len(s) - 1 ans = "YES" j = len(t) - 1 while j >= 0: if i < 0: ans = "NO" break if s[i] == t[j]: i -= 1 j -= 1 ...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING IF VAR VAR ...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
ntests = int(input()) for _ in range(ntests): s = input() t = input() ns = len(s) nt = len(t) if ns < nt: print("NO") else: answer = "YES" while nt > 0: nt -= 1 ns -= 1 while t[nt] != s[ns]: if ns < 2 or ns < nt: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 STRING ASSIGN VAR STRING WHILE VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): S = input().strip() T = input().strip() if len(T) > len(S): print("NO") continue if T == S[len(S) - len(T) :]: print("YES") continue LEN = len(S) NEXT = [([-10] * 26) for i in range(LEN...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
for _ in range(int(input())): s = input() t = input() ss = len(s) - 1 tt = len(t) - 1 flag = 1 while tt >= 0 and flag == 1: while ss >= 0 and s[ss] != t[tt]: ss = ss - 2 if ss < 0: print("NO") flag = 0 break ss = ss - 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
q = int(input()) for x in range(q): s = list(input()[::-1]) t = list(input()[::-1]) temp = [] it = 0 while it < len(s): if s[it] == t[len(temp)]: temp.append(s[it]) else: it += 1 if temp == t: break it += 1 if temp == t: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR V...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def solver(s, t): si = len(s) ti = len(t) while si and ti: si -= 1 if s[si] == t[ti - 1]: ti -= 1 elif si: si -= 1 print("NO" if ti else "YES") for _ in range(int(input())): s = input() t = input() solver(s, t)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def solve(): s = input() t = input() n = len(s) - 1 m = len(t) - 1 while n >= 0 and m >= 0: if s[n] == t[m]: m -= 1 n -= 1 else: n -= 2 if m >= 0: print("NO") else: print("YES") def main(): t = int(input()) for _ i...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def can_type(S, T): S, T = S[::-1], T[::-1] s, t = 0, 0 while True: if s < len(S) and t < len(T) and S[s] == T[t]: s += 1 t += 1 else: s += 2 if t == len(T): return True if s > len(S): return False for k in range(i...
FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUN...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def canSproduceT(s, t): n = len(s) m = len(t) if m == 0: return "YES" if n < m: return "NO" i = n - 1 j = m - 1 while i >= 0 and j >= 0: if s[i] == t[j]: i -= 1 j -= 1 else: i -= 2 if j == -1: return "YES" re...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN STRING IF VAR VAR RETURN STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def main(): for _ in range(int(input())): s, t = list(input()), list(input()) while s and t: if s[-1] == t[-1]: del s[-1] del t[-1] else: del s[-2:] print(("NO", "YES")[not t]) main()
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR EXPR FUNC_CALL VAR
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
import sys input = sys.stdin.readline for _ in range(int(input())): s = input()[:-1] t = input()[:-1] n, m = len(s), len(t) i, j = n - 1, m - 1 cnt = 0 while i >= 0 and j >= 0: while cnt: i -= 1 cnt -= 1 if i < 0: break if s[i] == t[j]...
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF V...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
from sys import stdin as sin def aint(): return int(input()) def amap(): return map(int, sin.readline().split()) def alist(): return list(map(int, sin.readline().split())) def astr(): return input() for _ in range(aint()): s = input() t = input() if len(s) >= len(t): j = le...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
import sys input = sys.stdin.readline I = lambda: list(map(int, input().split())) (t,) = I() for _ in range(t): s = list(input().strip()) t = list(input().strip()) ns = "" nt = "" n = len(s) m = len(t) tf = 1 i = n - 1 j = m - 1 while i >= 0 and j >= 0: if s[i] == t[j]: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_C...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def main(): S = input()[::-1] T = input()[::-1] Skip = 0 j = 0 for i in range(len(S)): if Skip: Skip = 0 elif S[i] == T[j]: j += 1 if j == len(T): break else: Skip = 1 else: return print("NO") pri...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER RETURN FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CAL...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def delete_backspace(s: str, t: str) -> bool: n = len(s) m = len(t) if n < m: return False i = n - m & 1 j = 0 while i < n: if j < m and t[j] == s[i]: j += 1 else: i += 1 i += 1 return j == m n_test_cases = int(input()) for _ in range...
FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSI...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def isPosible(s, t): string = s[::-1] wanted = t[::-1] i_string = 0 i_wanted = 0 while i_wanted < len(wanted) and i_string < len(string): if string[i_string] == wanted[i_wanted]: i_string += 1 i_wanted += 1 else: i_string += 2 if i_wanted == le...
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def check(s, t): s += "$" t += "$" j = len(s) - 1 for i in range(len(t) - 1, -1, -1): while j >= 0 and s[j] != t[i]: j -= 2 if j < 0: return False j -= 1 return True def main(): t = int(input()) for _ in range(t): s = input() ...
FUNC_DEF VAR STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN ...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
t = int(input()) while t > 0: t -= 1 s = input() a = input() last = len(s) fl = True j = len(a) - 1 for i in range(len(s) - 1, -1, -1): if a[j] == s[i]: if (last - i - 1) % 2 == 0: last = i j -= 1 if j < 0: break if ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
t = int(input()) for k in range(t): s = input() seq = input() i, j = len(s) - 1, len(seq) - 1 o = 0 while i >= 0 and o != len(seq): if s[i] == seq[j]: i -= 1 j -= 1 o += 1 if s[i] != seq[j]: i -= 2 if o == len(seq): print("Y...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
import sys def solver(source, target): if len(target) > len(source): return False elif len(target) == len(source): return source == target elif len(target) == 0: return True else: c_source = len(source) - 1 for i_target in range(len(target) - 1, -1, -1): ...
IMPORT FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
q = int(input()) def solve(s, t): m = len(s) n = len(t) if m % 2 != n % 2: s = s[1:] m -= 1 if m < n: return False u = [] cnt = 0 for i in range(m): if cnt == 0: u.append(s[i]) cnt += 1 elif cnt == n + 1: u.pop() ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
import sys input = sys.stdin.readline def solve(): s = input().strip() t = input().strip() n, m = len(s), len(t) even, odd = -1, -1 for i in range(n): if t[0] == s[i]: if i % 2 == 0: if even == -1: even = i elif odd == -1: ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def get_solution(s, t): n = len(s) n_2 = len(t) if n_2 > n: print("NO") return i = n - 1 j = n_2 - 1 while j >= 0 and i >= 0: if s[i] == t[j]: i -= 1 j -= 1 else: i -= 2 if j == -1: print("YES") return pr...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRIN...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
r = int(input()) for _ in range(r): s = input() t = input() try: for c in t[::-1]: no = True i = len(s) - 1 while i >= 0: if s[i] != c: i -= 2 else: s = s[:i] no = False ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING IF VAR EXPR ...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
for _ in range(int(input())): s = str(input()) t = str(input()) if len(s) < len(t): print("NO") else: a = len(s) - 1 b = len(t) - 1 while 1: if a < 0 or b < 0: break if s[a] == t[b]: b -= 1 a -= 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 IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE NUMBER IF VAR NUMBER VAR NUMBER IF ...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def run(*tasks): value = None def tick(): nonlocal value task = tasks[-1] try: subtask = task.send(value) tasks.append(subtask) value = None except TypeError as error: if error.args == ("can't send non-None value to a just-started ...
FUNC_DEF ASSIGN VAR NONE FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR NONE EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR RETU...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
from sys import stdin q = int(stdin.readline()) for loop in range(q): s = list(stdin.readline()[:-1]) t = list(stdin.readline()[:-1]) while len(s) > 0 and len(t) > 0: if s[-1] == t[-1]: del s[-1] del t[-1] else: del s[-1] if len(s) > 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
ans = [] for _ in range(int(input())): s = list(input()) t = list(input()) if len(s) % 2 != len(t) % 2: s = s[1:] if len(t) > len(s): ans.append("NO") continue i = 0 j = 0 while i < len(s): if s[i] == t[j]: i += 1 j += 1 if ...
ASSIGN VAR LIST 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 IF BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSI...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
q = int(input()) for _ in range(q): s = input() t = input() m, n = len(s), len(t) if n > m: print("NO") continue q = n - 1 k = 0 for i in range(m - 1, -1, -1): if k == 1: k = 0 continue if q >= 0 and s[i] == t[q]: q -= 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER AS...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def backspace(s, t): if len(s) < len(t): return "NO" if s == t: return "YES" if len(s) == len(t) and s != t: return "NO" i = len(s) - 1 j = len(t) - 1 while i > -1 and j > -1: if s[i] == t[j]: if j == 0: return "YES" else: ...
FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN STRING IF VAR VAR RETURN STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF VAR NUMBER RETURN STRING VAR NUMBER ...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
from sys import gettrace, stdin if gettrace(): def inputi(): return input() else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def solve(ss, tt): dp = [0] * len(ss) p = (len(ss) - len(tt)) % 2 for t in tt: while p < len(...
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def solve(): s = input() t = input() cur = len(s) & 1 ^ len(t) & 1 for i, a in enumerate(t): while True: if cur >= len(s): return "NO" if s[cur] == a: break cur += 2 cur += 1 return "YES" t = int(input()) for __ in...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE NUMBER IF VAR FUNC_CALL VAR VAR RETURN STRING IF VAR VAR VAR VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
for _ in range(int(input())): s1 = input() s2 = input() tr = 0 for i in range(len(s1) - 1, -1, -1): if s1[i] == s2[-1] and (len(s1) - i - tr) % 2 == 1: tr += 1 s2 = s2[:-1] if len(s2) == 0: break if len(s2) == 0: print("YES") el...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR V...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def solution(s, t): s = list(s) t = list(t) while len(s) >= len(t): if not t: return "YES" if s[-1] == t[-1]: s.pop() t.pop() else: s.pop() if s: s.pop() return "NO" def main(): for _ in range(int(i...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR RETURN STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR RETURN STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VA...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
zzzz = int(input()) for jj in range(zzzz): s = input() win = 1 ans = "" t = input() if len(s) % 2 != len(t) % 2: s = s[1:] i = -1 for k in range(len(s)): if s[k] == t[0] and k % 2 == 0: i = k break if i == -1: print("NO") continue ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ...
You are given two strings $s$ and $t$, both consisting of lowercase English letters. You are going to type the string $s$ character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the l...
def solve(s, t, start): z = start cnt = 0 n = len(s) m = len(t) latest = n - 1 while z < n and cnt < m: if s[z] == t[cnt]: latest = z z += 1 cnt += 1 else: z += 2 return cnt == m and (n - latest) % 2 def main(): q = int(in...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FU...
Read problems statements in English, Mandarin Chinese and Russian as well. Given an array A_{1},A_{2}...A_{N}, you have to print the size of the largest contiguous subarray such that LCM of all integers in that subarray is equal to the product of all integers in that subarray. Formally, For a subarray A_{i},A_{i+1}...
seive = [1] * (10**6 + 1) prev = [1] * (10**6 + 1) for i in range(2, len(seive)): if seive[i] > 1: continue t = 1 for j in range(i, len(seive), i): seive[j] = i prev[j] = t t += 1 t = int(input()) for _ in range(t): n = int(input()) arr = [int(c) for c in input().spli...
ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR...
Read problems statements in English, Mandarin Chinese and Russian as well. Given an array A_{1},A_{2}...A_{N}, you have to print the size of the largest contiguous subarray such that LCM of all integers in that subarray is equal to the product of all integers in that subarray. Formally, For a subarray A_{i},A_{i+1}...
p = 10**6 + 5 def sieve(): l = [1] * p i = 2 l[0] = l[1] = 0 spf = [i for i in range(p)] while i * i <= p: if l[i]: for j in range(2 * i, p, i): l[j] = 0 if spf[j] == j: spf[j] = i i += 1 return spf, [i for i in ra...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ...
Read problems statements in English, Mandarin Chinese and Russian as well. Given an array A_{1},A_{2}...A_{N}, you have to print the size of the largest contiguous subarray such that LCM of all integers in that subarray is equal to the product of all integers in that subarray. Formally, For a subarray A_{i},A_{i+1}...
import sys maxd = pow(10, 6) + 1 factors = [[] for i in range(maxd)] for i in range(2, maxd): if len(factors[i]) == 0: for j in range(i, maxd, i): factors[j].append(i) t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) arr = list(map(int, sys.stdin.readline()...
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_C...
Read problems statements in English, Mandarin Chinese and Russian as well. Given an array A_{1},A_{2}...A_{N}, you have to print the size of the largest contiguous subarray such that LCM of all integers in that subarray is equal to the product of all integers in that subarray. Formally, For a subarray A_{i},A_{i+1}...
maxlimt = int(1000000.0 + 5) factors = [list() for i in range(maxlimt)] def sieve(): factors[0], factors[1] = list(), list() for i in range(2, maxlimt): if len(factors[i]) == 0: for j in range(i, maxlimt, i): factors[j].append(i) sieve() t = int(input()) while t: n = ...
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_...
Read problems statements in English, Mandarin Chinese and Russian as well. Given an array A_{1},A_{2}...A_{N}, you have to print the size of the largest contiguous subarray such that LCM of all integers in that subarray is equal to the product of all integers in that subarray. Formally, For a subarray A_{i},A_{i+1}...
temp = [(1) for i in range(10**6 + 1)] for i in range(2, 10**6 + 1): for j in range(i, 10**6 + 1, i): if temp[j] == 1: temp[j] = i def getFactor(num): last = None factors = [] while num > 1: if temp[num] != last: factors.append(temp[num]) last = temp[num...
ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NONE ASSIGN VAR LIST WHILE VAR NUMBER IF VAR VAR VAR EXPR FUNC_...
Read problems statements in English, Mandarin Chinese and Russian as well. Given an array A_{1},A_{2}...A_{N}, you have to print the size of the largest contiguous subarray such that LCM of all integers in that subarray is equal to the product of all integers in that subarray. Formally, For a subarray A_{i},A_{i+1}...
from sys import stdin input = stdin.readline size = 10**6 + 1 primef = [[] for i in range(size)] prime = [] for i in range(2, size): if len(primef[i]) == 0: for j in range(i, size, i): primef[j].append(i) prime.append(i) def nextpossible(j, length, x): while their[ind[x]]: ...
ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR VAR VAR FOR VAR VAR VAR VAR VAR VAR V...
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether t...
from sys import stdin read = stdin.readline n = int(read()) S = read() T = read() for i in range(n): if S[i] != T[i]: break a = b = 1 for j in range(i, n - 1): if S[j] != T[j + 1]: a = S[j + 1 :] == T[j + 1 :] break for j in range(i, n - 1): if S[j + 1] != T[j]: b = S[j + 1 ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL...
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether t...
n = int(input()) s, t = input(), input() i = 0 while s[i] == t[i]: i += 1 j = n - 1 while s[j] == t[j]: j -= 1 print(int(s[i + 1 : j + 1] == t[i:j]) + int(s[i:j] == t[i + 1 : j + 1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN...
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether t...
def aux(s, t): n = len(s) lpr = 0 for i in range(n): if s[i] != t[i]: break lpr += 1 lsf = 0 for i in range(n - 1, -1, -1): if s[i] != t[i]: break lsf += 1 if lpr == n: return 2 return (s[lpr : n - lsf - 1] == t[lpr + 1 : n - ls...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP V...
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether t...
import sys try: while True: n = int(input()) s1 = input() s2 = input() L = 0 R = n - 1 while s1[L] == s2[L]: L += 1 while s1[R] == s2[R]: R -= 1 res = 0 i = L while i < R and s1[i] == s2[i + 1]: i +=...
IMPORT WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR...
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether t...
i, j = 0, int(input()) - 1 a, b = input(), input() while a[i] == b[i]: i += 1 while a[j] == b[j]: j -= 1 print((a[i + 1 : j + 1] == b[i:j]) + (b[i + 1 : j + 1] == a[i:j]))
ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
def maxSubsequenceSubstring(x, y, n, m): dp = [[(0) for i in range(n + 1)] for i in range(n + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if x[j - 1] == y[i - 1]: dp[i][j] = 1 + dp[i - 1][j - 1] else: dp[i][j] = dp[i][j - 1] ans = 0...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
T = int(input()) while T > 0: n = int(input()) arr = list(map(int, input().split())) b = arr.copy() b.sort() dic = {} dp = [0] * (n + 1) for i in range(n): dic[b[i]] = i + 1 for i in range(n): dp[dic[arr[i]]] = dp[dic[arr[i]] - 1] + 1 ma = max(dp) print(n - ma) ...
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 EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_O...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return list(map(int, minp().split())) def solve(): n = mint() a = list(mints()) b = list(enumerate(a)) b.sort(key=lambda a: a[1]) c1 = [0] * n c = 0 h = 0 p = -1 ...
IMPORT FUNC_DEF RETURN 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = sorted(range(n), key=lambda x: a[x]) ans = 0 c = 1 for i in range(1, n): if b[i] > b[i - 1]: c += 1 else: ans = max(ans, c) c = 1 print(n - max(ans, c))
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 VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
import sys input = sys.stdin.readline def main(): t = int(input()) for _ in range(t): N = int(input()) A = [int(x) for x in input().split()] Asort = sorted(A) dp = [0] * (N + 1) dic = {} for i, a in enumerate(Asort): dic[a] = i + 1 for a in ...
IMPORT ASSIGN VAR VAR FUNC_DEF 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 ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIG...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
def main(): n = int(input()) a = list(map(int, input().split())) b = sorted(a) d = dict() f = dict() for i in range(n - 1, -1, -1): d[b[i]] = i for i in range(n): where = d[a[i]] if where == 0 or b[where - 1] not in f: f[a[i]] = 1 else: ...
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 VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) id = list(zip(l, list(range(n)))) id.sort() val, pos = zip(*id) best = 1 i = 1 count = 1 while True: if i >= n: break if pos[i] > pos[i - 1]: count += 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 VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSI...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
def remainderSorted(x, n, a, b): mn = b[x[0]] mx = b[x[1]] prev = None for e in a: if e >= mn and e <= mx: if prev is not None and prev > e: return False prev = e return True def count(n, a): mincnt = 0 for i in range(1, n): if a[i - ...
FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NONE FOR VAR VAR IF VAR VAR VAR VAR IF VAR NONE VAR VAR RETURN NUMBER ASSIGN VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
def read_list(): return list(map(int, input().strip().split(" "))) def print_list(l): print(" ".join(map(str, l))) N = int(input()) for _ in range(N): n = int(input()) nums = read_list() dic = {} for i in range(n): dic[nums[i]] = i nums.sort() res = 0 tmp = 1 for i in...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR 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 ASSIGN VAR DICT FOR VAR FUNC_CALL V...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
from sys import stdin input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) id = list(zip(l, list(range(n)))) id.sort() val, pos = zip(*id) blok = [] cur = [pos[0]] for i in range(1, n): if val[i] == val[i - 1]: ...
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 VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
for p in range(int(input())): n = int(input()) a = [int(i) for i in input().split()][:n] b = a.copy() b.sort() c = [] e = 0 while True: x = b.index(a[e]) m = 1 for j in range(e, len(a)): if x <= len(a) - 2: if a[j] == b[x + 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 VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FU...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
from sys import setrecursionlimit, stdin, stdout for _ in range(int(input())): n = int(input()) a = [[int(i)] for i in input().split()] for i in range(n): a[i].append(i) a = sorted(a) ans = 1 cur = 1 for i in range(1, n): if a[i][1] > a[i - 1][1]: cur += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
T = int(input()) for _ in range(T): n = int(input()) ls = list(map(int, input().split())) cc = {u: i for i, u in enumerate(sorted(ls))} ls = [cc[u] for u in ls] def lcount(i, u): cc = 0 while i >= 0: if ls[i] == u: cc += 1 u -= 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 VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_numb...
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
from sys import stdin, stdout t = int(stdin.readline().strip()) for _ in range(t): n = int(stdin.readline().strip()) a = [(int(b), i) for i, b in enumerate(stdin.readline().split())] a.sort() ans, c = 0, 1 for i in range(1, n): if a[i][1] > a[i - 1][1]: c += 1 else: ...
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 VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUM...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
import sys def input(): return sys.stdin.readline()[:-1] def main(): for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = [[a[k], k] for k in range(n)] b = sorted(b) c = [b[k][1] for k in range(n)] c = [-1] + c + [100000] ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FU...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
tt = int(input()) for loop in range(tt): n = int(input()) a = list(map(int, input().split())) ai = [] for i in range(n): ai.append((a[i], i)) ai.sort() ind = 0 b = [0] * n non = [0] * (n + 1) for i in range(n): if i != 0 and ai[i][0] != ai[i - 1][0]: ind +...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIG...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for you in range(t): n = int(input()) l = input().split() li = [int(i) for i in l] z = list(li) z.sort() hashi = dict() for i in range(n): hashi[z[i]] = i + 1 for i in range(n): li[i] = hashi[li[i]] hashi = dict() dp = [(0) 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
from sys import stdin def search(lis, idx, val): low = 0 high = idx while low <= high: mid = (low + high) // 2 if lis[mid] == val: return mid if lis[mid] > val: high = mid - 1 else: low = mid + 1 def ans(arr): lis_f = sorted(arr) ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
from sys import stdin, stdout def findops(l): ans = 0 count = 1 for i in range(1, len(l)): if l[i] > l[i - 1]: count += 1 else: ans = max(ans, count) count = 1 return len(l) - max(ans, count) for _ in range(int(stdin.readline())): stdin.readlin...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
from itertools import islice for t in range(int(input())): n = int(input()) aa = list(map(int, input().split(" "))) asort = sorted(aa) ls = [None] * n for i, a in enumerate(asort): ai = aa.index(a) l = 1 if i >= 1: pi = aa.index(asort[i - 1]) if pi < ...
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 VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIG...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) narr = dict() for i in range(n): narr[arr[i]] = i arr.sort() ct = ans = 0 for i in range(n): if i > 0 and narr[arr[i]] < narr[arr[i - 1]]: ct = 0 ct += 1 ans...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR N...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
def flyingsort(L): d = {} for i in range(len(L)): d[L[i]] = i L.sort() prev = -1 run = 0 maxRun = -1 for i in L: if d[i] > prev: run += 1 else: run = 1 maxRun = max(maxRun, run) prev = d[i] return len(L) - maxRun T = int(i...
FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
I = lambda: list(map(int, input().split())) def lis(arr): n = len(arr) lis = [1] * n for i in range(1, n): for j in range(0, i): if arr[i] == arr[j] + 1 and lis[i] < lis[j] + 1: lis[i] = lis[j] + 1 maximum = 0 for i in range(n): maximum = max(maximum, li...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMB...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) d = {} for x in sorted(a): d[x] = len(d) b = [d[x] for x in a] l = [0] * n r = [0] * n for x in b: l[x] = 1 if x - 1 >= 0: l[x] += l[x - 1] for x in b[::-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 DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBE...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
test_case = int(input()) for _ in range(test_case): input() arr = list(map(int, input().split())) brr = sorted(arr) crr = [0] * (len(arr) + 1) for i in arr: index = brr.index(i) crr[index] = 1 + crr[index - 1] print(len(arr) - max(crr))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR 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 BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = [] for i in range(n): b.append([a[i], i]) b = sorted(b, key=lambda R: R[0]) positions = [0] * n for i in range(n): positions[b[i][1]] = i leftmin = [] rightmin = [] for 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER V...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) indexOf = {} for i in range(n): indexOf[a[i]] = i values = sorted(list(set(a))) visited = [(False) for _ in range(n)] ng = [n for _ in range(n)] for i in range(n): lo = 0 hi = len(v...
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 DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR AS...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) for i in range(n): a[i] = a[i] * n + i a.sort() p = [(0) for _ in range(n)] for i in range(n): p[a[i] % n] = i q = [(0) for _ in range(n)] for i in range(n): q[p[i]] = i c...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL V...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for _ in range(t): n = int(input()) a = [(int(x), i) for i, x in enumerate(input().split())] a.sort() mx = 0 curl = 0 prev = -1000 for x, i in a: if i > prev: curl += 1 else: curl = 1 prev = i if curl > mx: ...
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 VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN V...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = sorted(list(set(a))) max_r = 0 for i in range(n): a[i] = b.index(a[i]) while a != []: r = 0 last = a[-1] for i in range(len(a) - 1, -1, -1): if a[i] == last or a[i] ...
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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR LIST ASSIGN VAR ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for _ in range(t): n = int(input()) l = [[x, i] for i, x in enumerate(map(int, input().split()))] l.sort() c = 0 count = 0 now = -1 for i in range(n): if l[i][1] > now: now = l[i][1] count += 1 else: c = max(c, count) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = sorted(a) c = {} for i in range(n - 1): c[b[i + 1]] = b[i] c[b[0]] = -1 li = {} for i in a: if c[i] in li: li[i] = li[c[i]] + 1 ...
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 VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR A...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
for p in range(int(input())): n = int(input()) a = [int(i) for i in input().split()][:n] b = a.copy() b.sort() c = -1 for e in range(len(a)): m = 0 g = e for j in range(len(a)): if g < len(a) and a[j] == b[g]: g += 1 m += 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 VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
import sys def ii(): return int(sys.stdin.readline()) def mi(): return map(int, sys.stdin.readline().split()) def li(): return list(map(int, sys.stdin.readline().split())) def lli(rows_number): return [li() for _ in range(rows_number)] def si(): return sys.stdin.readline()[:-1] for p in ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUN...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for i in range(t): l = int(input()) s = list(map(int, input().split())) for j in range(l): s[j] += j / 100000.0 sor = sorted(s) b = [] for j in s: b.append(sor.index(j)) dp = [0] * (l + 1) for j in range(l): dp[b[j]] = 1 + dp[b[j] - 1] print(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 FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASS...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) p = [] for i in range(n): p.append((a[i], i)) p.sort(key=lambda x: x[0]) aOrder = [-1] * n for i in range(n): aOrder[p[i][1]] = i maxSubseq = [] for i in range(n): maxSubs...
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
import sys input = sys.stdin.readline for nt in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = sorted(a) l = {} for i in range(n): l[b[i]] = i if a == b: print(0) continue dp = [0] * (n + 1) for i in range(n): dp[l[a[i]]] = ...
IMPORT 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 VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ...
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem. You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array ele...
t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] indices = {} for i in range(n): indices[a[i]] = i ordered = sorted(a) seq_length = [1] * n for i in range(1, n): if indices[ordered[i - 1]] < indices[ordered[i]]: seq_length...
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 DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VA...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
def solve(): n = int(input()) a = sorted(map(int, input().split())) ans = 1, 0 cur = [a[0]] for i in range(1, n): if a[i] - a[i - 1] > 1: ans = max(ans, (len(cur), i - 1)) cur.clear() elif a[i - 1] < a[i] and (i == n - 1 or a[i] < a[i + 1]): cur.ap...
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 NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUN...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
import sys __version__ = "0.1" __date__ = "2019-04-26" def solve(n, a): max_a = max(a) counter = [(0) for i in range(max_a + 1)] for ai in a: counter[ai] += 1 best_group = [] best_total = 0 curr = 1 while curr <= max_a: if counter[curr] > 0: curr_group = [curr]...
IMPORT ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR WHILE VAR VAR...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
def create(s, e, cnt): arr = [] for i in range(s, e + 1): arr.extend([i for _ in range(cnt[i] - 1)]) arr.extend(list(range(e, s - 1, -1))) return arr n = int(input()) a = list(map(int, input().split())) def solve(a): cnt = [0] * 200001 for x in a: cnt[x] += 1 block = [] ...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
kk = lambda: map(int, input().split()) ll = lambda: list(kk()) n = int(input()) d = {} for v in kk(): if v not in d: d[v] = 0 d[v] += 1 k = list(d.keys()) k.sort() i = 0 m = 0 while i < len(k): start = x = k[i] total = d[start] while i + 1 < len(k) and k[i] + 1 == k[i + 1]: i += 1 ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
def unique(a): if len(a) == 0: return a i = 1 j = 1 last = a[0] while j < len(a): if a[j] > last: last = a[j] a[i], a[j] = a[j], a[i] i += 1 j += 1 return a[:i] def expand(cir): e = [] for i in range(len(cir)): e.appen...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_C...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
n = int(input()) a = [int(x) for x in input().split()] c = [0] * 2 * 100007 s = [0] * 2 * 100007 result = 0 dis = 0 result_list = [] for i in a: c[i] += 1 for i in range(len(c)): if c[i] > 0: s[i] = c[i] result = c[i] dis = i break for i in range(dis + 1, len(c)): if c[i] > 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF ...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
import sys class Main: def __init__(self): self.buff = None self.index = 0 def __next__(self): if self.buff is None or self.index == len(self.buff): self.buff = self.next_line() self.index = 0 val = self.buff[self.index] self.index += 1 ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) m = 200005 cnt = [0] * m for i in a: cnt[i] += 1 k = 0 lr = [-1, -1] r = -1 for i in range(m): if i < r: continue if 2 <= cnt[i]: l, r = i, i x = 0 while 2 <= cnt[r]: x += ...
IMPORT 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF NUMBER ...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
def process(A): d = {} for x in A: if x not in d: d[x] = 0 d[x] += 1 my_max = [0, None, None] current = None for x in sorted(d): if current is None or x - 1 not in d: current = [d[x], x, x] my_max = max(my_max, current) elif d[x] > ...
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST NUMBER NONE NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR IF VAR NONE BIN_OP VAR NUMBER VAR ASSIGN VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR AS...
There are $n$ people in a row. The height of the $i$-th person is $a_i$. You can choose any subset of these people and try to arrange them into a balanced circle. A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than $1$. For example, let heights of cho...
rint = lambda: int(input()) rmint = lambda: map(int, input().split()) rlist = lambda: list(rmint()) n = rint() a = [0, 0] * (10**5 + 1) for c in rlist(): a[c] += 1 pr = 0 t = 0 ans = 0 g = 0 for i in range(1, 2 * 10**5 + 1): if a[i] < 2: t = 0 pr = a[i] else: t += a[i] nx = a[i +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER A...