import bisect
class Solution(object):
    def maxEnvelopes(self, envelopes):
        """
        :type envelopes: List[List[int]]
        :rtype: int
        """
        envelopes.sort(key=lambda env : (env[0], -env[1]))
        inc_stack = [float("-inf")]
        seq_sizes = [0]
        for i, env in enumerate(envelopes):
            posi = bisect.bisect_left(inc_stack, env[1])
            if len(inc_stack) == posi:
                inc_stack.append(env[1])
                seq_sizes.append(seq_sizes[-1] + 1)
            else:
                inc_stack[posi] = env[1]
                seq_sizes[posi] = seq_sizes[posi - 1] + 1
        return max(seq_sizes)


6613435ae1699aa1317eecb978f5497d83cc24a3
<mask token>

<mask token>


class Solution(object):
    <mask token>

<mask token>


class Solution(object):

    def maxEnvelopes(self, envelopes):
        """
        :type envelopes: List[List[int]]
        :rtype: int
        """
        envelopes.sort(key=lambda env: (env[0], -env[1]))
        inc_stack = [float('-inf')]
        seq_sizes = [0]
        for i, env in enumerate(envelopes):
            posi = bisect.bisect_left(inc_stack, env[1])
            if len(inc_stack) == posi:
                inc_stack.append(env[1])
                seq_sizes.append(seq_sizes[-1] + 1)
            else:
                inc_stack[posi] = env[1]
                seq_sizes[posi] = seq_sizes[posi - 1] + 1
        return max(seq_sizes)

import bisect


class Solution(object):

    def maxEnvelopes(self, envelopes):
        """
        :type envelopes: List[List[int]]
        :rtype: int
        """
        envelopes.sort(key=lambda env: (env[0], -env[1]))
        inc_stack = [float('-inf')]
        seq_sizes = [0]
        for i, env in enumerate(envelopes):
            posi = bisect.bisect_left(inc_stack, env[1])
            if len(inc_stack) == posi:
                inc_stack.append(env[1])
                seq_sizes.append(seq_sizes[-1] + 1)
            else:
                inc_stack[posi] = env[1]
                seq_sizes[posi] = seq_sizes[posi - 1] + 1
        return max(seq_sizes)

import bisect
class Solution(object):
    def maxEnvelopes(self, envelopes):
        """
        :type envelopes: List[List[int]]
        :rtype: int
        """
        envelopes.sort(key=lambda env : (env[0], -env[1]))
        inc_stack = [float("-inf")]
        seq_sizes = [0]
        for i, env in enumerate(envelopes):
            posi = bisect.bisect_left(inc_stack, env[1])
            if len(inc_stack) == posi:
                inc_stack.append(env[1])
                seq_sizes.append(seq_sizes[-1] + 1)
            else:
                inc_stack[posi] = env[1]
                seq_sizes[posi] = seq_sizes[posi - 1] + 1
        return max(seq_sizes)

