Problem:


Score : 500 points

Problem Statement

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.

Constraints

1 \leq N \leq 10^5

0 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the minimum number of colors required to satisfy the condition.

Sample Input 1

5
2
1
4
5
3

Sample Output 1

2

We can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1, 4, and 5 blue.

Sample Input 2

4
0
0
0
0

Sample Output 2

4

We have to paint all the integers with distinct colors.



Sample input:
5
2
1
4
5
3


Sample output:
2

Submission status: Wrong Answer

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

cntbuf = -1

while True :
    cnt = 0
    B = []
    for i in range(len(A) - 1) :
        if A[i] >= A[i+1] :
            B.append(A[i])
            if i == len(A) - 2 :
                B.append(A[i+1])
            cnt += 1
    if cnt == cntbuf :
        break
    A.clear()
    A.extend(B)
    cntbuf = cnt
#    print(A, cnt)

print(len(B))

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
Ans=[A[-1]]
for i in reversed(range(n-1)):
  a=A[i]
  if a>=Ans[-1]:
    Ans.append(a)
  else:

    Ans[bisect.bisect_left(Ans,a)]=a

print(len(Ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import bisect

# いっこ入力
n =int(input())

# n行の数をリストへ
a = [int(input()) for i in range(n)] 

# color
c = [a[0]]

for i in range(1,n):
    if c[0] >= a[i]:
        c.insert(0,a[i])
    else:
        p = bisect.bisect_right(c, a[i])
        c[p-1]=a[i]
#        print(c)
#        print(p)

print(len(c))

Submission status: Wrong Answer

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

maxi = A[0]
mini = A[0]
ans = 1
for i in range(1, N):
    if A[i] <= mini:
        ans += 1
        mini = A[i]
    elif A[i] > mini and A[i] <= maxi:
        mini = A[i]
    else:
        maxi = A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
ans = 0
count = 1
for i in range(len(l)-1):
    if l[i] >= l[i+1]:
        count += 1
    else:
        ans = max(ans,count)
        count = 1
print(max(ans,count))

Submission status: Wrong Answer

Solution code:
N = int(input())
li = []
for _ in range(N):
    li.append(int(input()))

def aa(li):
    max_val = max(li)
    a = [i for i, x in enumerate(li) if x == max(li)]    
    b = max(a)
    return max_val, b

cnt = 0



while True:
    ans = []
    tmp = len(li)
    cnt += 1
    while True:
        mv, tmp = aa(li[:tmp])
        ans.append(tmp)
        if tmp == 0:
            break
    
    for i in ans:
        li.pop(i)
        
    if len(li) < 2:
        break

print(cnt)

Submission status: Wrong Answer

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

count = 0
while a:
    l = len(a)
    min_a = min(a)
    min_list = [i for i, x in enumerate(a) if x == min_a]
    m = min_list[-1]
    for i in range(l-m):
        if l-i-1<0:
            break
        if a[l-i-1] >= min_a:
            del a[l-i-1]
    del[]
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n,*A=map(int,open(0).read().split())
color=[-1]
for a in A:
    if a<=min(color):
        color.append(a)
    else:
        close_a = max(color,key=lambda x:min(x,a))
        close_a_index = color.index(close_a)
        color[close_a_index] = a
print(len(color))

Submission status: Wrong Answer

Solution code:
N = int(input())    
color_list =  [int(input())]
for i in range(N-1):
    new_value = int(input())
    if(new_value > color_list[0]):
        color_list[0] = new_value
    elif(new_value <= color_list[-1]):
        color_list.append(new_value)
    else:
        for i in range(len(color_list)):
          break
print(len(color_list))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
l = [int(input()) for i in range(n)]
a = np.array([0]+ l)
diff = np.diff(a)
ans = 0
if (diff>0).sum() == n:
  print(1)
else:  
  for i in range(n):
    if diff[i] <= 0 and ans < 2:
      ans += 1
    elif diff[i] <= 0 and diff[i-1]<=0:
      ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque
import sys
#import bisect
sys.setrecursionlimit(10**6)
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

def bisect(ls,x):
    l,r=0,len(ls)-1
    while r-l>1:
        mid=(l+r)//2
        if ls[mid]>x: # condition
            l=mid
        else:
            r=mid
    #print('bisect',ls,x,'=',r)
    return l

n=I()
a=deque()
q=[[] for _ in range(n)]
m=0 # num of queue now
for i in range(n):
    a+=[I()]
#print('a=',a)

q=deque()
q.append(a.popleft())
#print(q,'q[',0,']=')

while a:
    c=a.popleft()
    if c<=q[0]:
        q.appendleft(c)
        #print(q,'q[',0,']=',c)
    else:
        i=bisect(q,c)
        q[i]=c
        #print(q,'q[',i,']=',c)


ans=len(q)
print(ans)

t=[1,1,2,2,3,3]

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

B = []
minn = A[0]

for i in range(N - 1):
    if A[i] >= A[i + 1]:
        B.append([minn, A[i]])
        minn = A[i + 1]
        if i == N - 2:
            B.append([minn, minn])
    elif i == N - 2:
        B.append([minn, A[i + 1]])

res = 0
B = sorted(B, key=itemgetter(0))

if len(B) == 0:
    print(0)
    exit()

left = 0
right = 1
while right < len(B) and left < right:
    if B[left][1] < B[right][1]:
        right += 1
        continue
    else:
        left = right
        right += 1
        res += 1
print(res + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
ans = 0
count = 1
for i in range(len(l)-1):
    if l[i] > l[i+1]:
        count += 1
    else:
        ans = max(ans,count)
        count = 0
print(ans)

Submission status: Wrong Answer

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

li =[a[0]]
for i in range(1, n):
    if a[i] > li[-1]:
        li.append(a[i])
    else:
        for j in reversed(range(len(li))):
            if li[j] > a[i]:
                li[j] = a[i]
print(len(li))

Submission status: Wrong Answer

Solution code:
def resolve():

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

    color_L = [[] for _ in range(n)]
    last_num = [0] * n
    num_colors = 1

    for i in range(n):

        now_ai = ai[i]
        min_last_num = min(last_num[0:num_colors+1])

        good_last_num = [num for num in last_num[0:num_colors] if num < now_ai]
        if not good_last_num:
            last_num[num_colors - 1] = now_ai
            color_L[num_colors - 1].append(now_ai)
            num_colors += 1
        else:
            best_last_num = max(good_last_num)
            index_to_append = last_num.index(best_last_num)
            last_num[index_to_append] = now_ai
            color_L[index_to_append].append(now_ai)
    
    if sum(ai) == 0:
        num_colors -= 1
    
    print(num_colors)
    
resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(input()) for i in range(n)]
color = [0]*(n+1)
cnt = 0
m = A[0]
M = A[0]
for i in range(1,n):
    if m >=A[i]:
        m = A[i]
        cnt += 1
    if M>=A[i]:
        M = A[i]
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math




def search3(S):
    harf = int(len(A)/3-1)
    harf = max(0, harf)
    for i, a in enumerate(A[harf:]):
        if a < S:
            A[i] = S
            return 
    return

def search2(S):
    harf = int(len(A)/2)
    harf = max(0, harf)
    for i, a in enumerate(A[harf:]):
        if a < S:
            A[i] = S
            return 
    return

def search(S):
    for i, a in enumerate(A):
        if a < S:
            A[i] = S
            return 
    return



def main():
    N = int(input())
    A[0] = int(input())
    m = A[0]
    harf = 0
    th = 0
    for _ in range(N-1):
        S = int(input())
        if S <= m:
            A.append(S)
        elif S <= harf:
            search2(S)
        # elif S <= th:
        #     search3(S)
        else:
            search(S)
        m = A[-1]
        harf = A[int(len(A)/2)]
        th = A[int(len(A)/3)]
    print(len(A))

    

if __name__ == "__main__":
    A = [0]
    main()

Submission status: Wrong Answer

Solution code:
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 (nums_s) == 1:
    ans += 1



print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = []
for i in range(n):
	temp = int(input())
	arr.append(temp)

painted = [None for i in range(n)]
count = 1

for i in range(n):
	if i < n - 1 and painted[i] == None and painted[i + 1] == None:
		painted[i] = count
		for j in range(i + 1, n):
			if arr[i] < arr[j]:
				painted[j] = count
		count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
A = [int(input()) for _ in range(N)]
B = [A[0]]
ans = 1
for i in range(1,N):
    a = heapq.heappop(B)
    if a >= A[i]:
        ans += 1
    heapq.heappush(B,min(a,A[i]))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = []
for _ in range(N):
    li.append(int(input()))

def aa(li):
    max_val = max(li)
    a = [i for i, x in enumerate(li) if x == max(li)]    
    b = max(a)
    return max_val, b

cnt = 0



while True:
    ans = []
    tmp = len(li)
    cnt += 1
    while True:
        mv, tmp = aa(li[:tmp])
        ans.append(tmp)
        if tmp == 0:
            break
    
    for i in ans:
        li.pop(i)
        
    if len(li) == 0:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
i = 0
ls = []
ans = 1
while i < N:
    cur = A[i]
    i += 1
    while i < N and cur < A[i]:
        i += 1
    if i == N:
        break
    ls.append(A[i-1])
    find = False
    for j in range(len(ls)):
        if ls[j] < A[i]:
            ls.pop(j)
            find = True
            break
    if not find:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [-1 for i in range(N)]

color = 1
A[0] = int(input())


def search(A, color, a):
        left = 0
        right = color - 1
        signal = 0
        while left < right:
                mid = (left + right) // 2
                if A[mid] == a - 1:
                        return mid
                        signal = 1
                elif a <= A[mid]:
                        left = mid + 1
                else:
                        right = mid
        if signal == 0:
                return left


for i in range(N - 1):
        a = int(input())
        num = search(A, color, a)
        if num == color - 1 and a <= A[num]:
                A[color] = a
                color += 1

print(color)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
cnt=0
while len(a)>0:
  cnt+=1
  nokori=[]
  tmp = a[a.index(min(a))]
  for i in range(a.index(min(a))+1,len(a)):
    if tmp<a[i]:
      tmp=a[i]
    else:
      nokori.append(a[i])
  a = nokori
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
from collections import deque

fastinput = sys.stdin.readline
N = int(fastinput())
A = [int(fastinput()) for j in range(N)]
surface = deque([A[0]])#常に小さい順にソートされている
surfMax = A[0]
surfMin = A[0]
color = 1
for n,a in enumerate(A):
    if n==0:
        continue
    if a<=surfMin:
        color += 1
        surface.appendleft(a)
        surfMin = a
    elif a>surfMax:
        surface[color-1] = a
        surfMax = a
    else:
        pos = bisect.bisect_left(surface,a) -1 #a未満の最大の整数
        surface[pos] = a
        if pos==0:
            surfMin = a
        if pos == color-1:
            surfMax = a
print(color)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# 1 <= N <= 10^5
# 0 <= Ai <= 10^9
N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for _ in range(N)]

# ruiseki_max = [-INF]

# for i in range(N):
#     ruiseki_max.append(max(ruiseki_max[i], A[i]))

# cnt = 0
# for i in range(1, N):
#     if ruiseki_max[i] >= ruiseki_max[i+1]:
#         cnt += 1

# print(cnt)

before = deque([])
cnt = 1
for i in range(N-1):
    if A[i] >= A[i+1]:
        before.append(A[i])
        cnt += 1
    else:
        continue
    
    if len(before) != 0:
        num = before[-1]
        if num < A[i+1]:
            before.pop()
            cnt -= 1


print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
aa=list(map(int,sys.stdin.read().split()))
aa=aa[1:]
n=len(aa)
import bisect
bb=[]
for i in range(n):
    if not bb:
        bb.append(aa[i])
    else:
        if bb[0] >= aa[i]:
            bb = [aa[i]] + bb
        else:
            j = bisect.bisect_right(bb,aa[i])
            bb[j-1] = aa[i]
print(len(bb))

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heappush, heappop

def main():
    input = sys.stdin.readline
    N = int(input())
    heap = []
    a = int(input())
    min_ = a
    heappush(heap, a)

    for _ in range(N-1):
        a = int(input())
        if a <= min_:
            heappush(heap, a)
            continue

        heap_ = []
        while len(heap) > 0:
            b = heappop(heap)
            if b <= a:
                heappush(heap_, b)
            else:
                heappush(heap_, a)
                break

        while len(heap) > 0:
            b = heappop(heap)
            heappush(heap_, b)

        heap = heap_


    return len(heap)


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
B = [int(input().strip())]
min_value = B[0]
for i in range(N - 1):
  a = int(input().strip())
  if a <= min_value:
    min_value = a
    B.append(a)
  else:
    B = sorted(B, reverse=True)
    for i in range(len(B)):
      if a > B[i]:
        B[i] = a

print(len(B))

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = []
for i in range ( n ):
    a.append(int(input()))
c = [a[0]]
m = a[0]
for j in range(1,n):
    if a[j] <= m :
        c.insert(0,a[j])
        m = a[j]
    else:
        x = bisect.bisect_left(c,a[j])
        c[x-1]=a[j]
print(len(c))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def SeqDecomp(arr_len, arr):
    colors = []
    colors.append(arr[0])
    print(range(1,arr_len+1))
    for i in range(1,arr_len):
        if arr[i-1] < arr[i]:
            colors[0] = arr[i];
        else:
            tmp = list(filter(lambda x: x < arr[i], colors));
            if len(tmp) == 0:
                colors.append(arr[i]);
            else:
                colors[colors.index(tmp[0])] = arr[i]

    print(len(colors))

if __name__ == "__main__":
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    SeqDecomp(N,A)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

import sys

n= int(sys.stdin.readline())
ai= [ int(sys.stdin.readline()) for _ in range(n) ]
c= 1
l= [ -1 ]
for i in range(n-1):
    a = ai[i]
    k= -1
    for j in range(c):
        if l[j]==None: continue
        if l[j]<a:
            k= j
            break
    #
    if k>=0: l[k]= a
    else:
        c+=1
        l.append(None)
#
print( c )

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
for i in range(1, N):
    if A[i] < A[i - 1]:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]*n
for i in range(n):
    a[i]=int(input())
t = a[0]
ans = 0
count = 0

for i in a:
    if t >= i:
        ans += 1
        t = i
    count = a.count(i)

print(count)
if ans < count:
    ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3


def solv(n, a):
    color = 0
    v = 999999999999
    for pos in range(n):
        if a[pos] <= v:
            color += 1
        else:
            v = a[pos]
    return color-1


if __name__ == '__main__':

    n = int(input())

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

    ans = solv(n, a)

    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
l = [int(input()) for i in range(n)]
a = np.array([0]+ l)
diff = np.diff(a)
ans = 0
print(diff)
if (diff>0).sum() == n:
  print(1)
else:  
  for i in range(n):
    if diff[i] <= 0 and ans < 2:
      ans += 1
    elif diff[i] <= 0 and diff[i-1]<=0:
      ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
from collections import defaultdict
import sys
import bisect
input = sys.stdin.readline

n = int(input())
#####単位元######
ide_ele = -1
#ide_ele = 10**9+1

#num:n以上の最小の2のべき乗
num =2**((n-1).bit_length())
seg=[ide_ele]*(2*num)

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=max(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k+1:
        k = (k-1)//2
        seg[k] = max(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg[p])
        if q&1 == 1:
            res = max(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg[p])
    else:
        res = max(max(res,seg[p]),seg[q])
    return res
    
def main():
    used = defaultdict(int)
    aa = [int(input()) for i in range(n)]
    b = sorted(aa)
    for i in range(n):
        aa[i] = bisect.bisect_left(b,aa[i])
        
    
    a0 = aa[0]
    tank = [a0]
    used[a0] = 1
    update(a0,a0)
    
    for i in range(1,n):
        a = aa[i]
        while True:
            if used[tank[0]] > 0:
                break
            else:
                heapq.heappop(tank)
        #塗り替え
        if tank[0] < a:
            ma = query(0,a+1)

            used[ma] -= 1
            heapq.heappush(tank,a)
            used[a] += 1
            if used[ma] == 0:
                update(ma,-1)
        else:
            heapq.heappush(tank,a)
            used[a] += 1
        update(a,a)

    res = 0
    for e in tank:
        if used[e] > 0:
            res += 1
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
li = []
for _ in range(N):
    li.append(int(input()))

def aa(li):
    max_val = max(li)
    a = [i for i, x in enumerate(li) if x == max(li)]    
    b = max(a)
    return max_val, b

cnt = 0



while True:
    ans = []
    tmp = len(li)
    while True:
        mv, tmp = aa(li[:tmp])
        ans.append(tmp)
        cnt += 1
        if tmp == 0:
            break
    
    for i in ans:
        li.pop(i)
        
    if len(li) == 0:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())

answer = []
for i in range(n):
    input_num = int(input())
    list_num = len(answer)
    index = bisect.bisect_right(answer, input_num)
    if index == 0:
        answer.insert(index, input_num)
    else:
        answer[index -1] = input_num
print(len(answer))

Submission status: Wrong Answer

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

res = 1
m = a[0]
l = a[0]
for i in a[1:]:
    if i <= l:
         if i <= m:
             m = i
             res += 1
    l = i

print(res)

Submission status: Wrong Answer

Solution code:
n = input()
a = []
n = int(n)

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

prev_v = a[0]
count = 1
t_v = a[0]

for x in a[1:]:
    if prev_v < x:
        pass
    else:
        if t_v < x:
            t_v = x
        else:
            count += 1
    prev_v = x

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
n = 10**20

for i in range(N):
    a = int(input())
    if a <= n:
        n = a
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N, *A = map(int, open(0).read().split())

INF = 10 ** 9 + 7
dp = [INF] * (N + 1)
ans = 0
for i in range(N):
    idx = bisect_left(dp, A[i])
    dp[idx] = A[i]
    ans += 1 if idx == 0 else 0
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    Ai = int(input())
    A.append((i+1, Ai))

A = sorted(A, key=lambda x: (x[1], -1 * x[0]))
# print(A)

import heapq
memo = [0]
for a in A:
    num = a[0]
    smallest = heapq.heappop(memo)
    if num < smallest:
        heapq.heappush(memo, num)
        heapq.heappush(memo, smallest)
    else:
        heapq.heappush(memo, num)

print(len(memo))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())

color = 0
minv = A[0]
for i in range(N):
    if A[i] <= minv:
        if A[i] > minv:
            minv = A[i]
        color += 1

print(color)

Submission status: Wrong Answer

Solution code:
# -*- 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)

Submission status: Wrong Answer

Solution code:
n = int(input())
a=[]
for i in range(n):
  a.append(int(input()))
ans=[a[0]]

import bisect
#print(ans,a)
for i in range(1,n):
  if a[i] <= ans[0]:
     ans = [a[i]] + ans
  else:
    if i > n//2 and n > 10**3:
      continue
    else:
      j = bisect.bisect_left(ans,a[i])
      ans[j-1] = a[i] 

print(len(ans))

Submission status: Wrong Answer

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

cnt = 0
min_A = float("inf")
for i in range(N):
  if min_A >= A[i]:
    min_A = A[i]
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
a=[]
b=int(input())
i=0
y=0
z=0
s=0
while i<b:
    a.append(int(input()))
    i+=1

i=0
for x in a:
    if i==0:
        y=x
        z=x
        s+=1
    else:
        if y>=x and z<=x:
            s+=1
            z=x
        else:
            y=x
    i+=1
        
print(s)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = [_I() for i in range(N)]

"""
何個色を使えば塗れるか
最も小さい数字からはじめれば？
最も左からはじめれば？
"""

def bisect(arr, val, cmp):
    l = -1
    r = len(arr)
    while r - l > 1:
        e = (l + r) >> 1
        if cmp(arr[e], val): l = e
        else: r = e
    return r

res = [] 
for a in A:
    #  print('a res', a, res)
    if len(res) == 0:
        res.append(a)
    else:
        if a <= res[-1]:
            # 小さいので追加
            res.append(a)
        else:
            # 入れ替え
            p = bisect(res, a, lambda x, y: x > y)
            if res[p] == a:
                p = bisect(res, a-1, lambda x, y: x > y)
            else:
                res[p] = a

print(len(res))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
l = [int(input()) for i in range(n)]
a = np.array([0]+ l)
diff = np.diff(a)
ans = 0
if (diff>0).sum() == n:
  print("AAAAAA")
  print(1)
else:  
  for i in range(n):
    if diff[i] <= 0 and ans < 2:
      ans += 1
    elif diff[i] <= 0 and diff[i-1]<=0:
      ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
B = [int(input().strip())]
max_value = B[0]
for i in range(N - 1):
  a = int(input().strip())
  if a >= max_value:
    B = sorted(B, reverse=True)
    for i in range(len(B)):
      if a > B[i]:
        B[i] = a
  else:
    B.append(a)
    max_value = a

print(len(B))

Submission status: Wrong Answer

Solution code:
import math




def search3(S):
    harf = int(len(A)/3-1)
    harf = max(0, harf)
    for i, a in enumerate(A[harf:]):
        if a < S:
            A[i] = S
            return 
    return

def search2(S):
    harf = int(len(A)/2-1)
    harf = max(0, harf)
    for i, a in enumerate(A[harf:]):
        if a < S:
            A[i] = S
            return 
    return

def search(S):
    for i, a in enumerate(A):
        if a < S:
            A[i] = S
            return 
    return



def main():
    N = int(input())
    A[0] = int(input())
    m = A[0]
    harf = 0
    th = 0
    for _ in range(N-1):
        S = int(input())
        if S <= m:
            A.append(S)
        elif S <= th:
            search3(S)
        elif S <= harf:
            search2(S)
        else:
            search(S)
        m = A[-1]
        harf = A[int(len(A)/2)]
        th = A[int(len(A)/3)]
    print(len(A))

    

if __name__ == "__main__":
    A = [0]
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

cnt = 1

last = int(input())

buffer = [last]

for i in range(n - 1):
  a = int(input())
  # print(a, cnt)
  if a > last:
    last = a
  else:
    if len(buffer) == 0:
      buffer.append(last)
      cnt += 1
    if len(buffer) != 0:
      if a > buffer[-1]:
        buffer.append(last)
        last = a
        buffer.pop()
      else:
        buffer.append(last)
        cnt += 1
        last = a
    else:
      last = a
      cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
A = []
for i in range(N):
	A.append(int(input()))
	
def search(A, ans):
	if A[0] != max(A):
		cls = 999999999999999999999999999
		plc = -1
		for i in range(len(A)):
			if A[0] < A[i] and A[i] - A[0] < cls:
				cls = A[i] - A[0]
				plc = i

		if plc != -1:
			A.pop(0)
	if len(A) == 1:
		return ans
	else :
		ans += 1
		search(A[1 :], ans)
	
a = search(A, 0) 	
if a == 0:
	print(1)
else:
	print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

check = np.zeros(len(L))

n = len(L)
count = 0
i = 0
num_color = 0
while(count<n):
	while(i<n-1 and check[i]==1):
		i=i+1
	temp = L[i]
	check[i] = 1
	count+=1
	for x in range(i, len(L)):
		if(check[x]!=1 and temp < L[x]):
			check[x]=1
			count+=1
	num_color += 1

print(num_color)

Submission status: Wrong Answer

Solution code:
n = int( input() )
a = []
for i in range(n):
    a.append(int(input()))

max_color = 1
cnt_color = 1
stack = []
p = -1

for i in range(1,n):
    if a[i-1] >= a[i]:
        if p == -1:
            cnt_color += 1
            stack.append(a[i-1])
            p += 1
            max_color += 1
        else:
            if stack[-1] < a[i]:
                cnt_color -= 1
                stack.pop(-1)
                p -= 1
            else:
                cnt_color += 1
                stack.append(a[i-1])
                p += 1
                if cnt_color > max_color:
                    max_color = cnt_color

print(max_color)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = [0] * n

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

color = [a[0]]
color_min = a[0]

for i in range(1, n):
    if color_min >= a[i]:
        bisect.insort_left(color, a[i])
        color_min = a[i]
    else:
        j = bisect.bisect_left(color, a[i])
        color[j-1] = a[i]

print(len(color))

Submission status: Wrong Answer

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

count = 0
while a:
    l = len(a)
    min_a = min(a)
    min_list = [i for i, x in enumerate(a) if x == min_a]
    m = min_list[-1]
    for i in range(l-m+1):
        if l-i-1<0:
            break
        if a[l-i-1] >= min_a:
            del a[l-i-1]
    del[]
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque
import sys
#import bisect
sys.setrecursionlimit(10**6)
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

def bisect(ls,x):
    l,r=0,len(ls)-1
    while r-l>1:
        mid=(l+r)//2
        if ls[mid]>x: # condition
            l=mid
        else:
            r=mid
    #print('bisect',ls,x,'=',r)
    return r

n=I()
a=deque()
q=[[] for _ in range(n)]
m=0 # num of queue now
for i in range(n):
    a+=[I()]
#print('a=',a)

q=deque()
q.append(a.popleft())
#print(q,'q[',0,']=')

while a:
    c=a.popleft()
    if c<=q[0]:
        q.appendleft(c)
        #print(q,'q[',0,']=',c)
    else:
        i=bisect(q,c)
        q[i]=c
        #print(q,'q[',i,']=',c)


ans=len(q)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())

color = 0
minv = A[0]
minvs = [minv]
for i in range(N):
    if A[i] <= minv:
        minvs.append(A[i])
        minv = max(minvs)
        color += 1

print(color)