CodeEff/ECCO huggingface dataset:
# Original solution
import sys

x = int(sys.stdin.readline())
n = x // 11
r = x % 11
if r == 0:
    print((2*n))
elif r <= 6:
    print((2*n + 1))
else:
    print((2 * (n+1)))

# Optimized solution
import sys

x = int(sys.stdin.readline())

n = x // 11
r = x % 11
if r == 0:
    print((2*n))
elif r <= 6:
    print((2*n+1))
else:
    print((2*n+2))
# Original solution
import math

x = int(eval(input()))
if 1 <= x%11 <= 6:
    print((math.ceil(x/11)*2 - 1))
else:
    print((math.ceil(x/11)*2))

# Optimized solution
n = int(eval(input()))
ans = n//11*2
if 0 < n%11 <= 6:
    ans += 1
elif 6 < n%11 <= 10:
    ans += 2

print(ans)
# Original solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

x = I()
q,r = x//11,x % 11
ans = 2*q
if 1 <= r <= 6:
    ans += 1
elif r >= 7:
    ans += 2
print(ans)


# Optimized solution
import sys
def I(): return int(sys.stdin.readline().rstrip())

x = I()-1
print((x//11*2+1+(x%11)//6))
# Original solution
def main():
    x = int(eval(input()))
    ans = x//11
    x -= ans*11
    ans *= 2
    if 0 < x <= 6:
        ans += 1
    elif 6 < x:
        ans += 2
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    x = int(eval(input()))
    ans = x // 11
    x -= ans * 11
    ans *= 2
    if x <= 0:
        print(ans)
    elif x <= 6:
        print((ans + 1))
    else:
        print((ans + 2))


if __name__ == '__main__':
    main()
# Original solution
x = int(eval(input()))
if 1 <=x%11 <= 6:
    print((x//11*2+1))
elif 7 <= x%11 <= 10:
    print((x//11*2+2))
else:
    print((x//11*2))

# Optimized solution
N = int(eval(input()))
if N%11 == 0:
    print((N//11*2))
elif 0 < N%11 <=6 :
    print((N//11*2+1))
else:
    print((N//11*2+2))
# Original solution
def main():
    x = int(eval(input()))
    s = 0
    f = 0
    ans = 0
    while ans < x:
        s += 1
        ans += 6
        if ans >= x:
            print((s+f))
            exit()
        f += 1
        ans += 5
        if ans >= x:
            print((s+f))
            exit()

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    x = int(eval(input()))
    ans = x//11
    chk = x%11
    if chk == 0:
        print((2*ans))
    elif chk <=6:
        print((2*ans+1))
    else:
        print((2*ans+2))

if __name__ == "__main__":
    main()
# Original solution
x = int(eval(input()))
n = x//11
k = x%11
if k==0:
    print((2*n))
elif 0<k<=6:
    print((2*n+1))
else:
    print((2*n+2))

# Optimized solution
x = int(eval(input()))
n = x//11
a = x%11
if a==0:
    ans = 2*n
elif 1<=a<=6:
    ans = 2*n+1
else:
    ans = 2*n+2
print(ans)
# Original solution
import sys
import math
input = sys.stdin.readline

n = int(eval(input()))
ans = math.ceil(n / 11 * 2)
if (n - 6) % 11 == 0:
    ans -= 1
print(ans)


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ans = n // 11 * 2
if 1 <= n % 11 <= 6:
    ans += 1
elif 7 <= n % 11 <= 10:
    ans += 2
print(ans)
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    x = int(input().rstrip('\n'))
    cnt = (x + 10) // 11 * 2
    if x % 11 <= 6 and x % 11 != 0:
        print((cnt-1))
    else:
        print(cnt)


if __name__ == '__main__':
    slove()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x = int(readline())
    cnt = x // 11 * 2
    x %= 11
    if x == 0:
        print(cnt)
    elif 1 <= x <= 6:
        print((cnt + 1))
    elif 7 <= x <= 10:
        print((cnt + 2))


if __name__ == '__main__':
    solve()
# Original solution
x = int(eval(input()))
nums = [i for i in range(6, 0, -1)]

if x % 11 == 0:
    ans = (x // 11) * 2
else:
    if x % 11 <= 6:
        ans = (x // 11) * 2 + 1
    else:
        ans = (x // 11 + 1) * 2
print(ans)


# Optimized solution
x = int(eval(input()))

if x % 11 == 0:
    ans = x // 11 * 2
else:
    if x % 11 <= 6:
        ans = x // 11 * 2 + 1
    else:
        ans = (x // 11 + 1) * 2

print(ans)
# Original solution
a = int(eval(input()))
count = 0
if a % 11 < 7 and a % 11 != 0:
    count += 1
elif a % 11 != 0:
    count += 2
count += (a // 11) * 2
print(count)


# Optimized solution
a = int(eval(input()))
x = (a // 11) * 2
if a % 11 > 6:
    x += 2
elif a % 11 > 0:
    x += 1
print(x)
# Original solution
x = int(eval(input()))

ans = (x // 11) * 2
ans += 1 if x % 11 > 6 else 0
ans += 1 if x % 11 > 0 else 0

print(ans)


# Optimized solution
x=int(eval(input()))
print(((x//11)*2 + (x%11) // 6 + (1 if x%11%6 else 0)))
# Original solution
N = int(eval(input()))

if N < 11:
    d, m = divmod(N, 6)
    print((d + (m>0)))
else:
    d, m = divmod(N, 11)
    a = (1 if m else 0) if m < 7 else 2
    print((d * 2 + a))

# Optimized solution
N = int(eval(input()))
d, m = divmod(N, 11)
a = (1 if m else 0) if m < 7 else 2
print((d * 2 + a))
# Original solution
x = int(eval(input()))
if x % 11 == 0:
    r = 0
elif x % 11 <= 6:
    r = 1
else:
    r = 2
ans = 2 * (x // 11) + r
print(ans)

# Optimized solution
x = int(eval(input()))

ans = 2*(x // 11)
x %= 11
if x == 0:
    pass
elif 0 < x <= 6:
    ans += 1
elif 6 < x <= 11:
    ans += 2
print(ans)
# Original solution
def resolve():
    x=int(eval(input()))
    q,mod=divmod(x,11)
    if mod==0:
        print((q*2))
    elif 1<=mod<=6:
        print(((q+1)*2-1))
    else:
        print(((q+1)*2))





resolve()


# Optimized solution
def resolve():

    x=int(eval(input()))
    p,mod=divmod(x,11)

    if mod==0:
        print((p*2))
    elif mod<=6:
        print(((p+1)*2-1))
    else:
        print(((p+1)*2))

resolve()
# Original solution
from collections import deque as D
line, stack = D(input().split()), D()
while line:
    hoge = line.popleft()
    if hoge.isdigit():
        stack.append(hoge)
    else:
        a, b = int(stack.pop()),int(stack.pop())
        if hoge =="*":
            stack.append(a*b)
        elif hoge == "+":
            stack.append(a+b)
        elif hoge == "-":
            stack.append(b-a)
        else:
            stack.append(b//a)
print((stack.popleft()))


# Optimized solution
s = list(input().split())
a = []
for x in s:
    if  x in  ['+', '-', '*']:
        c, b = str(a.pop()), str(a.pop())
        b+= x+c
        a+=[int(eval(b))]
    else:
        a+= [int(x)]
print((a.pop()))
# Original solution
# stack
exp = [i for i in input().split()]
s = []

for lt in exp:
    if lt == '+':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs + rhs)
    elif lt == '*':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs * rhs)
    elif lt == '-':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs - rhs)
    else:
        s.append(int(lt))
        
print((str(s[0])))

# Optimized solution
# stack
exp = input().split()
s = []

for lt in exp:
    if lt == '+':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs + rhs)
    elif lt == '*':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs * rhs)
    elif lt == '-':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs - rhs)
    else:
        s.append(int(lt))
        
print((str(s[0])))
# Original solution
inputEnzan=input().split()

def keisan(inputEnzan):
    while True:
        stockFornumber=[]
        index=0
        length=len(inputEnzan)
        if length==1:
            break
        while index<length:
            if inputEnzan[index]=="+" or inputEnzan[index]=="-" or inputEnzan[index]=="*":
                if len(stockFornumber)==2:
                    if inputEnzan[index]=="+":
                        inputEnzan[index]=stockFornumber[0]+stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"

                    elif inputEnzan[index]=="-":
                        inputEnzan[index]=stockFornumber[0]-stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"

                    else:
                        inputEnzan[index]=stockFornumber[0]*stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"
                else:
                    pass

            else:
                stockFornumber.append(int(inputEnzan[index]))
            index+=1

        while "null" in inputEnzan:
            inputEnzan.remove("null")

    print((inputEnzan[0]))

keisan(inputEnzan)     



# Optimized solution
inputEnzan=input().split()

def keisan(inputEnzan):
    while True:
        stockFornumber=[]
        index=0
        length=len(inputEnzan)
        if length==1:
            break
        while index<length:
            if inputEnzan[index]=="+" or inputEnzan[index]=="-" or inputEnzan[index]=="*":
                if len(stockFornumber)==2:
                    if inputEnzan[index]=="+":
                        inputEnzan[index]=stockFornumber[0]+stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"

                    elif inputEnzan[index]=="-":
                        inputEnzan[index]=stockFornumber[0]-stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"

                    else:
                        inputEnzan[index]=stockFornumber[0]*stockFornumber[1]
                        stockFornumber=[]
                        inputEnzan[index-1]="null"
                        inputEnzan[index-2]="null"
                else:
                    stockFornumber=[]
                    pass

            else:
                if len(stockFornumber)==2:
                    del stockFornumber[0]
                stockFornumber.append(int(inputEnzan[index]))
                    
            index+=1

        while "null" in inputEnzan:
            inputEnzan.remove("null")

    print((inputEnzan[0]))

keisan(inputEnzan)
# Original solution
Sum = input().split()

def mak(che) :
    if Sum[che] == '+' : 
        Sum.insert((che - 2), (int(Sum.pop(che - 2)) + int(Sum.pop(che - 2))))
        del Sum[che - 1]
    elif Sum[che] == '-' :
        Sum.insert((che - 2), (int(Sum.pop(che - 2)) - int(Sum.pop(che - 2))))
        del Sum[che - 1]
    elif Sum[che] == '*' : 
        Sum.insert((che - 2), (int(Sum.pop(che - 2)) * int(Sum.pop(che - 2))))
        del Sum[che - 1]
    

while ('+' in Sum) or ('-' in Sum) or ('*' in Sum) :
    for che in 2, 3 :
        mak(che)
        if len(Sum) == 3 : break
        if ('+' not in Sum) and ('-' not in Sum) and ('*' not in Sum) : break
    
print((Sum[0]))

# Optimized solution
Sum = input().split()
cou = 1
while len(Sum) != 1 :
    cou += 1
    if Sum[cou] == '+' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) + int(Sum.pop(cou - 2)))
        cou -= 2
    elif Sum[cou] == '-' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) - int(Sum.pop(cou - 2)))
        cou -= 2
    elif Sum[cou] == '*' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) * int(Sum.pop(cou - 2)))
        cou -= 2

print((Sum[0]))
# Original solution
x = input().split()
A = []
for i in x:
    try:
        A.append(int(i))
    except:
        b = A.pop()
        a = A.pop()
        if i == '+':
            A.append(a + b)
        if i == '-':
            A.append(a - b)
        if i == '*':
            A.append(a * b)
print((A.pop()))

# Optimized solution
inList = input().split()
stack = []
for i in inList:
    if i in ['+', '-', '*']:
        b, a = stack.pop(), stack.pop()
        if i == '+':
            stack.append(b + a)
        if i == '-':
            stack.append(a - b)
        if i == '*':
            stack.append(b * a)
    else:
        stack.append(int(i))
print((stack.pop()))
# Original solution
import sys
sys.setrecursionlimit(10**9)

def build(t,arr,v,tl,tr):
    if tl == tr:
        t[v] = arr[tl]
    else:
        tm = (tl+tr)//2
        build(t,arr,2*v,tl,tm)
        build(t,arr,2*v+1,tm+1,tr)
        t[v] = max(t[2*v],t[2*v+1])

def maxQuery(t,v,tl,tr,l,r):
    if l > r:
        return 0
    if l == tl and r == tr:
        return t[v]
    tm = (tl+tr)//2
    return max(maxQuery(t,2*v,tl,tm,l,min(r,tm)),maxQuery(t,2*v+1,tm+1,tr,max(l,tm+1),r))

def update(t,v,tl,tr,pos,new_val):
    if tl == tr:
        t[v] = new_val
    else:
        tm = (tl+tr)//2
        if pos <= tm:
            update(t,2*v,tl,tm,pos,new_val)
        else:
            update(t,2*v+1,tm+1,tr,pos,new_val)
        t[v] = max(t[2*v],t[2*v+1])

def create(n,arr):
    t = [0]*4*n
    build(t,arr,1,0,n-1)

    return t
    

def main():
    n = int(eval(input()))
    hts = list(map(int,input().split()))
    beauties = list(map(int,input().split()))
    flowers = {}
    for i in range(n):
        flowers[hts[i]] = beauties[i]

    dp = [0]*n
    t = create(n,dp)
    for i in range(n-1,-1,-1):
        curr = hts[i]
        max_val = maxQuery(t,1,0,n-1,curr-1,n-1)
        dp[curr-1] += flowers[curr]+max_val
        update(t,1,0,n-1,curr-1,dp[curr-1])
        #print(t)

    print((max(t)))


main()


# Optimized solution
import sys
sys.setrecursionlimit(10**9)

def build(t,arr,v,tl,tr):
    if tl == tr:
        t[v] = arr[tl]
    else:
        tm = (tl+tr)//2
        build(t,arr,2*v,tl,tm)
        build(t,arr,2*v+1,tm+1,tr)
        t[v] = max(t[2*v],t[2*v+1])

def maxQuery(t,v,tl,tr,l,r):
    if l > r:
        return 0
    if l == tl and r == tr:
        return t[v]
    tm = (tl+tr)//2
    return max(maxQuery(t,2*v,tl,tm,l,min(r,tm)),maxQuery(t,2*v+1,tm+1,tr,max(l,tm+1),r))

def update(t,v,tl,tr,pos,new_val):
    if tl == tr:
        t[v] = new_val
    else:
        tm = (tl+tr)//2
        if pos <= tm:
            update(t,2*v,tl,tm,pos,new_val)
        else:
            update(t,2*v+1,tm+1,tr,pos,new_val)
        t[v] = max(t[2*v],t[2*v+1])

def create(n,arr):
    t = [0]*4*n
    build(t,arr,1,0,n-1)

    return t
    

def main():
    n = int(input())
    hts = list(map(int,input().split()))
    beauties = list(map(int,input().split()))
    flowers = {}
    for i in range(n):
        flowers[hts[i]] = beauties[i]

    dp = [0]*n
    t = create(n,dp)
    for i in range(n-1,-1,-1):
        curr = hts[i]
        max_val = maxQuery(t,1,0,n-1,curr-1,n-1)
        dp[curr-1] += flowers[curr]+max_val
        update(t,1,0,n-1,curr-1,dp[curr-1])
        #print(t)

    print((max(t)))


main()
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
H = list(map(int,readline().split()))
A = list(map(int,readline().split()))

"""
・最後の高さ -> 価値の総和
・BITでmaxを管理
"""

class BIT():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        
    def __repr__(self):
        return self.tree.__repr__()
        
    def get_max(self,i):
        s = 0
        while i:
            t = self.tree[i]
            if s<t:
                s=t
            i -= i & -i
        return s
 
    def update(self, i, x):
        while i < self.size:
            if self.tree[i] < x:
                self.tree[i] = x
            i += i & -i

bit = BIT(N)

for i,(a,h) in enumerate(zip(A,H),1):
    x = bit.get_max(h)
    bit.update(h,x+a)

answer = bit.get_max(N)
print(answer)

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
H = list(map(int,readline().split()))
A = list(map(int,readline().split()))

"""
・最後の高さ -> 価値の総和
・BITでmaxを管理
"""

class BIT():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        
    def __repr__(self):
        return self.tree.__repr__()
        
    def get_max(self,i):
        s = 0
        while i:
            t = self.tree[i]
            if s<t:
                s=t
            i -= i & -i
        return s
 
    def update(self, i, x):
        while i < self.size:
            if self.tree[i] >= x:
                return
            self.tree[i] = x
            i += i & -i

bit = BIT(N)

for i,(a,h) in enumerate(zip(A,H),1):
    x = bit.get_max(h)
    bit.update(h,x+a)

answer = bit.get_max(N)
print(answer)
# Original solution

import sys
input = sys.stdin.readline
#区間の管理は　[a, b)で管理していることに注意

# INT_MIN = -10 ** 18
# MAX_N = 4 * 10 ** 5
# MAX_N = 20


# def init(n_):
#     #簡単にするために2のべき乗に揃える
#     n = 1
#     while n <= n_:
#         n *= 2
#     return n

#初期化
N = int(eval(input()))
# n = 1
# while n <= N:
#     n *= 2

n = 262144
data = [0] * (2 * n - 1)

def update(k, a):
    k = k + n - 1
    # data[k] = a
    while k >= 0:
        data[k] = max(a, data[k])
        k = (k - 1) // 2
        # data[k] = max(data[2 * k + 1], data[2 * k + 2])

def query(a, b, k, l, r):
    if r <= a or b <= l:
        return 0
    elif a <= l and r <= b:
        return data[k]
    else:
        return max(query(a, b, 2 * k + 1, l, (l + r)//2), query(a, b, 2 * k + 2, (l + r)//2, r))

H = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))

# ans = 0

dp = [A[0]] + [0] * (N - 1)
update(H[0] - 1, A[0])
for i in range(1, N):
    # h = int(input())
    # a = int(input())
    dp[i] = query(0, H[i] - 1, 0, 0, n) + A[i]
    # h = H[i]
    # a = A[i]
    # tmp = query(1, h + 1) #[1, h)での最大値
    # print (h, tmp)
    update(H[i] - 1, dp[i])
    # ans = max(ans, tmp + a)
    # print (data)

print((query(0, N, 0, 0, n)))

# Optimized solution
def main():
    import sys
    input = sys.stdin.readline
    #区間の管理は　[a, b)で管理していることに注意

    # INT_MIN = -10 ** 18
    # MAX_N = 4 * 10 ** 5
    # MAX_N = 20


    # def init(n_):
    #     #簡単にするために2のべき乗に揃える
    #     n = 1
    #     while n <= n_:
    #         n *= 2
    #     return n

    #初期化
    N = int(eval(input()))
    # n = 1
    # while n <= N:
    #     n *= 2

    n = 262144
    data = [0] * (2 * n - 1)

    def update(k, a):
        k = k + n - 1
        # data[k] = a
        while k >= 0:
            data[k] = max(a, data[k])
            k = (k - 1) // 2
            # data[k] = max(data[2 * k + 1], data[2 * k + 2])

    def query(a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        elif a <= l and r <= b:
            return data[k]
        else:
            return max(query(a, b, 2 * k + 1, l, (l + r)//2), query(a, b, 2 * k + 2, (l + r)//2, r))

    H = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))

    # ans = 0

    dp = [A[0]] + [0] * (N - 1)
    update(H[0] - 1, A[0])
    for i in range(1, N):
        # h = int(input())
        # a = int(input())
        dp[i] = query(0, H[i] - 1, 0, 0, n) + A[i]
        # h = H[i]
        # a = A[i]
        # tmp = query(1, h + 1) #[1, h)での最大値
        # print (h, tmp)
        update(H[i] - 1, dp[i])
        # ans = max(ans, tmp + a)
        # print (data)

    print((query(0, N, 0, 0, n)))

if __name__ == '__main__':
    main()
# Original solution
class Max_Bit:
    """区間の最大値のＢＩＴ

    viの更新をする。
    v1からｖiまでの最大値を取得する。
    どちらもO(logn)時間にできる

    Attributes:
        size (int): BITのサイズ
        tree (list of int): 区間の最大値を管理するための二分木
    """
    def __init__(self, n):
        """
        Args:
            n(int): BITのサイズ
        """
        self.size = n
        self.tree = [0] * (n + 1)

    def get_max(self, i=None):
        if i is None:
            i = self.size
        m = -(10 ** 18)  # -INF
        while i > 0:
            m = max(m, self.tree[i])
            i -= i & -i
        return m

    def update(self, i, x):
        while i <= self.size:
            self.tree[i] = max(x, self.tree[i])
            i += i & -i

N = int(eval(input()))
H = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = Max_Bit(N)
for i in range(N):
    dp.update(i+1,A[i])
for i in range(2,N + 1):
    mask = []
    for j in range(1, i):
        if H[i-1] >= H[j-1]:
            mask.append(j)
    if mask:
        dp.update(i, max([dp.tree[k] for k in mask]) + A[i-1])
print((dp.get_max()))

# Optimized solution
class Max_Bit:
    """区間の最大値のＢＩＴ

    viの更新をする。
    v1からｖiまでの最大値を取得する。
    どちらもO(logn)時間にできる

    Attributes:
        size (int): BITのサイズ
        tree (list of int): 区間の最大値を管理するための二分木
    """
    def __init__(self, n):
        """
        Args:
            n(int): BITのサイズ
        """
        self.size = n
        self.tree = [0] * (n + 1)

    def get_max(self, i=None):
        if i is None:
            i = self.size
        m = 0  # -INF
        while i > 0:
            m = max(m, self.tree[i])
            i -= i & -i
        return m

    def update(self, i, x):
        while i <= self.size:
            self.tree[i] = max(x, self.tree[i])
            i += i & -i
def main():
    """
    dp: 花iを使うとした場合の1からiまでつかった美しさの最大値
    短い花から更新する

    """
    N = int(eval(input()))
    H = list(map(int, input().split()))
    A = list(map(int, input().split()))
    dp = Max_Bit(N)
    sort_H_i = sorted((h, i) for i, h in enumerate(H))
    for h, i in sort_H_i:
        dp.update(i+1,dp.get_max(i) + A[i])
    print((dp.get_max()))

if __name__ == '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline
n = int(eval(input()))
h = tuple([int(x)-1 for x in input().split()])
a = tuple(map(int,input().split()))

#update(i,x):Aiをxに更新する
def update(i,x):
    k = i + num - 1
    while k >= 0:
        seg[k] = max(x,seg[k])
        k = (k-1)//2

#query(a,b,0,0,num):[a,b)の最大値
def query(a,b,k,l,r):
    if r <= a or b <= l:
        return -float("inf")
    elif a <= l and r <= b:
        return seg[k]
    else:
        return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r))

#初期化
#num : nより大きい最小の2のべき乗
num = 1
while num <= n:
    num *= 2
seg = [0]*(2*num-1)

#dp[i]:i番目が最後となる時の美しさの最大値
dp = [a[0]] + [0]*(n-1)
update(h[0],a[0])
for i in range(1,n):
    dp[i] = max(0,query(0,h[i],0,0,num))+a[i]
    update(h[i],dp[i])

print((max(dp)))


# Optimized solution
import sys
input = sys.stdin.readline

n = int(eval(input())) + 1
h = list(map(int,input().split()))
a = list(map(int,input().split()))

def init_max(init_max_val):
    #set_val
    for i in range(n):
        seg_max[i+num_max-1]=init_max_val[i]    
    #built
    for i in range(num_max-2,-1,-1) :
        seg_max[i]=max(seg_max[2*i+1],seg_max[2*i+2]) 
    
def update_max(k,x):
    k += num_max-1
    seg_max[k] = x
    while k:
        k = (k-1)//2
        seg_max[k] = max(seg_max[k*2+1],seg_max[k*2+2])
    
def query_max(p,q):
    if q<=p:
        return ide_ele_max
    p += num_max-1
    q += num_max-2
    res=ide_ele_max
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg_max[p])
        if q&1 == 1:
            res = max(res,seg_max[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg_max[p])
    else:
        res = max(max(res,seg_max[p]),seg_max[q])
    return res

#####単位元######
ide_ele_max = 0

#num_max:n以上の最小の2のべき乗
num_max =2**(n-1).bit_length()
seg_max=[ide_ele_max]*2*num_max


#dp[i] : 最後の花の高さがiの時の最大値

dp = [0]*n

for i in range(n-1):
    tmp = query_max(0,h[i]) + a[i]
    if tmp + a[i] > dp[h[i]]:
        dp[h[i]] = tmp
        update_max(h[i],tmp)

print((query_max(0,n)))