Harryxun/stf_run huggingface dataset:
def f(N,K,h):
    dp = [0]*N

    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-K), i)])
    print(dp[-1])


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

### FIXED CODE ###

def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))
def resolve():
    a, b, c, d = map(int, input().split()
    w = a*c
    x = a*d
    y = b*c
    z = b*d
    ans = max(w, x, y, z)
    print(ans)
    
    
resolve()


### FIXED CODE ###

def resolve():
    a, b, c, d = map(int, input().split())
    w = a*c
    x = a*d
    y = b*c
    z = b*d
    ans = max(w, x, y, z)
    print(ans)

resolve()
a=input()
b=input()
s=[]
for i in range(a):
    s=append(s,a(i),b(i))


### FIXED CODE ###

a=input()
b=input()
s=[]
if len(a)==len(b):
    for i in range(len(a)):
        s.append(a[i])
        s.append(b[i])
else:
    for i in range(len(b)):
        s.append(a[i])
        s.append(b[i])
    s.append(a[-1])
print("".join(s))
x=input()
a,b=input().split()
x=int(x)
a=int()
b=int()
if abs(x-a)<abs(x-b):
   print("A")
else:
   print("B")

### FIXED CODE ###

x,a,b=map(int,input().split())
if abs(x-a) > abs(x-b):
	print("B")
else:
	print("A")
n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    for i in range(101):
        if map_list[i][2] > 0:
            x = int(map_list[i][0])
            y = int(map_list[i][1])
            h = int(map_list[i][2])
            break
        else:
            continue

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
            
            for data in map_list:
                xx, yy, hh = map(int, data)
                if hh != max(H - abs(xx - i) - abs(yy - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)



### FIXED CODE ###

n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    for i in range(101):
        if int(map_list[i][2]) > 0:
            x = int(map_list[i][0])
            y = int(map_list[i][1])
            h = int(map_list[i][2])
            break
        else:
            continue

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
            
            for data in map_list:
                xx, yy, hh = map(int, data)
                if hh != max(H - abs(xx - i) - abs(yy - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)
a, b, x = map(int, input().split())
r = 180 / math.pi
h = x / a ** 2
c = h * 2 - b
d = 2 * x / (a * b)
if h >= b / 2:
    th = math.atan((h - c) / (a / 2)) * r
else:
    th = ((math.pi / 2) - math.atan((d / b))) * r
print(th)

### FIXED CODE ###

import math


a, b, x = map(int, input().split())
r = 180 / math.pi
h = x / a ** 2
c = h * 2 - b
d = 2 * x / (a * b)
if h >= b / 2:
    th = math.atan((h - c) / (a / 2)) * r
else:
    th = ((math.pi / 2) - math.atan((d / b))) * r
print(th)
import sys

N = int(sys.stdin.readline().rstrip())
TMP_C = [x for x in input()]
C = []
for i in range(N - 1, -1, -1):
    C.append(TMP_C[i])
# print(C)

cnt = 0
for i in range(N - 1, -1, -1):
    if C[i] == "W":
        j = C.index("R")
        if j < i:
            C[i], C[j] = C[j], C[i]
            cnt += 1

print(cnt)


### FIXED CODE ###

import sys
from collections import Counter

N = int(sys.stdin.readline().rstrip())
S = [x for x in input()]

C = Counter(S)

W = C["W"]
R = C["R"]

SS = S[:R]
CC = Counter(SS)
RR = CC["W"]

print(RR)
a = map(int, raw_input().split())
print ' ',join(str, a.sort())

### FIXED CODE ###

a = map(str, raw_input().split())
print ' '.join(sorted(a))
# Sample Input:
# 4 1
# 5 4 2 1
# total votes = 12
# 1/4M * 12 = 1/4 * 12 = 3, can't select item < 3

first_input = input("").split(" ")
N, M = map(int, first_input)
items = input("")

items = items.split(" ")
total_votes = list(map(float, items))

total_votes = sum(total_votes)

min_N = total_votes * ( 1.0 / (4.0 * M) )

if(N < min_N):
    print("No")
else:
    print("Yes")

### FIXED CODE ###

input_arr = input("").split(" ")
a, b, c = map(str, input_arr)

print(c + " " + a + " " + b)
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bin_sort(A,n_min=None,n_max=None):
    if(n_min is None): n_min=min(A)
    if(n_max is None): n_max=max(A)
    bin=[0]*(n_max-n_min+1)
    for a in A: bin[a-n_min]+=1
    B=[]
    for i in range(n_min,n_max+1): B+=[i]*bin[i-n_min]
    return B

def resolve():
    n=int(input())
    A=[0]*n
    for a in map(int,input().split()): A[a-1]+=1
    A=bin_sort(A,0,n-1)
    S=[0]*(n+1)
    for i in range(n): S[i+1]=S[i]+A[i]
    # output
    p=n; i=n
    for k in range(1,n+1):
        while(1):
            while(1):
                if(i<=0 or A[i-1]<p): break
                i-=1
            if(S[i]+p*(n-i)>=k*p): break
            p-=1
        print(p)
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def bisection(l,r,f,discrete=True,left=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return h if not discrete else l if left else r

def resolve():
    from collections import Counter
    from bisect import bisect_left
    n=int(input())
    A=Counter(map(int,input().split()))
    A=list(A.values())
    A.sort()
    m=len(A)
    S=[0]*(m+1)# cumulative distribution
    for i in range(m):
        S[i+1]=S[i]+A[i]
    for k in range(1,n+1):
        def check(p):
            i=bisect_left(A,p)
            return S[i]+(m-i)*p>=k*p
        print(bisection(0,n//k+1,check))
resolve()
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ttl=[]
cnt=[]
count=0
for i in range(n):
  nxt=i+1
  grp=[]
  count=0
  pnt=[]
  pnt.append(0)
  for j in range(n):
    nxt=p[nxt-1]
    pnt.append(pnt[j]+c[nxt-1])
    count+=1
    if nxt==i+1:
      del pnt[0]
      ttl.append(pnt)
      cnt.append(count)
      break
ans=[]
for i in range(n):
  peak=ttl[i].index(max(ttl[i]))
  if k<=cnt[i]:
    ans.append(max(ttl[i][:k]))
  else:
    if ttl[i][-1]<0:
      ans.append(ttl[i][peak])
    else:
      ans.append(max((k//cnt[i])*ttl[i][-1]+max(ttl[i][0:k%cnt[i]]),((k-peak-1)//cnt[i])*ttl[i][-1]+ttl[i][peak]))
print(max(ans))

### FIXED CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ttl=[]
cnt=[]
count=0
for i in range(n):
  nxt=i+1
  grp=[]
  count=0
  pnt=[]
  pnt.append(0)
  for j in range(n):
    nxt=p[nxt-1]
    pnt.append(pnt[j]+c[nxt-1])
    count+=1
    if nxt==i+1:
      del pnt[0]
      ttl.append(pnt)
      cnt.append(count)
      break
ans=[]
for i in range(n):
  peak=ttl[i].index(max(ttl[i]))
  if k<=cnt[i]:
    ans.append(max(ttl[i][:k]))
  else:
    if ttl[i][-1]<0:
      ans.append(ttl[i][peak])
    else:
      if k%cnt[i]==0:
        ans.append(((k-peak-1)//cnt[i])*ttl[i][-1]+ttl[i][peak])
      else:
        ans.append(max((k//cnt[i])*ttl[i][-1]+max(ttl[i][0:k%cnt[i]]),((k-peak-1)//cnt[i])*ttl[i][-1]+ttl[i][peak]))
print(max(ans))
s = str(input())
s[3] = 8
print(s)

### FIXED CODE ###

s = list(map(str,input()))
s[3] = "8"
print(*s,sep="")
n, m = map(int, input().split())

jobs = [[] for i in range(10**4+1)]

for i in range(n):
    a, b = map(int, input().split())
    jobs[b].append(a)

job_schedules = [0 for _ in range(m+1)]
today = m
for i in range(len(jobs)-1, -1, -1):
    jobs[i].sort()
    for j in jobs[i]:
        day = min(today, m - j)
        while job_schedules[day] and day >= 0:
            day -= 1
        if day < 0:
            break
        job_schedules[day] = i

print(sum(job_schedules))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())

jobs = [[] for i in range(10**5+1)]

for i in range(n):
    a, b = map(int, input().split())
    jobs[a].append(b)

candidate = []
ans = 0
for i in range(m+1):
    for j in jobs[i]:
        heapq.heappush(candidate, -j)

    # print(i, candidate)
    if len(candidate) >= 1:
        ans += heapq.heappop(candidate) * -1


print(ans)
a,b=input().split()
a=int(a)
b=int(b)
if a-b>=2:
  print(2a-1)
if b-a>=2:
  print(2b-1)
else:
  print(a+b)

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=int(b)
if a-b>=2:
  print(2*a-1)
if b-a>=2:
  print(2*b-1)
if -2<a-b<2:
  print(a+b)
import itertools

nums = [int(e) for e in input().split()]

list0 = []
for i in range(0, nums[0]):
    val = [int(e) for e in input().split()]
    list0.append(val)

A = []
A0 = list(range(0,nums[0]))
for i in range(0,nums[0]):
    for x in itertools.combinations(A0,i+1):
        A1 = list(x)
        A1 = list(set(A1))
        A.append(A1)

X = []
for i in range(0,len(A)):
    Y = [0] * (nums[1]+1)
    for j in range(0,len(A[i])):
        Y = [x + y for (x, y) in zip(Y,list0[A[i][j]])]
    X.append(Y)

B = []
for i in range(0,len(X)):
    if X[i][1] >= nums[2] and X[i][2] >= nums[2] and X[i][3] >= nums[2]:
        B.append(X[i][0])

if len(B) == 0:
    print('-1')
else:
    print(min(B))

### FIXED CODE ###

import itertools

nums = [int(e) for e in input().split()]

list0 = []
A = []
A0 = list(range(0,nums[0]))
for i in range(0, nums[0]):
    val = [int(e) for e in input().split()]
    list0.append(val)
    for x in itertools.combinations(A0,i+1):
        A.append(list(x))

Z = [0]
for i in range(1,nums[1]+1):
    Z.append(nums[2])

X = []
for i in range(0,len(A)):
    Y = [0] * (nums[1]+1)
    for j in range(0,len(A[i])):
        Y = [x + y for (x, y) in zip(Y,list0[A[i][j]])]
    W = [x - y for (x, y) in zip(Y,Z)]
    if min(W) >= 0:
        X.append(Y[0])

if len(X) > 0:
    print(min(X))
else:
    print('-1')
line = input().rstrip().split(" ")
x = int(line[0])
y = int(line[1])
print(str(x*y) + " " + str(2*x + 2*y)

### FIXED CODE ###

x = input().split(" ")
print(int(x[0])*int(x[1]), 2*(int(x[0])+int(x[1])))
n = int(input())
     
    M = 0
    A = 0
    R = 0
    C = 0
    H = 0
     
    res = 0
     
    for i in range(n):
        char = input()[0]
        if char == "M":
            M += 1
        elif char == "A":
            A += 1
        elif char == "R":
            R += 1
        elif char == "C":
            C += 1
        elif char == "H":
            H += 1
     
    res += M * A * R;
    res += M * A * C;
    res += M * A * H;
    res += M * R * C;
    res += M * R * H;
    res += M * C * H;
     
    res += A * R * C;
    res += A * R * H;
    res += A * C * H;
     
    res += R * C * H;
     
    print(res)

### FIXED CODE ###

n = int(input())
 
M = 0
A = 0
R = 0
C = 0
H = 0
 
res = 0
 
for i in range(n):
    char = input()[0]
    if char == "M":
        M += 1
    elif char == "A":
        A += 1
    elif char == "R":
        R += 1
    elif char == "C":
        C += 1
    elif char == "H":
        H += 1

res += M * A * R;
res += M * A * C;
res += M * A * H;
res += M * R * C;
res += M * R * H;
res += M * C * H;
 
res += A * R * C;
res += A * R * H;
res += A * C * H;
 
res += R * C * H;
 
print(res)
a = int(input())
s = int(input())

if a >= 3200:
  print(s)
else:
  print('red')

### FIXED CODE ###

a = int(input())
s = input()

if a >= 3200:
  print(s)
else:
  print('red')
N = int(input())

nodes = []

for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) for v in input().split(' ')]
    a -= 1
    b -= 1
    nodes[a].append((b, i))
    nodes[b].append((a, i))

max_l = 0
max_i = 0
for i, links in enumerate(nodes):
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, links, edge, pc):
    c = 1
    while pc & (1 << c) != 0:
        c += 1

    next_fills = []
    for n, i in links:
        if edge[i] != 0:
            pc |= (1 << edge[i])
            continue
        edge[i] = c
        next_fills.append((n, c))

        c += 1
        while pc & (1 << c) != 0:
            c += 1

    for n, c in next_fills:
        fill(nodes, nodes[n], e, (c << 1))
    
e = [0] * (N - 1)
fill(nodes, nodes[max_i], e, 0)

print(max_l)
for i in e:
    print(i)



### FIXED CODE ###

N = int(input())

nodes = []
edge = []
for i in range(N):
    nodes.append([])

for i in range(N-1):
    a, b = [int(v) - 1 for v in input().split(' ')]
    if a >= len(nodes):
        exit()
    if b >= len(nodes):
        exit()
    nodes[a].append((b, i))
    nodes[b].append((a, i))
    edge.append(0)

max_l = 0
max_i = 0
if nodes is None:
    exit()

for i, links in enumerate(nodes):
    if links is None:
        exit()
    l = len(links)
    if max_l < l:
        max_l = l
        max_i = i

def fill(nodes, edge, queue):
    while len(queue) > 0:
        ni, pc = queue.pop(0)
        links = nodes[ni]

        c = 1
        if pc == c:
            c += 1

        if links is None:
            exit()

        next_links = []
        for n, i in links:
            if n < 0 or i < 0:
                exit()
            if n >= len(nodes) or i >= len(edge):
                exit()

            if edge[i] != 0:
                continue
            edge[i] = c
            queue.append((n, c))

            c += 1
            if pc == c:
                c += 1

queue = [(max_i, 0)]    
fill(nodes, edge, queue)

print(max_l)
for e in edge:
    print(e)
s=list(input())
fld="WA"
if s[0]=="A":
  if "C" in s[2:len(s)-1]:
    s.remove("A")
    s.remove("C")
    s=' '.join(s)
    if s.islower()==True:
      flg="AC"

print(flg)


### FIXED CODE ###

s = list(input())
flg = 'WA'
if s[0] == 'A':
    if 'C'in s[2:len(s)-1]:
        s.remove('A')
        s.remove('C')
        s = ''.join(s)
        if s.islower() == True:
            flg = 'AC'
print(flg)
from sys import stdin
import numpy as np

if __name__ == '__main__':

    N = int(stdin.readline())
    # A だけどNUMPYにあわせてｂ
    b = [int(x) for x in stdin.readline().rstrip().split()]

    # [NumPyで全要素を同じ値で初期化した配列ndarrayを生成 \| note\.nkmk\.me](https://note.nkmk.me/python-numpy-zeros-ones-full/)
    A = np.zeros((N, N))
    for i in range(N):
        if i == N - 1:
            A[i][0] = 0.5
            A[i][i] = 0.5
        else:
            A[i][i] = 0.5
            A[i][i+1] = 0.5

    B = np.array(b)

    # [\[Pythonで数値解析\]\(第5回\)連立一次方程式の数値解法 \- Qiita](https://qiita.com/Y_F_Acoustics/items/b386ff8da11e2c912712)
    ans = np.linalg.solve(A, B)

    int_ans = [str(int(x)) for x in ans]
    print(' '.join(int_ans))


### FIXED CODE ###

from sys import stdin

if __name__ == '__main__':

    N = int(stdin.readline())
    A = [int(x) for x in stdin.readline().rstrip().split()]

    tmp = list()
    for i in range(N):
        if i % 2 == 0:
            continue

        tmp.append(A[i])

    X = list()
    X.append(sum(A) - sum(tmp) * 2)

    for i in range(N):
        if i == 0:
            continue

        X.append(2 * A[i-1] - X[i-1])

    print(' '.join([str(x) for x in X]))
print(input()*input()*input())

### FIXED CODE ###

x = int(input())
print(x*x*x)
n = int(input())
d = list(map(int,input().split()))

s = int(0)

s += d[0] * d[n]


for i in range(n):
    s += d[n] * d[n+1]

print(s)

### FIXED CODE ###

n = int(input())

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

s = int(0)

for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        else:
            s += d[i] * d[j]

print(s)
n,k = map(int,input().split())
p_list = list(map(int,input().split()))
ruiseki = []
a = 0
for i in range(n):
  a += p_list[i]
  ruiseki.append(a)
res = -1
for m in (n-k):
  val = ruiseki[k+i] - ruiseki[i]
  if val > res:
    res = val
print(val) 

### FIXED CODE ###

n,k = map(int,input().split())
p_list = list(map(int,input().split()))
ruiseki = []
a = 0
for i in range(n):
  a += p_list[i]
  ruiseki.append(a)
res = -1
val_list = []
for m in range(n-k):
  val = ruiseki[k+m] - ruiseki[m]
  val_list.append(val)
if n ==k :
  	print((sum(p_list) + k)/2)
else:
	print((max(val_list)+k)/ 2)
N=int(input())
print((N*(N-1))/2)

### FIXED CODE ###

S=input()
T=input()
ans=0
for i in range(3):
  if S[i]==T[i]:
    ans+=1
print(ans)
n = int(input())
s = input()

if "." not in s or "#" not in s:
    print(0)
else:
    ans = len(s)

    s = s[s.find("#"):n-s[::-1].find(".")]
    cnt_b = [0 for i in range(len(s))]
    cnt = 0
    for i in range(len(s)):
        if s[i] == "#":
            cnt += 1
        cnt_b[i] = cnt
    ans = min(ans, len(s)-cnt_b[-1])
    for i in range(len(s)):
        ans = min(ans, cnt_b[i] + (len(s)-cnt_b[-1])-(i+1-cnt_b[i]))
    print(ans)


### FIXED CODE ###

n = int(input())
s = input()

if "." not in s or "#" not in s:
    print(0)
else:
    ans = len(s)

    s = s[s.find("#"):n-s[::-1].find(".")]
    if s == "":
        print(0)
    else:
        cnt_b = [0 for i in range(len(s))]
        cnt = 0
        for i in range(len(s)):
            if s[i] == "#":
                cnt += 1
            cnt_b[i] = cnt
        ans = min(ans, len(s)-cnt_b[-1])
        for i in range(len(s)):
            ans = min(ans, cnt_b[i] + (len(s)-cnt_b[-1])-(i+1-cnt_b[i]))
        print(ans)
n = int(input())
edges = [[int(i) for i in input().split()] for _ in range(n - 1)]

BLACK = 1
WHITE = 0
UNKNOWN = -1

if n == 1:
    print(BLACK)

colors = [UNKNOWN] * (n + 1)

graph = [[] for _ in range(n + 1)]
for e in edges:
    graph[e[0]].append((e[1], e[2]))
    graph[e[1]].append((e[0], e[2]))

def dfs(graph, colors, current_point, current_color):
    colors[current_point] = current_color

    for next_point_info in graph[current_point]:
        if colors[next_point_info[0]] != UNKNOWN:
            continue
        if (next_point_info[1] % 2 == 0):
            next_color = current_color
        else:
            next_color = 1 - current_color
        dfs(graph, colors, next_point_info[0], next_color)

dfs(graph, colors, 1, BLACK)
for c in colors[1:]:
    print(c)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n = int(input())
edges = [[int(i) for i in input().split()] for _ in range(n - 1)]

BLACK = 1
WHITE = 0
UNKNOWN = -1

import sys
if n == 1:
    print(BLACK)
    sys.exit(0)

colors = [UNKNOWN] * (n + 1)

graph = [[] for _ in range(n + 1)]
for e in edges:
    graph[e[0]].append((e[1], e[2]))
    graph[e[1]].append((e[0], e[2]))

def dfs(graph, colors, current_point, current_color):
    colors[current_point] = current_color

    for next_point_info in graph[current_point]:
        if colors[next_point_info[0]] != UNKNOWN:
            continue
        if (next_point_info[1] % 2 == 0):
            next_color = current_color
        else:
            next_color = 1 - current_color
        dfs(graph, colors, next_point_info[0], next_color)

dfs(graph, colors, 1, BLACK)
for c in colors[1:]:
    print(c)
n,m=map(int(input().split()))
if m=1:
    print(0)
else:
    print(n-m)

### FIXED CODE ###

n,m=map(int,input().split())
if m==1:
    print(0)
else:
    print(n-m)
S = input()
T = input()

flag = True
for i in range(len(S)):
    if S{i} == T[i]:
        pass
    else:
        flag = False
        
if flag:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

S = input()
T = input()

flag = True
for i in range(len(S)):
    if S[i] == T[i]:
        pass
    else:
        flag = False
        
if flag:
    print("Yes")
else:
    print("No")
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
if len(set(a)) == n:
    print(n - 2)
elif len(set(a)) == 1:
    print(n//2)
else:
    f = {}
    s = {}
    for i in range(n):
        if i % 2 == 0:
            if a[i] not in f:
                f[a[i]] = 0
            f[a[i]] += 1
        else:
            if a[i] not in s:
                s[a[i]] = 0
            s[a[i]] += 1
    fsum = sum(f.values())
    ssum = sum(s.values())
    f = sorted(f.items(), key=lambda x: x[1], reverse=True)
    s = sorted(s.items(), key=lambda x: x[1], reverse=True)
    if f[0][0] == s[0][0]:
        tmp1 = fsum - f[0][1] + ssum - s[0][2]
        tmp2 = fsum - f[0][2] + ssum - s[0][1]
        print(min(tmp1, tmp2))
    else:
        print(fsum - f[0][1] + ssum - s[0][1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
if len(set(a)) == n:
    print(n - 2)
elif len(set(a)) == 1:
    print(n//2)
else:
    f = {}
    s = {}
    for i in range(n):
        if i % 2 == 0:
            if a[i] not in f:
                f[a[i]] = 0
            f[a[i]] += 1
        else:
            if a[i] not in s:
                s[a[i]] = 0
            s[a[i]] += 1
    fsum = sum(f.values())
    ssum = sum(s.values())
    f = sorted(f.items(), key=lambda x: x[1], reverse=True)
    s = sorted(s.items(), key=lambda x: x[1], reverse=True)
    if f[0][0] == s[0][0]:
        tmp1 = fsum - f[0][1] + ssum - s[1][1]
        tmp2 = fsum - f[1][1] + ssum - s[0][1]
        print(min(tmp1, tmp2))
    else:
        print(fsum - f[0][1] + ssum - s[0][1])
x,y,z,k = map(int,input().split())

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

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

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

ab = []
ans = []
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort(reverse=True)

for i in range(k):
    for j in range(z):
        ans.append(ab[i]+c[j])
ans.sort(reverse=True)

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

### FIXED CODE ###

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

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

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

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

ab = []
ans = []
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort(reverse=True)

if len(ab) < k:
    for i in range(len(ab)):
        for j in range(z):
            ans.append(ab[i]+c[j])
else:
    for i in range(k):
        for j in range(z):
            ans.append(ab[i]+c[j])

ans.sort(reverse=True)

for i in range(k):
    print(ans[i])
import numpy as np

X=int(input())
ansa=0
ansb=0
for b in range(100):
    a5 = b**5 + X
    sig = False
    if a5 < 0:
        sig = True
        a5 = abs(a5)
    a1 = np.power(a5,1/5)

    if sig:
        a1 *= -1

    if a1 == int(a1):
        ansa=int(a1)
        ansb=b
        break
if ansa >0 or ansb>0:
    print(ansa,ansb)
    exit()

### FIXED CODE ###

from decimal import Decimal

X=Decimal(input())
ansa=0
ansb=0
# for b in range(1000):
#     a5 = Decimal(b**5) + X
#     sig = False
#     if a5 < 0:
#         sig = True
#         a5 = abs(a5)
#     a1 = pow(a5,Decimal('0.2'))

#     if sig:
#         a1 *= -1

#     if a1 == int(a1):
#         ansa=int(a1)
#         ansb=b
#         break
# if ansa >0 or ansb>0:
#     print(ansa,ansb)
#     exit()

for a in range(-1000,1000):
    b5 = Decimal(a**5) - X
    sig = False
    if a==100:
        print()
    if b5 < 0:
        sig = True
        b5 = abs(b5)
    b1 = pow(b5,Decimal('0.2'))

    if sig:
        b1 *= -1

    if b1 == int(b1):
        ansa=a
        ansb=int(b1)
        break
print(ansa,ansb)
S = input()
K = int(input())
if S[0] == "1":
  print(S[1])
else:
  print(S[0])

### FIXED CODE ###

S = input()
K = int(input())
for i in range(len(S)):
  if S[i] == "1":
    K -= 1
  else:
    K = 0
  if K == 0:
    break
print(S[i])
a,b,c=input()
if a="S":
  elif b="S":
    elif c="S":
      	print(0)
    else:
        print(1)
  else:
    elif c="S":
      print(1)
    else:
      print(2)
else:
  elif b="S":
    elif c="S":
      	print(1)
    else:
        print(1)
  else:
    elif c="S":
      print(2)
    else:
      print(3)

### FIXED CODE ###

x=list(input())
if x.count("R")==0:
  print(0)
elif x.count("R")==1:
  print(1)
elif x.count("R")==3:
  print(3)
else:
  if x[1]=="S":
    print(1)
  else:
    print(2)