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

import numpy as np

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

S = np.empty((N+1, M+1), dtype='int')

for n in range(1, N+1):
    S[n, :] = [0] + list(map(int, list(input())))

# count nodes
N_cum = np.cumsum(np.cumsum(S, axis=0), axis=1) 
# count edges(row)
ER_cum = np.cumsum(np.cumsum(S[:N, :]*S[1:, :], axis=0), axis=1) 
# count edges(col)
EC_cum = np.cumsum(np.cumsum(S[:, :M]*S[:, 1:], axis=0), axis=1) 


for _ in range(Q):
    x1, y1, x2, y2 = map(int, input().split())
    # nodes
    N_nodes = N_cum[x2, y2] - N_cum[x1-1, y2] - N_cum[x2, y1-1] + N_cum[x1-1, y1-1]
    # edges(row)
    N_edges1 = ER_cum[x2-1, y2] - ER_cum[x1-1, y2] - ER_cum[x2-1, y1-1] + ER_cum[x1-1, y1-1]
    # edges(col)
    N_edges2 = EC_cum[x2, y2-1] - EC_cum[x1-1, y2-1] - EC_cum[x2, y1-1] + EC_cum[x1-1, y1-1]
    
    print(N_nodes - N_edges1 - N_edges2)

### FIXED CODE ###

import numpy as np

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

S = np.zeros((N+1, M+1), dtype='float32')

for n in range(1, N+1):
    S[n, 1:] = list(map(int, list(input())))

# count nodes
N_cum = np.cumsum(np.cumsum(S, axis=0), axis=1) 
# count edges(row)
ER_cum = np.cumsum(np.cumsum(S[:N, :]*S[1:, :], axis=0), axis=1) 
# count edges(col)
EC_cum = np.cumsum(np.cumsum(S[:, :M]*S[:, 1:], axis=0), axis=1) 

sol_list = []

for _ in range(Q):
    x1, y1, x2, y2 = map(int, input().split())
    # nodes
    N_nodes = N_cum[x2, y2] - N_cum[x1-1, y2] - N_cum[x2, y1-1] + N_cum[x1-1, y1-1]
    # edges(row)
    N_edges1 = ER_cum[x2-1, y2] - ER_cum[x1-1, y2] - ER_cum[x2-1, y1-1] + ER_cum[x1-1, y1-1]
    # edges(col)
    N_edges2 = EC_cum[x2, y2-1] - EC_cum[x1-1, y2-1] - EC_cum[x2, y1-1] + EC_cum[x1-1, y1-1]
    
    sol_list.append(N_nodes - N_edges1 - N_edges2)

for q in range(Q):
    print(int(sol_list[q]))
### BUGGY CODE ###

n, q = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
  a, b = map(int,input().split())
  a, b = a-1, b-1
  g[a].append(b)
#print(g)

from collections import deque

c = [0]*n
visit = [[] for _ in range(n)]
visit_log = [0]*n

for j in range(q):
  x, p = map(int, input().split())
  x = x-1
  if visit_log[x] != 0:
    for y in visit[x]:
        c[y] += p
  else:
    queue = deque()
    c[x] += p
    visit[x].append(x)
    visit_log[x] = 1
    queue.append(x)
    while queue:
      y = queue.popleft()
      for y_ in g[y]:
        c[y_] += p
        visit[x].append(y_)
        if g[y_] == []:
          continue
        else:
          queue.append(y_)
          

print(' '.join(map(str, c)))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  g[a].append(b)
  #g[b].append(a)

ans = [0]*n  
for j in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
from collections import deque
s = deque()
s.append(0)

while s:
  v = s.pop()
  for v_ in g[v]:
    ans[v_] += ans[v]
    s.append(v_)

print(' '.join(map(str, ans)))
### BUGGY CODE ###

if __name__ == "__main__":
    N, K = [int(n) for n in input().split()]
    h = [int(n) for n in input().split()]
    # dp[i]はi番目までたどり着くのに必要な最小コスト
    # dp[0] = 0
    # dp[1] = |h[1] - h[0]|
    # dp[i] = min(dp[0]+h[i]-h[0], dp[1]+h[i]-h[1], ...)
    dp = [0] * N
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        dp[i] = min([dp[k] + abs(h[k] - h[i]) for k in range(max(i - K, 0), i)])
    print(dp[N-1])


### FIXED CODE ###

def a():
    N, K = [int(n) for n in input().split()]
    h = [int(n) for n in input().split()]
    # dp[i]はi番目までたどり着くのに必要な最小コスト
    # dp[0] = 0
    # dp[1] = |h[1] - h[0]|
    # dp[i] = min(dp[0]+h[i]-h[0], dp[1]+h[i]-h[1], ...)
    dp = [0] * N
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        dp[i] = min([dp[k] + abs(h[k] - h[i]) for k in range(max(i - K, 0), i)])
    print(dp[N-1])

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

from fractions import gcd
import sys
input = sys.stdin.readline

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

g=A[0]
l_1=A[0]
l_2=A[-1]
for i in range(N//2):
    g1=gcd(l_1,A[i])
    l_1=l_1*A[i]//g1
    g2=gcd(l_2,A[N-i-1])
    l_2=l_2*A[N-i-1]//g2
    
if N%2==1:
    g1=gcd(l_1,A[N//2])
    l_1=l_1*A[N//2]//g1
    
g=gcd(l_1,l_2)
l=l_1*l_2//g
    
ans=0
mod=10**9+7

for i in range(N):
    ans+=l//A[i]
    
print(ans%mod)

### FIXED CODE ###

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

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


for i in range(N):
    a=A[i]
    for j in range(2,a):
        temp=0
        while a%j==0:
            a=a//j
            temp+=1
        lcm[j]=max(lcm[j],temp)
        if a==1 or j*j>A[i]:
            break
    if a!=1:
        lcm[a]=max(lcm[a],1)
                
        
l=1
for d in lcm.items():
    l*=pow(d[0],d[1])
    

ans=0
mod=10**9+7

for i in range(N):
    ans+=l//A[i]
    
print(ans%mod)
### BUGGY CODE ###

n=int(input())
x=list(map(lambda x:int(x), input().split()))
mi = int(n/2)-1
sx=x[:]
sx.sort()
for item in x:
    cx=sx[:]
    cx.remove(item)
    print(cx[mi])

### FIXED CODE ###

n=int(input())
x=list(map(lambda x:int(x), input().split()))
mi = n//2 - 1
sx=sorted(x)
for item in x:
    if item > sx[mi]:
        print(sx[mi])
    else:
        print(sx[mi+1])
### BUGGY CODE ###

N,Y = map(int,input().split())
satu = [10000,5000,1000]
lst = []
flag = True
for i in range(N+1):
    for j in range(N+1):
        if(N-i-j)>=0:
            lst.append([i,j,N-i-j])
        else:
            break

for i in range(len(lst)):
    gaku = 10000*lst[i][0] + 5000*lst[i][1] + 1000*lst[i][2]
    if gaku == Y:
        print(lst[i][0],lst[i][1],lst[i][2])
        flag = False
        break
if flag:
    print("-1 -1 -1")


### FIXED CODE ###

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

satu = [1000,5000,10000]

sen = [1000 * i for i in range(n+1)]
gsen = [5000 * i for i in range(n+1)]
man = [10000 * i for i in range(n+1)]

#print(sen,gsen,man)
for i in range(n+1):
    for j in range(n+1-i):
        if man[i]+ gsen[j] + sen[n-i-j] == y:
            print(i,j,n-i-j)
            exit()

print("-1 -1 -1")
### BUGGY CODE ###

N = int(input())
S = list(input())

S_R = S.count('R')
S_B = S.count('B')
S_G = S.count('G')

con = S_R * S_B * S_G

for i in range(N):
    for j in range(i+1, N):
        if S[i] != S[j] and j + (j - i) < len(S):
            if S[i] != S[j + (j - i)] and S[j] != S[j + (j - i)]:
                con -= 1

print(con)


### FIXED CODE ###

import collections
import math

N = int(input())
S = list(input())

if 'R' in S and 'G'in S and 'B' in S:
    count = collections.Counter(S)
    c_value = list(count.values())
    con = c_value[0]*c_value[1]*c_value[2]
else:
    con = 0

for i in range(N):
    for j in range(i+1, int(math.ceil((N+i)/2))):
        if S[i] != S[j]:
            if S[i] != S[j + (j - i)] and S[j] != S[j + (j - i)]:
                con -= 1

print(con)
### BUGGY CODE ###

#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

#A,B,K = [int(x) for x in input().split()]
S = input()

def hoge(input):
    new = []
    i = 0
    remove = False
    while i < len(input) - 1:
        if input[i] != input[i+1]:
            i = i + 2
            remove = True
        else:
            i = i + 1
            new.append(input[i])
    if i == len(input) - 1:
        new.append(input[-1])
    return new,remove

input = S
while True:
    input, remove = hoge(input)
    if not remove:
        break
print(len(S) - len(input))


### FIXED CODE ###

#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

#A,B,K = [int(x) for x in input().split()]
S = input()

cnt_1 = 0
cnt_0 = 0

for s in S:
    if s == "0":
        cnt_0 += 1
    else:
        cnt_1 += 1

print(min(cnt_1,cnt_0) * 2)
### BUGGY CODE ###

from math import factorial

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

a.sort()

ai=a[n-1]

a0=factorial(ai)//(factorial(ai-a[0])*factorial(a[0]))


for i in range(1,n-1):
    j=a[i]
    temp=a0
    for k in range(1,a[i]-a[i-1]+1):
        temp*=(ai-(a[i-1]+k-1))/(a[i-1]+k)

    if a0>=temp:
        print(str(ai)+" "+str(a[i-1]))
        exit()
    a0=temp

print(str(ai)+" "+str(a[n-2]))





### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

ans1=a[0]

b=ans1//2
ans2=0
for i in range(n):
    if abs(a[i]-b)<abs(ans2-b):
        ans2=a[i]

print(ans1,ans2)
### BUGGY CODE ###

from sys import setrecursionlimit


def f(u, l, r, a, dp):
    if l > r:
        return 0
    if dp[l][r] is not None:
        return dp[l][r]
    if u == 0:
        t0 = f(u ^ 1, l + 1, r, a, dp) + a[l]
        t1 = f(u ^ 1, l, r - 1, a, dp) + a[r]
        if t0 > t1:
            result = t0
        else:
            result = t1
    else:
        t0 = f(u ^ 1, l + 1, r, a, dp) - a[l]
        t1 = f(u ^ 1, l, r - 1, a, dp) - a[r]
        if t0 < t1:
            result = t0
        else:
            result = t1
    dp[l][r] = result
    return result


setrecursionlimit(1000000)

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

dp = [[None] * N for _ in range(N)]
print(f(0, 0, N - 1, a, dp))


### FIXED CODE ###

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

dp = [[0] * (N + 1) for _ in range(N + 1)]
for l in range(1, N + 1):
  for i in range(N + 1 - l):
    j = i + l
    if (N - l) % 2 == 0:
      dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
    else:
      dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
print(dp[0][N])
### BUGGY CODE ###

h,w=map(int,input().split())
sl=[input() for i in range(h)]
ans=0
for i in range(h):
    for j in range(w):
        if sl[i][j]!='#':
            cnt=1
            for k in range(i-1,-1,-1):
                if sl[k][j]=='.':
                    cnt+=1
                else:
                    break
            for k in range(i+1,h):
                if sl[k][j]=='.':
                    cnt+=1
                else:
                    break
            for k in range(j-1,-1,-1):
                if sl[i][k]=='.':
                    cnt+=1
                else:
                    break
            for k in range(j+1,w):
                if sl[i][k]=='.':
                    cnt+=1
                else:
                    break
            ans=max(ans,cnt)
print(ans)

### FIXED CODE ###

h,w=map(int,input().split())
sl=[input() for i in range(h)]
ll=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if sl[i][j]=='.':
            if j==0:
                ll[i][j]=1
            else:
                ll[i][j]=ll[i][j-1]+1
        else:
            ll[i][j]=0
rl=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w-1,-1,-1):
        if sl[i][j]=='.':
            if j==w-1:
                rl[i][j]=1
            else:
                rl[i][j]=rl[i][j+1]+1
        else:
            rl[i][j]=0
ul=[[0]*w for i in range(h)]
for j in range(w):
    for i in range(h):
        if sl[i][j]=='.':
            if i==0:
                ul[i][j]=1
            else:
                ul[i][j]=ul[i-1][j]+1
        else:
            ul[i][j]=0
dl=[[0]*w for i in range(h)]
for j in range(w):
    for i in range(h-1,-1,-1):
        if sl[i][j]=='.':
            if i==h-1:
                dl[i][j]=1
            else:
                dl[i][j]=dl[i+1][j]+1
        else:
            dl[i][j]=0
ans=0
for i in range(h):
    for j in range(w):
            ans=max(ans,ll[i][j]+rl[i][j]+ul[i][j]+dl[i][j]-3)
print(ans)
### BUGGY CODE ###

n=int(input())
h=list(map(int,input().split()))
temp=0
if n==1:
  print("Yes")
else:
  for i in range(0,n-1):
    tempmax=min(h[i+1:])
    if h[i]-1>tempmax:
      temp=1
      break
  if temp==0:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))
base=0
for h in H:
    if base>h:
        print("No")
        break
    base=max(base,h-1)
else:
    print("Yes")
### BUGGY CODE ###

from sys import stdin
N = int(stdin.readline().rstrip())
num_list = [int(i) for i in stdin.readline().rstrip().split()]
output = 0
for n in range(0, N):
    now_value = num_list[n]
    over_list = [i for i in num_list[:n] if i > now_value]
    if len(over_list) == len(num_list[:n]):
        output += 1
print(output)

### FIXED CODE ###

from sys import stdin
N = int(stdin.readline().rstrip())
num_list = [int(i) for i in stdin.readline().rstrip().split()]
output = 0
min_value = float("inf")
for n in range(0, N):
    now_value = num_list[n]
    if min_value > now_value:
        output += 1
        min_value = now_value
    # over_list = [i for i in num_list[:n] if i > now_value]
    # if len(over_list) == len(num_list[:n]):
    #     output += 1
print(output)
### BUGGY CODE ###

import sys
a = [int(i) for i in input().split()]
N = a[0]
K = a[1]

if K == 1:
    print(0)
    sys.exit()


def resZ(i, K):
    return abs(i - K)


while True:
    ab = resZ(N, K)
    # print(ab)
    if N < ab:
        print(N)
        # print('end')
        sys.exit()

    N = ab
# def


### FIXED CODE ###

import sys
a = [int(i) for i in input().split()]
N = a[0]
K = a[1]

if K == 1:
    print(0)
    sys.exit()


def resZ(i, K):
    return abs(i - K)

ab = resZ(N, K)
# print(ab)
if N < ab:
    print(N)
    # print('end')
    sys.exit()

N = N % K
while True:
    ab = resZ(N, K)
    # print(ab)
    if N < ab:
        print(N)
        # print('end')
        sys.exit()

    N = ab
# def
### BUGGY CODE ###

n=int(input())
s=input()
c=[[0,0,0] for _ in range(n+1)]
R=G=B=0
for j,i in enumerate(s):
    if i=="R":
        R+=1
    elif i=="G":
        G+=1
    else:B+=1
    c[j+1]=[R,G,B]
a=0
for i,m in enumerate(s):
    for j in range(i):
        if m!=s[j]:
            k=3-"RGB".index(m)-"RGB".index(s[j])
            a+=c[-1][k]-c[i][k]
            if 2*i-j<=n-1:
                if s[2*i-j]=="RGB"[k]:
                    a-=1
print(a)

### FIXED CODE ###

n=int(input())
s=input()
c=s.count
a=c("R")*c("G")*c("B")
for i in range(n-2):
    for j in range((n-i+1)//2):
        if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i+2*j]!=s[i]:
            a-=1
print(a)
### BUGGY CODE ###

x=input()
x0=x.split()
n=int(x0[0])
k=int(x0[1])
x=input()
x0=x.split()
a=[int(n) for n in x0]
s=1
for i in range(k):
    s*=a[i]
for i in range(n-k):
    s1=s/a[i]*a[k+i]
    if s1>s:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

x=input()
x0=x.split()
n=int(x0[0])
k=int(x0[1])
x=input()
x0=x.split()
a=[int(n) for n in x0]
for i in range(n-k):
    if a[i]<a[k+i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


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


def ni(): return int(ns())


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


n = ni()
s = ns()
ans = 0
for num in product(range(0, 10), repeat=3):
    i = 0
    for si in s:
        if int(si) == num[i] and i == 2:
            ans += 1
            break
        elif int(si) == num[i]:
            i += 1
print(ans)


### FIXED CODE ###

#create date: 2020-08-11 09:28

import sys
stdin = sys.stdin
from itertools import product

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    s = ns()
    ans = 0

    for a in product(range(10), repeat=3):
        i = 0
        for si in s:
            if int(si) == a[i]:
                i += 1
            if i == 3:
                ans += 1
                break
    print(ans)

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

h,w=map(int, input().split())
ch,cw=map(int, input().split())
ch-=1
cw-=1
dh,dw=map(int, input().split())
dh-=1
dw-=1
grid=[]
es=[[] for _ in range(h*w)]

for i in range(h):
    s=list(input())
    news=[-1 if x=='#' else 0 for x in s]
    grid.append(news)
dif=set([(1,0),(-1,0),(0,1),(0,-1)])
warp=set([(i,j) for i in range(-2,3) for j in range(-2,3)])
warp=warp.difference(dif.union({(0,0)}))

for i in range(h):
    for j in range(w):
        if grid[i][j]==-1:
            continue
        else:
            for d in dif:
                newi=i+d[0]
                newj=j+d[1]
                if 0<=newi<h and 0<=newj<w and grid[newi][newj]!=-1:
                    es[i*w+j].append([newi*w+newj, 0])
            for d in warp:
                newi=i+d[0]
                newj=j+d[1]
                if 0<=newi<h and 0<=newj<w and grid[newi][newj]!=-1:
                    es[i*w+j].append([newi*w+newj, 1])

from heapq import heappush, heappop
def dijkstra(edges, size, source):
    distance = [float('inf')] * size
    distance[source] = 0
    visited = [False] * size
    pq = []
    heappush(pq, (0, source))
    while pq:
        dist_v, v = heappop(pq)
        visited[v] = True
        for u, weight in edges[v]:
            if not visited[u]:
                new_dist = dist_v + weight
                if distance[u] > new_dist:
                    distance[u] = new_dist
                    heappush(pq, (new_dist, u))
    return distance

dist=dijkstra(es,h*w,ch*w+cw)
if dist[dh*w+dw]==float('inf'):
    print(-1)
else:
    print(dist[dh*w+dw])

### FIXED CODE ###

h,w=map(int, input().split())
ch,cw=map(int, input().split())
ch-=1
cw-=1
dh,dw=map(int, input().split())
dh-=1
dw-=1
grid=[]
for i in range(h):
    s=list(input())
    news=[-1 if x=='#' else 0 for x in s]
    grid.append(news)
dif=[(1,0),(-1,0),(0,1),(0,-1)]
from collections import deque
col=0
for i in range(h):
    for j in range(w):
        if grid[i][j]==0:
            col+=1
            stack=deque([(i,j)])
            grid[i][j]=col
            while stack:
                nowi,nowj=stack.popleft()
                for di,dj in dif:
                    if 0<=nowi+di<h and 0<=nowj+dj<w and grid[nowi+di][nowj+dj]==0:
                        stack.append((nowi+di,nowj+dj))
                        grid[nowi+di][nowj+dj]=col
start=grid[ch][cw]-1
end=grid[dh][dw]-1
if start==end:
    print(0)
    exit()
es=[set([]) for _ in range(col)]
visited=[-1]*col

for i in range(h):
    for j in range(w):
        now=grid[i][j]
        if now!=-1: 
            for x in range(-2, 3):
                for y in range(-2, 3):
                    if 0<=i+x<h and 0<=j+y<w:
                        nex=grid[i+x][j+y]
                        if nex!=-1 and now!=nex:
                            es[now-1].add(nex-1)

stack=deque([start])
visited[start]=0
while stack:
    now=stack.popleft()
    for e in es[now]:
        if visited[e]==-1:
            visited[e]=visited[now]+1
            stack.append(e)
#print(grid)
print(visited[end])
### BUGGY CODE ###

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

exp = []
for i in range(1, N + 1):
    # i=1
    exp.append(sum(range(1, P[i - 1] + 1)) / P[i - 1])

max = 0
for i in range(N - K + 1):
    val = sum(exp[i:i + K])
    if val > max:
        max = val

print(max)


### FIXED CODE ###

import numpy as np

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

# N, K = 10, 4
# P = [17, 13, 13, 12, 15, 20, 10, 13, 17, 11]

exp = []
for i in range(N):
    exp.append((1 + P[i]) / 2)

cum_exp = np.cumsum(exp)

max = cum_exp[K-1]
for i in list(range(K, N)):
    val = cum_exp[i] - cum_exp[i - K]
    if val > max:
        max = val

print(max)
### BUGGY CODE ###

class RollingHash():
    def __init__(self,s):
        self.n=n=len(s)
        self.b=b=129
        self.M=M=2**61-1
        self.f=f=[1]*(n+1)
        self.h=h=[0]*(n+1)
        for i,c in enumerate(s.encode()):
            f[i+1]=f[i]*b%M
            h[i+1]=(h[i]*b+c)%M
    def get(self,l,r):
        return(self.h[r]-self.h[l]*self.f[r-l])%self.M
n=int(input())
s=RollingHash(input())
for i in range(1,n):
    d={}
    for j in range(0,n-i+1):
        k=s.get(j,j+i)
        if k in d:
            if d[k]+i<=j:
                break
        else:
            d[k]=j
    else:
        print(i-1)
        break

### FIXED CODE ###

from subprocess import*
with open('e.cpp','w')as f:f.write(r"""
#include<iostream>
using namespace std;
main(){
  int n;
  string s;
  cin>>n>>s;
  int a=0;
  for(int i=0;i<n;++i){
    int t=0;
    for(int j=0;j<n-i;++j){
      t=(t+1)*(s[j]==s[j+i]);
      a=max(a,min(t,i));
    }
  }
  cout<<a;
}""")
call(('g++','e.cpp'))
call('./a.out')
### BUGGY CODE ###

n = int(input())
a = [int(x) for x in input().split()]
ans = 10**10
for i in range(1, n):
    x = a[:i]
    y = a[i:]
    s = abs(sum(x)-sum(y))
    if s < ans:
        ans = s
print(ans)


### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]

x = a[0]
y = sum(a[1:])
ans = abs(x-y)

for i in range(1, n-1):
    x += a[i]
    y -= a[i]
    ans = min(ans, abs(x-y))
print(ans)
### BUGGY CODE ###

N = int(input())
c = input()

c = [c[i] for i in range(N)]

cR = c.count('R')
cW = c.count('W')

listR = [i for i, x in enumerate(c) if x == 'R']
listW = [i for i, x in enumerate(c) if x == 'W']

if all([i == 'R' for i in c[:cR]]):
    print(0)
    exit()

if all([i == 'W' for i in c[cR:cR+cW]]):
    print(0)
    exit()

cnt = 0

for i in range(N):
        c[listR[-(i+1)]] = 'W'
        c[listW[i]] = 'R'
        cnt += 1
        if all([i == 'R' for i in c[:cR]]):
            print(cnt)
            break

    


### FIXED CODE ###

N = int(input())
c = input()

cR = c.count('R')
cW = c.count('W')


if all([i == 'R' for i in c[:cR]]):
    print(0)
    exit()

if all([i == 'W' for i in c[cR:cR+cW]]):
    print(0)
    exit()

ans = c[:cR].count('W')

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

n = int(input())
a = list(map(int,input().split()))
cnt = [0]*(66)
for num in a:
    for j in range(60):
        cnt[j] += (num >> j)%2
ans = 0
for b in range(60):
    ans += (cnt[b]*(n-cnt[b])) << b
    ans %= 10**9+7
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
cnt = [0]*(66)
for num in a:
    for j in range(60):
        cnt[j] += (num >> j)%2
ans = 0
for b in range(60):
    ans += (cnt[b]*(n-cnt[b])) << b
    ans %= 10**9+7
print(ans)
### BUGGY CODE ###

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

out = 0

for i in range(n):
    w = i-a[i]
    for j in range(i):
        if(w == a[j] + j):
            out += 1
print(out)


### FIXED CODE ###

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

ml = [0] * n
pl = [0] * n

out = 0

for i in range(0, n):
    if(i+a[i]<n):
        pl[i+a[i]] += 1
    if(i-a[i]>=0):
        ml[i-a[i]] += 1

for i in range(0, n):
    out += pl[i] * ml[i]

print(out)