Harryxun/stf_run huggingface dataset:
s = input().strip()
x,y = map(int,input().split())
A = [0]
B = [0]
cur = 0
cnt = 0
for i in range(len(s)):
    if s[i]!="T":
        cnt += 1
    else:
        if cur==0 and cnt>0:
            A.append(cnt)
        elif cur==1 and cnt>0:
            B.append(cnt)
        cnt = 0
        cur = 1-cur
if s[-1]!="T":
    if cur==0:
        A.append(cnt)
    elif cur==1:
        B.append(cnt)
A = sorted(A)
B = sorted(B)
dpA = [[-1 for _ in range(4001)] for _ in range(len(A)+1)]
dpB = [[-1 for _ in range(4001)] for _ in range(len(B)+1)]
dpA[0][0] = 0
for i in range(len(A)):
    for j in range(4001):
        if j==0:
            dpA[i+1][j] = 1
        else:
            if dpA[i][j]>=0:
                dpA[i+1][j] = 1
            elif j<A[i] or dpA[i+1][j-A[i]]<=0:
                dpA[i+1][j] = -1
            else:
                dpA[i+1][j] = dpA[i+1][j-A[i]]-1
for i in range(len(B)):
    for j in range(4001):
        if j==0:
            dpB[i+1][j] = 1
        else:
            if dpB[i][j]>=0:
                dpB[i+1][j] = 1
            elif j<B[i] or dpB[i+1][j-B[i]]<=0:
                dpB[i+1][j] = -1
            else:
                dpB[i+1][j] = dpB[i+1][j-B[i]]-1
if (sum(A)-x)%2==1 or (sum(B)-y)%2==1:
    print("No")
else:
    nA = (sum(A)-x)//2
    nB = (sum(B)-y)//2
    flagA = dpA[len(A)][nA]
    flagB = dpB[len(B)][nB]
    if flagA>=0 and flagB>=0:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

s = input().strip()
x,y = map(int,input().split())
C = {}
cur = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        C[cur] = cnt
        cur += 1
        cnt = 0
C[cur] = cnt
AX = []
AY = []
for a in C:
    if a>0 and a%2==0 and C[a]>0:
        AX.append(C[a])
    elif a%2==1 and C[a]>0:
        AY.append(C[a])
cntx = sum(AX)
dpx = [[0 for _ in range(2*cntx+1)] for _ in range(len(AX)+1)]
dpx[0][cntx] = 1
if cntx>0:
    dpx[1][cntx-AX[0]] = 1
    dpx[1][cntx+AX[0]] = 1
    for i in range(2,len(AX)+1):
        for j in range(-cntx,cntx+1):
            if -cntx<=j-AX[i-1]:
                dpx[i][j+cntx] = dpx[i-1][j-AX[i-1]+cntx]
                if j+AX[i-1]<=cntx:
                    dpx[i][j+cntx] = max(dpx[i][j+cntx],dpx[i-1][j+AX[i-1]+cntx])
            elif j+AX[i-1]<=cntx:
                dpx[i][j+cntx] = dpx[i-1][j+AX[i-1]+cntx]
cnty = sum(AY)
dpy = [[0 for _ in range(2*cnty+1)] for _ in range(len(AY)+1)]
dpy[0][cnty] = 1
if cnty>0:
    dpy[1][cnty-AY[0]] = 1
    dpy[1][cnty+AY[0]] = 1
    for i in range(2,len(AY)+1):
        for j in range(-cnty,cnty+1):
            if -cnty<=j-AY[i-1]:
                dpy[i][j+cnty] = dpy[i-1][j-AY[i-1]+cnty]
                if j+AY[i-1]<=cnty:
                    dpy[i][j+cnty] = max(dpy[i][j+cnty],dpy[i-1][j+AY[i-1]+cnty])
            elif j+AY[i-1]<=cnty:
                dpy[i][j+cnty] = dpy[i-1][j+AY[i-1]+cnty]
if C[0]-cntx<=x<=C[0]+cntx and dpx[len(AX)][x-C[0]+cntx]==1 and -cnty<=y<=cnty and dpy[len(AY)][y+cnty]==1:
    print("Yes")
else:
    print("No")
import math

M=[]
for i in range(1001):
   m=(i+1)/2
   M.append(m) 

N,K=map(int,input().split())
P=list(map(int,input().split()))
S=[]
s=0
for i in range(N):
    a=P[i]
    s=s+M[a]
    S.append(s)
Q=[]
q=0
for i in range(N-K):
    if i ==0:
        q=S[K]
    else:
        q=S[i+K]-S[i] 
    Q.append(q)
    q=0
print(max(Q))

       

### FIXED CODE ###

M=[]
for i in range(1001):
   m=(i+1)/2
   M.append(m) 

N,K=map(int,input().split())
P=list(map(int,input().split()))
S=[]
s=0
for i in range(N):
    a=P[i]
    s=s+M[a]
    S.append(s)
Q=[]
Q.append(S[K-1])
q=0
for i in range(N-K):
    q=S[i+K]-S[i] 
    Q.append(q)
    q=0
print(max(Q))
b = input()
if s == "A":
  print("T")
elif s == "C":
  print("G")
elif s == "G":
  print("C")
else:
  print("A")

### FIXED CODE ###

s = input()
if s == "A":
  print("T")
elif s == "C":
  print("G")
elif s == "G":
  print("C")
else:
  print("A")
import numpy as np
N = int(input())
h = list(map(int, input().split()))
default = 9999
dp = [default] * N

def rec(i):
  global dp
  if i == 0:
    return 0
  if dp[i] != default:
    return dp[i]
  dp[i] = min(dp[i], rec(i-1) + np.abs(h[i] - h[i-1]))
  if i > 1:
    dp[i] = min(dp[i], rec(i-2) + np.abs(h[i] - h[i-2]))
  return dp[i]
print(rec(N-1))

### FIXED CODE ###

import numpy as np
N = int(input())
h = list(map(int, input().split()))
dp = [9999] * N
dp[0] = 0
for i in range(1,N):
  if i<2:
    dp[i] = dp[i-1] + np.abs(h[i] - h[i-1])
  else:
    min1 = dp[i-2] + np.abs(h[i] - h[i-2])
    min2 = dp[i-1] + np.abs(h[i] - h[i-1])
    dp[i] = min(min1, min2)
print(dp[N-1])
import numpy as np

a1 = list(int(i) for i in input().split())  
x = list(int(i) for i in input().split())  
x = np.sort(x)
n = a[0]

delta = []
for i in range(0,len(x) - 1):
    delta.append(x[i + 1] - x[i])

if n == 1:
    print(np.sum(delta))
else:
    delta = np.sort(delta)
    print(np.sum(delta[0:delta.size - (n - 2)]))

### FIXED CODE ###

import numpy as np

a1 = list(int(i) for i in input().split())  
x = list(int(i) for i in input().split())  
x = np.sort(x)
n = a1[0]

delta = []
if len(x) <= n:
    print(0)
else:
    for i in range(0,len(x) - 1):
        delta.append(x[i + 1] - x[i])

    if n == 1:
        print(np.sum(delta))
    else:
        delta = np.sort(delta)
        f = delta.size - (n - 2)
        print(np.sum(delta[0:-(n-1):]))
s = int(input())
if a[0] == s[1] or s[1] == s[2] or s[2] == s[3] or s[3] == s[4]:
    print('Bad')
else:
    print('Yes')

### FIXED CODE ###

s = str(input())
if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
    print('Bad')
else:
    print('Good')
N=int(input())
A=list(map(int,input().split()))
D=[[-1]*(N+1)for _ in range(N+1)]
M=0
r=[-1]*(N+1)
def c(i,j,k):
    D[i][j]=max(k,D[i][j])
    D[j][i]=max(k,D[j][i])
    r[i]=max(r[i],D[i][j])
    r[j]=max(r[j],D[i][j])
    global M
    M=max(M,k)
a=0
A[0]=X
A[1]=Y
D[X][Y]=0
D[Y][X]=0
r[X]=0
r[Y]=0
for i in range(N-1):
    n=A[3*i+2:3*i+5]
    C=[]
    if len(set(n))==1:
        a+=1
        continue
    if len(set(n))==2:
        for j in range(3):
            if n.count(n[j])==2:
                X=n[j]
            else:
                Y=n[j]
        for j in range(1,N+1):
            C.append((j,Y,D[X][j]+1))
    X,Y,Z =n
    C.append((X,Y,D[Z][Z]+1))
    C.append((Y,Z,D[X][X]+1))
    C.append((X,Z,D[Y][Y]+1))
    C.append((X,Y,M))
    C.append((X,Z,M))
    C.append((Y,Z,M))
    for j in range(1,N+1):
        for k in range(3):
            C.append((j,n[k],r[j]))
    for j,k,l in C:
        c(j,k,l)
M=max(M,D[A[-1]][A[-1]]+1)
print(a+M)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
INF = 2*N
DP = [[-INF]*(N+1) for _ in range(N+1)]
M = 0
rowM = [-INF]*(N+1)

def chmax(i,j,k):
    DP[i][j] = max(k,DP[i][j])
    DP[j][i] = max(k,DP[j][i])
    rowM[i] = max(rowM[i],DP[i][j])
    rowM[j] = max(rowM[j],DP[i][j])
    global M
    M = max(M,k)

ans = 0
DP[A[0]][A[1]] = 0
DP[A[1]][A[0]] = 0
rowM[A[0]] = 0
rowM[A[1]] = 0
for i in range(N-1):
    new = A[3*i+2:3*i+5]
    change = []
    if len(set(new)) == 1:
        ans += 1
        continue
    if len(set(new)) == 2:
        for j in range(3):
            if new.count(new[j]) == 2:
                X = new[j]
            else:
                Y = new[j]
        for j in range(1,N+1):
            change.append((j,Y,DP[X][j]+1))
    X,Y,Z = new
    change.append((X,Y,DP[Z][Z]+1))
    change.append((Y,Z,DP[X][X]+1))
    change.append((X,Z,DP[Y][Y]+1))
    change.append((X,Y,M))
    change.append((X,Z,M))
    change.append((Y,Z,M))
    for j in range(1,N+1):
        for k in range(3):
            change.append((j,new[k],rowM[j]))
    for j,k,l in change:
        chmax(j,k,l)
M = max(M,DP[A[-1]][A[-1]]+1)
print(ans+M)
N, M = map(int, input().split())
dp = [[0 for i in range(M+1)] for j in range(N+1)]
l = [0 for i in range(N)]
for i in range(N):
    A,B = map(int, input().split())
    l[i] = [-A, -B]
l.sort()
tmp = 1
for n in range(1, N+1):
    for m in range(tmp):
        if -l[n-1][0]  + m <= M:
            dp[n][m] = max(dp[n][m], dp[n-1][m-1] - l[n-1][1])
            tmp += 1
        dp[n][m-1] = max(dp[n][m-1], dp[n-1][m-1])
print(max(dp[N]))


### FIXED CODE ###

import heapq

N, M = map(int, input().split())
l = [0 for i in range(N)]

for i in range(N):
    A, B = map(int, input().split())
    l[i] = [A,-B]
l.sort()

tmp = []
ans = 0
j = 0

for i in range(1, M + 1):
    while j < N:
        A, B = l[j][0], -l[j][1]
        memo = [-B, A]
        if A <= i:
            heapq.heappush(tmp, memo)
            j += 1
        else:
            break
    if len(tmp) > 0:
        ans -= heapq.heappop(tmp)[0]
print(ans)
while True:
  n,x=map(int,input().split())
  count=0
  if n==x==0 : break
  else:
  for i in range(1,n-1) :
    for j in range(i+1,n):
      for k in range(j+1,n+1):
        if i+j+k==x :
          count = count +1

  print('count')   

### FIXED CODE ###

while True:
  n,x=map(int,input().split())
  
  if n==x==0 : break
  
  count = 0 
  for i in range(1,n-1) :
    for j in range(i+1,n):
      for k in range(j+1,n+1):
        if i+j+k==x :
          count = count +1

  print(count)
import numpy as np
N, M = map(int, input().split())

key = np.zeros(N)
for i in range(0, M):
    L, R = map(int, input().split())
    for j in range(L, R+1):
        key[j-1]+=1

print(np.sum(key==M))

### FIXED CODE ###

#!/usr/bin/env python3

n, m = list(map(int, input().split()))

min_, max_ = 0, 10**5
for i in range(m):
    a, b = list(map(int, input().split()))

    min_ = max(min_, a)
    max_ = min(max_, b)

print(max(max_-min_+1, 0))
n,m=map(int,input().split())
MOD = 1000000007 
D=[1] * (n + 1)
for _ in range(m):
    D[int(input())] = 0
for i in range(2, n+1):
    if D[i] == 0:
        continue
    D[i] = (D[i-1] + D[i-2]) % MOD
print(D[i])

### FIXED CODE ###

n,m=map(int,input().split())
MOD = 1000000007 
D=[0] * (n+2)
D[0] = 1
for _ in range(m):
    D[int(input())] = -1
for i in range(n):
    if D[i] == -1:
        continue
    if D[i+1] != -1:
        D[i+1] += D[i]
    if D[i+2] != -1:
        D[i+2] += D[i]
    D[i]%=MOD
print(D[n] % MOD)
while True:
    try:
        a = int(input())
        b = int(input())
    except EOFError:
        break
    if a <= 9 and a>=1 and b <= 9 and b>=1:
        print(a * b)
    else:
        print(-1)

### FIXED CODE ###

a,b=map(int, input().split())
if a<=9 and b<=9:
    print(a*b)
else:
    print(-1)
K,X = [map(int,input().split())]
if K*500>=X:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

K,X = map(int,input().split())
if K*500>=X:
    print("Yes")
else:
    print("No")
def isprime(n):
    if n < 2: return 0
    elif n == 2: return 1

    if n % 2 == 0: return 0

    for i in range(3, n, 2):
        if i >= n/i: return 1
        if n % i == 0 : return 0

    return 1

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

a = [i for i in n if isprime(i)]

print(len(a))


### FIXED CODE ###

x, y = map(int, input().split())

def gcd(x,y):
    if x < y:
        x, y = y, x
    d = int()
    while y > 0:
        r = x % y
        x, y = y, r

    return x

print(gcd(x, y))
a = int(raw_input())
print(a + a**2 + a**3)

### FIXED CODE ###

a = int(input())
print(a + a**2 + a**3)
#import sys
#sys.setrecursionlimit(20000)

def solve(i,sum):
    if i==n:
        ans[sum] = 1
        ans[sum+A[i]] = 1
    solve(i+1,sum)
    if sum+A[i] <=2000:
        solve(i+1,sum+A[i])

n=int(input())
A=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
ans=[0]*2001    
solve(0,0)   

m=int(input())
B=list(input().split())
for i in range(m):
    if ans[B[i]]==1:
        print("yes")
    else:
        print("no")



### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))

T = [[0]*2001 for i in range(n)]

T[0][0] = 1
T[0][A[0]] = 1
for i in range(1,n):
    for j in range(2001):
        T[i][j] = T[i-1][j]
        if (j - A[i] >=0) and (T[i-1][j-A[i]] == 1):
            T[i][j] = 1
    
for i in range(m):
    if T[n-1][B[i]] == 1: print("yes")
    else: print("no")
import math


def main():
    a = list(input())
    b = list(input())
    dica = {}
    dicb = {}
    dif = 0
    alpha = list("abcdefghijklmnopqrstuvwxyz")
    for aa,bb in zip(a,b):
        if aa != bb:
            if bb not in dica:  
                dica[bb] = aa
            if aa not in dicb:
                dicb[aa] =bb
        
            if dica[bb] != aa or dicb[aa] != bb:            
                print("No")
                return 0
        
            # if aa not in dica:
            #     dica[aa] = bb
            # if bb not in dicb:
            #     dicb[bb] = aa
            
    if dica[b[-1]] != a[-1] or dicb[a[-1]] != b[-1]:            
                print("No")
                return 0
            
    print("Yes")
    
    # for c in alpha:
    #     dica[c] = 0
    #     dicb[c] = 0
    # for temp in a:
    #     dica[temp] +=1
    # for temp in b:
    #     dicb[temp] +=1
    # for c in alpha:
    #     dif += (dica[c]-dicb[c])
    
    

if __name__ == '__main__':
    main()


### FIXED CODE ###

s1 = input()
s2 = input()
di1 = {} #s1 → s2 の対応表
di2 = {} #s2 → s1 の対応表

ans = "Yes"
for c1,c2 in zip(s1,s2):
    if c1 not in di1:
        di1[c1] = c2
    else:
        if di1[c1] != c2:
            ans = "No"

    if c2 not in di2:
        di2[c2] = c1
    else:
        if di2[c2] != c1:
            ans = "No"

print(ans)
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
import numpy as np
# D

N, M = list(map(int, input().split()))
ABs = np.array([list(map(int, input().split())) for i in range(M)])

ABsT = ABs.T
row = list(ABsT[0]-1) + list(ABsT[1]-1)
col = list(ABsT[1]-1) + list(ABsT[0]-1)
data = [1] * (2 * M)

csr = csr_matrix((data, (row, col)), shape=(N, N))
from_starts, procs = dijkstra(csr, indices=[0], return_predecessors=True)
proc = procs[0]
 
print(csr.toarray())
print(proc)
if -9999 in proc[1:]:
  print('No')
else:
  print('Yes')
  for i in range(N-1):
    print(int(proc[i+1]) + 1)

### FIXED CODE ###

# D

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import breadth_first_order

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

row = []
col = []
for i in range(M):
    r, c = list(map(int, input().split()))
    row.append(c-1)
    col.append(r-1)

data = [1] * (M)

csr = csr_matrix((data, (row, col)), shape=(N, N))
_, proc = breadth_first_order(csr, 0, directed=False)

if -9999 in proc[1:]:
  print('No')
else:
  print('Yes')
  print('\n'.join((proc[1:]+1).astype('str')))
n = int(input())
print(800*n - 200(n//15))

### FIXED CODE ###

n = int(input())
print(800*n - 200*(n//15))
a, b = map(int, input().split())
from fraction import gcd
print(a*b // gcd(a, b))

### FIXED CODE ###

a, b = map(int, input().split())
from fractions import gcd
print(a*b // gcd(a, b))
a=int(input())
b=int(input())

if a>8 or b>8 or a<0 or b<0:
  print(":(")
else:
  print("Yay!")

### FIXED CODE ###

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

if a>8 or b>8 or a<0 or b<0:
  print(":(")
else:
  print("Yay!")
a = int(input())
b = int(input())

print("%d %d", % (a*b, 2*a + 2*b))



### FIXED CODE ###

a, b = map(int,input().split())
print("%d %d" %(a*b, 2*(a+b) ) )
a,b,k = map(int,input().split())

ans = []
for val in range(1,101):
    if val % a == 0 and val %b ==0:
        ans.append(val)

print(ans[k+1])

### FIXED CODE ###

a,b,k = map(int,input().split())

ans = []
for val in range(1,min(a,b)+1):
    #print(val)
    if a % val == 0 and b % val ==0:
        ans.append(val)
        #print(val)

print(ans[-k])
print(eval(input()+'%9'))

### FIXED CODE ###

s=list(input())
print(int(s[0])+int(s[1])+int(s[2]))
total = [int(i) for i in input().split()]
n = total[0]
time_limit = total[1]

ci = []
ti = []
for i in range(n):
    list = [int(j) for j in input().split()]
    ci.append(list[0])
    ti.append(list[1])

min = 1000
for i in range(len(ci)):
    if ci[i] < min and ti[i] < time_limit:
        min = ci[i]

if min != 1000:
    print(min)
else:
    print("TLE")

### FIXED CODE ###

n = int(input())

if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print("{0}".format(a + b))
import string
s = string.ascii_lowercase


def f(x, tmp):
    if x == 0:
        return ""
    x -= 1
    if x <= 26:
        return s[x] + tmp
    else:
        return f(x // 26, s[x % 26] + tmp)


n = int(input())
r = f(n, "")
print(r)


### FIXED CODE ###

import string
s = string.ascii_lowercase


def f(x, tmp):
    if x == 0:
        return ""
    x -= 1
    if x < 26:
        return s[x] + tmp
    else:
        return f(x // 26 , s[x % 26] + tmp)


n = int(input())
r = f(n, "")
print(r)
a,b,c,k=map(int,input().split())
if a>=k:
  ans=k
elif a+b>=k:
  ans=a
else:
  ans=a-(k-(a+b))
print(ans)

### FIXED CODE ###

s=input()
t=input()
if s==t[0:len(t)-1]:
  print("Yes")
else:
  print("No")
a,b,c =map(int,input().split())
if a+b>=c
    print("YES")
else:
    print("NO")



### FIXED CODE ###

a,b,c =map(int,input().split())
if a+b>=c:
    print("Yes")
else:
    print("No")
N, M, X = map(int, input().split())

A = [[] for i in range(N)]
c = [0] * N
for i in range(N):
    c_as = list(map(int, input().split()))
    c[i], A[i] = c_as[0], c_as[1:]

INF = 10**9
ans = INF
for s in range(0, 1 << N):
    smart = [0] * M
    cost_sum = 0
    for i in range(N):
        if (s >> i) % 2 == 0:continue
        cost_sum += c[i]
        for j in range(M):
            smart[j] += A[i][j]
    ok = True
    for i in range(N):
        if smart[i] < X:
            ok = False
    if ok:
        ans = min(ans, cost_sum)

print(ans)


### FIXED CODE ###

N, M, X = map(int, input().split())

A = [[] for i in range(N)]
C = [0] * N
for i in range(N):
    c_as = list(map(int, input().split()))
    C[i], A[i] = c_as[0], c_as[1:]

INF = 10**9
ans = INF
for s in range(0, 1 << N):
    smart = [0] * M
    cost_sum = 0
    for i in range(N):
        if (s >> i) % 2 == 0:
            continue
        cost_sum += C[i]
        for j in range(M):
            smart[j] += A[i][j]
    ok = True
    for j in range(M):
        if smart[j] < X:
            ok = False
    if ok:
        ans = min(ans, cost_sum)
if ans == INF:
    ans = -1
print(ans)
n=int(input())
A=[]
X=[]
Y=[]
for i in range(n):
  A=int(input())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
    　　l[X[j][k]] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)  
   

### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)
n,a,b = list(map(int,input().split()))
if((b-a)%2==0):
    print((a2-a1)//2)
else:
    print(min(n-a, b-1))

### FIXED CODE ###

n,a,b = list(map(int,input().split()))
if((b-a)%2==0):
    print(int((b-a)//2))
else:
    u = (b-a-1)//2
    if(n>(a+b-1)):
        print(u+a)
    else:
        print(u+(n-b+1))
import sys
sys.setrecursionlimit(10**9)
N,W = map(int,input().split())
info = [list(map(int,input().split())) for i in range(N)]
# dp[i+1][w] i+1番目まで品物を選んで重さwのときの価値の最大値
# dp[0] = [0]*(W+1)
dp = [[0]*(W+1) for i in range(N+1)]
for i in range(N):
    for w in range(W+1):
        if  w - info[i][0] >= 0:
            dp[i+1][w] = max(dp[i][w-info[i][0]] + info[i][1],dp[i][w])
        else:    
            dp[i+1][w] = dp[i][w]
print(dp[N][W])

### FIXED CODE ###

N,W = map(int,input().split())
value,weight = [],[]
def chmin(a,b):
    if (a > b):
        a = b
        return True
    return False
for i in range(N):
    w,v = map(int,input().split())
    value.append(v)
    weight.append(w)
# dp[i][v]: i番目までの品物から価値vを超えるように選んだ時の重さの最小値
dp = [[float("inf")] * (sum(value)+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    for v in range(sum(value)+1):
        if v - value[i-1] >= 0:
            dp[i][v] = min(dp[i-1][v-value[i-1]] + weight[i-1],dp[i-1][v])
        else:
            dp[i][v] = dp[i-1][v]
ans = 0
for v in range(sum(value),-1,-1):
    if dp[N][v] <= W:
        ans = v
        break
print(ans)
a=input()
a=int(a)
if a%2==0:
  print(int((a/2)**2))
else:
  print(int(a/2)*2(int(a/2)+1))


### FIXED CODE ###

a=input()
a=int(a)
if a%2==0:
  print(int((a/2)**2))
else:
  print(int(a/2)*(int(int(a/2)+1)))
from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r = [0],[0]
for i in range(n//2+1):
    l.append(gcd(l[i],a[i]))
    r.append(gcd(a[n-i-1],r[i]))

#print(l,r)
ans = 0
for i in range(min(len(l),len(r))):
    ans = max(ans,gcd(l[i],r[n-i-1]))
print(ans)


### FIXED CODE ###

from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r = [0],[0]
for i in range(1,n):
    l.append(gcd(l[i-1],a[i-1]))
    r.append(gcd(r[i-1],a[-i]))
r = r[::-1]
ans = 0

for i in range(n):
    ans = max(ans,gcd(l[i],r[i]))
print(ans)
import math
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(10**10)
b.append(10**10)

if a[0]>k and b[0]>k:
  print(0)
else:
  if sum(a)+sum(b)<=k:
    print(n+m)
  else:
    ans=0
    time=0
    for i in range(n+m):
      ans += 1    
      if a[0]<=b[0]:
        time+=a.pop(0)
      else:
        time+=b.pop(0)
      
      if time>k:
        break
    print(ans-1)

### FIXED CODE ###

a = int(input())

ans = a + a*a + a*a*a
ans = int(ans)

print(ans)
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
a = [0] * M
keys = [0] * M
inf = 10 ** 12
for i in range(M):
    a[i], _ = map(int, input().split())
    c_list = list(map(int, input().split()))
    keys[i] = sum([2 ** j for j in range(N) if j + 1 in c_list])

dp = [inf] * (N ** 2)
dp[0] = 0

# print(keys)

for i in range(M):  # use key i
    for j in range(N ** 2):
        dp[j | keys[i]] = min(dp[j] + a[i], dp[j | keys[i]])
        # print(dp, j, keys[i], dp[j | keys[i]], dp[j], a[i])

ans = dp[-1]
if ans == inf:
    ans = -1
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
a = [0] * M
keys = [0] * M
inf = 10 ** 12
for i in range(M):
    a[i], _ = map(int, input().split())
    c_list = list(map(int, input().split()))
    keys[i] = sum([2 ** j for j in range(N) if j + 1 in c_list])

dp = [inf] * (2 ** N)
dp[0] = 0

# print(keys)

for i in range(M):  # use key i
    for j in range(2 ** N):
        # print(dp, j, keys[i], dp[j | keys[i]], dp[j], a[i])
        dp[j | keys[i]] = min(dp[j] + a[i], dp[j | keys[i]])

ans = dp[-1]
if ans == inf:
    ans = -1
print(ans)
n, m = map(int,(input().split()))
d = {}
for i in range(n):
    a, b = map(int,(input().split()))
    d[a]=b
d = sorted(d.items())
ans = 0
for i in range(n):
    if d[i][1] >= m: # 残り本数 >= この値段の本数
        ans += d[i][0]*m
        break
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]
print(ans)

### FIXED CODE ###

n, m = map(int,(input().split()))
d = []
for i in range(n):
    a, b = map(int,(input().split()))
    d.append([a,b])
d = sorted(d)
ans = 0
for i in range(n):
    if d[i][1] >= m: # 残り本数 >= この値段の本数
        ans += d[i][0]*m
        break
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]
        if m <= 0:
            break
print(ans)
n = int(input())

count = 0
for i in range(1, n+1, 2):
    n_divisor = 1
    for j in range(2, n+1):
        if i%j == 0:
            n_divisor += 1
    if n_divisor == 8:
        count += 1

print(count)

### FIXED CODE ###

A, B = map(int, input().split())
s = (A * B) - (A + B - 1)
print(s)