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

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


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    AB = list( itertools.product(A,B) )

    ABS = list(map(lambda c: sum(c), AB))
    ABS.sort(reverse=True)
    ABS2 = ABS[0:K]

    ABC = list( itertools.product(ABS2,C) )
    ABCS = list(map(lambda c: sum(c), ABC))
    ABCS.sort(reverse=True)

    for k in range(K):
        print(ABCS[k])



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

if __name__ == '__main__':
    main()


### FIXED CODE ###

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


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    ABC = []
    for x in range(X):
        for y in range(Y):
            if ((x+1)*(y+1)) > K:
                break
            for z in range(Z):
                if ((x+1)*(y+1)*(z+1)) > K:
                    break
                ABC.append(A[x]+B[y]+C[z])

    ABC.sort(reverse=True)

    for k in range(K):
        print(ABC[k])



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

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


import numpy as np
N,M=map(int, input().split())
A = np.array([input().split() for i in range(M)])


if M>0:
    P=A[:,0]
    S=A[:,1]
    wa={}
    ac=[]
    key=[]
    for i in range(M):
        if P[i] not in ac:
            if P[i] not in key:
                key.append(P[i])
                wa[P[i]]=0
                
            if S[i]=="WA":
                wa[P[i]]+=1
            else:
                ac.append(P[i])
    ans=0
    for i in key:
        if i in ac:
            ans+=wa[i]
    print(len(ac),ans)
else:
    print(0,0)

### FIXED CODE ###

N,M=map(int,input().split())
AC={}
WA={}
for i in range(M):
    a,b=input().split()
    if not(a in AC.keys()):
        if b=="AC":
            AC[a]=1
        else:
            if a in WA.keys():
                WA[a]+=1
            else:
                WA[a]=1
y=0
for i in AC.keys():
    if i in WA.keys():
        y+=WA[i]
print(sum(AC.values()),y)
### BUGGY CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
A = LI()

A.sort()
B = copy.deepcopy(A)
B.reverse()
ans = 0

def ncr(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
# max
tmp_n = N
tmp_k = K - 1
for b in B:
    tmp_n -= 1
    if tmp_n < tmp_k:
        break
    ans = (ans + b * ncr(tmp_n, tmp_k))%mod

# print(ans, "max")
# min
tmp_n = N
tmp_k = K - 1
for a in A:
    tmp_n -= 1
    if tmp_n < tmp_k:
        break
    ans = (ans - a * ncr(tmp_n, tmp_k))%mod

print(ans)


### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
def LI(): return list(map(int, sys.stdin.readline().split()))

P = 10**9 + 7
N = 10000

n_ = 10**5 + 3

fun = [1 for i in range(n_+1)]
for i in range(1, n_ + 1):
    fun[i] = fun[i-1] * i % mod

rev = [1 for i in range(n_+1)]
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1) % mod

def nCr(n,r):
    if n <= 0 or r < 0 or r> n:return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

N, K = LI()
A = LI()

A.sort()
B = copy.deepcopy(A)
B.reverse()
ans = 0

# max
tmp_n = N
tmp_k = K - 1
for b in B:
    tmp_n -= 1
    if tmp_n < tmp_k:
        break
    ans = (ans + b * nCr(tmp_n, tmp_k))%mod

# print(ans, "max")
# min
tmp_n = N
tmp_k = K - 1
for a in A:
    tmp_n -= 1
    if tmp_n < tmp_k:
        break
    ans = (ans - a * nCr(tmp_n, tmp_k))%mod

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

import sys

h, w, k = map(int, input().split())
s = []
for i in range(h):
    s.append(list(map(int, input())))

if h == 1:
    j = 0
    c = 0
    cnt = 0
    while j < w:
        c += s[j]
        if c > k:
            flag = True
        if flag:
            c = 0
            cnt += 1
            flag = False
            j -= 1
        j += 1
    print(w + cnt - 1)
    sys.exit()

ans = h + w - 2
for i in range(2**(h-1)):
    l = []
    tmp = s[0]
    for j in range(h-1):
        if i >> j & 1:
            tmp = [tmp[m] + s[j+1][m] for m in range(w)]
        else:
            l.append(tmp)
            tmp = s[j+1]
    l.append(tmp)
    c = [0] * len(l)
    cnt = 0
    flag = False
    j = 0
    while j < w:
        for m in range(len(l)):
            c[m] += l[m][j]
            if c[m] > k:
                flag = True
        if flag:
            c = [0] * len(l)
            cnt += 1
            flag = False
            j -= 1
        j += 1
    ans = min(ans, len(l) + cnt - 1)

print(ans)

### FIXED CODE ###

H, W, K = map(int, input().split())
S = [list(input()) for _ in range(H)]

res = float('inf')
for i in range(2**(H-1)):
    c = bin(i).count('1')
    cnt = c
    sum_l = [0] * (c+1)
    j = 0
    flag = True
    while j < W:
        tmp = sum_l.copy()
        pos = 0
        for k in range(H):
            if S[k][j] == '1':
                tmp[pos] += 1
            if (i >> k) & 1:
                pos += 1
        if max(tmp) <= K:
            sum_l = tmp.copy()
            j += 1
            flag = False
        else:
            if flag:
                cnt = float('inf')
                break
            cnt += 1
            flag = True
            sum_l = [0] * (c+1)

    res = min(res, cnt)

print(res)
### BUGGY CODE ###

import os, sys, re, math

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

print(' '.join(['%s' % (A.index(s) + 1) for s in sorted(A)]))


### FIXED CODE ###

import os, sys, re, math

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

ta = [(A[i], i + 1) for i in range(N)]
sa = sorted(ta, key=lambda k: k[0])

result = ''
for s in sa:
    result += '%s ' % s[1]
print(result.strip())
### BUGGY CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

def hurui(n):
  data = [i for i in range(2, n + 1)]
  for d in data:
    data = [x for x in data if (x == d or x % d != 0)]
  return data

MAX = 3*(10**5)

fac = [1]*(MAX+1)
for i in range(1,MAX+1):
    fac[i] = (fac[i-1]*i)%mod

rev_m = [1]*(MAX+1)
rev_m[MAX] = pow(fac[MAX],mod-2,mod)
for i in range(MAX,0,-1):
    rev_m[i-1] = (rev_m[i]*i)%mod

def Comb(n,k):#nCk
    return (fac[n]*rev_m[k]*rev_m[n-k])%mod


N,M = inpl()
Primes = hurui(10000)
kk = [0]*10000

while M > 1:
  for i,p in enumerate(Primes):
    if M%p == 0:
      kk[i]+=1
      M//=p
      break
      
ans =1
for k in kk:
  ans *= Comb(k+N-1,k)
  ans %= mod
  
print(ans)
  






### FIXED CODE ###

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string

def factors_nojit(n):
    gaps = [1,2,2,4,2,4,2,4,6,2,6]
    length, cycle = 11, 3
    f, fs, nxt = 2, [], 0
    while f * f <= n:
        while n % f == 0:
            fs.append(f)
            n0 = n
            n //= f
        f += gaps[nxt]
        nxt += 1
        if nxt == length:
            nxt = cycle
    if n > 1: fs.append(n)
    return fs

MAX = 10**5 + 100
mod = 10**9+7

fac = [1]*(MAX+1)
for i in range(1,MAX+1):
    fac[i] = (fac[i-1]*i)%mod

rev_m = [1]*(MAX+1)
rev_m[MAX] = pow(fac[MAX],mod-2,mod)
for i in range(MAX,0,-1):
    rev_m[i-1] = (rev_m[i]*i)%mod

def Comb(n,k):#nCk
    return (fac[n]*rev_m[k]*rev_m[n-k])%mod

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

fs =  factors_nojit(M)
fs.sort()

dd = defaultdict(int)
ed = []
for f in fs:
    if dd[f] == 0:
        ed.append(f)
    dd[f] += 1

ans =1
for e in ed:
  k = dd[e]
  ans *= Comb(k+N-1,k)
  ans %= mod

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

from collections import deque
N = int(input())
T = []
for k in range(N-1):
    t = list(map(int,input().split()))
    T.append(t)

T = sorted(T, key = lambda x: (x[0],x[1]))
T = deque(T)
A = [-1 for k in range(N)]
A[0] = 0

while len(T) > 0:
    t = T.popleft()
    u = t[0]-1
    v = t[1]-1
    w = t[2]
    if w%2 == 0:
        if A[u] == 0 and A[v] == -1:
            A[v] = 0
        elif A[u] == 1 and A[v] == -1:
            A[v] = 1
        elif A[u] == -1 and A[v] == 0:
            A[u] = 0
        elif A[u] == -1 and A[v] == 1:
            A[u] = 1
        elif A[u] == -1 and A[v] == -1:
            T.append([u+1,v+1,w])
    else:
        if A[u] == 0 and A[v] == -1:
            A[v] = 1
        elif A[u] == 1 and A[v] == -1:
            A[v] = 0
        elif A[u] == -1 and A[v] == 0:
            A[u] = 1
        elif A[u] == -1 and A[v] == 1:
            A[u] = 0
        elif A[u] == -1 and A[v] == -1:
            T.append([u+1,v+1,w])

print(*A, sep="\n")

### FIXED CODE ###

N = int(input())
T = [[] for k in range(N)]
for k in range(N-1):
    u,v,w = map(int,input().split())
    T[u-1].append([v-1,w])
    T[v-1].append([u-1,w])

kyori = [-1 for k in range(N)]
kyori[T[0][0][0]] = 0
que = [T[0][0][0]]

while len(que) > 0:
    now = que.pop()
    for tsugi in T[now]:
        if kyori[tsugi[0]] == -1:
            kyori[tsugi[0]] = kyori[now] + tsugi[1]
            que.append(tsugi[0])

for a in kyori:
    print(a%2)
### BUGGY CODE ###

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

### FIXED CODE ###

n=int(input())
a=sorted(list(map(int,input().split())))
if a[0]==0:
    print(0)
else:
    ans=1
    for i in a:
        ans=ans*i
        if ans>10**18:
            print(-1)
            break
    else:
        if ans>10**18:
            print(-1)
        else:
            print(ans)
### BUGGY CODE ###

N, M, P = map(int, input().split())
from collections import deque,defaultdict
edge1 = [[] for _ in range(N)]
edge2 = [[] for _ in range(N)]
for i in range(M):
    a,b,c= map(int, input().split())
    edge1[a-1].append([b-1,P-c])
    edge2[b-1].append([a-1,P-c])
edges1 = set()
d = deque([0])
visited1 = defaultdict(lambda: False)
while len(d):
    v = d.popleft()
    for u,w in edge1[v]:
        if visited1[(w,v,u)] == False:
            visited1[(w,v,u)] = True
            edges1.add((w,v,u))
            d.append(u)
edges2 = set()
d = deque([N-1])
visited2 = defaultdict(lambda: False)
while len(d):
    v = d.popleft()
    for u,w in edge2[v]:
        if visited2[(w,u,v)] == False:
            visited2[(w,u,v)] = True
            edges2.add((w,u,v))
            d.append(u)
new_edge = list(edges1&edges2)
d = [10**10]*N
d[0] = 0
n = 0
while True:
    n += 1
    update = False
    for w,v,u in new_edge:
        if d[u]>d[v]+w:
            d[u] = d[v]+w
            update = True
    if update == False:
        break
    if n==N and update==True:
        print(-1)
        exit()
print(max(0,-d[-1]))

### FIXED CODE ###

N, M, P = map(int, input().split())
from collections import deque,defaultdict
edge1 = [[] for _ in range(N)]
edge2 = [[] for _ in range(N)]
for i in range(M):
    a,b,c= map(int, input().split())
    edge1[a-1].append([b-1,P-c])
    edge2[b-1].append([a-1,P-c])
edges1 = set()
d = deque([0])
visited1 = defaultdict(lambda: False)
while len(d):
    v = d.popleft()
    for u,w in edge1[v]:
        if visited1[w*10**8+v*10**4+u] == False:
            visited1[w*10**8+v*10**4+u] = True
            edges1.add(w*10**8+v*10**4+u)
            d.append(u)
edges2 = set()
d = deque([N-1])
visited2 = defaultdict(lambda: False)
while len(d):
    v = d.popleft()
    for u,w in edge2[v]:
        if visited2[w*10**8+u*10**4+v] == False:
            visited2[w*10**8+u*10**4+v] = True
            edges2.add(w*10**8+u*10**4+v)
            d.append(u)
new_edge = list(edges1&edges2)
d = [10**10]*N
d[0] = 0
n = 0
while True:
    n += 1
    update = False
    for e in new_edge:
        w = e//10**8
        v = e%10**8//10**4
        u = e%10**4
        if d[u]>d[v]+w:
            d[u] = d[v]+w
            update = True
    if update == False:
        break
    if n==N and update==True:
        print(-1)
        exit()
print(max(0,-d[-1]))
### BUGGY CODE ###

import sys
from collections import deque

def solve():
      input = sys.stdin.readline
      K = int(input())
      low, high = 0, 3234566668
      while high - low > 1:
            mid = (low + high) // 2
            midS = str(mid)
            lenS = len(midS)
            q = deque()
            for j in range(lenS):
                  for i in range(1, 10): q.append((i, i, j + 1))
            count = 0
            isRunrun = False
            while q:
                  ns, last, length = q.pop()
                  if length == lenS:
                        if ns <= mid: count += 1
                        if ns == mid: isRunrun = True
                  else:
                        if last == 0: 
                              q.append((ns*10 + 1, 1, length + 1))
                              q.append((ns*10 + 0, 0, length + 1))
                        elif last == 9: 
                              q.append((ns*10 + 8, 8, length + 1))
                              q.append((ns*10 + 9, 9, length + 1))
                        else:
                              q.append((ns*10 + last+1, last + 1, length + 1))
                              q.append((ns*10 + last-1, last - 1, length + 1))
                              q.append((ns*10 + last, last, length + 1))
            if count > K: high = mid
            elif count == K:
                  if isRunrun: low = mid
                  else: high = mid
            else: low = mid
            #print(mid, count)
      print(low)
            
      return 0

if __name__ == "__main__":
      solve()

### FIXED CODE ###

import sys
from collections import deque

def solve():
      input = sys.stdin.readline
      K = int(input())
      low, high = 0, 3234566668
      while high - low > 1:
            mid = (low + high) // 2
            midS = str(mid)
            lenS = len(midS)
            q = deque()
            for j in range(lenS):
                  for i in range(1, 10): q.append((i, i, j + 1))
            count = 0
            isRunrun = False
            while q:
                  ns, last, length = q.pop()
                  if length == lenS:
                        if ns <= mid: count += 1
                        if ns == mid: isRunrun = True
                  else:
                        if last == 0: 
                              q.append((ns*10 + 1, 1, length + 1))
                              q.append((ns*10 + 0, 0, length + 1))
                        elif last == 9: 
                              q.append((ns*10 + 8, 8, length + 1))
                              q.append((ns*10 + 9, 9, length + 1))
                        else:
                              q.append((ns*10 + last+1, last + 1, length + 1))
                              q.append((ns*10 + last-1, last - 1, length + 1))
                              q.append((ns*10 + last, last, length + 1))
            if count > K: high = mid
            elif count == K:
                  if isRunrun: low = mid
                  else: high = mid
            else: low = mid
            #print(mid, count)
      print(low)
            
      return 0

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

import sys

def main():
	n, q = map(int, sys.stdin.readline().split())
	c = list(map(int, sys.stdin.readline().split()))
	fenwick = [0] * n
	
	def add(i, v):
		while i < n:
			fenwick[i] += v
			i = (i | (i + 1))
	
	def get(r):
		res = 0
		while r >= 0:
			res += fenwick[r]
			r = (r & (r + 1)) - 1
		return res
	
	def get_seg(l, r):
		return get(r) - get(l - 1)
		
	by_r = [[] for i in range(n)]
	for t in range(q):
		l, r = map(int, sys.stdin.readline().split())
		l, r = l - 1, r - 1
		by_r[r].append((l, t))
	last_ent = [-1] * (n + 1)
	ans = [0] * q
	for r in range(n):
		p = last_ent[c[r]]
		if p != -1:
			add(p, -1)	
		last_ent[c[r]] = r
		add(r, 1)
		for quer in by_r[r]:
			l, num = quer
			ans[num] = get_seg(l, r)
	print('\n'.join([str(x) for x in ans]))
	
main()



### FIXED CODE ###

import sys

def main():
	n, q = map(int, sys.stdin.readline().split())
	c = list(map(int, sys.stdin.readline().split()))
	fenwick = [0] * n
	
	def add(i, v):
		while i < n:
			fenwick[i] += v
			i = (i | (i + 1))
	
	def get(r):
		res = 0
		while r >= 0:
			res += fenwick[r]
			r = (r & (r + 1)) - 1
		return res
	
	def get_seg(l, r):
		return get(r) - get(l - 1)
		
	by_r = [[] for i in range(n)]
	for t in range(q):
		l, r = map(int, sys.stdin.readline().split())
		l, r = l - 1, r - 1
		by_r[r].append((l, t))
	last_ent = [-1] * (n + 1)
	ans = [0] * q
	for r in range(n):
		p = last_ent[c[r]]
		if p != -1:
			add(p, -1)	
		last_ent[c[r]] = r
		add(r, 1)
		for quer in by_r[r]:
			l, num = quer
			ans[num] = get_seg(l, r)
	print('\n'.join([str(x) for x in ans]))
	
main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

import itertools

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()))

amax = max(a)
a_diff = [a[i]-amax for i in range(0,x)]
bmax = max(b)
b_diff = [b[i]-bmax for i in range(0,y)]
cmax = max(c)
c_diff = [c[i]-cmax for i in range(0,z)]

minus= [a_+b_+c_ for a_,b_,c_ in itertools.product(a_diff, b_diff, c_diff)]
minus.sort(reverse=True)

ans0 = amax+bmax+cmax
for i in range(k):
    ans = ans0 + minus[i]
    print(ans)


### FIXED CODE ###

import itertools

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()))

mix_ab= [a_+b_ for a_,b_ in itertools.product(a, b)]
mix_ab.sort(reverse=True)
c.sort(reverse=True)

mix_abc= [ab_+c_ for ab_,c_ in itertools.product(mix_ab[:k], c[:k])]
mix_abc.sort(reverse=True)

print(*mix_abc[:k], sep='\n')
### BUGGY CODE ###

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

cmba=1
cmbb=1
p=(10**9)+7
lst=[]
num=pow(2,n,p)-1
for i in range(1,b+1):
  cmbb*=(n-i+1)*(pow(i,p-2,p))%p
  cmba=cmbb
  if i==a:
    lst.append(cmba)
    
num=num-lst[0]-cmbb
num=num%p

print(num)

### FIXED CODE ###

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

cmba=1
cmbb=1
p=(10**9)+7
lst=[]
num=pow(2,n,p)-1
for i in range(1,b+1):
  cmbb*=((n-i+1)*(pow(i,p-2,p)))%p
  if cmbb>p:
    cmbb=cmbb%p
  cmba=cmbb
  if i==a:
    lst.append(cmba)
    
num=num-lst[0]-cmbb
num=num%p

print(num)
### BUGGY CODE ###

import copy

K,N = map(int, input().split())
An = list(map(int, input().split()))
ans = [max(An) - min(An)]
for i in range(int(len(An)/2),len(An)):
    A_list = copy.copy(An)
    A_list[i] = A_list[i]-K
    ans.append(max(A_list) - min(A_list))
print(min(ans))

### FIXED CODE ###

import numpy as np

K,N = map(int, input().split())
An = list(map(int, input().split()))
arr = np.array(An)
arr = np.diff(arr)
ans = list(arr)
ans.append(K-An[-1]+An[0])
# print(ans)
ans.remove(max(ans))
print(sum(ans))
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
res = 0

for i in range(N):
  for j in range(i+1, N):
    for k in range(j+1, N):
      if L[i] < L[j]+L[k] and L[j] < L[i]+L[k] and L[k] < L[i]+L[j]:
        res += 1
        
print(res)

### FIXED CODE ###

from bisect import bisect_left

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

L.sort()
result = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        result += bisect_left(L, L[i] + L[j]) - j - 1
print(result)
### BUGGY CODE ###

import itertools
while 1:
    n=int(input())
    if n==0:break
    l=[int(input()) for _ in range(n)]
    print(min(sum([sum(j[:i]) for i in range(1,5)]) for j in itertools.permutations(l,len(l)-1)))


### FIXED CODE ###

import itertools

while 1:
    n=int(input())
    if n==0:break
    l=[int(input()) for _ in range(n)]
    ll=len(l)
    m=sorted(l)[:ll-1]
    print(sum([sum(m[:i]) for i in range(1,ll)]))
### BUGGY CODE ###

import copy
import itertools
N=int(input())
A=list(map(int,input().split()))
dp={}

for k in range(N):
  if A[k] in dp:
    print(dp[A[k]])
  else:
    B=copy.copy(A)
    B.remove(A[k])
    p=itertools.combinations(B,2)
    c=0
    for i in p:
      if i[0]==i[1]:
        c+=1
    dp[A[k]]=c
    print(c)

### FIXED CODE ###

import collections
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)

#全体の数列について答えを求めるnC2=n(n-1)/2
ALL=0
for i in c.values():
  if i>1:
    ALL += i*(i-1)//2

#各要素が影響する分を求める
for i in A:
  if c[i]>2:
    print(ALL-c[i]+1)
  elif c[i]==2:
    print(ALL-1)
  else:
    print(ALL)
### BUGGY CODE ###

n = int(input())
c = list(input())
cnt = 0

for i in range(n):
    if c[i] == 'W':
        for j in range(n-1,0,-1 ):
            if c[j] == 'R':
                if i < j:
                    c[i] = 'R'
                    c[j] = 'W'
                    cnt += 1
                break
print(cnt)

### FIXED CODE ###

n = int(input())
c = input()
cnt = 0
ans = 0

for i in range(n):
    if c[i] == 'R':
        cnt += 1
    
for j in range(cnt):
    if c[j] == 'W':
        ans += 1
        
print(ans)
### BUGGY CODE ###

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

LR = [[] for i in range(M)]

for i in range(M):
	L,R = map(int, input().split())
	for j in range(L,R + 1):
		LR[i].append(j)


for i in range(M):
	LR[i] = set(LR[i])

for i in range(M):
	LR[i] = LR[i] & LR[i-1]

print(len(LR[M-1]))

### FIXED CODE ###

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

inf = []
sup = []

for i in range(0,M):
	L,R = map(int,input().split())
	inf.append(L)
	sup.append(R)
	
inf = max(inf)
sup = min(sup)

ran = sup - inf

if ran >= 0:
	print(ran + 1)
else:print(0)