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

import sys

input = sys.stdin.readline

def main():
    ans = 1
    N = int(input())
    for i in range(1,N+1):
        ans *= i 
    print(ans%(10**9+7))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

input = sys.stdin.readline

def main():
    ans = 1
    N = int(input())
    for i in range(1,N+1):
        ans = ans*i%(10**9+7)
    print(ans)

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

n, m = map(int,input().split())
p = list(map(int,input().split()))
ikeru = [[] for _ in range(n)]

for i in range(m):
	a, b = map(int, input().split())
	ikeru[a-1].append(b-1)
	ikeru[b-1].append(a-1)

union = []
imada = list(range(n))

while len(imada) != 0:
	kaisuu = 0
	settansaku = set([])
	setmada = {imada[0]}
	kouho = 1
	
	while kouho != 0:
		kaisuu += 1
		for i in list(setmada):
			settansaku.add(i)
			setmada.remove(i)
			imada.remove(i)
			kouho -= 1
			for k in ikeru[i]:
				if not k in setmada:
					if not k in settansaku:
						setmada.add(k)
						kouho += 1
	
	union.append(settansaku)


ans = 0
for i in range(len(union)):
	for j in union[i]:
		if p[j]-1 in union[i]:
			ans += 1

print(ans)

### FIXED CODE ###

class UnionFind:
	"""
	class UnionFind
	https://note.nkmk.me/python-union-find/
	
	order O(log(n))
	
	n = the number of elements
	parents = the list that contains "parents" of x. be careful that it doesn't contain "root" of x.
	"""
	def __init__(self, n):
		"""
		make UnionFind
		:param n: the number of elements
		"""
		self.n = n
		self.parents = [-1] * n
	
	def find(self, x):
		"""
		:param x: an element
		:return: the root containing x
		"""
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]
	
	def union(self, x, y):
		"""
		:param x, y: an element
		"""
		# root
		x = self.find(x)
		y = self.find(y)
		if x == y:
			# already same group so do nothing
			return
		if self.parents[x] > self.parents[y]:
			# the root should be min of group
			x, y = y, x
		# remind that x, y is the root, x < y, then, y unions to x.
		self.parents[x] += self.parents[y]
		# and then y's parent is x.
		self.parents[y] = x
	def size(self, x):
		# return the size of group
		return -self.parents[self.find(x)]
	
	def same(self, x, y):
		# return whether the x, y are in same group
		return self.find(x) == self.find(y)
	
	def members(self, x):
		# return members of group
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i) == root]
	
	def roots(self):
		# return all roots
		return [i for i, x in enumerate(self.parents) if x < 0]
	
	def group_count(self):
		# return how many groups
		return len(self.roots())
	
	def all_group_members(self):
		# return all members of all groups
		return {r: self.members(r) for r in self.roots()}

n, m = map(int,input().split())
p = list(map(int,input().split()))
union = UnionFind(n)
ans = 0

for i in range(m):
	x, y = map(int,input().split())
	union.union(x-1, y-1)

for cnt, j in enumerate(p):
	if union.same(cnt, j-1):
		ans += 1

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

N=int(input())
*A,=map(int,input().split())
S=[list(map(lambda x : abs(x-a),A)) for a in A]
print(max(s.count(1) for s in S)+1)

### FIXED CODE ###

input()
*A,=map(int,input().split())
D=[0]*(10**7)

for a in A:
    D[a-1]+=1
    D[a]+=1
    D[a+1]+=1
print(max(D))
### BUGGY CODE ###

import numpy as np
#from numba import njit

#@njit #処理の並列化

def imos(n, a):
    
    l=np.zeros((n+1), dtype = np.int64)

    for i in range(n):
        ai = a[i] # 光の強さ_これにより照らせる範囲が決まる
        start = max(0, i - ai) #StartIndex_照らせる範囲
        end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲
        l[start] += 1 # 各々を'+1'と'-1'で表し...
        l[end] -= 1
    return np.cumsum(l)[:n] # 累積和をとる_cumulative sum

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

for _ in range(k):
    a = imos(n, a)
    if a.min() == n: # すべての要素が最大値'n'になるとbreak
        break

print(*a)


### FIXED CODE ###

import numpy as np
from numba import njit

@njit #処理の並列化

def imos(n, a):
    
    l=np.zeros((n+1), dtype = np.int64)

    for i in range(n):
        ai = a[i] # 光の強さ_これにより照らせる範囲が決まる
        start = max(0, i - ai) #StartIndex_照らせる範囲
        end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲
        l[start] += 1 # 各々を'+1'と'-1'で表し...
        l[end] -= 1
    return np.cumsum(l)[:n] # 累積和をとる_cumulative sum

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

for _ in range(k):
    a = imos(n, a)
    if a.min() == n: # すべての要素が最大値'n'になるとbreak
        break

print(*a)
### BUGGY CODE ###

N = int(input())
nums = list(map(int, input().split()))
count = [0]*N
nums.sort()
for i in range(N):
  fNum = nums[i]
  for j in range(0,N):
    if (nums[j] > fNum):
      break
    if (count[i] == 1):
      break
    if (i == j):
      continue
    else:
      sNum = nums[j]
      if (fNum%sNum == 0):
      	count[i] += 1
answer = 0
for i in count:
  if (i == 0):
    answer += 1
print(answer)

  
    
  



### FIXED CODE ###

N = int(input())
nums = list(map(int, input().split()))
nums.sort()
div_length = max(nums)+1
divisible_list = {}
#initialize
for i in range(0, div_length):
  divisible_list[i] = 0

#count divisible numbers
for fNum in nums:
  for j in range(fNum, div_length, fNum):
   	divisible_list[j] += 1

#check for numbers
answer = 0
for num in nums:
  if (divisible_list[num] == 1):
    answer += 1
print(answer)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b=[]
for i in range(len(a)):
    if i%2==0:
        b.append(a[i])
    if not i%2==0:
        b.insert(0,a[i])
if not n%2==0:
    b=b[::-1]
print(*b)

### FIXED CODE ###

n=int(input())
a=input().split()
b=" ".join(a[-1::-2] + a[(n%2)::2])
print(b)
### BUGGY CODE ###

input()
A = list(map(int,input().split()))
count = 0
while all(a % 2 == 0 for a in A):
    count += 1
else: print(count)

### FIXED CODE ###

input()
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
    A = [a/2 for a in A]
    count += 1
print(count)
### BUGGY CODE ###

class BIT:
    """1-indexed BIT
    """

    def __init__(self, size: int):
        """サイズを指定して BIT を初期化します。
        """
        self.__size = size
        self.__bit = [0] * (self.__size+1)

    def add(self, idx: int, val: int):
        """位置 idx (1-indexed) に値 val をたす。
        :param idx: 値を追加したいインデックス
        :param val: 追加したい値
        """
        while idx <= self.__size:
            self.__bit[idx] += val
            idx += idx & (-idx)

    def sum(self, idx: int)->int:
        s = 0
        while idx > 0:
            s += self.__bit[idx]
            idx -= idx & (-idx)
        return s


def median_of_medians(N: int, A: list) -> int:
    def check(x: int)->int:
        bit = BIT(2 * N + 1)
        s = 0
        a = 0
        for i in range(N):
            s += bit.sum(a + N)
            bit.add(a + N, 1)
            a = a + (1 if x <= A[i] else - 1)

        s += bit.sum(a + N)

        return s

    alpha = sorted(A)
    l, r = 0, N
    while r - l > 1:
        m = (r + l + 1) // 2
        if 2*check(alpha[m]) >= (N * (N + 1)) // 2:
            l = m
        else:
            r = m

    return alpha[l]


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = median_of_medians(N, A)
    print(ans)


### FIXED CODE ###


def median_of_medians(N: int, A: list)->int:
    def search(c):
        bar = N
        r = 0
        res_nega = 0
        dp_arr = [0]*(2*N+1)
        for i in range(N):
            dp_arr[bar] += 1
            if A[i] < c:
                r += dp_arr[bar]
                bar += 1
            else:
                r -= (dp_arr[bar-1])
                bar -= 1
            res_nega += r
        return res_nega

    # binary search
    a_sorted = sorted(A)
    left = 0
    right = N
    mid = N // 2
    C = N*(N+1) // 2
    while True:
        if search(a_sorted[mid]) <= C // 2:
            if mid == N-1:
                break
            elif search(a_sorted[mid+1]) > C // 2:
                break
            else:
                left = mid
                mid = (mid + right) // 2
        else:
            right = mid + 1
            mid = (mid + left) // 2

    return a_sorted[mid]


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = median_of_medians(N, A)
    print(ans)
### BUGGY CODE ###


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

#n=4
#a=8
#x=[7,9,8,9]

#n=8
#a=5
#x=[3,6,2,8,7,6,5,9]

for i in range(n):
    x[i]=x[i]-a
    
n2=n//2
n3=n-n2

y=[]
for i in range(n3):
    y.append(x[i+n2])

# itertools 使用 bit全探索
import itertools

xsum=dict()
for i in itertools.product([0,1], repeat=n2):
    isum=0
    for ii in range(n2):
        if i[ii]==0:
            isum=isum+x[ii]
    if isum in xsum:
        xsum[isum]=xsum[isum]+1
    else:
        xsum[isum]=1
#xsum[0]=xsum[0]
#print(xsum)        
    
icnt=0
for i in itertools.product([0,1], repeat=n3):
    isum=0
    for ii in range(n3):
        if i[ii]==0:
            isum=isum+y[ii]
#    print(isum)
    for xs in xsum.items():
        if xs[0]==-isum:
            icnt=icnt+(xs[1])
#            print(isum,xs[1],(xs[1]),icnt)

print(icnt-1)

### FIXED CODE ###

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

for i in range(n):
    x[i]=x[i]-a
    
nx=n*n
dp=[[0]*(2*nx+1) for i in range(n+1)]

#print(dp)

dp[0][nx]=1

for j in range(1,n+1):
    jj=j-1
    for t in range(2*nx+1):
        if t-x[jj]<0 or 2*nx<t-x[jj]:
            dp[j][t]=dp[j-1][t]
        elif 0<t-x[jj] and  t-x[jj]<2*nx:
            dp[j][t]=dp[j-1][t]+dp[j-1][t-x[jj]]
        else:
            dp[j][t]=0

print(dp[n][nx]-1)
### BUGGY CODE ###

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

ans = [0]*N
for i in range(N):
  if min(P[0:i+1]) >= P[i]:
    ans[i] = 1

print(sum(ans))

### FIXED CODE ###

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

ans = [0]*N
min_cal = [0]*N
min_cal[0] = P[0]

for i in range(N-1):
  min_cal[i+1] = min(min_cal[i],P[i+1])

for i in range(N):
  if min_cal[i] >= P[i]:
    ans[i] = 1

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

import heapq
def SME(Whole,start,end,L,ANS):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == 0 and idx < end:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > K * 0.999 : break
    for i in range(L):
        if ANS[i] == 0 : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == 0 : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ANS = [0]*N
start = 0
K = N // 2
if K > N : K = N
end = K
while (end <= N):
    ANS = SME(A, start, end, L, ANS)
    start = end
    end += K 
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

d = dict()


def gcd(a, b):
    if (a, b) in d:
        return d[(a, b)]
    if b == 0:
        return a
    else:
        res = gcd(b, a % b)
        d[(a, b)] = res
        return res
    return


def gcd_3(a, b, c):
    return gcd(gcd(a, b), c)


def main():
    res = 0
    n = int(input())
    for a in range(1, n+1):
        for b in range(1, n+1):
            for c in range(1, n+1):
                res += gcd_3(a, b, c)
    print(res)


def input(): return stdin.readline().rstrip()


main()


### FIXED CODE ###

from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

d = dict()


def gcd(a, b):
    if (a, b) in d:
        return d[(a, b)]
    if b == 0:
        return a
    else:
        res = gcd(b, a % b)
        d[(a, b)] = res
        return res
    return


def gcd_3(a, b, c):
    return gcd(gcd(a, b), c)


def main():
    res = 0
    n = int(input())
    for a in range(1, n+1):
        for b in range(1, n+1):
            m = gcd(a, b)
            if m == 1:
                res += 1*n
            else:
                for c in range(1, n+1):
                    res += gcd(m, c)
    print(res)


def input(): return stdin.readline().rstrip()


main()
### BUGGY CODE ###

from collections import deque
h,w = list(map(int,input().split()))
s = []
for i in range(h):
    sh = list(input())
    s.append(sh)   
ki = [[] for i in range(h*w)]
def ichi(a,b):
    return a + b*h
for a in range(h):
    for b in range(w):
        if s[a][b] == ".":
            if  a+1 < h and s[a+1][b] == "." :
                ki[ichi(a+1,b)].append(ichi(a,b))
                ki[ichi(a,b)].append(ichi(a+1,b))
            if  a-1 >= 0 and s[a-1][b] == ".":
                ki[ichi(a-1,b)].append(ichi(a,b))
                ki[ichi(a,b)].append(ichi(a-1,b))
            if b-1 >= 0 and s[a][b-1] == ".":
                ki[ichi(a,b-1)].append(ichi(a,b))
                ki[ichi(a,b)].append(ichi(a,b-1))
            if b+1 < w and s[a][b+1] == "." :
                ki[ichi(a,b+1)].append(ichi(a,b))
                ki[ichi(a,b)].append(ichi(a,b+1))
        else:
            pass
for i in range(w*h):
    ki[i] = list(set(ki[i]))
ans = [0]
for i in range(w*h):
    ikeru = deque([i])
    sumi = []
    kaisuu = [-1]*(w*h)
    kaisuu[i] = 0
    while ikeru:
        j = ikeru.popleft()
        sumi.append(j)
        for k in range(len(ki[j])):
            if not ki[j][k] in sumi:
                ikeru.append(ki[j][k])
                if kaisuu[ki[j][k]] > kaisuu[j] + 1:
                    kaisuu[ki[j][k]] = kaisuu[j] + 1
                elif kaisuu[ki[j][k]] == -1:
                    kaisuu[ki[j][k]] = kaisuu[j] + 1 
#        print(i,kaisuu,ikeru)
    ans.append(max(kaisuu))
#print(ans)
print(max(ans))        

### FIXED CODE ###

from collections import deque
h,w = list(map(int,input().split()))
s = []
for i in range(h):
    sh = list(input())
    s.append(sh)
ki = [[] for i in range(h*w)]
def ichi(a,b):
    return a + b*h
for a in range(h):
    for b in range(w):
        if s[a][b] == ".":
            if  a+1 < h and s[a+1][b] == "." :
                ki[ichi(a+1,b)].append(ichi(a,b))
                ki[ichi(a,b)].append(ichi(a+1,b))
            if  a-1 >= 0 and s[a-1][b] == ".":
                ki[ichi(a-1,b)].append(ichi(a,b))
                ki[ichi(a,b)].append(ichi(a-1,b))
            if b-1 >= 0 and s[a][b-1] == ".":
                ki[ichi(a,b-1)].append(ichi(a,b))
                ki[ichi(a,b)].append(ichi(a,b-1))
            if b+1 < w and s[a][b+1] == "." :
                ki[ichi(a,b+1)].append(ichi(a,b))
                ki[ichi(a,b)].append(ichi(a,b+1))
        else:
            pass
for i in range(w*h):
    ki[i] = list(set(ki[i]))
ans = [0]
for i in range(w*h):
    ikeru = deque([i])
    sumi = []
    kaisuu = [-1]*(w*h)
    kaisuu[i] = 0
    while ikeru:
        j = ikeru.popleft()
        sumi.append(j)
        for k in range(len(ki[j])):
            if ki[j][k] in sumi:
                pass
            else:
                if ki[j][k] not in ikeru:
                    ikeru.append(ki[j][k])
                if kaisuu[ki[j][k]] > kaisuu[j] + 1:
                    kaisuu[ki[j][k]] = kaisuu[j] + 1
                elif kaisuu[ki[j][k]] == -1:
                    kaisuu[ki[j][k]] = kaisuu[j] + 1 
#        print(i,kaisuu,ikeru)
    ans.append(max(kaisuu))
#print(ans)
print(max(ans))
### BUGGY CODE ###

K, S = map(int, input().split())

cnt = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if (i + j + k == S):
                cnt += 1
print(cnt)

### FIXED CODE ###

K, S = map(int, input().split())

cnt = 0
for i in range(K+1):
    for j in range(K+1):
        ij = i + j
        if ij > S:
            break
        if (S - ij <= K):
            cnt += 1
print(cnt)
### BUGGY CODE ###

import collections
n = int(input())
ls = [input() for i in range(n)]
c = collections.Counter(ls)
a = c.most_common()[0][1]
t = len(set(ls))
b = [c.most_common()[p][0] for p in range(t) if c.most_common()[p][1] == a]
b.sort()
for k in range(len(b)):
    print(b[k])


### FIXED CODE ###

import collections
n = int(input())
ls = [input() for i in range(n)]
c = collections.Counter(ls)
mx = max(c.values())
A = [e for e,j in c.items() if j == mx]
A.sort()
for p in A:
  print(p)
### BUGGY CODE ###

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

class segtree:
    x_unit=0 # 要素として入れられる最大値
    def __init__(self,N):
        self.n=(1<<len(bin(N-1)[2:]))
        self.x=[self.x_unit]*(2*self.n)

    def build(self, seq):
        for i,j in enumerate(seq, start=self.n):  # n番目からseqをx配列に移していく
            self.x[i] = j
        for i in range(self.n-1, 0, -1):
            self.x[i] = 0
            # セグ木トーナメント表の左右を比較
            # 例えばn=8の時、seq[4]はx[12]に、seq[5]はx[13]に入っている
            # さらにx[14]とx[15]の間に来るのはx[7]、x[12]とx[13]の間に来るのはx[6]

    def fold(self,l,r): # 区間[l, r)値に+1 
        l+=self.n
        r+=self.n-1
        while l<r:
            if l%2==1: # lが奇数
                self.x[l]+=1
                l+=1 # 偶数に調節
            if r%2==0: # rが偶数
                self.x[r]+=1
                r-=1 # 開区間なので1個前は奇数番目の要素
            l //= 2
            r //= 2
        if l==r:
            self.x[l]+=1
        #print(self.x)
    def get(self,i): # seq[i]に対する値を取得 
        i+=self.n
        ret=self.x[i]
        while i>1:
            i //= 2
            ret+=self.x[i]
        return ret

for z in range(min(k,50)):
    seq=[0]*n
    q=[(max(0, i-a[i]), min(n,i+a[i]+1)) for i in range(n)]
    seg=segtree(n)
    seg.build(seq)
    for i in range(n):
        l,r=q[i]
        seg.fold(l,r)
    ans=[]
    for i in range(n):
        ans.append(seg.get(i))
    a=ans+[]
print(*a)

### FIXED CODE ###

n,k=map(int, input().split())
a=list(map(int, input().split()))
from itertools import accumulate
for _ in range(k):
    new=[0]*n
    for i in range(n):
        j=a[i]
        l=max(0,i-j)
        r=min(n-1,i+j)
        new[l]+=1
        if r+1<n:
            new[r+1]-=1
    new=list(accumulate(new))
    a=new
    if all([i==n for i in a]):
        break
print(*a)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]

L = []
sums = []
ans = []

def main():
    global L,ans,sums
    N,Q= map(int, input().split())
    ans = [0]*(N+1)
    sums = [0]*(N+1)
    L=[]
    [L.append([])for _ in range(N+1)]
    for _ in range(N-1):
        A,B = map(int, input().split())
        L[A].append(B)
        L[B].append(A)
    for _ in range(Q):
        p,x = map(int, input().split())
        sums[p]+=x
    dfs(1,0)

    print(*ans[1:N+1])


def dfs(p,pre):
    global L,ans,sums
    ans[p] = ans[pre] + sums[p]
    for i in range(len(L[p])):
        if pre!=L[p][i]:
            dfs(L[p][i],p)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

L = []
sums = []
ans = []

def main():
    global L,ans,sums
    N,Q= map(int, input().split())
    ans = [0]*(N+1)
    sums = [0]*(N+1)
    L=[]
    [L.append([])for _ in range(N+1)]
    for _ in range(N-1):
        A,B = map(int, input().split())
        L[A].append(B)
        L[B].append(A)
    for _ in range(Q):
        p,x = map(int, input().split())
        sums[p]+=x
    dfs(1,0)

    print(*ans[1:N+1])


def dfs(p,pre):
    global ans
    ans[p] = ans[pre] + sums[p]
    for ki in L[p]:
        if pre==ki:
            continue    
        dfs(ki,p)


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

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

A = list(map(lambda x: int(x), input().split(' ')))
A.sort(reverse=True)

for _ in range(M):
    A[0] = A[0] // 2
    A.sort(reverse=True)

print('{}'.format(sum(A)))

### FIXED CODE ###

import heapq
 
N, M = list(map(int, input().split()))
A = input().split(" ")
neg_A = [-int(a) for a in A]
 
heapq.heapify(neg_A)
 
for t in range(M):
    heapq.heappush(neg_A, -(-heapq.heappop(neg_A)//2))
print(-sum(neg_A))
### BUGGY CODE ###

def knapsack_123(values,weights,capacity):
    work = [0 for i in range(capacity+1)]
    for c in range(1, capacity+1):
        candidates = [val + work[c-weight]
                      for val,weight in zip(values,weights) if weight <= c]
        work[c] = max(candidates) if candidates != [] else 0
    return work[-1]
def sol(inp=input):
    n=int(inp())
    prices_a=list(map(int,inp().split()))+[1]
    prices_b=list(map(int,inp().split()))+[1]
    valA=knapsack_123(values=prices_b,weights=prices_a,capacity=n)
    valB=knapsack_123(values=prices_a,weights=prices_b,capacity=valA)
    return '{}'.format(valB)

print(sol())

### FIXED CODE ###

def knapsack_123(values,weights,capacity):
    work = [0 for i in range(capacity+1)]
    for v,w in zip(values,weights):
        for c in range(w, capacity+1):
            work[c]=max(work[c],work[c-w]+v)
    return work[-1]
def sol(inp=input):
    n=int(inp())
    prices_a=list(map(int,inp().split()))+[1]
    prices_b=list(map(int,inp().split()))+[1]
    
    valA=knapsack_123(values=prices_b,weights=prices_a,capacity=n)
    valB=knapsack_123(values=prices_a,weights=prices_b,capacity=valA)
    return '{}'.format(valB)
print(sol())
### BUGGY CODE ###

N=int(input(''))
C=0
F=N-C

a=0
k=0
v=0

while C<N-1:
  C=C+1
  while a<=F:
      a=a+1
      v=v+(F%a)
      if v==0:
          k=k+1
      v=0
      a=0
  F=N-C
print(k)


### FIXED CODE ###

N=int(input(''))
a=1
k=0
F=int(N**(1/2))

while a<N:
  if N%a>0:
    b=N//a
    k=k+b
    b=0
  else:
    b=N//a
    k=k+b-1
    b=0
  a=a+1

print(k)
### BUGGY CODE ###

def main():
  n=int(input())
  a=list(map(int,input().split()))
  ans=float('inf')
  for i in range(1,n):
    ans=min(ans,abs(sum(a[i:])-sum(a[:i])))
  print(ans) 
if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  n=int(input())
  a=list(map(int,input().split()))
  ans,s,x=abs(sum(a)-2*a[0]),sum(a),a[0]
  for i in range(1,n-1):
    x+=a[i]
    ans=min(ans,abs(s-2*x))
  print(ans)
if __name__=='__main__':
  main()