Harryxun/stf_run huggingface dataset:
def back_home():
    r=input()
    t=r.count('S') +1
    y=r.count('N') +1
    u=r.count('W') +1
    i=r.count('E')+1
    if (t>1 and y>1 and u==1 and i==1):
        print("YES")
    elif((t==1 and y==1 and u>1 and i>1):
       print("YES")
    elif ((t>1 and y>1 and u>1 and i>1):
        print("YES")
    else:
        print("NO")
        
back_home()

### FIXED CODE ###

def back_home():
    S=input()
    if((('S'in S) and ('N' in S)) and not (('E' in S) or  ('W' in S))):
        print('Yes')
    elif(not (('S' in S) or ('N'  in S)) and (('E' in S) and ('W' in S))):
        print("Yes")
    elif((('S'in S) and ('N' in S)) and (('E' in S) and ('W' in S))):
        print("Yes")
    else:
        print("No")
          
back_home()
ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

ab.sort(key=lambda x:x[1])

res=0
milestone=0
while(1):
    for j in range(len(ab)):
        if ab[0][1] < ab[j][0]:
          milestone=j
          res+=1
          break
    ab.remove[0:milestone]
    if len(ab)==0:break

print(res)

### FIXED CODE ###

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

ab.sort(key=lambda x:x[1])

res=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[0][0]:
            del ab[0]
        else:
            res+=1
            break
    if len(ab)==0:
        res+=1
        break
    
print(res)
N = input()


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

ls_sorted = sorted(ls)

K = ls_sorted[N//2] - ls_sorted[N//2 - 1]

print(K)

### FIXED CODE ###

N = int(input())


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

ls.sort()

K = ls[N//2] - ls[N//2 - 1]

print(int(K))
import numpy as np
a, b = list(map(int, input().split()))

n = int(np.ceil(np.log2(b)))+1
c = [0]*n
for i in range(n):
    ra = (a-1) % (2**(i+1))
    if ra < 2**i:
        ra1 = 0
    else:
        ra1 = 1
    rb = b % (2**(i+1))
    if rb < 2**i:
        rb1 = 0
    else:
        rb1 = 1    
    if ra1 == rb1:
        c[n-(i+1)] = '0'
    else:
        c[n-(i+1)] = '1'

s = ''.join(c)
ans = int(s, 2)
print(ans)    

### FIXED CODE ###

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

a2 = True
b2 = False
if a % 2 != 0:
    a0 = a
    a += 1
    a2 = False
if b % 2 == 0:
    b0 = b
    b -= 1
    b2 = True

c = b-(a-1)
if c % 2 == 0:
    if (c // 2) % 2 == 0:
        ans = 0
    else:
        ans = 1 
elif ((c-1) // 2) % 2 == 0:
    ans = 0 ^ b
else:
    ans = 1 ^ b
    
if a2 == False:
    ans = ans ^ a0
if b2 == True:
    ans = ans ^ b0

print(ans)
X=input()
m=int(X[0])
t=int(X[1:3])
print(1 if m*5>=t else 0)

### FIXED CODE ###

X=input()
Xi=int(X)
if Xi>=100:
    if len(X)>=4 and Xi>=2000:
        print(1)
    else:
        if Xi<1000:
            print(1 if int(X[0])*5>=int(X[1:3]) else 0)
        else:
            print(1 if int(X[0:2])*5>=int(X[2:4]) else 0)
else:
    print(0)
# -*- coding: utf-8 -*-

def solve():
    R, G, B, N = map(int, input().split())
    dp = [[0 for __ in range(8)] for _ in range(N+1)]
    for n in range(1,N+1):
        if n == R:
            dp[R][4] += 1
        if n == G:
            dp[G][2] += 1
        if n == B:
            dp[B][1] += 1

        dp[n][1] += dp[n-B][1]
        dp[n][2] += dp[n-G][2]
        dp[n][3] += (dp[n-G][1] + dp[n-G][3] + dp[n-B][2] + dp[n-B][3])//2
        dp[n][4] += dp[n-R][4]
        dp[n][5] += (dp[n-R][1] + dp[n-R][5] + dp[n-B][4] + dp[n-B][5])//2
        dp[n][6] += (dp[n-R][2] + dp[n-R][6] + dp[n-G][4] + dp[n-G][6])//2
        dp[n][7] += (dp[n-R][3] + dp[n-R][7] + dp[n-G][5] + dp[n-G][7] + dp[n-B][6] + dp[n-B][7])//3
    return str(sum(dp[N]))

if __name__ == '__main__':
    print(solve())


### FIXED CODE ###

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

def solve():
    R, G, B, N = map(int, input().split())
    dp = [[0 for __ in range(8)] for _ in range(6002)]
    for n in range(1,N+1):
        if n == R:
            dp[R][4] += 1
        if n == G:
            dp[G][2] += 1
        if n == B:
            dp[B][1] += 1

        dp[n][1] += dp[n-B][1]
        dp[n][2] += dp[n-G][2]
        dp[n][3] += (dp[n-G][1] + dp[n-G][3] + dp[n-B][2] + dp[n-B][3])//2
        dp[n][4] += dp[n-R][4]
        dp[n][5] += (dp[n-R][1] + dp[n-R][5] + dp[n-B][4] + dp[n-B][5])//2
        dp[n][6] += (dp[n-R][2] + dp[n-R][6] + dp[n-G][4] + dp[n-G][6])//2
        dp[n][7] += (dp[n-R][3] + dp[n-R][7] + dp[n-G][5] + dp[n-G][7] + dp[n-B][6] + dp[n-B][7])//3
    return str(sum(dp[N]))

if __name__ == '__main__':
    print(solve())
N=int(input())
S=input()

l="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
out=""

for i in S:
    out += l[(l.index(i)+n)%26]

print(out)

### FIXED CODE ###

n = int(input())
s = input()
 
l = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
out = ""
 
for c in s:
    out += l[(l.index(c)+n)%26]
 
print(out)
import math
n = list(map(int, input().split()))
d = max(m)-min(m)
if d:
  cnt = 0
  while d%2 == 0:
    d //= 2
    cnt += 1
  print(cnt)
elif n[0]%2:
  print(0)
else:
  print(-1)

### FIXED CODE ###

a,b,c = map(int, input().split())
if a==b==c:
  if a%2:
    print(0)
  else:
    print(-1)
else:
  cnt = 0
  while a%2 == b%2 == c%2 == 0:
    a,b,c = (b+c)//2,(a+c)//2,(a+b)//2
    cnt += 1
  print(cnt)
nk = list(map(int, input().split()))
p = list(map(int, input().split()))
n = nk[0]
k = nk[1]
maxnum = 0
for i in range(n-k):
    if p[i+k] >= p[i]:
        maxnum = i+k

ans = (sum(p

### FIXED CODE ###

def main():    
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    s = sum(p[:k])
    maxs = s
    for i in range(n-k):
        s = s - p[i] + p[i+k]
        if s > maxs:
            maxs = s
    ans = (maxs+k)/2
    print(ans)
main()
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

a, b, c, d = map(int, input().split())
num = 0
cd = c*d/(gcd(c,d))
s = b - a + 1
s_c = int(s/c)
s_d = int(s/d)
s_cd = int(s/cd)
if(a%c >= b%c):
  num = num + 1
if(a%d >= b%d):
  num = num + 1
if(a%cd >= b%cd):
  num = num - 1
print(s -(s_c + s_d - s_cd) - num)

### FIXED CODE ###

abcd = int(input())
d = int(abcd % 10)
c = int(((abcd - d) % 100)/10)
b = int((abcd - c*10 - d)%1000/100)
a = int(abcd / 1000)

if(a == b):
  print("Bad")
elif(b == c):
  print("Bad")
elif(c == d):
  print("Bad")
else:
  print("Good")
a,b,c=map(str,input().split())
s=list[b]
print("A"+s[0]+"C")


### FIXED CODE ###

a,b,c = map(str,input().split())
B = list(b)
print("A"+B[0]+"C")
s=list(input())
from copy import copy
t=s.copy()

for i in range(len(t)):
  if len(s)%2==0 and s[:len(s)/2]==s[len(s)/2:]:
    print(len(s))
    exit()
  else:
    s.pop(-1)
    

### FIXED CODE ###

s=list(input())
from copy import copy
t=s.copy()

for i in range(len(t)):
  p=int(len(s)/2)
  if len(s)%2==0 and s[:p]==s[p:] and len(s)!=len(t):
    print(len(s))
    exit()
  else:
    s.pop(-1)
nn=int(input())
kk=int(input())
num_value = list(map(int, input().split())) 
num_value.sort()
goukei=0
for i in range(kk):
    for k in range(nn-i):
        if num_value[i]>num_value[k]:
            num_value[i],num_value[k]=num_value[k],num_value[i]
goukei=goukei+num_value[i]
print(goukei)



### FIXED CODE ###

nn,kk=map(int,input().split())
num_value = list(map(int, input().split())) 
num_value.sort()
gokei=0
for i in range(kk):
   gokei=gokei+num_value[i]
print(gokei)
A = int(input())
B = int(input())
res = (A-1)*(B-1)

print(int(res))


### FIXED CODE ###

A, B = map(int, input().split())
res = (A-1)*(B-1)

print(int(res))
n = int(input())
s = input()
s2 = input()
s3 = input()
alp = "abcdefghijklmnopqrstuvwxyz"
ans = ""
for a in alp:
  for i in range(min(s.count(a),s2.count(a),s3.count(a))):
    ans += a
print(ans)

### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
    s.append(input())
alp = "abcdefghijklmnopqrstuvwxyz"
ans = ""
for a in alp:
    cnt = 1e10
    for ss in s:
        cnt = min(cnt,ss.count(a))
    for i in range(cnt):
        ans += a
print(ans)
n,m = map(int, input().split())

from collections import defaultdict 
V = defaultdict(list)

for _ in range(m):
    a,b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

def dfs(source):
    dist = [-1]*(n+1)
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b]!=-1:
                continue
            dist[b] = dist[a] + 1
            q.append(b)
    return dist

d1 = dfs(1)
if dfs(n) <=2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

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

from collections import defaultdict 
V = defaultdict(list)

for _ in range(m):
    a,b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

from collections import deque

def bfs(u):
    queue = deque([u])
    d = [None] * (n+1) # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in V[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                queue.append(i)
    return d

b1 = bfs(1)
if b1[n] ==2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
def K1(n):
    ans = 0
    d = len(str(n))
    ans += int(str(n)[0])
    ans += 9 * (d-1)
    return ans


def K2(n):
    d = len(str(n))
    ans = 9**2*(d-2)*(d-1)//2
    ans += (int(str(n)[0]) - 1) * 9 * (d-1)
    ans += K1(int(str(n)[1:]))
    return ans


def K3(n):
    d = len(str(n))
    ans = 9**3*(d-2)*(d-3)//2
    ans += (int(str(n)[0]) - 1) * 9 * (d-1)
    ans += K2(int(str(n)[1:]))
    return ans


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

    if K == 1:
        print(K1(N))

    if K == 2:
        print(K2(N))

    if K == 3:
        print(K3(N))



if __name__ == "__main__":
    main()


### FIXED CODE ###

def K1(n):
    ans = 0
    d = len(str(n))
    ans += int(str(n)[0])
    ans += 9 * (d-1)
    return ans


def K2(n):
    d = len(str(n))
    ans = 9**2*(d-2)*(d-1)//2
    ans += (int(str(n)[0]) - 1) * 9 * (d-1)
    ans += K1(int(str(n)[1:]))
    return ans


def K3(n):
    d = len(str(n))
    ans = 0
    for i in range(2,d-1):
        ans += i*(i-1)//2
    ans *= 9**3
    ans += (int(str(n)[0]) - 1) * 9**2 * (d-1)*(d-2) // 2
    ans += K2(int(str(n)[1:]))
    return ans


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

    if K == 1:
        print(K1(N))

    if K == 2:
        if N < 10:
            print(0)
            exit()
        print(K2(N))

    if K == 3:
        if N < 100:
            print(0)
            exit()
        print(K3(N))



if __name__ == "__main__":
    main()
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
from collections import Counter,deque,defaultdict
# import itertools
# import math
import networkx as nx
# from bisect import bisect_left,bisect_right
n,m=n1()
ab=n3(m)

ans={}
d=[0]*(n+1)
p=[1]
p2=[]
while len(ans)<n-1:
    for c in p:
        d[c]=1
        for a,b in ab:
            if a==c and d[b]==0:
                p2.append(b)
                d[b]=1
                ans[b]=a
            if b==c and d[a]==0:
                p2.append(a)
                d[a]=1
                ans[a]=b
    p=p2.copy()
    p2=[]

A=list(ans.items())
A.sort(key=lambda x:x[0])
print("Yes")
for line in A:
    print(line[1])

### FIXED CODE ###


def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right

n,m=n1()
ab=n3(m)

node=defaultdict(list)
for a,b in ab:
    node[a].append(b)
    node[b].append(a)
    
p=deque([1])
d=[0]*(n+1)
while len(p)>0:
    c=p.popleft()
    for i in node[c]:
        if d[i]==0:
            d[i]=c
            p.append(i)
            
print("Yes")
for i in range(2,n+1):
    print(d[i])
N, M = map(int,input().split())
H=list(map(int,input().split()))

A=[0]*(N+1)
for i in range(M):
    x,y=map(int,input().split())
    A[x]=max(A[x],H[y-1])
    A[y]=max(A[y],H[x-1])

count=0
for i in range(1,N+1):
    if H[i-1]>A[i]:
        count+=1

print(count)

### FIXED CODE ###

N=input()
aru=0
for s in N:
    if s == "7":
        aru=1
        break
if aru==0:
    print("No")
else:
    print("Yes")
from collections import deque
n = int(input())

d = deque()

for _ in range(n):
    com = input()
    if ( len(com) == 8):
        com , i = com.split()

    if (com[0] == 'i'):
        d.appendleft(int(i))
    elif (com[0] == 'd'):
        if (len(com) == 6):
            d.remove(int(i))
        elif (com[6] == 'F'):
            d.popleft()
        elif (com[6] == 'L'):
            d.pop()
ans = map(str, d)
ans = " ".join(ans)
print(ans)

### FIXED CODE ###

from collections import deque
n = int(input())

d = deque()

for _ in range(n):
    com = input()
    if (com[0] == 'i'):
        com ,i = com.split()
        d.appendleft(int(i))
    elif (com[0] == 'd'):
        if (com[6] == ' '):
            com, i = com.split()
            try:
                d.remove(int(i))
            except ValueError:
                pass
        elif (com[6] == 'F'):
            d.popleft()
        elif (com[6] == 'L'):
            d.pop()
ans = map(str, d)
ans = " ".join(ans)
print(ans)
R = input()
import math
print(2 * math.pi * R)

### FIXED CODE ###

R = int(input())
import math
print(2 * math.pi * R)
# load
N = int(input())
a = []
x = []
y = []
for i in range(N):
  a.append(int(input()))
  for j in range(a[i]):
    xtmp, ytmp = map(int, input().split())
    x.append(xtmp)
    y.append(ytmp)

# honest?
b = 0
for i in range(N):
  b += (2**i)

b = format(b, 'b') # string representing binary

contradiction = False
while True:
  for i in range(N):
    if int(b[i]) == 1 and (int(b[x[i]-1]) != y[i]):
      contradiction = True
      break
  if contradiction:
    contradiction = False
    b = format(int(b, 2) - 1, 'b')
  else:
    break

h = 0
for i in range(N):
  h += int(b[i])

print(h)

### FIXED CODE ###

import itertools

# load
N = int(input())
a = []
x = []
y = []
for i in range(N):
  a.append(int(input()))
  xtmp = []
  ytmp = []
  for j in range(a[i]):
    xtmp2, ytmp2 = map(int, input().split())
    xtmp.append(xtmp2)
    ytmp.append(ytmp2)
  x.append(xtmp)
  y.append(ytmp)

#print('x:%s' % x)
#print('y:%s' % y)
#print(x[0][0])

# honest?

contra = False
stop = False
for r in range(N+1):
  for v in itertools.combinations(range(N), r):
    h = [1] * N
    for t in range(len(v)):
      h[v[t]] = 0

    for i in range(N):
      for j in range(a[i]):
      	if h[i] == 1 and (h[x[i][j]-1] != y[i][j]): # contradiction
          contra = True
          #print('contra: h:%s, i:%d, j:%d, h[x[i][j]-1]:%d, y[i][j]:%d' % (h, i, j, h[x[i][j]-1], y[i][j]))
          break
      if contra:
        contra = False
        break
    else:
      stop = True
      #print('answer? h: %s' % h)
      break
  if stop:
    break
    
print(sum(h))
N, M, Q = map(int, input().split())
vec = [list(map(int, input().split())) for i in range(Q)]
A = itertools.combinations_with_replacement(range(1,M+1), N)
ans = 0

for a in A:
    tmp = 0
    for v in vec:
        if (a[v[1]-1] - a[v[0]-1]) == v[2]:
            tmp += v[3]
    if ans < tmp:
        ans = tmp
        
print(ans)

### FIXED CODE ###

import itertools
N, M, Q = map(int, input().split())
vec = [list(map(int, input().split())) for i in range(Q)]
A = itertools.combinations_with_replacement(range(1,M+1), N)
ans = 0

for a in A:
    tmp = 0
    for v in vec:
        if (a[v[1]-1] - a[v[0]-1]) == v[2]:
            tmp += v[3]
    if ans < tmp:
        ans = tmp
        
print(ans)
n,m=map(int,,input().split())
ans=[0]*m
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  k=l[i][0]
  for j in (1,k+1):
    ans[l[i][j]-1]+=1
cnt=0
for aa in ans:
  if aa==n:
    cnt+=1
print(cnt)

### FIXED CODE ###

n,m=map(int,input().split())
lists=[list(map(int,input().split())) for x in range(n)]
ans=[0]*m
for x in range(n):
  k=lists[x][0]
  for t in range(k):
    ans[lists[x][t+1]-1]+=1
count=0
for y in range(m):
  if ans[y]==n:
    count+=1
print(count)
l,r = map(int,input().split())
a = []
if r-l>=2019:
  print(2)
else:
  for i in range(l,r+1):
    a.append(i%2019)
a.sort()
print(a[0]*a[1])

### FIXED CODE ###

l,r = map(int,input().split())
m = 2018
if r-l>=2019:
  print(0)
else:
  for i in range(l,r+1):
    for j in range(i+1,r+1):
      a = (i*j)%2019
      m = min(a,m)
  print(m)
n = int(input())

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

ans = 1
for _ in range(n):
    if ans >= 10 ** 18:
        print(-1)
        exit()
    ans = ans * a[i]

print(ans)

### FIXED CODE ###

n = int(input())

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

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

ans = 1
for i in range(n):
    ans = ans * a[i]

    if ans > 10 ** 18:
        print(-1)
        exit()
print(ans)
a, b, k = [int(m) for m in input().split(" ")]

ab_nums = list(range(a, b+1))
end_nums = list(set(ab_nums[:k] + ab_nums[-k:]))
end_nums.sort()

for num in end_nums:
    print(num)

### FIXED CODE ###

a, b, k = [int(m) for m in input().split(" ")]

for i in range(a, min(a+k, b+1)):
    print(i)
for i in range(max(b+1-k, a+k), b+1):
    print(i)
#-*- coding: utf-8 -*-
N = int(input())
L_list = [int(input()) for n in range(2N)]

L_list.sort()
print(sum(L_list[::2]))

### FIXED CODE ###

#-*- coding: utf-8 -*-
N = int(input())
L_list = list(map(int, input().split()))
L_list.sort()
print(sum(L_list[::2]))
#!python3

LI = lambda: list(map(int, input().split()))

# input
N, M = LI()
AB = [LI() for _ in range(M)]

# params
link = [[] for _ in range(N)]
for a, b in AB:
    link[a - 1].append(b - 1)
impossible = [False] * N


def joint(v, visit):
    if impossible[v]:
        return None
    visit = visit + [v]
    for u in link[v]:
        if u in visit:
            i = visit.index(u)
            return visit[i:]
        t = joint(u, visit)
        if t is not None:
            return t
    impossible[v] = True
    return None


def main():
    ans = None
    for i in range(N):
        ans = joint(i, [])
        if ans is not None:
            break
    if ans is None:
        print(-1)
        return
    print(len(ans))
    for x in ans:
        print(x + 1)
        

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!python3

import sys
sys.setrecursionlimit(10 ** 6)

LI = lambda: list(map(int, input().split()))

# input
N, M = LI()
AB = [LI() for _ in range(M)]

# params
link = [[] for _ in range(N)]
for a, b in AB:
    link[a - 1].append(b - 1)
impossible = [False] * N


def joint(v, visit):
    if impossible[v]:
        return None
    visit = visit + [v]
    for u in link[v]:
        if u in visit:
            i = visit.index(u)
            return visit[i:]
        t = joint(u, visit)
        if t is not None:
            return t
    impossible[v] = True
    return None


def solve(l):
    n = len(l)
    d = {l[i]: i for i in range(n)}
    for i in range(n):
        x = l[i]
        for y in link[x]:
            if y in d:
                j = d[y]
                if (i + 1) % n == j:
                    continue
                if j < i:
                    l = l[j : i + 1]
                else:
                    l = l[: i + 1] + l[j:]
                return solve(l)
    return l
            

def main():
    t = None
    for i in range(N):
        t = joint(i, [])
        if t is not None:
            break
    if t is None:
        print(-1)
        return
    
    ans = solve(t)
    print(len(ans))
    for x in ans:
        print(x + 1)
        

if __name__ == "__main__":
    main()
n, m, X, Y = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))
xlist.sort()
ylist.sort()

if xlist[-1] <= ylist[0]:
   for i in range(xlist[-1]+1, ylist[0]+1):
      if X < i and i <= Y:
          print("No War")
          break
else:
   print("War")


### FIXED CODE ###

nums = list(map(int, input().split()))
nums.sort()
nums.reverse()
num = nums[0]*10 + nums[1] + nums[2]
print(num)
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()))
D = set()
for i in range(X):
    for j in range(Y):
        D.add(A[i]+B[j])
D = sorted(list(D),reverse=True)
C = sorted(C,reverse=True)
E = []
for i in range(min(int(K**0.5)+10,len(D))):
    for j in range(min(int(K**0.5)+10,len(C))):
        E.append(D[i]+C[j])
E = sorted(E,reverse=True)
for i in range(K):
    print(E[i])

### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())),reverse=True)
D = []
for i in range(X):
    for j in range(Y):
        D.append(A[i]+B[j])
D = sorted(D,reverse=True)
E = []
for i in range(min(K,X*Y)):
    for j in range(Z):
        E.append(D[i]+C[j])
E = sorted(E,reverse=True)
for i in range(K):
    print(E[i])
s, w = map(int, input().split(" "))
print(["safe", "unsafe"][s <= w])

### FIXED CODE ###

s, w = map(int, input().split(" "))
print(["safe", "unsafe"][s <= w])
import heapq

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(lambda x :-int(x), input().split()))

p.sort(reverse=True)
q.sort(reverse=True)

p = p[:x]
q = q[:y]

pq = p+q
pq.sort(reverse=True)

heapq.heapify(r)
ans = 0

for i in range(x+y) :
    print(i, pq[i], -r[0])
    if len(r) != 0 :
        if  pq[i] < -r[0] :
            ans += -heapq.heappop(r)
        else :
            ans += pq[i]

print(ans)


### FIXED CODE ###

import heapq

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
pq = p[:x]+q[:y]
heapq.heapify(pq)

for e in r :
    heapq.heappushpop(pq, e)

print(sum(pq))
import math
import sys 
input = sys.stdin.readline
N = int(input())
x = list(map(int,input().split()))
mod = 10**9+7

d = [0]*(N-1)
"""
for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= mod
"""

kaijou = 1
for i in range(1,N):
    i %= mod
    kaijou *= i
    kaijou %= mod

ans=0
x=0
"""
def pow_r(x, n):
    """
    O(log n)
    """
    x %= mod
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%mod
    else:  # standard case ② n is odd
        return (x * (pow_r(x ** 2, (n - 1) // 2)))%mod

for i in range(N-1):
    #(i+1)%(mod-2)を計算してyへ
    y = pow_r(i+1,mod-2)
    #x+= kaijou//(i+1))%(10**9+7)
    x += (kaijou*y)%mod
    ans+= (d[i]*x)%mod
"""
print(ans%mod)


### FIXED CODE ###

import math
import sys 
input = sys.stdin.readline

N = int(input())
x = list(map(int,input().split()))
mod = 10**9+7

d = [0]*(N-1)

for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= mod


kaijou = 1
for i in range(1,N):
    kaijou *= i
    kaijou %= mod


ans=0
x=0

def pow_r(x, n):
    """
    O(log n)
    """
    x %= mod
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%mod
    else:  # standard case ② n is odd
        return (x * (pow_r(x ** 2, (n - 1) // 2)))%mod

for i in range(N-1):
    #(i+1)%(mod-2)を計算してyへ
    y = pow_r(i+1,mod-2)
    #x+= kaijou//(i+1))%(10**9+7)
    x += kaijou*y
    ans += d[i]*x
    ans %= mod

print(ans)