TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

seq = deque()
for a in A:
    i = bisect.bisect_left(seq, a)
    if i == 0:
        seq.appendleft(a)
    else:
        seq[i - 1] = a
        while i < len(seq) and seq[i - 1] < seq[i]:
            seq[i], seq[i - 1] = seq[i - 1], seq[i]
            i += 1
print(len(seq))


import bisect
import os
import sys
from collections import deque

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

seq = deque()
for a in A:
    i = bisect.bisect_left(seq, a)
    if i == 0:
        seq.appendleft(a)
    else:
        seq[i - 1] = a
        while i < len(seq) and seq[i - 1] > seq[i]:
            seq[i], seq[i - 1] = seq[i - 1], seq[i]
            i += 1
print(len(seq))


Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
N = int(input())

a = int(input())
maxVal = [a]

ans = 1
for _ in range(N-1) :
    a = int(input())
    i = 0
    for i in range(len(maxVal)) :
        if a <= maxVal[i] :
            maxVal.append(a)
            ans += 1
            break
    else :
        maxVal[i] = max(maxVal[i] , a)


print(ans)

from bisect import bisect_right

N = int(input())
A = [int(input()) for _ in range(N)]
INF = 10**18

dp = [INF] * N
for a in A:
    dp[bisect_right(dp, -a)] = -a
ans = N - dp.count(INF)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
from sys import stdin
from bisect import bisect

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

dp = []
for a in A[::-1]:
    i = bisect(dp, a)
    if i < len(dp):
        dp[i] = a
    else:
        dp.append(a)
print(len(dp))

from sys import stdin
from bisect import bisect

N = int(stdin.readline().rstrip())
A = []
for i in range(N):
    A.append(int(input()))

dp = []
for a in A[::-1]:
    i = bisect(dp, a)
    if i < len(dp):
        dp[i] = a
    else:
        dp.append(a)
print(len(dp))

Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect

n = int(input())
a = []

for i in range(n):
    a.append(int(input()))

a.reverse()
cnt = 0
for i in range(1,n):
    if a[i] + cnt == c[i-1]:
        cnt += 1
    a[i] += cnt
        
INF = 10000000000
dp = [INF] * n

for i in range(n):
    t = bisect.bisect_left(dp,a[i])
    if t != n:
        dp[t] = a[i]

print(bisect.bisect_left(dp,INF))

import bisect

n = int(input())
c = []

for i in range(n):
    c.append(int(input()))

INF = 100000000
dp = [INF] * n

for i in range(n):
    dp[bisect.bisect_left(dp,c[i])] = c[i]

print(n - bisect.bisect_left(dp,INF)+1)


import bisect

INF = 10000000000

n = int(input())
a = [0] * n

for i in range(n):
    a[i] = int(input())
    a[i] = - a[i]

dp = [INF] * n

for i in range(n):
    dp[bisect.bisect_right(dp,a[i])] = a[i]
    
print(bisect.bisect_left(dp,INF))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect

n = int(input())
a = [int(input()) for _ in range(n)]
t = [a[-1]]

for i in reversed(a[:-1]):
    idx = bisect.bisect_left(t, i + 1)
    print(i, idx)
    if idx == len(t):
        t.append(i)

    else:
        t[idx] = i
    print(t)

print(len(t))

import bisect
 
n = int(input())
a = [int(input()) for _ in range(n)]

t = [a[-1]]
 
for i in reversed(a[:-1]):
    
    idx = bisect.bisect_left(t, i+1)
    # print(i, idx)
    if idx == len(t):
        t.append(i)
    
    else:
        t[idx] = i
    # print(t)
 
print(len(t))

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect
N = int(input())
A = deque()
for _ in range(N):
    x = int(input())
    i = bisect.bisect_left(A,x)
    j = bisect.bisect_right(A,x)
    if len(A) == 0:
        A.append(x)
    elif i > 0:
        if x <= A[i-1]:
            A.insert(i-1, x)
        else:
            A[i-1] = x
    elif x <= A[i]:
        A.insert(i, x)
    elif x > A[i]:
        A[i] = x

print(len(A))

from collections import deque
import bisect
N = int(input())
A = deque()
for _ in range(N):
    x = int(input())
    i = bisect.bisect_left(A,x)
    if i == 0:
        A.appendleft(x)
    else:
        A[i-1] = x

print(len(A))

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
def se(c, x, h, l):
    if h == l:
        return l
    t = (h+l)//2
    if c[t] < x:
        a = se(c,x,h,t)
    else:
        a = se(c,x,t,h)
    return a
        
    
import numpy as np
n = int(input())
a = [int(input()) for i in range(n)]
c = [a[-1]]
if len(np.unique(a)) == 1:
    print(len(a))
else:
    for i in a[::-1][1:]:
        if max(c) <= i:
            c.append(i)
        else:
            c[se(c,i,len(c),0)] = i
    print(len(c))

import numpy as np
n = int(input())
a = [int(input()) for i in range(n)]
c = [a[-1]]
if len(np.unique(a)) == 1:
    print(len(a))
else:
    for i in a[::-1][1:]:
        if max(c) <= i:
            c.append(i)
        else:
            mask = np.array(c) - i > 0
            c[mask][np.argmin(c[mask])] = i
    print(len(c))

def se(c, x, h, l):
    if h == l:
        return l
    t = (h+l)//2
    if c[t] <= x:
        a = se(c,x,h,t+1)
    else:
        a = se(c,x,t,l)
    return a
        
    
import numpy as np
n = int(input())
a = [int(input()) for i in range(n)]
c = [a[-1]]
diff = np.diff(a)
tmp = np.sum(diff<=0)
if tmp == len(diff):
    print(len(a))
elif tmp == 0:
    print(1)
else:
    for i in a[::-1][1:]:
        if c[-1] <= i:
            c.append(i)
        else:
            c[se(c,i,len(c),0)] = i
    print(len(c))




Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]

ans = [A[0]]
l = 1

for i in range(1, N):
    n = bisect.bisect_left(ans, A[i])
    if A[i] >= ans[-1]:
        ans.append(A[i])
    else:
        ans[n] = A[i]

print(len(ans))


import bisect

N = int(input())
A = [int(input()) for _ in range(N)]

A.reverse()
ans = [A[0]]

for i in range(1, N):
    n = bisect.bisect_right(ans, A[i])
    if A[i] >= ans[-1]:
        ans.append(A[i])
    else:
        ans[n] = A[i]

print(len(ans))


Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect
# from collections import deque
# from collections import Counter

# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt
 
n = int(input())
li = [int(input()) for i in range(n)]
li = [-x for x in li]

X = []
X.append(li[0])

for i in range(1,n):
    idx = bisect.bisect_right(X,li[i])
    if idx==len(X):
        X.append(li[i])
    else:
        X[idx-1] = li[i]

print(len(X))

import bisect
# from collections import deque
# from collections import Counter

# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt
 
n = int(input())
li = [int(input()) for i in range(n)]
li = [-x for x in li]

X = []
X.append(li[0])

for i in range(1,n):
    idx = bisect.bisect_right(X,li[i])
    if idx==len(X):
        X.append(li[i])
    else:
        X[idx] = li[i]

print(len(X))

Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
N = int(input())
A = []
for _ in range(N):
  a = int(input())
  A.append(a)

check = [False for _ in range(N)]
cnt = 0
while len(A) > 0:
  A0 = min(A)
  A.pop(A.index(A0))
  cnt += 1
  i = 0
  while i < len(A):
    if A[i] > A0:
      A.pop(i)
    else:
      i += 1
print(cnt)

N = int(input())
A = []
for _ in range(N):
  a = int(input())
  A.append(a)

ans = 0
cnt = 0
for i in range(1, N):
  if A[i - 1] >= A[i]:
    cnt += 1
  else:
    cnt = 0
  ans = max(ans, cnt)
print(ans)

import bisect
from collections import deque

N = int(input())
A = []
for _ in range(N):
  a = int(input())
  A.append(a)

b = deque([])
for a in A:
  if len(b) == 0:
    b.append(a)
  else:
    if a <= b[0]:
      b.appendleft(a)
    else:
      b[bisect.bisect_left(b, a) - 1] = a
print(len(b))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
n = int(input())
a = [int(input()) for _ in range(n)]
l = []

for i in range(n):
    if i == 0:
        l.append([a[i]])
    for j in range(len(l)):
        if l[j][-1] < a[i]:
            l[j].append(a[i])
            break
    else:
        l.append([a[i]])
print(len(l))

from bisect import bisect_left
from collections import deque

n = int(input())
A = [int(input()) for _ in range(n)]

D = deque([])

for a in A:
    i = bisect_left(D, a)
    if i == 0:
        D.appendleft(a)
    else:
        D[i-1] = a

print(len(D))

Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):

import bisect

N = int(input())
A = [int(input()) for i in range(N)]
B = []
for i in range(N):
    if len(B) == 0:
        B.append(A[i])
    else:
        if B[0] >= A[i]:
            B.append(A[i])
        else:
            index = bisect.bisect_left(B,A[i])-1
            B[index] = A[i]
    B.sort()
print(len(B)+1)


import heapq
import bisect
N = int(input())
A = [int(input()) for i in range(N)]
A = A[::-1]

C = []
for i in range(N):
    if i == 0:
        C.append(A[i])
    else:
        li = bisect.bisect_right(C,A[i])
        if li == len(C):
            C.append(A[i])
        else:
            C[li] = A[i]
    
print(len(C))

Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
N = int(input())

A = []

for _ in range(N):
    A.append(int(input()))

colored = [False] * N
goal = [True] * N

color_num = 0

while colored != goal:
    start = colored.index(False)
    base = A[start]
    colored[start] = True

    print("check from {}".format(start))

    for i in range(start+1, N):
        if colored[i] == False:
            if base < A[i] :
                colored[i] = True
                base = A[i]

    color_num += 1

print(color_num)


N = int(input())

A = []

for i in range(N):
    A.append(int(input()))

color = 1

def hantei(start):
    global color
    current = start - 1

    while current >= 0:
        if A[current] >= A[start]:
            color += 1
            hantei(current)
            return
        else:
            current -= 1
            start -= 1

hantei(N-1)

print(color)


import bisect

N = int(input())

A = [int(input()) for _ in range(N)]

colors = []

for i in range(N-1, -1, -1):
    target = bisect.bisect_right(colors, A[i])

    if target == len(colors):
        colors.append(A[i])
    else:
        colors[target] = A[i]

print(len(colors))


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
n = int(input())
l = [int(input()) for i in range(n)]
#print(n,l)

L = 0
cnt = 0
for i in range(n):
    if l[i] >= l[i+1]:
        cnt += 1
    else:
        cnt = 0
    if L <= cnt:
        L = cnt
print(L)

import bisect

N = int(input())
A = [10**10 - int(input()) for i in range(N)]
INF = 10**12

dp = [INF for i in range(N+1)]
#print(A,dp)

for a in A:
    i = bisect.bisect_right(dp,a)
    dp[i] = a
#print(dp)
res = bisect.bisect_left(dp,INF)
print(res)

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)[::-1]
q = deque([])

for i,j in enumerate(a):
  if i == 0:
    q.append(j)
    continue
  c = bisect.bisect_left(q,j)
  if c == 0:
    q.appendleft(j)
  else:
    q[c] = j
    
print(len(q))
  


from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)[::-1]
q = deque([])

for i,j in enumerate(a):
  if i == 0:
    q.append(j)
    continue
  c = bisect.bisect_left(q,j)
  if c == 0:
    q.appendleft(j)
  else:
    q[c-1] = j
    
print(len(q))
  


from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)
q = deque([])

for i,j in enumerate(a):
  if i == 0:
    q.append(j)
    continue
  c = bisect.bisect_left(q,j)
  if c == 0:
    q.appendleft(j)
  else:
    q[c-1] = j
    
print(len(q))
  


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):

def desc_bin(a, x, lo=0, hi=None):
    """Insert item x in list a, and keep it reverse-sorted assuming a
    is reverse-sorted.

    If x is already in a, insert it to the right of the rightmost x.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x > a[mid]: hi = mid
        else: lo = mid+1
    return lo
N=int(input())
ans=[]
for _ in range(N):
    num=int(input())
    
    index=desc_bin(ans,num)
    if index==len(ans):
        ans.append(num)
    else:
        ans[index]=num
    print(ans)
print(len(ans))


def desc_bin(a, x, lo=0, hi=None):
    """Insert item x in list a, and keep it reverse-sorted assuming a
    is reverse-sorted.

    If x is already in a, insert it to the right of the rightmost x.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x > a[mid]: hi = mid
        else: lo = mid+1
    return lo
N=int(input())
ans=[]
for _ in range(N):
    num=int(input())
    
    index=desc_bin(ans,num)
    if index==len(ans):
        ans.append(num)
    else:
        ans[index]=num
    #print(ans)
print(len(ans))

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):

def bisect_desc(a,x):
    r = len(a)
    if r == 0:
        return 0
    l = 0
    while l != r:
        f = (l+r)//2
        if a[f] >= x:
            l = f+1
        else:
            r = f
    return l

n=int(input())
a=[int(input()) for _ in range(n)]

q=[]

def bisect_desc(a,x):
    r = len(a)
    if r == 0:
        return 0
    l = 0
    while l != r:
        f = (l+r)//2
        if a[f] >= x:
            l = f+1
        else:
            r = f
    return l

for sa in a:
    t = bisect_desc(q,sa)
    if t ==len(q):
        q.append(sa)
    else:
        q[t] = sa

print(len(q))


Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
from collections import deque

n=int(input())
a=[]
for i in range(n):
    A=int(input())
    a.append(A)
l=deque([a[0]])
for i in range(1,n):
    if l[0]>=a[i]:
        l.appendleft(a[i])
    elif l[-1]<=a[i]:
        l.append(a[i])
    else:
        p=0
        q=len(l)-1
        while q-p!=1:
            if l[(p+q)//2]>=a[i]:
                q=(p+q)//2
            else:
                p=(p+q)//2
        l[p]=a[i]
print(len(l))


n=int(input())
a=[]
for i in range(n):
    A=int(input())
    a.append(A)
l=deque([a[0]])
for i in range(1,n):
    if l[0]>=a[i]:
        l.appendleft(a[i])
    elif l[-1]<=a[i]:
        l.append(a[i])
    else:
        p=0
        q=len(l)-1
        while q-p!=1:
            if l[(p+q)//2]>=a[i]:
                q=(p+q)//2
            else:
                p=(p+q)//2
        l[p]=a[i]
print(len(l))


from collections import deque

n=int(input())
a=[]
for i in range(n):
    A=int(input())
    a.append(A)
l=deque([a[0]])
for i in range(1,n):
    if l[0]>=a[i]:
        l.appendleft(a[i])
    elif l[-1]<a[i]:
        l[-1]=a[i]
    else:
        p=0
        q=len(l)-1
        while q-p!=1:
            if l[(p+q)//2]>=a[i]:
                q=(p+q)//2
            else:
                p=(p+q)//2
        l[p]=a[i]
print(len(l))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect
from collections import deque

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans = deque([A[0]])
for i in range(1, N):
    index = bisect.bisect_left(ans, A[i])
    if index > 0:
        ans[index - 1] = A[i]
    else:
        ans = [A[i]] + ans

print(len(ans))


import bisect
from collections import deque

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans = deque([A[0]])
for i in range(1, N):
    index = bisect.bisect_left(ans, A[i])
    if index > 0:
        ans[index - 1] = A[i]
    else:
        ans.appendLeft(A[i])

print(len(ans))


import bisect

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans = [A[0]]
for i in range(1, N):
    index = bisect.bisect_left(ans, A[i])
    if index > 0:
        ans[index] = A[i]
    else:
        ans.insert(0, A[i])

print(len(ans))


import heapq

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans = []
heapq.heappush(ans, A[0])
for i in range(1, N):
    if A[i] > ans[0]:
        ans[0] = A[i]
    else:
        heapq.heappush(ans, A[i])

print(len(ans))


import bisect
from collections import deque

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans = deque([A[0]])
for i in range(1, N):
    index = bisect.bisect_left(ans, A[i])
    if index > 0:
        ans[index - 1] = A[i]
    else:
        ans.appendleft(A[i])

print(len(ans))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect
N = int(input())
A = [int(input()) for i in range(N)]
A = [-a for a in A]

dp = []
for a in A:
    i = bisect.bisect_right(dp, a)
    if i >= len(dp):
        dp.append(a)
    else:
        dp[i] = a

print(N-len(dp))

import bisect
N = int(input())
A = [-int(input()) for i in range(N)]

dp = []
for a in A:
    i = bisect.bisect_right(dp, a)
    if i >= len(dp):
        dp.append(a)
    else:
        dp[i] = a

print(N-len(dp))

import bisect
N = int(input())
A = [-int(input()) for i in range(N)]


dp = []
for a in A:
    i = bisect.bisect_right(dp, a)
    if i >= len(dp):
        dp.append(a)
    else:
        dp[i] = a

print(len(dp))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
from collections import defaultdict
from bisect import bisect_left

N = int(input())
d = defaultdict(list)

for i in range(N):
    v = int(input())
    d[v].append(i)

keys = sorted(d.keys())
s = d[keys[0]]

for k in keys[1:]:
    used = set()
    for i in d[k]:
        j = bisect_left(s, i)
        if 0<j<len(s):
            if not j-1 in used:
                s[j-1] = i
            else:
                s = s[:j] + [i] + s[j:]
            used |= {j-1}
        elif j==0:
            s = [i]+s
        else:
            s = s+[i]

print(len(s))

from collections import deque
from bisect import bisect_left

N = int(input())
d = deque([])
l = [int(input()) for _ in range(N)]

d.append(l[0])

for i in l[1:]:
    v = bisect_left(d, i)
    if v == 0:
        d.appendleft(i)
    else:
        d[v-1] = i

print(len(d))

Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect

n=int(input())
a=[int(input()) for x in range(n)]
c=[]

c.append(a[0])

for i in range(1,n):
  j=bisect.bisect_right(c,a[i])
  if c[j-1]<a[i]:
    c[j-1]=a[i]
  else:
    c.insert(j,a[i])
  print(c)
print(len(c))


mport bisect

N=int(input())
A=[int(input()) for i in range(N)]

B=[]
for a in A:
  p=bisect.bisect_left(B,a)
  if p==0:
    B.insert(0,a)
  else:
    B[p-1]=a

print(len(B))


import bisect

N=int(input())
A=[int(input()) for i in range(N)]

c=0
B=[]
for a in A:
  p=bisect.bisect_left(b,a)
  if p==0:
    B.insert(0,a)
  else:
    B[p-1]=a

print(len(B))


import bisect

N=int(input())
A=[-int(input()) for i in range(N)]

B=[]
c=0
for a in A:
  p=bisect.bisect_right(B,a)
  if p==c:
    B.append(a)
    c += 1
  else:
    B[p]=a

print(len(B))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
c = 0
col_min = []

for i in range(N-1, -1, -1):
  if i == N-1:
    col_min.append(arr[i])
    c += 1
  else:
    check = 0
    for k, v in enumerate(col_min):
      if v > arr[i]
      	col_min[k] = arr[i]
        check = 1
        break
    if check == 0:
      col_min.append(arr[i])
      c += 1
print(c)
        

N = int(input())
arr = [int(input()) for i in range(N)]
max_v= []

for v in arr:
  check = 0
  for i, k in enumerate(max_v):
    if v < k:
      max_v[i] = k
      check = 1
      break
  if check == 0:
    max_v.append(v)
print(len(max_v))


N = int(input())
arr = [int(input()) for i in range(N)]
c = 0
col_min = []

for i in range(N-1, -1, -1):
  if i == N-1:
    col_min.append(arr[i])
    c += 1
  else:
    check = 0
    for k, v in enumerate(col_min):
      if v > arr[i]
      	col_min[k] = arr[i]
        check = 1
        break
    if check == 0:
      col_min.append(arr[i])
      c += 1
print(c)

import bisect
N = int(input())
arr = [int(input()) for i in range(N)]
dp = [-1 for _ in range(N)]
for i in arr:
    dp[bisect.bisect_left(dp, i) - 1] = i
print(sum([i >= 0 for i in dp]))


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect
import sys
input = sys.stdin.readline

N = int(input())
A = [-1*int(input()) for _ in range(N)]

maxims = [A[0]]
ans = 1
minim = A[0]
for a in A[1:]:
    if maxims[-1] < a:
        idx = bisect.bisect(maxims,a)
        maxims[idx] = a
    else:
        maxims.append(a)
        ans += 1
    
print(ans)
    
    
    

import bisect
import sys
input = sys.stdin.readline

N = int(input())
A = [-1*int(input()) for _ in range(N)]

maxims = [A[0]]
ans = 1
for a in A[1:]:
    if maxims[-1] > a:
        idx = bisect.bisect(maxims,a)
        maxims[idx] = a
    else:
        maxims.append(a)
        ans += 1
    
print(ans)
    
    
    

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF]* (N)
for n in range(N):
    i = bisect.bisect(lis, A[n])    
    lis[i] = A[n]
    #print (lis)
print (bisect.bisect_left(lis, INF)) a

import bisect
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF] * N
for n in range(N):
    i = bisect.bisect(lis, A[n])    
    lis[i] = A[n]
print (bisect.bisect_left(lis, INF))

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import sys
import bisect
import collections


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    la = [int(input()) for _ in range(n)]
    result = collections.deque()
    for a in la:
        idx = bisect.bisect_left(result, a)
        if idx == 0:
            result.appendleft(a)
        else:
            result[idx - 1] = a
    print(len(result))
    print(result)


main()


import sys
import bisect
import collections


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    la = [int(input()) for _ in range(n)]
    result = collections.deque()
    for a in la:
        idx = bisect.bisect_left(result, a)
        if idx == 0:
            result.appendleft(a)
        else:
            result[idx - 1] = a
    print(len(result))


main()


Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
#E
from collections import deque
import bisecit
n = int(input())
a = [int(input()) for _ in range(n)]
result = deque()

for i in a:
    idx = bisect.bisect_left(result,i)
    if idx == 0:
        result.appendleft(i)
        
    else:
        result[idx-1] = i
        
print(len(result))

#E
from collections import deque
import bisect
n = int(input())
a = [int(input()) for _ in range(n)]
result = deque()

for i in a:
    idx = bisect.bisect_left(result,i)
    if idx == 0:
        result.appendleft(i)
        
    else:
        result[idx-1] = i
        
print(len(result))
        

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
N = int(input())
a =[0]*(N)
for i in range(N):
  a[i] = int(input())
color = [0]*N
color[0]=a[0]
cnt = a[0]
ans = 1
for i in range(1,N):
    if cnt <= a[i] and a[i] <= color[ans-1]:
        color[ans] = a[i]
        cnt = a[i]
        ans +=1
    elif cnt <= a[i] and a[i] > color[ans-1]:
        color[ans-1] = a[i]
        cnt = a[i]
    else:
        cnt = a[i]
print(ans)

from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right,bisect
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
LIS = []
for i in range(N):
    a =- int(input())
    idx = bisect(LIS,a)
    if idx == len(LIS):
        LIS.append(a)
    else:
        LIS[idx]=a
print(len(LIS))

Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
# -*- coding: utf-8 -*-
N = int(input())
a_list = []
for i in range(N):
    a_list.append(int(input()))
color_counter = 0
for i in range(N):
    color_counter += 1
    compare_a = a_list[0]
    next_a_list = []
    for i in range(N):
        if compare_a < a_list[i]:
            compare_a = a_list[i]
        else:
            next_a_list.append(a_list[i])
    if len(next_a_list) == 0:
        break
    else:
        a_list = next_a_list
print(color_counter)

# -*- coding: utf-8 -*-
N = int(input())
a_list = []
for i in range(N):
    a_list.append(int(input()))
color_counter = 0
for i in range(N):
    color_counter += 1
    compare_a = a_list[0]
    next_a_list = []
    for ite in a_list:
        if compare_a < ite:
            compare_a = ite
        else:
            next_a_list.append(ite)
    if len(next_a_list) == 0:
        break
    else:
        a_list = next_a_list
print(color_counter)

# -*- coding: utf-8 -*-
from bisect import bisect_right, bisect_left
N = int(input())
a_list = [int(input()) for _ in range(N)]

color_list = [1]
for a in a_list:
    a *= -1
    index = bisect_right(color_list, a)
    if index < len(color_list):
        color_list[index] = a
    else:
        color_list.append(a)
#     print(color_list, a)
print(len(color_list))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
from bisect import bisect as bl

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

def lds(X: list):
    L = [-X[0]]
    for x in X[1:]:
        if L[-1] <= -x:
            L.append(-x)
        else:
            L[bl(L, -x)] = -x
    return L

print(lds(A))

from bisect import bisect as bl

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

def lds(X: list):
    L = [-X[0]]
    for x in X[1:]:
        if L[-1] <= -x:
            L.append(-x)
        else:
            L[bl(L, -x)] = -x
    return len(L)

print(lds(A))

Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):

from bisect import bisect
n = int(input())
A = [int(input()) for _ in range(n)]
dp = [1]
for a in A:
    a *= -1
    i = bisect(dp,a)   
    print(dp)
    if i < len(dp):    
        dp[i] = a      
    else:
        dp.append(a)    
    print(dp)

print(len(dp))


import sys
input = sys.stdin.readline  

def main():
        
    from bisect import bisect
    import sys
    input = sys.stdin.readline
    n = int(input())
    A = [int(input()) for _ in range(n)]
    dp = [1]
    for a in A:
        a *= -1
        i = bisect(dp,a)   

        if i < len(dp):    
            dp[i] = a     
        else:
           dp.append(a)    

        print(len(dp))

if __name__ == '__main__':
    main()


import sys
input = sys.stdin.readline  

def main():
        
    from bisect import bisect
    import sys
    input = sys.stdin.readline
    n = int(input())
    A = [int(input()) for _ in range(n)]
    dp = [1]
    for a in A:
        a *= -1
        i = bisect(dp,a)   

        if i < len(dp):    
            dp[i] = a     
        else:
           dp.append(a)    

    print(len(dp))

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
N = int(input())
nums = [int(input()) for _ in range(N)]
ans = 0
nums_sorted = nums[:]
nums_sorted = list(set(nums_sorted))
nums_sorted.sort(reverse=True)
di = {}





for i in range(N-1):
    if nums[i] > nums[i+1]:
        ans += 1

nums_l = len(nums)
nums_s = len(list(set(nums)) )
ans += nums_l - nums_s
if len(nums_s) == 1:
    ans += 1



print(ans)

import bisect
from collections import deque
N = int(input())
nums = deque()

for i in range(N):
    temp =  int(input())
    ind = bisect.bisect_left(nums, temp)
    if ind == 0:
        nums.appendleft(temp)
    else:
        nums[ind - 1] = temp
print(len(nums))

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect
N = int(input())
A = [-int(input()) for _ in range(N)]
tmp = [A[0]]
for i in A[1:N]:
    index = bisect.bisect_left(tmp, i)
    if index == 0:
        tmp.append(i)
    else:
        tmp[index-1] = i

print(len(tmp))


import bisect
N = int(input())
A = [-int(input()) for _ in range(N)]
tmp = [A[0]]
for i in A[1:N]:
    index = bisect.bisect(tmp, i)
    if index == 0:
        tmp.append(i)
    else:
        tmp[index-1] = i

print(len(tmp))


import bisect
N = int(input())
A = [int(input()) for _ in range(N)]
tmp = [A[0]]
ans = 0
for i in range(1, N):
    index = bisect.bisect_left(tmp, A[i])
    print(A[i], index)
    if index == 0:
        tmp.append(A[i])
        tmp.sort()
    else:
        tmp[index-1] = A[i]

print(len(tmp))


import bisect
N = int(input())
A = [-int(input()) for _ in range(N)]
tmp = [A[0]]
for i in A[1:N]:
    index = bisect.bisect(tmp, i)
    if index == len(tmp):
        tmp.append(i)
    else:
        tmp[index] = i

print(len(tmp))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
n=int(input())
import bisect

a=[int(input()) for _ in range(n)]
x=[a[0]]
for i in a[1:]:
  y=bisect.bisect(x,i)
  if y==len(x):x.append(i)
  else:x[y]=i
print(len(x))

from bisect import bisect_right
N = int(input())
A = []
for i in range(N):
    A.append(-int(input()))
INF = float('inf')
D = [INF] * N
for i in range(len(A)):
  
    D[bisect_right(D, A[i])] = A[i]

print(N - D.count(INF))


Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
from bisect import bisect_left
import heapq
n=int(input())
l=[]
l.append(int(input()))
heapq.heapify(l)
for i in range(n-1):
    a=int(input())
    x=bisect_left(l,a)
    if x==0:
        heapq.heappush(l,a)
    else:
        l[x-1]=a
    print(l)
print(len(l))

from bisect import bisect_left,bisect_right
n=int(input())
INF=float('inf')
l=[INF]*n
a=[int(input()) for _ in range(n)]
for i in a[::-1]:
    l[bisect_right(l,i)]=i
print(bisect_left(l,INF))

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
import bisect

n = input()
a = []
n = int(n)

for i in range(n):
    a.append(int(input()))


t = []

for i in a:
    
    
    if len(t) > 0 and i < t[0]:
        t.insert(0, i)
    
    idx = bisect.bisect_left(t, i)
    t[idx-1] = i
    # print(t)

print(len(t))


import bisect

n = int(input())
a = [int(input()) for _ in range(n)]

t = [a[-1]]

for i in reversed(a[:-1]):
    
    idx = bisect.bisect_left(t, i+1)
    # print(i, idx)
    if idx == len(t):
        t.append(i)
    
    else:
        t[idx] = i
    # print(t)

print(len(t))

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
print(1)

#%%
import bisect

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

ans_list = [-1] * n
for i in range(n):
    tmp = bisect.bisect_left(ans_list, a[i])
    #print(tmp)
    if tmp == 0:
        ans_list.insert(0, a[i])
    else:
        ans_list[tmp-1] = a[i]
    #print(ans_list)

ans = 0
for i in range(n):
    if ans_list[i] != -1:
        ans += 1
print(ans)

    


Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:    * If A_i and A_j (i < j) are painted with the same color, A_i < A_j.  Find the minimum number of colors required to satisfy the condition.

Submission attempts (in order):
from collections import deque

n = int(input())
L = deque([int(input())])
for i in range(1,n):
    t = int(input())
    a = L.popleft()
    if t <= a:
        L.append(t)
        L.append(a)
    else:
        L.append(t)
print(len(L))


from collections import deque
import bisect
n = int(input())
L = deque([int(input())])
for i in range(1,n):
    t = int(input())
    k = bisect.bisect_left(L, t)
    if k == 0:
        L.appendleft(t)
    else:
        L[k-1] = t
print(len(L))


Verdicts: Wrong Answer

Accepted