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

N = int(input())
v = round(N ** 0.5)
while N % v != 0:
    v += 1
print(len(str(v)))

### FIXED CODE ###

from math import sqrt
N = int(input())
ans = []
for i in range(1, int(sqrt(N)) + 1):
    if i * (N // i) == N:
        ans.append(max(len(str(i)), len(str(N // i))))
print(min(ans))
### BUGGY CODE ###

from fractions import gcd

K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1, K+1):
        t = gcd(i,j)
        for k in range(1, K+1):
            ans += gcd(k,t)

print(ans)

### FIXED CODE ###

from fractions import gcd

K = int(input())
ans = (K * (K+1)) // 2

for i in range(1,K-1):
    for j in range(i+1,K):
        t = gcd(i,j)
        for k in range(j+1,K+1):
            ans += gcd(k,t) * 6

for i in range(1,K):
    for j in range(i+1,K+1):
        ans += gcd(i,j) * 6
    
print(ans)
### BUGGY CODE ###

# Picking Up
# グラフ,有向グラフ,ベクトル, ２次元、コスト,

N = int(input())
S = []
for _ in range(N):
    x, y = map(int, input().split())
    S.append([x, y])
cost = N

for k, ke in enumerate(S):
    for i, ie in enumerate(S):
        if k == i:
            continue
        t_vec_x1 = ie[0] - ke[0]
        t_vec_y1 = ie[1] - ke[1]
        edge = 0
        for l,le in enumerate(S):
            for m, me in enumerate(S):
                if l == m:
                    continue
                vec_x = me[0] - le[0]
                vec_y = me[1] - le[1]
                if t_vec_x1 == vec_x and t_vec_y1 == vec_y:
                    edge += 1
        cost = min(cost, N - edge)
        # t_vec_x2 = S[k][0] - S[i][0]
        # t_vec_y2 = S[k][1] - S[i][1]
        # edge = 0
        # for l in range(sl):
        #     for m in range(sl):
        #         if l == m:
        #             continue
        #         vec_x = S[l][0] - S[m][0]
        #         vec_y = S[l][1] - S[m][1]
        #         if t_vec_x2 == vec_x and t_vec_y2 == vec_y:
        #             edge += 1
        # print(edge)
        cost = min(cost, N - edge)

print(cost)


### FIXED CODE ###

# Picking Up
# グラフ,有向グラフ,ベクトル, ２次元、コスト,

N = int(input())
S = []
for _ in range(N):
    x, y = map(int, input().split())
    S.append([x, y])
cost = N
d = {}

if N==1:
    print(1)
    exit()
for l,le in enumerate(S):
    for m, me in enumerate(S):
        if l == m:
            continue
        t = (me[0] - le[0], me[1] - le[1])
        if t in d:
            d[t] +=1
        else:
            d[t] = 1

print(N - max(d.values()))
### BUGGY CODE ###

import sys
K,S = map(int,input().split())
#0<=S<=3K
res = 0
for X in range(0,K+1):
    if X > S:
        break
        print(res)
        sys.exit(0)
    for Y in range(0,K+1):
        if X + Y > S:
            break
        elif (0<=(S-X-Y)) and ((S-X-Y) <= K):
            res += 1
print(res)


### FIXED CODE ###

K,S = map(int,input().split())
print(sum([0<=S-X-Y<=K for X in range(0,K+1) for Y in range(0,K+1)]))
### BUGGY CODE ###

def f(num):
    ans=0
    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                if x**2+y**2+z**2+x*y+y*z+z*x==num:
                    ans+=1
    return ans

N=int(input())
for i in range(N):
    print(f(i+1))

### FIXED CODE ###

N=int(input())
ans=[0 for _ in range(10050)]
for x in range(1,105):
    for y in range(1,105):
        for z in range(1,105):
            v=x**2+y**2+z**2+x*y+y*z+z*x
            if v<10050:
                ans[v]+=1

for i in range(N):
    print(ans[i+1])
### BUGGY CODE ###

import time

def solve(i, m):
    if m == 0:
        return True
    if m < 0:
        return False
    if i >= n:
        return False
    return solve(i+1, m) or solve(i+1, m-A[i])

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    #start = time.time()
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"
    #end = time.time()
    #print end - start

### FIXED CODE ###

def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"
### BUGGY CODE ###

N = int(input().strip())
A = list(map(int, input().strip().split(' ')))
for i in range(max(A), 1, -1):
  if len([1 for a in A if a%i==0]) >= N-1:
    print(i)
    exit()
print(1)


### FIXED CODE ###

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

# 約数列挙
def divisor(n):
  result = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      result.append(i)
      if i != n // i:
        result.append(n//i)
  return result

# A(intのlist)のうちdで割り切れるものがlen(A)-1個以上あればTrue
def check(A, d):
  count = 0
  for a in A:
    if a % d == 0:
      continue
    count += 1
    if count > 1:
      return False
  return True

for i in sorted(list(set(divisor(A[0])+divisor(A[1]))))[::-1]:
  if check(A, i):
    print(i)
    exit()
### BUGGY CODE ###

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

W, H, N = map(int, input().split())
X = []
for k in range(N):
  x,y,a = map(int, input().split())
  if a == 1:
    for z in range(1,x+1):
      for j in range(1,H+1):
        X.append([z,j])
        X = get_unique_list(X)
  elif a == 2:
    for z in range(x+1,W+1):
      for j in range(1,H+1):
        X.append([z,j])
        X = get_unique_list(X)
  elif a == 3:
    for z in range(1,y+1):
      for i in range(1,W+1):
        X.append([i,z])
        X = get_unique_list(X)
  else:
    for z in range(y+1,H+1):
      for i in range(1,W+1):
        X.append([i,z])
        X = get_unique_list(X)
print(W*H - len(get_unique_list(X)))

### FIXED CODE ###

W, H, N = map(int, input().split())
X = [0, 0, W, 0, H]
for k in range(N):
  x,y,a = map(int, input().split())
  if a == 1:
    X[a] = max(x,X[a])
  elif a == 2:
    X[a] = min(x,X[a])
  elif a == 3:
    X[a] = max(y,X[a])
  else:
    X[a] = min(y,X[a])
tate = X[4] - X[3]
yoko = X[2] - X[1]
ans = tate*yoko
if tate<0 or yoko<0:
  print(0)
else:
  print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, K = [int(item) for item in input().split()]
h =[0] + [int(item) for item in input().split()]

dp = [0 for _ in range(N+1)]

for i in range(2, N+1):
    for k in range(1, K+1):
        if i - k >= 1:
            if dp[i] != 0:
                dp[i] = min(dp[i-k] + abs(h[i] - h[i-k]), dp[i])
            else:
                dp[i] = dp[i-k] + abs(h[i] - h[i-k])
print(dp[N])


### FIXED CODE ###

import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

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

class Puzzle:
    def __init__(self,panel,space,cnt):
        self.panel=panel
        self.space=space
        self.cnt=cnt

d=(1,-1,4,-4)
model=map(str,range(8))
def check(s):
    if s==model:
        return True
    return False

def bfs(s):
    m=set()
    que=[s]
    m.add(tuple(s.panel))
    while que!=[]:
        now=que[0]
        del que[0]
        if check(now.panel):
            return now.cnt
        idx1=now.space
        for i in range(4):
            idx2=idx1+d[i]
            if idx2<0 or idx2>7:
                continue
            if (idx1==3 and d[i]==1) or (idx1==4 and d[i]==-1):
                continue
            next_panel=now.panel[:]
            next_panel[idx2],next_panel[idx1]=now.panel[idx1],now.panel[idx2]
            next=Puzzle(next_panel,idx2,now.cnt+1)
            if tuple(next.panel) not in m:
                m.add(tuple(next.panel))
                que.append(next)
    return -1

while True:
    try:
        panel=raw_input().split()
    except EOFError:
        break
    space=panel.index("0")
    s=Puzzle(panel,space,0)
    ans=bfs(s)
    print ans

### FIXED CODE ###

from collections import defaultdict
d=(1,-1,4,-4)

def solve():
    que=["01234567"]
    while que!=[]:
        v=que[0]
        del que[0]
        pos=v.index("0")
        for i in range(4):
            idx2=pos+d[i]
            if idx2<0 or idx2>7:
                continue
            if (pos==3 and d[i]==1) or (pos==4 and d[i]==-1):
                continue
            u=list(v)
            u[pos],u[pos+d[i]]=u[pos+d[i]],u[pos]
            u="".join(u)
            if res[u]==0:
                que.append(u)
                res[u]=res[v]+1
res=defaultdict(int)
res["01234567"]=1
solve()
while True:
    try:
        s=raw_input().split()
    except EOFError:
        break
    s="".join(s)
    print res[s]-1
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

????????±?????¨??????
"""
# 3/5??§Time Limit Exceeded 14.27s ????????????5s??\???????????????????????????

def calc_lcs(X, Y):
    from array import array
    max_lcs = 0
    m = len(X)
    n = len(Y)
    X = ' ' + X
    Y = ' ' + Y
    c = array('l', [0] * (1001 * 1001))
    for i in range(1, m+1):
        for j in range(1, n+1):
            if X[i] == Y[j]:
                c[i*1001 + j] = c[(i-1)*1001 + j - 1] + 1
            elif c[(i-1)*1001 + j] >= c[i*1001 + j - 1]:
                c[i*1001 + j] = c[(i-1)*1001 + j]
            else:
                c[i*1001 + j] = c[i*1001 + j - 1]
            max_lcs = max(max_lcs, c[i*1001 + j])
    return max_lcs


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    # f = open('input.txt')
    # num = int(f.readline())

    for _ in range(num):
        X = input()
        Y = input()
        # X = f.readline().strip()
        # Y = f.readline().strip()

        # ???????????????
        result = calc_lcs(X, Y)

        # ???????????¨???
        print(result)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

最長共通部分列
"""


c = []
def prep_array(X, Y):
    global c
    """ 値が0の2次元配列を用意する。サイズは入力データの最大値を想定して縦横(1000+1)以上必要。 """
    # from array import array
    # c = [array('I', [0] * (len(X)+1)) for _ in range(len(Y)+1)]  #  arrayで用意
    c = [[0]*(len(Y)+2) for _ in range(len(X)+2)] #  リストで用意
    return c


def check_max(array):
    """ 2次元配列の中の最大の値を返す """
    max_lcs = 0
    for row in array:
        temp_max = max(row)
        if temp_max > max_lcs:
            max_lcs = temp_max
    return max_lcs


def calc_lcs4(X, Y, c):
    """
    Y[j]のアクセス方法を変更
    リストの値を一旦変数に保存するように変更
    最長共通部分長を関数内で計算するように変更
    4/5 のテストデータを使用してプロファイリングすると実効時間は 5.6秒
    """
    X = ' ' + X
    Y = ' ' + Y
    m = len(X)
    n = len(Y)
    max_lcs = 0

    pre_row = c[0]
    for i in range(1, m):
        row = c[i]
        XX = X[i]
        for j, YY in enumerate(Y):
            if XX == YY:
                pr_j1 = pre_row[j - 1]
                row[j] = pr_j1 + 1
                if pr_j1+1 > max_lcs:
                   max_lcs = pr_j1 + 1
            else:
                pr_j = pre_row[j]
                r_j1 = row[j-1]
                if pr_j >= r_j1:
                    row[j] = pr_j
                else:
                    row[j] = r_j1
        pre_row = row
    return max_lcs


if __name__ == '__main__':
    # データの入力
    num = int(input())
    #f = open('input.txt')
    #num = int(f.readline())

    for _ in range(num):
        X = input().strip()
        Y = input().strip()

        # 処理の実行
        result = calc_lcs4(X, Y, prep_array(X, Y))

        # 結果の表示
        print(result)
### BUGGY CODE ###

n,s=map(int,input().split())
a=list(map(int,input().split()))
t=[[0]*(s+1) for i in range(n+1)]
t[0][0]=1
m=998244353
for i in range(n):
    for j in range(s+1):
        t[i+1][j]=t[i][j]*2
        if j>=a[i]:
            t[i+1][j]+=t[i][j-a[i]]
        t[i+1][j]%=m
print(t[-1][-1])

### FIXED CODE ###

n,s=map(int,input().split())
a=list(map(int,input().split()))
t=[[0]*(s+1) for i in range(n+1)]
t[0][0]=1
m=998244353
for i in range(n):
    for j in range(s+1):
        t[i+1][j]=t[i][j]*2
        if j>=a[i]:
            t[i+1][j]+=t[i][j-a[i]]
        t[i+1][j]%=m
print(t[-1][-1])
### BUGGY CODE ###


def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

n = int(input())
s = 0
for i in range(1, n+1):
  for j in range(1, n + 1):
    for k in range(1, n+1):
      s += gcd(gcd(i, j), k)
print(s)
    

### FIXED CODE ###


def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

def permutation(n):
    if n == 1:
        return 1
    elif n == 2:
        return 3
    else:
        return 6

def solve():
    n = int(input())
    s = 0
    for i in range(1, n + 1):
        for j in range(i, n + 1):
            for k in range(j, n + 1):
                diff = 1
                if j != k:
                    diff += 1
                if i != j:
                    diff += 1
                s += gcd(i, gcd(j, k)) * permutation(diff)

    print(s)
    return s

solve()
### BUGGY CODE ###

def e(a,b):
    x=(a+b)/2
    return x
ans=0
Max=0
n,k=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n-k+1):
    tmp=0
    for j in range(i,i+k):
        tmp+=l[j]
        Max=max(tmp,Max)
print(e(Max,k))

### FIXED CODE ###

def e(a,b):
    x=(a+b)/2
    return x
ans=0
Max=0
n,k=map(int,input().split())
l=list(map(int,input().split()))
tmp=0
for i in range(k):
    Max+=l[i]
tmp=Max
for j in range(k,n):
    tmp+=l[j]
    tmp-=l[j-k]
    Max=max(tmp,Max)
print(e(Max,k))
### BUGGY CODE ###

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

a = []
for i in range(M):
    A, B = map(int, input().split())
    a.append([A, B])

count = 0

for i in range(1, N + 1):
    h_i = H[i - 1]
    a_i = []
    for j in a:
        if j[0] == i:
            a_i.append(j[1])
        elif j[1] == i:
            a_i.append(j[0])
    flg = True
    for k in a_i:
        if h_i <= H[k - 1]:
            flg = False
    if flg:
        count = count + 1

print(count)


### FIXED CODE ###

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

r = [1] * len(H)
a = []
for i in range(M):
    A, B = map(int, input().split())
    if H[A - 1] >= H[B - 1]:
        r[B - 1] = 0
    if H[B - 1] >= H[A - 1]:
        r[A - 1] = 0

print(r.count(1))
### BUGGY CODE ###

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7

dp = [0] * (1 << n)
dp[0] = 1

for bit in range((1 << n) - 1):
    i = bin(bit).count('1')
    for j in range(n):
        newbit = bit | (1 << j)
        if (a[i][j] == 1) and ((bit >> j) & 1 == 0):
            dp[newbit] += dp[bit]
            dp[newbit] %= mod
print(dp[-1])


### FIXED CODE ###

mod = 10**9+7
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
dp = [0]*(1 << n)
dp[0] = 1
for i in range(1, 1 << n):
    k = bin(i).count("1")
    for j in range(n):
        if i >> j & 1 and a[k-1][j]:
            dp[i] += dp[i ^ (1 << j)]
    dp[i] %= mod
print(dp[(1 << n)-1])
### BUGGY CODE ###

a = input()
c = input()
d=[]
alist = list(a)
for i in range(int(c)):
  e = input().split()
  d.append(e)
for i in range(int(c)):
  if d[i][0]=="1":
    l = len(alist)
    for x in range(int(l//2)):
      alist[x],alist[l-x-1] = alist[l-x-1],alist[x]
  else:
    if d[i][1] == "1":
      alist = [d[i][2]] + alist
    else:
      alist = alist + [d[i][2]]
le = len(alist)
answer =""
for i in range(le):
  answer = answer + alist[i]
print(answer)
      

### FIXED CODE ###

from collections import deque
a = input()
c = input()
d = []
alist = list(a)
adeque = deque(a)
count = 0
for i in range(int(c)):
  e = input().split()
  d.append(e)
for i in range(int(c)):
  if d[i][0]=="1":
    count = count + 1
  else:
    if d[i][1] == "1" and count % 2 == 0:
      adeque.appendleft(d[i][2])
    elif d[i][1] == "2" and count % 2 == 1:
      adeque.appendleft(d[i][2])
    else:
      adeque.append(d[i][2])
alist = list(adeque)
if count % 2 == 1:
  l = len(alist)
  for x in range(int(l//2)):
    alist[x],alist[l-x-1] = alist[l-x-1],alist[x]
answer = "".join(alist)
print(answer)
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

N = int(readline())
T, A = map(int,readline().split())

import math
for i in range(N - 1):
  t,a = map(int,readline().split())
  i = 1
  while True:
    if t * i >= T and a * i >= A:
      T,A = t * i,a * i
      break
    i += 1

print(T + A)

### FIXED CODE ###

import sys
readline = sys.stdin.readline

N = int(readline())
T, A = map(int,readline().split())

for i in range(N - 1):
  t,a = map(int,readline().split())
  # newT % t == 0 , newA % a == 0である
  # newT >= T , newA >= Aである
  
  # T以上の、tの倍数の最小値 = T / tの切り上げ
  minT = ((T + t - 1) // t) * t
  minA = minT * a // t
  if minA >= A:
    T,A = minT,minA
    continue
  minA = ((A + a - 1) // a) * a
  minT = minA * t // a
  T,A = minT,minA
  
print(T + A)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline

    def ask(n):
        print(n)
        sys.stdout.flush()
        s = input().strip('\n')
        if s == 'Vacant':
            exit()
        elif s == 'Male':
            return 0
        else:
            return 1

    N = int(input())

    a0 = ask(0)
    ok = 0
    ng = N-1
    mid = (ok+ng)//2
    while ng - ok > 1:
        a = ask(mid)
        if a == a0:
            ok = mid
        else:
            ng = mid
        mid = (ok+ng)//2
    _ = ask(N-1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline

    def ask(n):
        print(n)
        sys.stdout.flush()
        s = input().rstrip('\n')
        if s == 'Vacant':
            exit()
        elif s == 'Male':
            return 0
        else:
            return 1

    N = int(input())

    a0 = ask(0)
    ok = 0
    ng = N-1
    mid = ((ng//2)//2) * 2
    while ng - ok > 2:
        a = ask(mid)
        if a == a0:
            ok = mid
        else:
            ng = mid
        mid = (((ok//2)+(ng//2))//2)*2
    ask((ok+ng)//2)
    ask(N-1)


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

def val(num):
    print(num, flush=True)
    sex = input()
    if sex == "Vacant":
        exit(0)
    return 1 if sex == "Male" else 0


n = int(input())

l_sex = val(0)

left = 0
right = n - 1

while left < right:
    mid = (left + right) // 2
    sex = val(mid)
    if (mid - left) % 2 == 0 and sex != sex:
        left = mid + 1
    elif (mid - left) % 2 == 1 and sex == sex:
        left = mid + 1
    else:
        right = mid - 1

print(left, flush=True)
exit(0)


### FIXED CODE ###

def val(num):
    print(num, flush=True)
    sex = input()
    if sex == "Vacant":
        exit(0)
    return 1 if sex == "Male" else 0


n = int(input())

l_sex = val(0)
r_sex = val(n - 1)

left = 0
right = n - 1

while left < right:
    mid = (left + right) // 2
    sex = val(mid)
    if (mid - left) % 2 == 0 and sex != l_sex:
        right = mid
        r_sex = sex
    elif (mid - left) % 2 == 1 and sex == l_sex:
        right = mid
        r_sex = sex
    else:
        left = mid
        l_sex = sex

print(left, flush=True)
exit(0)
### BUGGY CODE ###

def main():

    N, W = map(int, input().split())
    knap = []

    for i in range(N):
        knap.append(list(map(int, input().split())))
    
    dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

    for i in range(N):
        for j in range(W+1):
            if(j >= knap[i][0]):
                dp[i+1][j] = max(dp[i][j], dp[i][j-knap[i][0]]+knap[i][1])
            else:
                dp[i+1][j] = dp[i][j]

    print(dp[N][W])
main()

### FIXED CODE ###

import numpy as np

N, W = map(int, input().split())
knap = []

for _ in range(N):
    knap.append(tuple(map(int, input().split())))
    
dp = np.zeros((N+1, W+1), dtype=np.int64)

for i, (w, v) in enumerate(knap):
    dp[i+1] = np.maximum(dp[i+1], dp[i])
    dp[i+1][w:] = np.maximum(dp[i][w:], dp[i][:-w]+v)
       
print(dp[N][-1])
### BUGGY CODE ###

from collections import deque
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
d=deque()
dc=0
b=[]
for i in range(h):
  s=input()
  for j in range(w):
    if s[j]=="#":d.append((i,j));dc+=1
  b.append(list(s))
count=0
while dc!=0:
  ld=dc
  dc=0
  for i in range(ld):
    x=d.popleft()
    if x[0]<h-1:
      if b[x[0]+1][x[1]]==".":b[x[0]+1][x[1]]=count;d.append((x[0]+1,x[1]));dc+=1
    if 0<x[0]:
      if b[x[0]-1][x[1]]==".":b[x[0]-1][x[1]]=count;d.append((x[0]-1,x[1]));dc+=1
    if x[1]<w-1:
      if b[x[0]][x[1]+1]==".":b[x[0]][x[1]+1]=count;d.append((x[0],x[1]+1));dc+=1
    if 0<x[1]:
      if b[x[0]][x[1]-1]==".":b[x[0]][x[1]-1]=count;d.append((x[0],x[1]-1));dc+=1
  count+=1
print(count-1) 

### FIXED CODE ###

from collections import deque
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
d=deque()
dc=0
b=[]
for i in range(h):
  t=[]
  s=input()
  for j in range(w):
    if s[j]=="#":d.append((i,j));dc+=1;t.append(1)
    else:t.append(0)
  b.append(t)
count=0
while dc!=0:
  ld=dc
  dc=0
  for i in range(ld):
    x=d.popleft()
    if x[0]<h-1:
      if b[x[0]+1][x[1]]==0:b[x[0]+1][x[1]]=1;d.append((x[0]+1,x[1]));dc+=1
    if 0<x[0]:
      if b[x[0]-1][x[1]]==0:b[x[0]-1][x[1]]=1;d.append((x[0]-1,x[1]));dc+=1
    if x[1]<w-1:
      if b[x[0]][x[1]+1]==0:b[x[0]][x[1]+1]=1;d.append((x[0],x[1]+1));dc+=1
    if 0<x[1]:
      if b[x[0]][x[1]-1]==0:b[x[0]][x[1]-1]=1;d.append((x[0],x[1]-1));dc+=1
  count+=1
print(count-1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

h, w, d = [ int(v) for v in input().split() ]
def manhattan(intuple1,intuple2):
	return abs(intuple1[2]-intuple2[2]) + abs(intuple1[1]-intuple2[1])

grid_list = [ None for i in range(w*h) ]
for i in range(h):
	num_list = [ int(v) for v in input().split() ]
	for j in range(w):
		grid_list[i*w+j] = (num_list[j],i,j)
grid_list = sorted(grid_list)


m = int(input())
for i in range(m):
	l, r = [ int(v) for v in input().split() ]
	score = 0
	left = grid_list[l-1]
	for j in range(l+d,r+d,d):
		right = grid_list[j-1]
		score += manhattan(left,right)
		left = right
	print(score)

### FIXED CODE ###

import sys
input = sys.stdin.readline

h, w, d = [ int(v) for v in input().split() ]
def manhattan(intuple1,intuple2):
	return abs(intuple1[2]-intuple2[2]) + abs(intuple1[1]-intuple2[1])

grid_list = [ None for i in range(w*h) ]
for i in range(h):
	num_list = [ int(v) for v in input().split() ]
	for j in range(w):
		grid_list[i*w+j] = (num_list[j],i,j)
grid_list = sorted(grid_list)

sum_list = []

for i in range(1,d+1):
	temp_list = []
	left = i
	s = 0
	for j in range(i,w*h+1,d):
		s +=  manhattan(grid_list[left-1],grid_list[j-1])
		temp_list.append(s)

		left = j
	sum_list.append(temp_list)

m = int(input())
for i in range(m):
	l, r = [ int(v) for v in input().split() ]
	print(sum_list[r%d-1][(r-1)//d]-sum_list[l%d-1][(l-1)//d])
### BUGGY CODE ###

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

summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)]
print(min(summation))


### FIXED CODE ###

def main():
    N = int(input())
    a = list(map(int, input().split()))
    #N = 1000
    #a = [i for i in range(N)]

    #summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)]

    summation = []
    sumtemp = sum(a)
    tmp1 = 0
    for i in range(len(a)-1):
        tmp1 += a[i]
        tmp2 = sumtemp - tmp1
        tmp = abs(tmp1 - tmp2)
        summation.append(tmp)
        
    print(min(summation))

main()