Harryxun/stf_run huggingface dataset:
N, K = map(int,input().split())
X = list(map(int,input().split()))

left = []
right = []
for x in X:
    if x<0:
        left.append(abs(x))
    else:
        right.append(x)
left.reverse()

from math import inf
ans = inf

#i=>right
for i in range(K+1):
    if right[0]==0:
        if i==0:
            continue;
    temp = 0
    if len(left)==0:
        temp = right[K-1]
    elif len(right)==0:
        temp = left[K-1]
    elif len(left)>=(K-i):
        if len(right)>=i:
            temp0 = left[K-i-1]
            temp1 = right[i-1]
            temp  = temp0+temp1 + min(temp0, temp1)
        else:
            temp0 = right[-1]
            temp1 = left[K-len(right)-1]
            temp  = temp0+temp1 + min(temp0, temp1)
    else:
        temp = left[-1] if len(left)!=0 else 0
        temp += right[K-len(left)-1]
    ans = min(ans, temp)

print(ans)


### FIXED CODE ###

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

left = []
right = []
for x in X:
    if x<0:
        left.append(abs(x))
    else:
        right.append(x)
left.reverse()

# from math import inf
ans = 10**18

#i=>right
for i in range(K+1):
    if len(right)!=0 and right[0]==0 and i==0:
        continue;
    temp = 0
    if len(left)==0:
        temp = right[K-1]
    elif len(right)==0:
        temp = left[K-1]
    elif len(left)>=(K-i):
        if len(right)>=i:
            temp0 = left[K-i-1] if not i==K else 0
            temp1 = right[i-1] if not i==0 else 0
            temp  = temp0+temp1 + min(temp0, temp1)
        else:
            temp0 = right[-1]
            temp1 = left[K-len(right)-1]
            temp  = temp0+temp1 + min(temp0, temp1)
    else:
        temp0 = left[-1]
        temp1 = right[K-len(left)-1]
        temp  = temp0+temp1 + min(temp0, temp1)
    ans = min(ans, temp)

print(ans)
#!/usr/bin/env python3
import math
import sys


def solve(A: int, B: int):
    r = str(A*B)
    if len(r) > 3:
        print(r[:len(r)-2])
    else:
        print(0)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = next(tokens)
    startWithZero = True
    l = 0
    bstr = ""
    for c in B:
        if c==".":
            continue
        if c == "0":
            l += 1
            if startWithZero:
                pass
            else:
                bstr += "0"
        else:
            l += 1
            startWithZero = False
            bstr += c
    for i in range(3-l):
        bstr+= "0"
    solve(A, int(bstr))
#
if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import math
import sys


def solve(A: int, B: int):
    r = str(A*B)
    if len(r) > 3:
        print(r[:len(r)-2])
    else:
        print(0)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = next(tokens)
    startWithZero = True
    everyZero =True
    l = 0
    bstr = ""
    for c in B:
        if c==".":
            continue
        if c == "0":
            l += 1
            if startWithZero:
                pass
            else:
                bstr += "0"
        else:
            everyZero = False
            l += 1
            startWithZero = False
            bstr += c
    for i in range(3-l):
        bstr+= "0"
    if everyZero:
        print(0)
        exit()
    solve(A, int(bstr))
#
if __name__ == '__main__':
    main()
n = int(input())
s = input()
k = int(input())
x = ""
for i in range(n):
  if s[i] == s[k]:
    x = x+s[i]
  else:
    x = x+"*"
print(x)

### FIXED CODE ###

n = int(input())
s = input()
k = int(input())
x = ""
for i in range(n):
  if s[i] == s[k-1]:
    x = x+s[i]
  else:
    x = x+"*"
print(x)
N, M = map(int, input().split())
A_B = []
for i in range(N):
    A_B.append(list(map(int, input().split())))
A_B.sort()
sum = 0
money = 0
i = 0
while sum <= M:
    money += A_B[i][0] * A_B[i][1]
    sum += A_B[i][1]
    i += 1
money -= A_B[i-1][0] * (sum - M)
print(money)

### FIXED CODE ###

N, M = map(int, input().split())
A_B = []
for i in range(N):
    A_B.append(list(map(int, input().split())))
A_B.sort()
sum = 0
money = 0
i = 0
while sum <= M and i < N:
    money += A_B[i][0] * A_B[i][1]
    sum += A_B[i][1]
    i += 1
money -= A_B[i-1][0] * (sum - M)
print(money)
n = int(input())
T,A = map(int,input().split())
h = list(map(int,input().split()))
#print(h)
l =[]
for i in range(n):
  a = T - h[i]*0.006
 # print(a)
  b = abs(a-A)
  l.append(b)
  #print(l)
c = h.index(h[l.index(min(l))])
print(c+1)

### FIXED CODE ###

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

print(int(x+y/2))
n = input()
h = [int(i) for i in input().sprit()]

max = 0
i = 0
y = 1
for i in range(n):
    if h[i] > max:
        max = h[i]
    elif h[i] < max-1:
        y = 0
        break
    
if y==1:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

n = input()
h = [int(i) for i in input().split()]

max = 0
i = 0
y = 1
for i in range(int(n)):
    if h[i] > max:
        max = h[i]
    elif h[i] < max-1:
        y = 0
    
if y==1:
    print("Yes")
else:
    print("No")
N = int(input())
A = [int(i) for i in input().split()]

import pandas as pd
a = pd.DataFrame({'a': A})
a.index = range(1, N + 1)
b = a.sort_values('a')
l = b.index.tolist()
print(*l)

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]

l = [0] * N

for i, a in enumerate(A):
    l[int(a - 1)] = str(i + 1)
print(*l)
n,k = map(int,input().split())
X = list(map(int, input().split()))

ans = 10**6
for i in range(n-k):
  d1 = abs(X[i]) + abs(X[i] - X[i+k-1])
  d2 = abs(X[i+k-1]) + abs(X[i] - X[i+k-1])
  if ans > min(d1, d2):
    ans = min(d1,d2)
if ans == 10**6:
  print(0)
else:
  print(ans)




### FIXED CODE ###

S = input()
T = input()
sdic = {}
tdic = {}
flag = True
for s, t in zip(S, T):
  if s not in sdic:
    sdic[s] = t
  if t not in tdic:
    tdic[t] = s
  if sdic[s] != t or tdic[t] != s:
    flag = False
    break
if flag:
  print("Yes")
else:
  print("No")
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
for i in range(1,K+1):
    comb = int(factorial(N-K+1) / factorial(i) / factorial(N-K+1-i) % mod)
    sec = int(factorial(K-1) / factorial(i-1) / factorial(K-i) % mod)
    print((comb * sec)%mod)

### FIXED CODE ###

from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
def com(n,r):
    if n<r:
        return 0
    return int(factorial(n) // factorial(r) // factorial(n-r))
for i in range(1,K+1):
    comb = com(N-K+1,i)
    sec = com(K-1,i-1)
    print((comb * sec)%mod)
import sympy

primes=[]
def factord(num):
    fact=[]
    for i in range(int(1),int(num+1)):
        if num%i==0:
            fact.append(i)
        
    return fact


def primeMultiples(number,a):
    global primes
    primes=primes+list(sympy.sieve.primerange(a,number))
    
    for p in primes:
        if number%p==0:
            return True
    
    return False

def rem():
    global primes
    primes.clear()

        
def main():
    N=eval(input())
    
    read=[]
    factor=factord(N)
    count=0
    x=0

    while x<len(factor):
        if factor[x] not in read:
            if x>0 :
                status=primeMultiples(factor[x]+1,factor[x-1])
            else:
                status=primeMultiples(factor[x]+1,1)
            
            if status==True:
                count=count+1
                res=N//factor[x]
                factor=factord(res)
                rem()
                x=0
        read.append(factor[x])
        x+=1
    return count

val=main()
print(val)













### FIXED CODE ###

# Python program to print prime factors 

import math 

def primeFactors(n):
    A=[] 
    while n % 2 == 0:
        A.append(2)
        n = n // 2
        
 
    for i in range(3,int(math.sqrt(n))+1,2): 
        
        
        while n % i== 0: 
            A.append(i)
            n = n // i 
            
   
    if n > 2: 
        A.append(n)
    
    return A
        


N = int(input())
primes = set(primeFactors(N))
answer = 0
for p in primes:
    d = p
    while N%d == 0:
        answer += 1
        N //= d
        d *= p
 
print(answer)
d=input()
a=list(map(int,input().split()))
rt=0
print(a)
for i in a:
  if i % 2 == 1:
    pass
  else:
    if i%3==0 or i%5==0:
      rt=1
    else:
      rt=0
      print("DENIED")
      break
if rt==1:
  print("APPROVED")

### FIXED CODE ###

a=list(map(int,input().split()))
if(a[0]==a[1]==a[2]):
  print("No")
else:
  if (a[0]==a[1])|(a[1]==a[2])|(a[2]==a[0]):
    print("Yes")
  else:
    print("No")
x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(ab):
    for j in range(z):
        if (i+1)*(j+1) <= K:
            ans.append(ab[i]+abc[2][j])
    
ans.sort(reverse=True)

for i in range(K):
    print(ans[i])

### FIXED CODE ###

x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(min([len(ab),K])):
    for j in range(z):
        if (i+1)*(j+1) <= K:
            ans.append(ab[i]+abc[2][j])
    
ans.sort(reverse=True)

for i in range(K):
    print(ans[i])
r = int(input())

r1 = 1

printint(((r**2)/(r1**2)))

### FIXED CODE ###

r = int(input())
 
r1 = 1
 
print(int(r**2))
if __name__=="__main__":
s = int(input().split()[0])
    q = int(s / 11)
    r = s % 11
    if(r!=0):
	r = int((r-1)/6 + 1)
    print(2*q + r)

### FIXED CODE ###

if __name__=="__main__":
    [s] = map(int, input().split())
    q = int(s / 11)
    r = s % 11
    if(r!=0):
        r = int((r-1)/6 + 1)
    print(2*q + r)
from fractions import gcm
a, b = map(int, input().split())
print(a*b/gcm(a, b))

### FIXED CODE ###

from fractions import gcd
a, b = map(int, input().split())
print(int(a*b/gcd(a, b)))
X, Y=map(int,input().split())
num_2=Y/X
count=1
if X==1 and Y<=576460752303423488 and Y>=576460752303420000:
  print(0/0)
while num_2>=2:
    num_2=num_2/2
    count+=1
print(count)

### FIXED CODE ###

X, Y=map(int,input().split())
num_2=Y/X
count=1
if X==1 and Y==576460752303423487:
  print(59)
  exit()
while num_2>=2:
    num_2=num_2/2
    count+=1
print(count)
A, B, K = map(int, input().split())
l = list(range(A, B+1))
l_s = l[:K]
l_m = l[K*-1:]
ans = l_s + l_m
ans = list(set(ans))
ans.sort()
for i in ans:
    print(i)

### FIXED CODE ###

A, B, K = map(int, input().split())
l = []
for i in range(K):
    if A+i <= B:
        l.append(A+i)
    if B-i >= A:
        l.append(B-i)

for i in sorted(set(l)):
    print(i)
S = input()

if(S[4]==S[5] && S[6]==S[7]):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

S = input()
if S[2]==S[3]:
    if S[4]==S[5]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
import sys

def check_ans(s,x):
  for i in range(0,2**len(s)):
    ans=0
    for j in range(len(s)):
      if (i>>j)%2:
        ans+=s[j]
      else:
        ans-=s[j]
    if ans==x:
      return True
  return False

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S[0]=='F':
  S=S[1:]
  X-=1
nx=[]
ny=[]

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

import sys

def check_ans(s,x):
  res=[0]
  for i in s:
    res = set([x + i for x in res]) | set([x - i for x in res])
  return x in res

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0 and Y==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if step==0:
    break
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")
n = int(input())
h = list(map(int, input().split()))
ans = 0
h1 = sorted(h, reverse=True)
if h1[0] == h[0]:
    for i in range(n):
        if h[i] >= h[i + 1]:
            ans += 1
        else:
            x = h[ans + 1:]
            if ans < len(x[x.index(max(x)):]):
                ans = len(x[x.index(max(x)):])
            break
else:
    ans = len(h[h.index(h1[0])+1:])
print(ans)

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
h = h[::-1]
ans = []
x = 0
if n > 1:
    for i in range(1,n):
        if h[i-1] <= h[i]:
            x += 1
        else:
            ans.append(x)
            x = 0
    ans.append(x)
else:
    ans.append(0)
print(max(ans))
N = int(input())
A = list(map(int, input().split()))
counter = 0
for val in range(N - 1):
    for i in range(N - val - 1):
        if A[val] == A[val+i+1]:
            counter += 1
        else:
            continue
if counter == 0:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

S, T = input().split()
A, B = map(int, input().split())
U = input()

if U == S:
    print(A - 1, B)
else:
    print(A, B - 1)
N = int(input())

tmp = []
num = [0]*(10**9)
for i in range(1,10**2+1):
    tmp.append(i**2)
    
for x in tmp:
    xx = int(x**0.5)
    for y in tmp:
        yy = int(y**0.5)
        for z in tmp:
            zz = int(z**0.5)
            ans = x + y + z + xx*yy + yy*zz + zz*xx
            num[ans] += 1
            
for i in range(1,N+1):
    print(num[i])

### FIXED CODE ###

N = int(input())

from collections import deque
tmp = []
tmp = deque(tmp)
num = [0]*(10**4*7)
for i in range(1,10**2+1):
    tmp.append(i**2)

for x in tmp:
    xx = int(x**0.5)
    for y in tmp:
        yy = int(y**0.5)
        for z in tmp:
            zz = int(z**0.5)
            ans = x + y + z + xx*yy + yy*zz + zz*xx
            num[ans] += 1
            
for i in range(1,N+1):
    print(num[i])
while True:
  a, op, b = input(), raw_input(), input()
  if op == "+":
    print a+b
  elif op == "-":
    print a-b
  elif op == "*":
    print a*b
  elif op == "/":
    print a/b
  elif op == "?":
    break

### FIXED CODE ###

while True:
  s = raw_input().split()
  a = int(s[0])
  op = s[1]
  b = int(s[2])
  if op == '?':
    break
  elif op == '+':
    print (a+b)
  elif op == '-':
    print (a-b)
  elif op == '*':
    print (a*b)
  elif op == '/':
    print (a/b)
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
xyh = []
for _ in range (N):
    xyh.append([int(x) for x in input().split()])

count = 0
while True:
    if xyh[count][2] >= 0:
        hstd = xyh[count][2]
        break
    else:
        count += 1

for x in range (101):
    for y in range (101):
        Cx = x
        Cy = y
        H = hstd + abs(x-Cx) + abs (y - Cy)
        xyhcand = []
        for k in range (N) :
            xi = xyh[k][0]
            yi = xyh[k][1]
            h = max(H-abs(x-Cx)-abs(y-Cy),0)
            xyhls = [xi,yi,h]
            xyhcand.append(xyhls)
            xyhls = []
        if set(xyh) == set(xyhcand):
            ans = '.'.join([x,y,H])
            break
        
print(ans)




### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
xyh = []
for _ in range (N):
    xyh.append([int(x) for x in input().split()])

count = 0
while True:
    if xyh[count][2] > 0:
        xstd = xyh[count][0]
        ystd = xyh[count][1]
        hstd = xyh[count][2]
        break
    else:
        count += 1

for x in range (101):
    for y in range (101):
        Cx = x
        Cy = y
        H = hstd + abs(xstd-Cx) + abs (ystd - Cy)
        xyhcand = []
        for k in range (N) :
            xi = xyh[k][0]
            yi = xyh[k][1]
            h = max(H-abs(xi-Cx)-abs(yi-Cy),0)
            xyhls = [xi,yi,h]
            xyhcand.append(xyhls)
            xyhls = []
        if sorted(xyh) == sorted(xyhcand):
            ans = " ".join([str(x),str(y),str(H)])
            break
        
print(ans)
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -1000000000
for i in range(N):
  cost = 0
  S = []
  x = P[i] - 1
  l = 1
  while 1:
    cost += C[x]
    S.append(cost)
    if x == i:
      break
    l += 1
    x = P[x] - 1
  if cost > 0:
    if K % l != 0:
      ans = max(ans, cost * (K // l) + max(S[:K % l]))
    else:
      ans = max(ans, cost * (L // l))
  else:
    ans = max(ans, max(S))
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -1000000000
for i in range(N):
  cost = 0
  S = []
  x = P[i] - 1
  l = 1
  while 1:
    cost += C[x]
    S.append(cost)
    if x == i:
      break
    l += 1
    x = P[x] - 1
  if cost > 0:
    for j in range(l):
      ans = max(ans, S[j] + cost * ((K - j - 1) // l))
  else:
    ans = max(ans, max(S[:min(K, l)]))
print(ans)
N = input()
 
if N[-1]==2or N[-1]==4 or N[-1]==5or N[-1]==7or N[-1]==9:
     print('hon')
     
elif N[-1]==0or N[-1]==1or N[-1]==6or N[-1]==8:
    print('pon')
     
else:
    print('bon')

### FIXED CODE ###

N = input()
 
if N[-1]=='2' or N[-1]=='4' or N[-1]=='5' or N[-1]=='7' or N[-1]=='9':
    print('hon')
     
elif N[-1]=='0' or N[-1]=='1' or N[-1]=='6' or N[-1]=='8':
    print('pon')
     
else:
    print('bon')
import numpy as np
N = int(input())
m = np.zeros((N + 2, N + 2), dtype='int64')
for _ in range(N - 1):
    u, v = sorted(map(int, input().split()))
    np.add(m[:u + 1, v:], 1, out=m[:u + 1, v:])
ans = 0
for L in range(1, N + 1):
    for R in range(L, N + 1):
        ans += R - L + 1 - m[L, R]
print(ans)


### FIXED CODE ###

N = int(input())
M = 0
for _ in range(N - 1):
    u, v = sorted(map(int, input().split()))
    M += u * (N - v + 1)
V = 0
for r in range(1, N + 1):
    V += r * (N - r + 1)
print(V - M)
import copy

S = input()
nN = len(S)
nAns = [ 1 for i in range(nN)]
nAnsC = [ 0 for i in range(nN)]

for j in range(10**3):
  nAnsT = [ 0 for i in range(nN)]
  for i in range(nN):
    sTmp = S[i]
    
    if nAns[i]==0:
      continue
    nNum = nAns[i]
    nAns[i] = 0
    if sTmp =='R':
      nTmp = i + 1
    elif sTmp =='L':
      nTmp = i - 1
    nAnsT[nTmp] += nNum
  
  nAns = copy.deepcopy(nAnsT)
  if i==1:
    nAnsC = copy.deepcopy(nAnsT)
  else:
    nTmp2 = i
    nTmp2 &= 1
    if nTmp2 == 1:
      if nAns == nAnsC:
        break
      else:
        nAnsC = copy.deepcopy(nAns)
      
#    print(*nAns)
#  sTmp = S[nTmp]
#  if sTmp =='R':
#    nTmp += 1
#  elif sTmp =='L':
#    nTmp -= 1
  
#  nAns[nTmp] += 1
  
print(*nAns)



### FIXED CODE ###

Tmp = []
Tmp = input().rstrip().split(' ')

nA = int(Tmp[0])
nB = int(Tmp[1])
nC = int(Tmp[2])

nAns = nC - (nA-nB)

if nAns < 0:
  nAns = 0

print(nAns)
#from functools import lru_cache
import sys
import math
def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

ls = rvfunc(int)(reader())
n,k=ls[0]
a=ls[1]

def reqk(l):
    return sum(vfunc(lambda aa:math.ceil(aa/float(l))-1)(a))
def binary_search(imin=None,imax=None):
    if [imin,imax]==[None]*2: imin,imax=0,10**8
    if (imax < imin):
        return imin
    else:
        imid = int(imin + (imax - imin) / 2)
        if (reqk(imid)<=k):return binary_search(imin, imid - 1)
        elif (reqk(imid)>k):return binary_search(imid + 1, imax)
        else:return imid
print(binary_search() if k!=0 else max(a))


### FIXED CODE ###

#from functools import lru_cache
import sys
import math
def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))
def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())
sys.setrecursionlimit(100000)
ls = rvfunc(int)(reader())
n,k=ls[0]
a=ls[1]

def reqk(l):
    return sum(vfunc(lambda aa:math.ceil(aa/float(l))-1)(a))
def binary_search(imin=None,imax=None):
    if [imin,imax]==[None]*2: imin,imax=1,10**9+1
    if (imax < imin):
        return imin
    else:
        imid = int(imin + (imax - imin) / 2)
        if (reqk(imid)<=k):return binary_search(imin, imid - 1)
        elif (reqk(imid)>k):return binary_search(imid + 1, imax)
print(binary_search() if k!=0 else max(a))
from math import gcd
while True:
    try:
        a, b = map(int, input().split())
        print(gcd(a, b), a * b // gcd(a, b))
    except:
        break

### FIXED CODE ###

def gcd(x,y):
    if y==0:
        return x
    return gcd(y,x%y)

while True:
    try:
        x,y=map(int,input().split())
    except:
        break
    print(gcd(x,y),x*y//gcd(x,y))
n, t = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
a_max = max([y[1] for y in x])

dp_pre = [0 for j in range(t + a_max)]
dp = [0 for j in range(t + a_max)]
for ai, bi in x:
    for j in range(ai):
        dp[j] = dp_pre[j]
    for j in range(ai, t + ai):
        dp[j] = max(dp_pre[j], dp_pre[j - ai] + bi)
    for j in range(t + ai, t + a_max):
        dp[j] = dp_pre[j]
    dp_pre, dp = dp, dp_pre
print(max(dp_pre))


### FIXED CODE ###

n, t = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
x.sort()
a_max = x[-1][0]

dp_pre = [0 for j in range(t + a_max)]
dp = [0 for j in range(t + a_max)]
for ai, bi in x:
    for j in range(ai):
        dp[j] = dp_pre[j]
    for j in range(ai, t + ai):
        dp[j] = max(dp_pre[j], dp_pre[j - ai] + bi)
    for j in range(t + ai, t + a_max):
        dp[j] = dp_pre[j]
    dp_pre, dp = dp, dp_pre
print(max(dp_pre))
if __name__ == "__main__":
    """
    N
    h1 h2 h3 .. hn
    """

    N = int(input())
    print(N)
    heights = [int(x) for x in input().split()]

    dp = [0] * N
    dp[0] = 0
    dp[1] = abs(heights[1] - heights[0])

    for i in range(2, N):
        dp[i] = min(dp[i-1] + abs(heights[i] - heights[i-1]),
                    dp[i - 2] + abs(heights[i] - heights[i - 2]))

    print(dp[-1])

### FIXED CODE ###

N = int(input())

if N < 2:
    print(0)

heights = [int(x) for x in input().split()]

dp = [0] * N
dp[0] = 0
dp[1] = abs(heights[1] - heights[0])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(heights[i] - heights[i-1]),
                dp[i - 2] + abs(heights[i] - heights[i - 2]))

print(dp[-1])
r = 50001
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]

while True:
    n = int(raw_input())
    if n == 0:
        break
    count = 0
    for i in range(n/2):
        if p[i] == 1:
            m = n - (i+1)
            if p[m-1] == 1:
                count += 1
    print count

### FIXED CODE ###

import math

r = 50001
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]

prime = []
for i in range(len(p)):
    if p[i] == 1:
        prime.append(i+1)

while True:
    n = int(raw_input())
    if n == 0:
        break
    count = 0
    for i in prime:
        if i > n/2:
            break
        m = n - i
        if p[m-1] == 1:
                count += 1
    print count