from isanez import DS t = int(input()) while t > 0: t -= 1 A = input().split() x = DS.Stack() for i in range(len(A)): if x.isEmpty(): x.push(A[i]) elif A[i] == x.peek(): x.pop() continue else: x.push(A[i]) if x.isEmpty(): print('yes') else: print('no')
from isanez import DS t = int(input()) while t>0: t-=1 n = int(input()) A = [int(number) for number in input().split(" ")] x = DS.Stack() y = DS.Stack() p = 0 count = 1 i =0 while i<n: if A[i] == count: count+=1 y.push(A[i]) i = i+1 continue while x.peek() == count and x.isEmpty() != True: count+=1 y.push(x.pop()) if x.isEmpty() == True: x.push(A[i]) i+=1 continue elif A[i] < x.peek(): x.push(A[i]) i+=1
from isanez import DS t = int(input()) while t > 0: t -= 1 n = int(input()) A = [int(number) for number in input().split(" ")] d = DS.Queue() p = 0 l = len(A) for i in range(len(A) - 1): if A[-(l - i)] <= A[(l - i - 1)]: d.push(A[-(l - i)]) del A[-(l - i)] elif A[-(l - i)] > A[(l - i - 1)]: p = 1 mini = A[(l - i - 1)] del A[(l - i - 1)] check = 0 while d.isEmpty() != True: f = d.pop() if mini <= f: A.append(mini) check = 1 A.append(f) if check == 0: A.append(mini) if p == 0: print(-1) else: