Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N, W = [int(_) for _ in input().split()]
WV = [[int(_) for _ in input().split()] for _ in range(N)]
dp = {}
dp[0] = 0
for w, v in WV:
    dp_o = dp.copy()
    for k in dp_o:
        if k + w <= W:
            dp[k + w] = max(dp_o.get(k + w, 0), dp_o[k] + v)
print(max([v for k, v in dp.items()]))


### FIXED CODE ###

N, W = [int(_) for _ in input().split()]
WV = [[int(_) for _ in input().split()] for _ in range(N)]
dp = {}
dp[0] = 0
for w, v in WV:
    dp_o = dp.copy()
    for k in dp_o:
        dp[k + v] = min(dp_o.get(k + v, float('inf')), dp_o[k] + w)
print(max([k for k, v in dp.items() if v <= W]))
### BUGGY CODE ###

import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N, M)
box = ["" for _ in range(L)]
for i in range(N):
    box[i * (L // N)] = S[i]
for j in range(M):
    temp = j * (L // M)
    if box[temp] == "":
        box[temp] = T[j]
    elif box[temp] == T[j]:
        continue
    else:
        print(-1)
        break
else:
    print(L)

### FIXED CODE ###

import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N, M)
G = math.gcd(N, M)
for i in range(G):
    if S[N//G * i] != T[M//G * i]:
        print(-1)
        break
else:
    print(L)
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
l = []
y = 0
for x in range(1, 1001):
    y += x
    l.append(y/x)
m = []
for i in p:
    m.append(l[i-1])
s = [0]
z = 0
for i in m:
    z += i
    s.append(z)
ans = []
for i in range(n-k+1):
    List = p[i:i+k]
    ans.append(s[i+k] - s[i])
print(max(ans))

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
l = []
y = 0
for x in range(1, 1001):
    y += x
    l.append(y/x)
m = []
for i in p:
    m.append(l[i-1])
s = [0]
z = 0
for i in m:
    z += i
    s.append(z)
ans = 0
for i in range(n-k+1):
    ans = max(ans, s[i+k] - s[i])
print(ans)
### BUGGY CODE ###

s = input()

s2 = s
for i in range(len(s)):
    s2 = s2.replace('10', '')
    s2 = s2.replace('01', '')
    if len(s) == len(s2):
        break

print(len(s) - len(s2))

### FIXED CODE ###

s = input()

print(min(s.count('0'), s.count('1')) * 2)
### BUGGY CODE ###

def Warshall_Floyd(edges,N):
  import copy
  d=copy.deepcopy(edges)
  for k in range(N):
    for i in range(N):
      for j in range(N):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
  return d

inf=float("inf")
N,M=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(M)]
A=[[inf for j in range(N)] for i in range(N)]#最短距離map
for i in range(N):
  A[i][i]=0
for i in range(M):
  A[abc[i][0]-1][abc[i][1]-1]=abc[i][2]
  A[abc[i][1]-1][abc[i][0]-1]=abc[i][2]
Ans=Warshall_Floyd(A,N)
ans=0
for j in range(M):
  B=[[inf for j in range(N)] for i in range(N)]#最短距離map
  for i in range(N):
    B[i][i]=0
  for i in range(M):
    if i!=j:
      B[abc[i][0]-1][abc[i][1]-1]=abc[i][2]
      B[abc[i][1]-1][abc[i][0]-1]=abc[i][2]
  Bns=Warshall_Floyd(B,N)
  if Bns==Ans: ans+=1
print(ans)

### FIXED CODE ###

def Warshall_Floyd(edges,N):
  import copy
  d=copy.deepcopy(edges)
  for k in range(N):
    for i in range(N):
      for j in range(N):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
  return d

inf=float("inf")
N,M=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(M)]
A=[[inf for j in range(N)] for i in range(N)]#最短距離map
for i in range(N):
  A[i][i]=0
for i in range(M):
  A[abc[i][0]-1][abc[i][1]-1]=abc[i][2]
  A[abc[i][1]-1][abc[i][0]-1]=abc[i][2]
Ans=Warshall_Floyd(A,N)
ans=0
for j in range(M):
  u=abc[j][0]-1
  v=abc[j][1]-1
  for s in range(N):
    if Ans[s][u]+abc[j][2]==Ans[s][v]:
      ans+=1
      break
print(M-ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in a:
	ans *= i
if ans <= 10**18:
	print(ans)
else:
	print(-1)

### FIXED CODE ###

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

if 0 in a:
	print(0)
	exit()

for i in a:
	ans *= i
	if ans > 10**18:
		print(-1)
		exit()

print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

T1, T2 = rl()
A1, A2 = rl()
B1, B2 = rl()

A1 = (A1 - B1) * T1
A2 = (A2 - B2) * T2
#print(A1, A2)
if A1 + A2 == 0:
    print('infinity')
    exit()
if A1 * (A1 + A2) > 0:
    print(0)
    exit()
cur = 0
answer = -1
while True:
    cur1 = cur + A1
    if cur * cur1 <= 0:
        answer += 1
    else:
        break
    if cur1 == 0:
        break
    cur = cur1
    cur2 = cur + A2
    if cur * cur2 <= 0:
        answer += 1
    else:
        break
    if cur2 == 0:
        break
    cur = cur2
print(answer)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

T1, T2 = rl()
A1, A2 = rl()
B1, B2 = rl()

if T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2:
    print('infinity')
    exit()
if (A1 > B1 and A1 * T1 + A2 * T2 > B1 * T1 + B2 * T2) or \
        (A1 < B1 and A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2):
    print(0)
    exit()
diff = abs(A1-B1) * T1
diff2 = abs(T1 * A1 + T2 * A2 - (T1 * B1 + T2 * B2))
x, y = divmod(diff, diff2)
print(x * 2 if y == 0 else x * 2 + 1)
### BUGGY CODE ###

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

def lcm(x,y):
    return x*y//gcd(x,y)
mod = 10**9+7
n = int(input())
a = list(map(int,input().split()))
L = a[0]
for i in a:
    L = lcm(L,i)
    
ans = 0
for i in a:
    ans += (L // i )
print(ans % mod)

### FIXED CODE ###

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

def lcm(x,y):
    return x*y//gcd(x,y)

mod = 10**9+7
n = int(input())
a = list(map(int,input().split()))
L = a[0]
for i in a:
    L = lcm(L,i)
    
ans = 0
for i in a:
    ans += (L // i )
print(ans % mod)
### BUGGY CODE ###

n = int(input())

for h in range(1,3501):
    for w in range(1,3501):
        if 4 * h * w - n * w - n * h != 0:
            N = (n * h * w) / (4 * h * w - n * w - n * h)
            if N.is_integer() and N > 0:
                print(h,w,int(N))
                exit()


### FIXED CODE ###

n = int(input())

for h in range(1,3501):
    for w in range(1,3501):
        if 4 * h * w - n * w - n * h != 0:
            N = (n * h * w) / (4 * h * w - n * w - n * h)
            if N.is_integer() and N > 0:
                print(h,w,int(N))
                exit()
### BUGGY CODE ###

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

A = A + [0]
for k in range(K):
    t = [0]*(N+1)
    for i in range(N):
        l = max(i-A[i], 0)
        r = min(i+A[i], N-1)
        t[l] += 1
        t[r+1] -= 1

    S = [0]*N
    S[0] = t[0]
    for i in range(1, N):
        S[i] = S[i-1] + t[i]

    A = S.copy()
    if all(a == N for a in A):
        print(*A)
        exit()
print(*S)

### FIXED CODE ###

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

A = A + [0]
K = min(K, 50)
for k in range(K):
    t = [0]*(N+1)
    for i in range(N):
        l = max(i-A[i], 0)
        r = min(i+A[i], N-1)
        t[l] += 1
        t[r+1] -= 1

    S = [0]*N
    S[0] = t[0]
    for i in range(1, N):
        S[i] = S[i-1] + t[i]

    A = S.copy()
print(*S)
### BUGGY CODE ###

N, Q = list(map(int, input().split()))
s = input()

dic = {}
for n in range(len(s)):
    if s[n] in dic:
        dic[s[n]].append(n)
    else:
        dic[s[n]] = [n]

go = [1] * N
Z = N

for q in range(Q):
    t, d = input().split()
    if t in dic:
        loc = dic[t]
        if d == 'L':
            for l in loc:
                if l == 0:
                    Z -= go[l]
                    go[l] = 0
                else:
                    go[l - 1] += go[l]
                    go[l] = 0
        else:
            for l in loc:
                if l == N - 1:
                    Z -= go[l]
                    go[l] = 0
                else:
                    go[l + 1] += go[l]
                    go[l] = 0

print(Z)

### FIXED CODE ###

N, Q = list(map(int, input().split()))
s = input()

lt = []
ld = []

for q in range(Q):
    t, d = input().split()
    lt.append(t)
    ld.append(d)

pl = -1
pr = N

for q in range(Q-1, -1, -1):
    if ld[q] == 'L':
        if pl < N - 1 and s[pl + 1] == lt[q]:
            pl += 1
        if pr <= N - 1 and s[pr] == lt[q]:
            pr += 1
    else:
        if pr > 0 and s[pr - 1] == lt[q]:
            pr -= 1
        if pl >= 0 and s[pl] == lt[q]:
            pl -= 1

print(max(pr - pl -1, 0))
### BUGGY CODE ###

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

a_max = max(a)
max_idx = [i for i, x in enumerate(a) if x == a_max]

for i in range(n):
    if i in max_idx:
        print(max(a[0:i]+a[i+1:]))
    else:
        print(a_max)

### FIXED CODE ###

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

a_max = max(a)
idx = [i for i, x in enumerate(a) if x==a_max]

if len(idx) > 1:
    for i in range(n):
        print(a_max)
else:
    for i in range(n):
        if a[i] == a_max:
            print(max(a[0:i]+a[i+1:]))
        else:
            print(a_max)
### BUGGY CODE ###

s = input()
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(s)+1)]
for i in range(10):
    if s[0] == "?":
        dp[1][i] += 1
    else:
        dp[1][int(s[0])] = 1
        break

for i, v in enumerate(s):
    if i == 0:
        continue
    for j in range(13):
        for k in range(10):
            x = (10 * j + k) % 13
            if v != "?":
                if int(v) == k:
                    dp[i + 1][x] += dp[i][j]
                    dp[i + 1][x] %= mod
                else:
                    dp[i + 1][x] += 0
            else:
                dp[i + 1][x] += dp[i][j]
                dp[i + 1][x] %= mod

print(dp[-1][5])

### FIXED CODE ###

s = input()
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(s)+1)]
for i in range(10):
    if s[0] == "?":
        dp[1][i] += 1
    else:
        dp[1][int(s[0])] = 1
        break

for i, v in enumerate(s):
    if i == 0:
        continue
    for j in range(13):
        for k in range(10):
            x = (10 * j + k) % 13
            if v != "?":
                if int(v) == k:
                    dp[i + 1][x] += dp[i][j]
                    dp[i + 1][x] %= mod
                else:
                    dp[i + 1][x] += 0
            else:
                dp[i + 1][x] += dp[i][j]
                dp[i + 1][x] %= mod

print(dp[-1][5])
### BUGGY CODE ###

input()
A = map(int,input().split())
ans = 1
for a in A:
    if a==0:
        ans = 0
        break
    ans*=a
print(-1 if ans>10**18 else ans)

### FIXED CODE ###

input()
A = list(map(int,input().split()))
if 0 in A:
    print(0)
    quit()
else:
    prod = 1
    for a in A:
        prod*=a
        if prod > 10**18:
            print(-1)
            quit()
    print(prod)
### BUGGY CODE ###

import numpy as np
from numba import njit, prange

N, Q = map(int, input().split())
C = np.asarray(list(map(int, input().split())))
LR = np.asarray([list(map(int, input().split())) for _ in range(Q)])

@njit('(i8, i8, i8[:], i8[:,:])', parallel=True)
def solve(N, Q, C, LR):
    ans = np.zeros(N, dtype=np.int64)
    for i in prange(Q):
        l, r = LR[i]
        used = np.zeros(N + 1, dtype=np.int32)

        for j in range(l - 1, r):
            if used[C[j]] == 0:
                ans[i] += 1
                used[C[j]] += 1

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

solve(N, Q, C, LR)


### FIXED CODE ###

class BIT:
    """
    1-indexed
    """
    def __init__(self, size):
        self.size = size
        self.data = [0] * (size + 1)

    def add(self, index, value=1):
        while index <= self.size:
            self.data[index] += value
            index += index & (-index)

    def sum(self, index):
        """
        右端含める
        """
        ret = 0
        while index:
            ret += self.data[index]
            index -= index & (-index)
        return ret

    def search(self, val):
        """
        x_1 + ... x_i >= val を満たす最小のi
        """
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)  # 一番上の長さ

        while step:
            if i + step <= self.size and s + self.data[i + step] < val:
                i += step
                s += self.data[i]
            step //= 2
        return i + 1

N, Q = map(int, input().split())
C = [-1] + list(map(int, input().split()))
tree = BIT(N)

query = [[] for _ in range(N + 1)]
for q in range(Q):
    l, r = map(int, input().split())
    query[r].append((q, l))

index = [-1] * (N + 1)
ans = [0] * Q

for r in range(1, N + 1):
    if index[C[r]] > 0:
        tree.add(index[C[r]], -1)
    tree.add(r, 1)
    index[C[r]] = r

    for q, l in query[r]:
        ans[q] = tree.sum(r) - tree.sum(l - 1)

print(*ans, sep='\n')
### BUGGY CODE ###

from heapq import *
h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())

g = []
for i in range(h):
    g.append(input())

#dp[i][j][direction] = (count, rem)
inf = 10**18
dp = [[[(inf, inf) for i in range(4)] for j in range(w)] for k in range(h)]

q = [((0, 0), x1-1, y1-1, i) for i in range(4)]
used = [[[False for l in range(4)] for i in range(w)] for j in range(h)]

for i in range(4):
    dp[x1-1][y1-1][i] = (0, 0)

while q:
    count, x, y, d = heappop(q)
    if used[x][y][d]:
        continue
    used[x][y][d] = True

    for dx, dy, dd in [(-1, 0, 2), (1, 0, 0), (0, -1, 1), (0, 1, 3)]:
        if 0 <= x+dx <= h-1 and 0 <= y+dy <= w-1:
            if g[x+dx][y+dy] == "@":
                continue

            if dd == d:
                if count[1] == k-1:
                    nextcount = (count[0]+1, 0)
                else:
                    nextcount = (count[0], count[1]+1)

            else:
                nextcount = (count[0]+1, 0)

            if dp[x+dx][y+dy][dd] < nextcount:
                continue
            dp[x+dx][y+dy][dd] = nextcount
            heappush(q, (nextcount, x+dx, y+dy, dd))

ans = inf
for i in range(4):
    temp = dp[x2-1][y2-1][i][0]
    if dp[x2-1][y2-1][i][1] > 0:
        temp += 1
    ans = min(ans, temp)

if ans >= inf:
    ans = -1
print(ans)


### FIXED CODE ###

from collections import deque
h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())

g = []
for i in range(h):
    g.append(input())

inf = 10**9
dp = [[inf for j in range(w)] for k in range(h)]
dp[x1-1][y1-1] = 0
q = deque([(x1-1, y1-1)])

while q:
    x, y = q.popleft()
    if (x, y) == (x2-1, y2-1):
        break
    c = dp[x][y]
    for i in range(x+1, min(x+k+1, h)):
        if g[i][y] == "@":
            break

        if dp[i][y] == inf:
           q.append((i, y))

        if dp[i][y] >= c + 1:
            dp[i][y] = c + 1
        else:
            break


    for i in range(x-1, max(x-k-1, -1), -1):
        if g[i][y] == "@":
            break

        if dp[i][y] == inf:
           q.append((i, y))

        if dp[i][y] >= c + 1:
            dp[i][y] = c + 1
        else:
            break

    for j in range(y+1, min(y+k+1, w)):
        if g[x][j] == "@":
            break

        if dp[x][j] == inf:
            q.append((x, j))

        if dp[x][j] >= c + 1:
            dp[x][j] = c + 1
        else:
            break


    for j in range(y-1, max(y-k-1, -1), -1):
        if g[x][j] == "@":
            break

        if dp[x][j] == inf:
            q.append((x, j))

        if dp[x][j] >= c + 1:
            dp[x][j] = c + 1
        else:
            break

if dp[x2-1][y2-1] == inf:
    print(-1)
else:
    print(dp[x2-1][y2-1])
### BUGGY CODE ###

from collections import deque
n, m = map(int, input().split())
graph = [set([]) for _ in range(n+1)]
for _ in range(m):
    u, v = map(int, input().split())
    graph[u].add(v)

graph2 = [set([]) for _ in range(n+1)]
graph3 = [set([]) for _ in range(n+1)]
for i, g in enumerate(graph):
    if i == 0:
        continue

    for r in g:
        graph2[i] |= graph[r]
    
    for r in graph2[i]:
        graph3[i] |= graph[r]


s, t = map(int, input().split())
q = deque([s])
visited = [False] * (n+1)
visited[s] = True
dist = [-1] * (n+1)
dist[s] = 0
while q:
    now = q.popleft()
    for i in graph3[now]:
        if visited[i]:
            continue
        if i == now:
            continue
        q.append(i)
        visited[i] = True
        dist[i] = dist[now] + 1

print(dist[t])


### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
graph = [[[] for _ in range(3)] for _ in range(n+1)]
for _ in range(m):
    u, v = map(int, input().split())
    graph[u][0].append([v, 1])
    graph[u][1].append([v, 2])
    graph[u][2].append([v, 0])


s, t = map(int, input().split())
q = deque([[s, 0]])
visited = [[False] * 3 for _ in range(n+1)]
visited[s][0] = True
dist = [[-3] * 3 for _ in range(n+1)]
dist[s][0] = 0
while q:
    num, cnt = q.popleft()
    for i, j in graph[num][cnt]:
        if visited[i][j]:
            continue
        q.append([i, j])
        visited[i][j] = True
        dist[i][j] = dist[num][cnt] + 1

print(dist[t][0]//3)
### BUGGY CODE ###

import math
import itertools
k = int(input())
t = list(map(lambda x:list(x),itertools.product([i+1 for i in range(k)],repeat=3)))
ans = 0
for i in range(len(t)):
    ans += math.gcd(math.gcd(t[i][0],t[i][1]),t[i][2])
print(ans)

### FIXED CODE ###

import math
import itertools
k = int(input())
t = list(map(lambda x:list(x),itertools.product([i+1 for i in range(k)],repeat=2)))
ans = 0
for i in range(len(t)):
    cu = math.gcd(t[i][0],t[i][1])
    for j in range(1,k+1):
        ans += math.gcd(j,cu)
print(ans)
### BUGGY CODE ###

n = int(input())
a = input().split()
b = []
for i in a:
    b.append(i)
    b.reverse()
for i in range(n):
    print(b[i],end=" ")


### FIXED CODE ###

n = int(input())
a = input().split()
b = []
ans = []
even = a[1::2]
odd = a[0::2]
b.append(even)#even number
b.append(odd)#odd number
# print(b)
if len(a) % 2 == 0:
    for i in range(1,len(even) + 1):
        ans.append(even[-i])
    ans = ans + odd
else:
    for i in range(1,len(odd) + 1):
        ans.append(odd[-i])
    ans = ans + even
for i in range(len(ans)):
    if i != len(ans) -1:
        print(ans[i],end=" ")
    else:
        print(ans[i])
### BUGGY CODE ###

import bisect, functools
N = int(input())
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

@functools.lru_cache(maxsize=None)
def b_i(i):
    return sum(a(x) for x in B[:i])

@functools.lru_cache(maxsize=None)
def b(n):
    i = bisect.bisect_left(B, n)
    if len(B) + 1 == i:
        return b_i(i - 2) + a(B[i - 2])
    elif 2 <= i:
        return b_i(i - 1) + a(B[i - 1])
    elif 1 == i:
        return a(B[i - 1])
    else:
        return 0

def c():
    return sum(b(x) for x in C)

print(c())

### FIXED CODE ###

import bisect, functools, sys
sys.setrecursionlimit(10**6)
N = int(input())
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

b_cache = [0] * (N + 1)
b_cached = [False] * (N + 1)
def b_i(i):
    global b_cache, b_cached
    if i >= 1:
        if not b_cached[i - 1]: b_i(i - 1)
        t = b_cache[i - 1] + a(B[i - 1])
        b_cache[i] = t
        b_cached[i] = True
        return t
    return 0

@functools.lru_cache(maxsize=None)
def b(n):
    return b_i(min(N, bisect.bisect_left(B, n)))

def c():
    return sum(b(x) for x in C)

print(c())
### BUGGY CODE ###

n=int(input())
s=input()
R=[]
G=[]
B=[]

for i in range(n):
    if s[i]=="R":
        R.append(i)
    elif s[i]=="G":
        G.append(i)
    else:
        B.append(i)

b=len(B)
ans=0

for j in R:
    for k in G:
        cnt=b
        if 2*j-k in B:cnt-=1
        if 2*k-j in B:cnt-=1
        if (j+k)/2 in B:cnt-=1
        ans+=cnt

print(ans)


### FIXED CODE ###

from collections import Counter
n=int(input())
s=list(input())
C=Counter(s)
r,g,b=C["R"],C["G"],C["B"]
ans=r*g*b

for i in range(n-2):
    for j in range(i+1,n-1):
        k=2*j-i
        if k<=n-1 and s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ans-=1

print(ans)
### BUGGY CODE ###

n = int(input())

spot = input().split()

for i in range(n):
    total = 0

    pos = 0
    
    for l in range(n):
        if i == l:
            pass
        
        else:
            money = pos - int(spot[l])
            pos = int(spot[l])
            
            if money < 0:
                money *= -1
            total += money

    if pos < 0:
        pos *= -1
    total += pos
    
    print(total)

### FIXED CODE ###

from collections import deque

N = int(input())
A = deque(map(int, input().split()))

A.append(0)
A.appendleft(0)

A_diff = [abs(A[i+1] - A[i]) for i in range(N+1)]
A_sum = sum(A_diff)

for i in range(N):
    print(A_sum - (A_diff[i] + A_diff[i+1]) + abs(A[i+2] - A[i]))
### BUGGY CODE ###

c=[[0]*50for _ in range(50)]
r=0
for a in[*open(0)][1:]:
  a=round(float(a)*10**9)
  x=y=0
  while a%2<1:
    a//=2
    x+=1
  while a%5<1:
    a//=5
    y+=1
  r+=sum(sum(d[max(0,18-y):])for d in c[max(0,18-x):])
  c[x][y]+=1
print(r)

### FIXED CODE ###

c=[[0]*50for _ in range(50)]
r=0
for a in[*open(0)][1:]:
  a=round(float(a)*10**9)
  x=y=0
  while a%2<1:
    a//=2
    x+=1
  while a%5<1:
    a//=5
    y+=1
  r+=sum(sum(d[max(0,18-y):])for d in c[max(0,18-x):])
  c[x][y]+=1
print(r)
### BUGGY CODE ###

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

ans = 0
for i in range(0, n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if j-i == k-j: continue
            x = s[i] + s[j] + s[k]
            if x == 'RGB' or x == 'RBG' or x == 'BRG' or x == 'BGR' or x == 'GRB' or x == 'GBR': ans += 1
            #c = x.count('R') * x.count('G') * x.count('B')
            #if c == 1: ans += 1
print(ans)

### FIXED CODE ###

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

r = s.count('R')
g = s.count('G')
b = s.count('B')

count = 0
#count second conditions satisfied
for i in range(n):
    for j in range(i+1,n):
        #search j - i = k - j ⇔ k = 2 * j - i
        k = 2 * j - i
        if k >= n: break
        if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]: count += 1
print((r * g * b) - count)
### BUGGY CODE ###

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

mul = 1
for i in range(n):
    mul *= a[i]
print(mul if mul <= 1e18 else -1)

### FIXED CODE ###

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

mul = 1
if 0 in set(a): mul = 0
else:
    iter = 0
    for i in range(n):
        mul *= a[i]
        if mul > 1e18:
            mul = -1
            break
print(mul)
### BUGGY CODE ###

n = int(input())
num_list = [int(i) for i in input().split()]
ans = 0
mod = 10 ** 9 + 7

while len(num_list) > 1:
    x = num_list[0]
    num_list.remove(x)
    ans += (x * sum(num_list)) % mod

print (ans % mod)

### FIXED CODE ###

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

s = sum(a**2 for a in n_list)
ans = sum(n_list) ** 2 - s

print((ans//2)%(10**9+7))
### BUGGY CODE ###

x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

a_b = []
for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= k:
            a_b.append(a[i] + b[j])
        else:
            break
a_b.sort(reverse=True)
ans = []
for i in range(min(k, len(a_b))):
    for j in range(min(k, z)):
        ans.append(a_b[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 = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

ans = []
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i+1) * (j+1) * (l+1) <= k:
                ans.append(a[i] + b[j] + c[l])
            else:
                break

ans.sort(reverse=True)
for i in range(k):
    print(ans[i])