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

from collections import Counter

N = int(input())
s = [None] + [list(input()) for _ in range(N)]

count = [None]*(N+1)

answer = 0
for i in range(1,N+1):
    count[i] = Counter(s[i])
    answer += count[:i].count(count[i])

print(answer)

### FIXED CODE ###

from collections import Counter,defaultdict
import sys
input = sys.stdin.readline

N = int(input())
s = [None] + [list(input()) for _ in range(N)]

count = defaultdict(int)

answer = 0
for i in range(1,N+1):
    c = Counter(s[i])
    c = sorted(c.items(), key=lambda x:x[0])
    # O(len(c))
    str_c = ""
    for key,item in c:
        str_c += key*item
    answer += count[str_c]
    count[str_c] += 1

print(answer)
### BUGGY CODE ###

S = input()
Q = int(input())
for i in range(Q):
  s = input().split()
  if s[0] == "1": # 反転
    S = S[::-1]
  elif s[0] == "2":
    if s[1] == "1": # 先頭
      S = s[2] + S
    elif s[1] == "2": # 末尾
      S = S + s[2]
print(S)

### FIXED CODE ###

S = input()
Q = int(input())
turn = 0
head = ""
tail = ""
for i in range(Q):
  s = input().split()
  if s[0] == "1": # 反転
    turn += 1
  elif s[0] == "2": # 足す
    if (s[1] == "1" and turn % 2 == 0) or (s[1] == "2" and turn % 2 == 1):
      head = s[2] + head
    elif (s[1] == "2" and turn % 2 == 0) or (s[1] == "1" and turn % 2 == 1):
      tail = tail + s[2]
if turn % 2 == 0:
  print(head + S + tail)
else:
  print((head + S + tail)[::-1])
### BUGGY CODE ###

def prime_factorization(N):
  n = int(N**0.5)
  primeList = [i if i != 1 else 2 for i in range(1, n, 2) ]
  for data in primeList:
    primeList = [x for x in primeList if (x == data or x%data != 0)]
  return primeList
 
N = int(input())
ans = 0
 
primeList = prime_factorization(N)

for p in primeList:
  e = 1
  while N % p == 0:
    if N % p ** e == 0:
      N //= p ** e
      e += 1
      ans += 1
    else:
      N = N / p
    
print(ans)

### FIXED CODE ###

N = int(input())
 
def prime_factorization(N):
  n = int(N**0.5)+1
  numList = [i if i != 1 else 2 for i in range(1, n, 2) ]
  primeList = [2]
  ansDict = {}
  idx = 0
  for data in numList:
    for x in primeList:
      if (data%x != 0 or x == 2):
        count = 0
        while N%data == 0:
          count += 1
          N //= data
        if count > 0:
          ansDict[data] = count
        if N == 1:
          return ansDict
        if x != 2:
          primeList.append(data)
        break
  if N != 1:
    ansDict[N] = 1
  
  return ansDict 

if N <= 1:
  print(0)
  exit()
  
ansDict = prime_factorization(N)
ansCount = 0
for p,v in ansDict.items():
  e = 1
  while e <= v:
    ansCount += 1
    v -= e 
    e += 1  

print(ansCount)
### BUGGY CODE ###

from collections import deque
s=deque(input())
q=int(input())
for i in range(q):
  query=input()
  if len(query)==1:
    s.reverse()
  else:
    if query[2]=="1":
      s.appendleft(query[4])
    else:
      s.append(query[4])
print("".join(s))

### FIXED CODE ###

from collections import deque
s=deque(input())
q=int(input())
flag=0
for i in range(q):
  query=input()
  if len(query)==1:
    flag+=1
  else:
    if query[2]=="1" and flag%2==0 or query[2]=="2" and flag%2==1:
      s.appendleft(query[4])
    else:
      s.append(query[4])
if flag%2==1:
  s.reverse()
print("".join(s))
### BUGGY CODE ###

from bisect import bisect_left, bisect_right

N, *L = map(int, open(0).read().split())

L.sort()

cnt = 0
for i in range(1, N - 1):
    b = L[i]
    for j in range(i):
        a = L[j]
        l, r = bisect_left(L, b - a + 1, lo=i), bisect_right(L, a + b - 1, lo=i)
        cnt += r - l - (l <= i <= r) - (l <= j <= r)

print(cnt)


### FIXED CODE ###

from bisect import bisect_left, bisect_right

N, *L = map(int, open(0).read().split())

L.sort()

cnt = 0
for i in range(1, N - 1):
    b = L[i]
    for j in range(i):
        a = L[j]
        l, r = bisect_left(L, b - a + 1, lo=i), bisect_right(L, a + b - 1, lo=i)
        cnt += r - l - (l <= i <= r) - (l <= j <= r)

print(cnt)
### BUGGY CODE ###

s = input()
q = int(input())
Q = [list(map(str, input().split())) for i in range(q)]

for i in range(q):
  if int(Q[i][0]) == 1:
    s = s[::-1]
  else:
    if int(Q[i][1]) == 1:
      s = Q[i][2] + s
    else:
      s = s + Q[i][2]
      
print(s)


### FIXED CODE ###

from collections import deque

s = input()
q = int(input())
Q = [list(map(str, input().split())) for i in range(q)]

ans = deque(s)

reverse_num = 0
for i in range(q):
  if int(Q[i][0]) == 1:
    reverse_num += 1
  else:
    if int(Q[i][1]) == 1:
      if reverse_num % 2 == 0:
        ans.appendleft(Q[i][2])
      else:
        ans.append(Q[i][2])
    else:
      if reverse_num % 2 != 0:
        ans.appendleft(Q[i][2])
      else:
        ans.append(Q[i][2])

res = ''
if reverse_num % 2 == 0: 
  for i in range(len(ans)):
    res += ans.popleft()
  print(res)
else:
  for i in range(len(ans)):
    res += ans.pop()
  print(res)
### BUGGY CODE ###

N=int(input())
actlist=list(map(int,input().split()))
As = sorted([(A, i) for i, A in enumerate(actlist)])[::-1]

INF = float('inf')
left=1
right=N
maxnum=0

dp = [[-INF] * (N+1) for _ in range(N+1)]
        
for r in range(N+1):
    for l in range(N-r+1):
        if r==0 and l==0:
            dp[l][r]=0
        else:
            dp[l][r]=max(dp[l][r-1]+As[l+r-1][0]*abs(N-r-As[l+r-1][1]),\
              dp[l-1][r]+As[l+r-1][0]*abs(l-1-As[l+r-1][1]))
            maxnum=dp[l][r] if maxnum<dp[l][r] else maxnum

print(maxnum)

### FIXED CODE ###

def main():
  N = int(input())
  INF = float('inf')
  A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
  A = sorted(A, key=lambda x: x[1], reverse = True)
 
  dp = [[-INF] * (N+1) for _ in range(N+1)]
  dp[0][0] = 0
 
  for s in range(1, N+1):
    for l in range(s+1):
      r = s - l
      dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
  ans = 0
  for m in range(N):
    if(dp[m][N-m] > ans):
      ans = dp[m][N-m]
    
  print(ans)
 
main()
### BUGGY CODE ###

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

M = 10**9 + 7

for n in range(N):
    A[n] = A[n] % M

ans = 0

for i in range(N-1):
    for n in range(i + 1, N):
        ans += A[i] * A[n]
    ans = ans % M

print(ans)

### FIXED CODE ###

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

M = 10**9 + 7

Total = sum(A) -A[0]

ans = 0

for i in range(N-1):
    ans += A[i] * Total
    ans = ans % M
    Total -= A[i+1]

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

import numpy as np

def count_num_light(a):
  ret = [0 for _ in range(len(a))]
  n = len(a)
  for i in range(n):
    start = max(0, i-a[i])
    end = min(n-1, i+a[i])
    ret[start] += 1
    if end+1 < n:
      ret[end+1] -= 1
  for i in range(1,n):
    ret[i] += ret[i-1]
  
  return ret
                  
n, k = map(int, input().split())
a = list(map(int, input().split()))
num_light = count_num_light(a)
 
for i in range(k-1):
  num_light = count_num_light(num_light)
  if np.all(num_light == n):
    break
    
print(*num_light)


### FIXED CODE ###

def count_num_light(a):
  ret = [0 for _ in range(len(a))]
  n = len(a)
  for i in range(n):
    start = max(0, i-a[i])
    end = min(n-1, i+a[i])
    ret[start] += 1
    if end+1 < n:
      ret[end+1] -= 1
  for i in range(1,n):
    ret[i] += ret[i-1]
  
  return ret
                  
n, k = map(int, input().split())
a = list(map(int, input().split()))
num_light = count_num_light(a)
 
for i in range(k-1):
  num_light = count_num_light(num_light)
  if sum(num_light) == n**2:
    break
    
print(*num_light)
### BUGGY CODE ###

N, Q=map(int, input().split())
import sys
sys.setrecursionlimit(10**6)
T=[[] for _ in range(N)]
for i in range(N-1):
  a,b=map(int, input().split())
  T[a-1].append(b-1)
  T[b-1].append(a-1)
P=[0]*N
ans=[0]*N
for i in range(Q):
  p,x=map(int, input().split())
  P[p-1]+=x

def dfs(start, pre_node, pre_val):
  now_val=(pre_val+P[start])
  ans[start]=now_val
  
  for next_node in T[start]:
    if next_node==pre_node:
      continue
    dfs(next_node, start,now_val)
    
dfs(0,-1,0)   
for a in ans:
  print(a, end=" ")

### FIXED CODE ###

from collections import deque 
N,Q=map(int, input().split())
G=[[] for _ in range(N)]
for i in range(N-1):
    a,b=map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
X=[0]*N
for i in range(Q):
    p,x=map(int, input().split())
    X[p-1]+=x
que=deque([(0,-1)])
#print(que)
while que:
    now, pre=que.pop()
    for nex in G[now]:
        if nex==pre:
            continue
        else:
            X[nex]+=X[now]
            que.append((nex,now))

print(" ".join(map(str, X)))
### BUGGY CODE ###

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

ac = []
wa = [0 for i in range(N)]

for _ in range(M):
    p_i, s_i = input().split()
    if s_i == "AC" and int(p_i) not in ac:
        ac.append(int(p_i))
    if s_i == "WA" and int(p_i) not in ac:
        wa[int(p_i) - 1] += 1
        
ac = set(ac)
wa_num = 0
for i in range(N):
    if i + 1 not in ac:
        continue
    else:
        wa_num += wa[i]

print(len(ac), wa_num)

### FIXED CODE ###

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

ac = 0
wa = 0
ac_status = [0 for i in range(N)]
wa_status = [0 for i in range(N)]

for _ in range(M):
    p_i, s_i = input().split()
    if s_i == "AC" and ac_status[int(p_i) - 1] == 0:
        ac += 1
        ac_status[int(p_i) - 1] += 1
        wa += wa_status[int(p_i) - 1]
    if s_i == "WA":
        wa_status[int(p_i) - 1] += 1

print(ac, wa)
### BUGGY CODE ###

import sys
import math
from collections import deque
from collections import Counter

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


#隣接リスト 1-order
def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res


#nCr
def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    N = NI()
    A = NLI()
    Q = NI()
    querys = [NLI() for _ in range(Q)]

    Dic = dict(Counter(A))
    for b, c in querys:
        Dic.setdefault(c, 0)
        Dic.setdefault(b, 0)
        Dic[c] += Dic[b]
        del Dic[b]
        res = 0
        for n, x in Dic.items():
            res += n * x
        print(res)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import math
from collections import deque
from collections import Counter

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


#隣接リスト 1-order
def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res


#nCr
def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    N = NI()
    A = NLI()
    Q = NI()
    querys = [NLI() for _ in range(Q)]
    res = sum(A)
    Dic = dict(Counter(A))
    for b, c in querys:
        Dic.setdefault(c, 0)
        Dic.setdefault(b, 0)
        gap = (c-b) * Dic[b]
        Dic[c] += Dic[b]
        del Dic[b]
        res += gap
        print(res)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

M = 61
D1 = [0] * M

for a in A:
    k = 0
    while a > 0:
        if a & 1:
            D1[k] += 1
        a >>= 1
        k += 1

MOD = 10 ** 9 + 7
ans = 0
for k in range(M):
    d = D1[k]
    ans += d * (N - d) * pow(2, k, MOD)
    ans %= MOD

print(ans)


### FIXED CODE ###

N = int(input())

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

num = [[0, 0] for _ in range(60)]

for Ai in A:
    for digit in range(60):
        if (Ai >> digit) & 1:
            num[digit][1] += 1
        else:
            num[digit][0] += 1

res = 0
for i, p in enumerate(num):
    res += (1 << i) * p[0] * p[1]

m = 10 ** 9 + 7
print(res % m)
### BUGGY CODE ###

import collections as C
n, q = map(int,input().split())

g = C.Counter([])
p = C.Counter([])
for i in range(n-1):
	a,b = map(int,input().split())
	if a not in g.keys():
		g[a] = [b]
	elif a in g.keys():
		g[a] = g[a] + [b]

for i in range(q):
	a,b = map(int,input().split())
	if a not in p.keys():
		p[a] = b
	elif a in p.keys():
		p[a] = p[a] + b

ans = [0 for _ in range(n)]
que = [0]
i = 1
while i > 0:

	if i in p.keys():
		ans[i-1] += p[i]
	if i in g.keys():
		for j in g[i]:
			ans[j-1] = ans[i-1]
			que.append(j)
	i = que.pop()


for i in ans:
	print(i, end=" ")






### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

N, Q = map(int ,input().split())
E = [[] for _ in range(N+1)]
for _ in range(N-1):
	at,bt = map(int ,input().split())
	E[at].append(bt)
	E[bt].append(at)
cnt = [0 for _ in range(N+1)]
for _ in range(Q):
	pt,xt = map(int, input().split())
	cnt[pt] += xt

flg = [0 for _ in range(N+1)]
q = [[1,-1]]
while q:
	cp, root = q.pop()
	for np in E[cp]:
		if np == root:
			continue
		cnt[np] += cnt[cp]
		q.append([np,cp])

cnt.pop(0)
for c in cnt:
	print(c, end = " ")
print()
### BUGGY CODE ###

from sys import stdin


class DisjointSet():
    def __init__(self):
        self.parent = None


def ancestor(elems, x):
    s = elems[x]
    while s.parent is not None:
        s = s.parent
    return s


def unite(elems, x, y):
    ax = ancestor(elems, x)
    ay = ancestor(elems, y)
    if ax is not ay:
        parent = DisjointSet()
        ax.parent = ay.parent = parent


def same(elems, x, y):
    return ancestor(elems, x) is ancestor(elems, y)


def main():
    n, q = [int(x) for x in stdin.readline().split()]
    elems = [DisjointSet() for _ in range(n)]

    lines = stdin.readlines()
    for line in lines:
        com, x, y = [int(x) for x in line.split()]
        if com == 0:
            unite(elems, x, y)
        else:
            print(1 if same(elems, x, y) else 0)


if __name__ == '__main__':
    main()



### FIXED CODE ###

class DisjointSetElement():
    def __init__(self, x):
        self.parent = x
        self.rank = 0


class DisjointSet():
    def __init__(self, n):
        self.elems = [DisjointSetElement(n) for n in range(n)]

    def _find_set(self, x):
        if x != self.elems[x].parent:
            self.elems[x].parent = self._find_set(self.elems[x].parent)
        return self.elems[x].parent

    def same(self, x, y):
        return self._find_set(x) == self._find_set(y)

    def _link(self, x, y):
        if self.elems[x].rank > self.elems[y].rank:
            self.elems[y].parent = x
        else:
            self.elems[x].parent = y
            if self.elems[x].rank == self.elems[y].rank:
                self.elems[y].rank += 1

    def unite(self, x, y):
        self._link(self._find_set(x), self._find_set(y))


def main():
    n, q = [int(x) for x in input().split()]
    ds = DisjointSet(n)

    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        if com == 0:
            ds.unite(x, y)
        else:
            print(1 if ds.same(x, y) else 0)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
import fractions
from functools import reduce
mod = 10**9+7

def gcd(numbers):
    return reduce(fractions.gcd,numbers)
def lcm_bace(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm(numbers):
    return reduce(lcm_bace,numbers,1)

A_lcm = lcm(A)
ans = 0
for i in A:
    ans += (A_lcm//i)%mod
print(ans%mod)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
import fractions
mod = 10**9+7
lcm = A[0]
for i in range(1,N):
    lcm = lcm*A[i]//fractions.gcd(lcm,A[i])
ans = 0
for i in range(N):
    ans += lcm*pow(A[i],mod-2,mod)
print(ans%mod)
### BUGGY CODE ###

from math import gcd
from functools import reduce

k = int(input())
li = []
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      n = (a,b,c)
      li.append(reduce(gcd,n))

print(sum(li))

### FIXED CODE ###

from math import gcd
from functools import reduce

def func(a,b,c):
  if a == b and b == c:
    return a
  elif a == b and b !=c:
    return gcd(a,c)
  elif a != b and b ==c:
    return gcd(a,b)
  else:
    return reduce(gcd,(a,b,c))

k = int(input())
li = []
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      li.append(func(a,b,c))

print(sum(li))
### BUGGY CODE ###

import numpy as np

n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

ans = 0

for i in range(n-1, -1, -1):
    if A[i] % B[i] == 0:
        pass
    else:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(int(ans))

### FIXED CODE ###

n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)
### BUGGY CODE ###

from operator import mul
from functools import reduce
n = int(input())
a = map(int,input().split())
s = list(a)
p = reduce(mul, s)
if p>10**18:
  print(-1)
else:
  print(p)

### FIXED CODE ###

def solve(N, A):
    ret = 1
    upper = 10**18
    if 0 in A:
      return 0
    for i in A:
        ret *= i
        if upper < ret:
          return -1
    return ret
 
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))
### BUGGY CODE ###

import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


color, depth, graph = [], [], {}
def func(v, d, c):
    if not color[v]:
        color[v] = c
    if depth[v] >= d or d == 0:
        return

    for u in graph[v]:
        func(u, d - 1, c)


def main():
    global color, depth, graph
    N, M = map(int, input().split())
    graph = defaultdict(list)
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)

    Q = int(input())
    q = []
    for _ in range(Q):
        v, d, c = map(int, input().split())
        q.append((v - 1, d, c))

    color = [0] * N
    depth = [0] * N
    for i in range(Q - 1, -1, -1):
        func(q[i][0], q[i][1], q[i][2])
    print(*color, sep="\n")

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


color, depth, graph = [], [], {}
def func(v, d, c):
    if not color[v]:
        color[v] = c
    if depth[v] >= d or d == 0:
        return
    depth[v] = d
    for u in graph[v]:
        func(u, d - 1, c)


def main():
    global color, depth, graph
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)

    Q = int(input())
    q = []
    for _ in range(Q):
        v, d, c = map(int, input().split())
        q.append((v - 1, d, c))

    color = [0] * N
    depth = [0] * N
    for i in range(Q - 1, -1, -1):
        func(q[i][0], q[i][1], q[i][2])
    print(*color, sep="\n")

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import itertools


X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = [a + b for (a, b) in list(itertools.product(A, B))]
AB.sort(reverse=True)
ans = [ab + c for (ab, c) in list(itertools.product(AB[:min(3000, X*Y*Z)], C))]
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

### FIXED CODE ###

from itertools import product

X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = [a + b for a, b in product(A, B)]
AB.sort(reverse=True)

ABC = [ab + c for ab, c in product(AB[:K], C)]
ABC.sort(reverse=True)

for abc in ABC[:K]:
    print(abc)
### BUGGY CODE ###

S = input()
lst = ["dreamer", "dream", "eraser", "erase"]
lst = [ "".join(list(reversed(k))) for k in lst]
S = "".join(list(reversed(S)))

i  = 0
while i < len(S):
    found = False
    for k in lst:
        try:
            # print("k: ",k, "i: ", i, "S[i:]: ", S[i:])
            if S[i:].index(k) == 0:
                found = True
                i += len(k)
                # print("FOUND! i  = ", i, ", S[i:] ", S[i:])
                break
        except:
            continue

    if not found:
        print("NO")
        exit(0)
print("YES")


### FIXED CODE ###

S = input()
lst = ["dreamer", "dream", "eraser", "erase"]
lst = [ "".join(list(reversed(k))) for k in lst]
S = "".join(list(reversed(S)))

i  = 0
while i < len(S):
    found = False
    for k in lst:
        try:
            if S[i:].index(k) == 0:
                found = True
                i += len(k)
                break
        except:
            continue

    if not found:
        print("NO")
        exit(0)
print("YES")
### BUGGY CODE ###

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
for i in a:
    aa.append(aa[-1]+i)
bb = [0]
for i in b:
    bb.append(bb[-1]+i)
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    for j in range(m+1):
        if aa[i]+bb[m-j] <= k:
            ans = max(ans, i+m-j)
            break
print(ans)

### FIXED CODE ###

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
for i in a:
    aa.append(aa[-1]+i)
bb = [0]
for i in b:
    bb.append(bb[-1]+i)
ans = 0
j = m
for i in range(n+1):
    if aa[i] > k:
        break
    while aa[i] + bb[j] > k and j > 0:
        j -= 1
    ans = max(ans, i+j)
print(ans)