CodeEff/ECCO huggingface dataset:
# Original solution
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from collections import Counter

n,k = li()
a = li()
a = [ai for ai in a if ai <= k]
a.sort()

cnt = Counter(a)
ans = 0

for ai in a:
    ai_pass = True

    a_wo_ai = [aj for aj in a]
    a_wo_ai.remove(ai)
    
    dp = [[0 for _ in range(k)] for _ in range(len(a_wo_ai)+1)]
    dp[0][0] = 1
    
    
    for i, aj in enumerate(a_wo_ai):        
        for sm in range(k):
            dp[i+1][sm] += dp[i][sm]
            if sm-aj >= 0:
                dp[i+1][sm] += dp[i][sm-aj]
                
    if sum(dp[len(a_wo_ai)][k-ai:]) == 0:
        ans += 1
            

        
print(ans)

# Optimized solution
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from collections import Counter

n,k = li()
a = li()
a = [ai for ai in a if ai <= k]
a.sort()

cnt = Counter(a)
ans = 0

left = 0
right = len(a)+1

while right - left > 1:
    mid = (right+left) // 2
    ai = a[mid-1]
    ai_pass = True

    a_wo_ai = [aj for aj in a]
    a_wo_ai.remove(ai)
    
    dp = [[0 for _ in range(k)] for _ in range(len(a_wo_ai)+1)]
    dp[0][0] = 1
    
    
    for i, aj in enumerate(a_wo_ai):        
        for sm in range(k):
            dp[i+1][sm] += dp[i][sm]
            if sm-aj >= 0:
                dp[i+1][sm] += dp[i][sm-aj]
                
    if sum(dp[len(a_wo_ai)][k-ai:]) == 0:
        left = mid
    else:
        right = mid
        
            
print(left)
# Original solution
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from copy import deepcopy
 
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
    s += a
    S.append(s)

A = A[::-1]
DP = [False for _ in range(K)]
DP[0] = 1
OK = [False for _ in range(N)]
 
for i, a in enumerate(A):
    DP0 = deepcopy(DP)
    if a >= K:
        OK[i] = True
        continue
    for j, d in enumerate(DP0[-S[::-1][i]:], max(0, K-S[::-1][i])):
        if d:
            if j + a >= K:
                OK[i] = True
                break
            else:
                DP[j+a] = True
 
if sum(OK) == 0:
    print(N)
else:
    print((OK[::-1].index(True)))

# Optimized solution
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
 
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
    s += a
    S.append(s)

A = A[::-1]
DP = [True]+[False for _ in range(K-1)]

OK = [False for _ in range(N)]
 
for i, a in enumerate(A):
    DP1 = [False] * K
    if a >= K:
        OK[i] = True
        continue
    for j, d in enumerate(DP[-S[::-1][i]:], max(0, K-S[::-1][i])):
        if d:
            DP1[j] = True
            if j + a >= K:
                OK[i] = True
                break
            else:
                DP1[j+a] = True
    DP = DP1 
if sum(OK) == 0:
    print(N)
else:
    print((OK[::-1].index(True)))
# Original solution
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
 
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
    s += a
    S.append(s)

A = A[::-1]
DP = [True]+[False for _ in range(K-1)]

OK = [False for _ in range(N)]
 
for i, a in enumerate(A):
    DP1 = [False] * K
    if a >= K:
        OK[i] = True
        continue
    for j, d in enumerate(DP[-S[::-1][i]:], max(0, K-S[::-1][i])):
        if d:
            DP1[j] = True
            if j + a >= K:
                OK[i] = True
                break
            else:
                DP1[j+a] = True
    DP = DP1 
if sum(OK) == 0:
    print(N)
else:
    print((OK[::-1].index(True)))

# Optimized solution
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
 
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
    s += a
    S.append(s)

A = A[::-1]
DP = [True]+[False for _ in range(K-1)]

OK = [False for _ in range(N)]
 
for i, a in enumerate(A):
    DP1 = [False for _ in range(K)]
    if a >= K:
        OK[i] = True
        continue
    for j, d in enumerate(DP):
        if d:
            DP1[j] = True
            if j + a >= K:
                OK[i] = True
            else:
                DP1[j+a] = True
    DP = DP1

if sum(OK) == 0:
    print(N)
else:
    print((OK[::-1].index(True)))
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

dp = [[0]*(k + 1) for i in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    for j in range(k+1):
        if j - a[i] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = dp[i][j] + dp[i][j - a[i]]
dp = dp[n]

ans = 0
for i in range(n):
    tmp = dp[0:]
    if a[i] > k:
        continue
    for j in range(a[i], k + 1):
        tmp[j] = dp[j] - tmp[j - a[i]]
    if max(tmp[k-a[i]:k]) <= 0:
        ans += 1
print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [0] + sorted(a) + [k]

def subset_sum(mid):
    if a[mid] > k:
        return False

    li = a[0:mid] + a[mid+1:]
    n = len(li)
    dp = [False]*(k + 1)
    dp[0] = True    
    for i in range(n):
        for j in range(k+1)[::-1]:
            if j - li[i] < 0:
                break
            else:
                dp[j] = dp[j] or dp[j - li[i]]

    if not any(dp[k-a[mid]:k]):
        return True
    else:
        return False
  
ok = 0
ng = n+2
while abs(ng - ok) > 1:
    mid = (ok + ng) // 2
    if subset_sum(mid):
        ok = mid
    else:
        ng = mid
print(ok)
# Original solution

N,K = list(map(int,input().split()))

a = list(map(int,input().split()))

ans = [False] * N
able = [False] * (2*K+1)
able[0] = True
lis = [ [False] * N for i in range(2*K+1) ]

for i,na in enumerate(a):

    if na >= K:
        ans[i] = True
        continue

    nable = able.copy()

    for j in range(K):

        if able[j]:

            for nown in range(N):

                if not lis[j+na][nown] and lis[j][nown]:
                    lis[j + na][nown] = True

            lis[j+na][i] = True
            nable[j+na] = True

    able = nable

for i,na in enumerate(a):

    if na < K:

        for j in range(K,K+na,1):

            if lis[j][i]:
                ans[i] = True

#print (able)
r = N
for i in ans:
    if i:
        r -= 1

print (r)
        
    


# Optimized solution

N,K = list(map(int,input().split()))

a = list(map(int,input().split()))
ans = N

q = 0

a.sort()
a.reverse()
nmax = 0

for i in range(N):

    q += 1
    
    if nmax + a[i] >= K:
        ans -= q
        q = 0

    else:
        nmax = nmax + a[i]

print (ans)
# Original solution
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k,*a = list(map(int,read().split()))

a = [i for i in a if i<k]
n = len(a)


mask = (1<<k)-1

dpl = [1]
dp = 1
for i in a:
    dp |= dp<<i
    dp &= mask
    dpl.append(dp)

dpr = [1]
dp = 1
for i in a[::-1]:
    dp |= dp<<i
    dp &= mask
    dpr.append(dp)


ans = 0
for i in range(n):
    l = dpl[i]
    r = dpr[n-1-i]
    #print(bin(l),bin(r))
    mask = ((1<<a[i])-1)<<(k-a[i])
    #print(bin(mask))
    for j in range(k):
        if l>>j&1 and r&mask:
            break
        mask >>= 1
    else:
        #print(i)
        ans += 1


print(ans)



# Optimized solution
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k,*a = list(map(int,read().split()))

a = [i for i in a if i<k]
n = len(a)

a.sort(reverse=True)

K = 2*k+1
mask = (1<<K)-1

dpl = [1]
dp = 1
for i in a:
    dp |= (dp<<i)&mask
    dpl.append(dp)

#print(dpl)
for i in range(n):
    x = dpl[n-1-i]<<a[n-1-i]
    mask = ((1<<a[n-1-i])-1)<<(k)
    #print(bin(x)[::-1])
    #print(bin(mask)[::-1])
    if x&mask:
        print(i)
        break
else: print(n)
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
dpm = [[0]*(K+1) for _ in range(N+1)]
dpm[0][0] = 1
for i, a in enumerate(A):
    for j in range(K, -1, -1):
        dpm[i+1][j] = dpm[i][max(0, j-a)] + dpm[i][j]

r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
    for j in range(K, -1, -1):
        # 後ろiこの合計がjのもの
        if dp2&(1<<j) and dpm[N-i-1][max(0, K-j-a)] > dpm[N-i-1][K-j]:
            # K-j > x >= K-j-a
            break
    else:
        r += 1
    dp2 |= dp2<<a
    dp2 &= (1<<(K+1))-1
print(r)


# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
#dpm = [+1) for _ in range(N+1)]
dpm = [0]*(N+1)
dpm[0] = 1<<(K-1)
for i, a in enumerate(A):
    dpm[i+1] = dpm[i] | (dpm[i] >> a)

#print(bin(dpm[-1]))
r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
#    print(bin(dpm[N-i-1]))
    tmp = dpm[N-i-1]
    for j in range(1, a):
        tmp |= tmp>>1
#    print(bin(tmp), bin(dp2), len(bin(tmp)))
    if not dp2&tmp:
#        print("aa")
        r += 1
#    for j in range(K, -1, -1):
        # 後ろiこの合計がjのもの
#        if dp2&(1<<j) and dpm[N-i-1][max(0, K-j-a)] > dpm[N-i-1][K-j]:
            # K-j > x >= K-j-a
#            break
#    else:
#        r += 1
    dp2 |= dp2<<a
    dp2 &= (1<<K)-1
print(r)
# Original solution
while True:
    a, l = list(map(int, input().split()))
    if((a|l) == 0): break
    dic = {}
    cnt = 0
    dic[a] = cnt
    while True:
        cnt+=1
        Sa = str(a)
        Sa = [ x for x in list(Sa) if x is not '0']
        if len(Sa) is 0: Sa.append('0')
        Sa.sort()
        S = int("".join(Sa))
        La = [x for x in Sa]
        La.reverse()
        while len(La) < l: La.append('0')
        L = int("".join(La))
        a = L - S
        if a in dic:
            print(dic[a], a, cnt - dic[a])
            break
        else:
            dic[a] = cnt

# Optimized solution
while True:
    a, l = list(map(int, input().split()))
    if((a|l) == 0): break
    dic = {}
    cnt = 0
    dic[a] = cnt
    while True:
        cnt+=1
        La = list(str(a).zfill(l))
        La.sort()
        a = int(''.join(La[::-1])) - int(''.join(La))
        if a in dic:
            print(dic[a], a, cnt-dic[a])
            break
        else:
            dic[a] = cnt
# Original solution
N = int(eval(input()))
s = [0]*N
l = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    s[i] = (a, b)
 
for i in range(N):
    c, d = list(map(int, input().split()))
    l[i] = (c, d)




V = N*2 # 頂点数
MAX_V = V
G = [0]*MAX_V # グラフの隣接リスト表現
for i in range(MAX_V):
    G[i] = []
match = [0]*MAX_V # マッチングのペア
used = [False]*MAX_V # DFSで既に調べたかのフラグ

# uとvを結ぶ辺をグラフに追加する
def addEdge(u, v):
    G[u].append(v)
    G[v].append(u)

##
for a in range(N):
    (rx, ry) = s[a]
    for b in range(N):
        (bx, by) = l[b]
        if rx < bx and ry < by:
            addEdge(a, b+N)


# 増加パスをDFSで探す
def dfs(v):
    used[v] = True
    for i in range(len(G[v])):
        u = G[v][i]
        w = match[u]
        if w < 0 or (not used[w]) and dfs(w):
            match[v] = u
            match[u] = v
            return True
    return False

# 二部グラフの最大マッチングを求める
def bipartiteMatching():
    res = 0
    for i in range(len(match)):
        match[i] = -1
    for v in range(V):
        if match[v] < 0:
            for i in range(len(used)):
                used[i] = False
            if dfs(v):
                res += 1
    return res


#print(G)
#print(match)
print((bipartiteMatching()))



# Optimized solution
N = int(eval(input()))
s = [0]*N
l = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    s[i] = (a, b)
 
for i in range(N):
    c, d = list(map(int, input().split()))
    l[i] = (c, d)




V = N*2 # 頂点数
MAX_V = V

G = [0]*MAX_V # グラフの隣接リスト表現
for i in range(MAX_V):
    G[i] = []
match = [0]*MAX_V # マッチングのペア
used = [False]*MAX_V # DFSで既に調べたかのフラグ

# uとvを結ぶ辺をグラフに追加する
def addEdge(u, v):
    G[u].append(v)
    G[v].append(u)


##
for a in range(N):
    (rx, ry) = s[a]
    for b in range(N):
        (bx, by) = l[b]
        if rx < bx and ry < by:
            addEdge(a, b+N)


# 増加パスをDFSで探す
def dfs(v):
    used[v] = True
    for i in range(len(G[v])):
        u = G[v][i]
        w = match[u]
        if w < 0 or not used[w] and dfs(w):
            match[v] = u
            match[u] = v
            return True
    return False

# 二部グラフの最大マッチングを求める
def bipartiteMatching():
    res = 0
    for i in range(len(match)):
        match[i] = -1
    for v in range(V):
        if match[v] < 0:
            for i in range(len(used)):
                used[i] = False
            if dfs(v):
                res += 1
    return res

print((bipartiteMatching()))
# Original solution
n = int(eval(input()))
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))

ab |= {(-1, -1)}
for c, d in cd:
    tmp = max((b, a) for a, b in ab if (a < c and b < d))[::-1]
    if tmp != (-1, -1):
        ab.remove(tmp)
print((n - (len(ab) - 1)))


# Optimized solution
n = int(eval(input()))
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))

ab |= {(-1, -1)}
for c, d in cd:
    tmp = max((b, a) for a, b in ab if (a < c and b < d))
    if tmp != (-1, -1):
        ab.remove(tmp[::-1])
print((n - (len(ab) - 1)))
# Original solution
n = int(eval(input()))
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))
ab |= {(-1, -1)}

ans = 0
for c, d in cd:
    tmp = max((b, a) for a, b in ab if (a < c and b < d))
    if tmp != (-1, -1):
        ab.remove(tmp[::-1])
        ans += 1
print((n - (len(ab) - 1)))


# Optimized solution
n = int(eval(input()))
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))
ab |= {(-1, -1)}

ans = 0
for c, d in cd:
    tmp = max((b, a) for a, b in ab if (a < c and b < d))
    if tmp != (-1, -1):
        ab.remove(tmp[::-1])
        ans += 1
print(ans)
# Original solution
N = int(eval(input()))
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]

dp = {}


def check(v, p):
    return p & (1 << v)


def visit(v, p):
    return p ^ (1 << v)


def count(p):
    return bin(p).count('1')


def solve(i, p):
    if i == N:
        return count(p)

    k = (i, p)
    if k in dp:
        return dp[k]

    a, b = R[i]
    # ペアにならなかった
    m = solve(i+1, p)
    for j, (c, d) in enumerate(B):
        # すでにペアを持つ要素は無視
        if check(j, p):
            continue
        # ペアになった
        if a < c and b < d:
            m = max(m, solve(i+1, visit(j, p)))
    dp[k] = m
    return m


print((solve(0, 0)))


# Optimized solution
N = int(eval(input()))
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]


R.sort(reverse=True, key=lambda k: k[1])
B.sort()

p = []
q = []
for c, d in B:
    for a, b in R:
        if (a, b) in p:
            continue
        if a < c and b < d:
            p.append((a, b))
            q.append((c, d))
            break

print((len(p)))
# Original solution
N=int(eval(input()))
a=[0 for i in range(N)]
b=[0 for i in range(N)]
c=[0 for i in range(N)]
d=[0 for i in range(N)]
for i in range(N):
    a[i], b[i] = list(map(int, input().split()))
for i in range(N):
    c[i], d[i] = list(map(int, input().split()))
m=[[0 for i in range(N)] for i in range(N)]
s=[set() for i in range(N)]
for i in range(N):
    for j in range(N):
        if a[i]<c[j] and b[i]<d[j]:
            m[i][j]+=1
            s[i].add(j)
ans=0
import itertools
q=list(itertools.permutations(list(range(N))))
for sg in q:
    z=0
    for i in range(N):
        z+=m[i][sg[i]]
    if ans<z:
        ans=z
print(ans)


# Optimized solution
N=int(eval(input()))
r=[(0,0) for i in range(N)]
b=[(0,0) for i in range(N)]

for i in range(N):
    x,y=list(map(int,input().split()))
    r[i]=(x,y)
for i in range(N):
    x,y=list(map(int,input().split()))
    b[i]=(x,y)
b.sort()
ru=[0 for i in range(N)]
ans=0
for i in range(N):
    k=-1
    for j in range(N):
        if b[i][0]>r[j][0] and b[i][1]>r[j][1]:
            if k==-1 and ru[j]==0:
                k=j
            elif r[k][1]<r[j][1] and ru[j]==0:
                k=j
    if k!=-1:
        ru[k]=1
        ans+=1
print(ans)
# Original solution
#!python3

INF = 10 ** 15


# input
N = int(eval(input()))
a, b, c, d = [None] * N, [None] * N, [None] * N, [None] * N
for i in range(N):
    a[i], b[i] = list(map(int, input().split()))
for i in range(N):
    c[i], d[i] = list(map(int, input().split()))


class MaxFlow():

    def __init__(self, n):
        self.n = n
        self.c = [[0] * n for _ in range(n)]
        self.visit = [False] * n
        self.link = [set() for _ in range(n)]

    def add_link(self, x, y, capa):
        self.c[x][y] += capa
        self.link[x].add(y)
    
    def solve(self, t, v, f):
        if v == t:
            return f
        self.visit[v] = True
        
        w = 0
        
        for i in self.link[v]:
            if self.visit[i] or self.c[v][i] == 0:
                continue
            d = self.solve(t, i, min(f - w, self.c[v][i]))
            if d > 0:
                self.c[v][i] -= d
                self.c[i][v] += d
                self.link[i].add(v)
                w += d
                if w == f:
                    break
        
        self.visit[v] = False
        return w
        

def main():
    w = MaxFlow(2 * N + 2)
    for i in range(N):
        w.add_link(0, i + 1, 1)
        w.add_link(N + i + 1, 2 * N + 1, 1)
        for j in range(N):
            if a[i] < c[j] and b[i] < d[j]:
                w.add_link(i + 1, N + j + 1, 1)
    
    ans = w.solve(2 * N + 1, 0, INF)
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
#!python3

INF = 10 ** 15


# input
N = int(eval(input()))
a, b, c, d = [None] * N, [None] * N, [None] * N, [None] * N
for i in range(N):
    a[i], b[i] = list(map(int, input().split()))
for i in range(N):
    c[i], d[i] = list(map(int, input().split()))


class MaxFlow():

    def __init__(self, n):
        self.n = n
        self.c = [[0] * n for _ in range(n)]
        self.visit = [False] * n

    def add_link(self, x, y, capa):
        self.c[x][y] += capa
    
    def dfs(self, v, t, f):
        if v == t:
            return f
        self.visit[v] = True
        
        for i in range(self.n):
            if self.visit[i] or self.c[v][i] == 0:
                continue
            d = self.dfs(i, t, min(f, self.c[v][i]))
            if d > 0:
                self.c[v][i] -= d
                self.c[i][v] += d
                return d
                
        return 0

    
    def max_flow(self, s, t):
        ans = 0
        while True:
            f = self.dfs(s, t, INF)
            self.visit = [False] * self.n
            if f == 0:
                return ans
            else:
                ans += f
        

def main():
    w = MaxFlow(2 * N + 2)
    for i in range(N):
        w.add_link(0, i + 1, 1)
        w.add_link(N + i + 1, 2 * N + 1, 1)
        for j in range(N):
            if a[i] < c[j] and b[i] < d[j]:
                w.add_link(i + 1, N + j + 1, 1)
    
    ans = w.max_flow(0, 2 * N + 1)
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
N=int(eval(input()))
RED=[tuple(map(int, input().split())) for _ in range(N)]
BLUE=[tuple(map(int, input().split())) for _ in range(N)]

RED.sort(key=lambda x:x[1], reverse=True)
BLUE.sort(key=lambda x:x[0])

ans=0
r_used=[False]*N
for b in BLUE:
    for j,r in enumerate(RED):
        if r_used[j]: continue
        if r[0]<b[0] and r[1]<b[1]:
            ans+=1
            r_used[j]=True
            break
print(ans)

# Optimized solution
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, AB, CD):
    ans = 0
    AB.sort(key=lambda x: x[0], reverse=True)
    for a, b in AB:
        CD.sort(key=lambda x: x[1])
        idx = 0
        while idx < len(CD):
            c, d = CD[idx]
            if a < c and b < d:
                break
            idx += 1
        else:
            continue
        ans += 1
        del CD[idx]
    print(ans)


if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(eval(input()))
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    CD = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, AB, CD)
# Original solution
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return list(map(int,input().split()))
def lmp(): return list(map(int,input().split()))

a=int(eval(input()))
print((a+a**2+a**3))

# Optimized solution
a=int(eval(input()))
print((a+a**2+a**3))
# Original solution
#!/usr/bin/python3
a = int(eval(input()))
ans = a + a**2 + a**3
print(ans)

# Optimized solution
a = int(eval(input()));print((a + a**2 + a**3))
# Original solution
a = int(eval(input()))

print((a + a * a  + a * a * a))

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

print((a + a ** 2 + a ** 3))
# Original solution
a=int(eval(input()))
print((a+(a**2)+(a**3)))

# Optimized solution
a=int(eval(input()))
print((a+a**2+a**3))
# Original solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(eval(input()))

    print((N+N*N+N*N*N))

if __name__ == '__main__':
    main()

# Optimized solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    a = int(eval(input()))

    print((a+a*a+a*a*a))

if __name__ == '__main__':
    main()
# Original solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
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())  #空白なし

a = I()

print((a+a**2+a**3))

# Optimized solution
import sys

def I(): return int(sys.stdin.readline().rstrip())

a = I()

print((a+a**2+a**3))
# Original solution
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: list(map(int, read().split()))
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    a = in_n()
    print((a + a**2 + a**3))


if __name__ == '__main__':
    main()


# Optimized solution
a=int(eval(input()))
print((a+a*a+a**3))
# Original solution
N = 10**7

M = 10**5
arr = list(range(M))


def f(x):
    return x


for i in range(N):
    b = arr[i % M]
    b = f(b)

a = int(eval(input()))
print((a + a**2 + a**3))


# Optimized solution
N = 10**7

# M = 10**5
# arr = list(range(M))


# def f(x):
#     return x


for i in range(N):
    pass

# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
# Original solution
N = 10**7

M = 10**5
arr = list(range(M))
for i in range(N):
    t = arr[i % M]

# 答え
a = int(eval(input()))
print((a + a**2 + a**3))


# Optimized solution
N = 10**7

arr = [0]
for i in range(N):
    t = arr[0]

# 答え
a = int(eval(input()))
print((a + a**2 + a**3))
# Original solution
N = 10**7


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(eval(input()))
print((a + a**2 + a**3))


# Optimized solution
N = 10**6


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(eval(input()))
print((a + a**2 + a**3))