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

from collections import deque

n, m  = map(int, input().split())
g     = {}
maxD  = [-1 for i in range(n)]
color = [0  for _ in range(n)]

for _ in range(m):
    u, v = map(int, input().split())
    u-=1
    v-=1
    if u not in g:
        g[u] = []
    if v not in g:
        g[v] = []
    g[u].append(v)
    g[v].append(u)
    
q = int(input())
Q = []

for _ in range(q):
    node, dis, col = map(int, input().split())
    Q.append([node-1, dis, col])
Q = Q[::-1]

def bfs(curQ):
    while len(curQ) > 0:
        node, dis, col = curQ.popleft()
    
        if maxD[node] > dis:
            continue
            
        if dis < 0:
            continue
            
        maxD[node] = dis
    
        if color[node] == 0:
            color[node] = col

        if node in g:
            for v in g[node]:
                curQ.append([v, dis-1, col])
                    
for node, dis, col in Q:
    curQ = deque()
    curQ.append([node, dis, col])
    bfs(curQ)

ans = ''
for x in color:
    ans += str(x)+'\n'
print(ans)    


### FIXED CODE ###

n, m  = map(int, input().split())
g     = {}
used  = {i:[False for _ in range(11)] for i in range(n)}
color     = [0  for _ in range(n)]

for _ in range(m):
    u, v = map(int, input().split())
    u-=1
    v-=1
    if u not in g:
        g[u] = []
    if v not in g:
        g[v] = []
    g[u].append(v)
    g[v].append(u)
    
q = int(input())
Q = []

for _ in range(q):
    node, dis, col = map(int, input().split())
    Q.append([node-1, dis, col])
Q = Q[::-1]

def bfs(now, dist, col):
    if dist < 0:
        return
    
    if used[now][dist]:
        return
 
    used[now][dist] = True
    
    if not color[now]:
        color[now] = col
 
    if now in g:
        for x in g[now]:
            bfs(x, dist - 1, col)
            
for node, dis, col in Q:
    bfs(node, dis, col)

for x in color:
    print(x)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
k, q = map(int, input().split())
d = list(map(int, input().split()))

for _ in range(q):
    n, x, m = map(int, input().split())
    l = []
    for i in range(k):
        l.append(d[i]%m)
    zero = l.count(0)
    total = x%m
    total += sum(l)*((n-1)//k)
    zero_total = zero*((n-1)//k)

    s = n
    n -= 1
    n -= n//k * k
    t = 0
    for i in range(n):
        t += l[i]

    total += t

    zero_total += l[:n].count(0)
    print(s-1-total//m-zero_total)


### FIXED CODE ###

import sys
input = sys.stdin.readline
k, q = map(int, input().split())
d = list(map(int, input().split()))
query = [None]*q
for i in range(q):
    query[i] = list(map(int, input().split()))

def answer_query(n, x, m):
    l = [m if i%m == 0 else i%m for i in d]
    count = n // k
    rem = n % k
    s = sum(l)
    total = s%m * count + x%m
    for i in range(rem):
        total += l[i]

    total //= m
    total += s//m * count

    print(n-total)


for n, x, m in query:
    answer_query(n-1, x, m)
### BUGGY CODE ###

import sys
def input():
	return sys.stdin.buffer.readline()[:-1]
n = int(input())
men = [tuple(map(int, input().split())) for _ in range(n)]
men.sort(key=lambda x: (x[0]+x[1], -x[0]))
allowed = [-1 for _ in range(n)]
allowed[n-1] = men[-1][0]
for i in range(n-2, -1, -1):
	allowed[i] = max(allowed[i+1], men[i][0])

INF = 10**10
dp = [[INF for _ in range(n+1)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
	dp[i+1][0] = 0
	for j in range(1, i+2):
		dp[i+1][j] = min(dp[i+1][j], dp[i][j])
		if dp[i][j-1] <= men[i][0]:
			dp[i+1][j] = min(dp[i+1][j], dp[i][j-1] + men[i][1])

#print(dp)
for i in range(n+1):
	if dp[n][i] < INF:
		ans = i
print(ans)

### FIXED CODE ###

import sys
def input():
	return sys.stdin.buffer.readline()[:-1]
n = int(input())
men = [tuple(map(int, input().split())) for _ in range(n)]
men.sort(key=lambda x: (x[0]+x[1], -x[0]))
allowed = [-1 for _ in range(n)]
allowed[n-1] = men[-1][0]
for i in range(n-2, -1, -1):
	allowed[i] = max(allowed[i+1], men[i][0])

INF = 10**10
dp = [INF for _ in range(n+1)]
dp[0] = 0
for i in range(n):
	for j in range(i+1, 0, -1):
		if dp[j-1] <= men[i][0]:
			dp[j] = min(dp[j], dp[j-1] + men[i][1])

#print(dp)
for i in range(n+1):
	if dp[i] < INF:
		ans = i
print(ans)
### BUGGY CODE ###

N=int(input())
a=4/N
h_st=max(int(N*(1/4))-1,1)
#h_st=1
for h in range(h_st,3501):
    H=1/h
    for n in range(h,3501):
        flag=0
        if 4*h*n*n-(n*n+h*n+h*n)*N<=0 and 4*h*n*3500-(n*3500+h*3500+h*3500)*N>=0:

            st,end=n,3500
            for w in [st,end]:
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
            while st!=end:
                #print(h,n,st,end)
                w=int((st+end)/2)
                if end-st==1:
                    end=w
                    st=w
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
                elif B>0:
                    end=w
                else:
                    st=w

        if flag:
            break
    if flag:
        break

print(h,n,w)


### FIXED CODE ###

N=int(input())
a=4/N
h_st=max(int(N*(1/4))-1,1)
#h_st=1
for h in range(h_st,3501):
    H=1/h
    for n in range(h,3501):
        flag=0
        if 4*h*n*n-(n*n+h*n+h*n)*N<=0 and 4*h*n*3500-(n*3500+h*3500+h*n)*N>=0:

            st,end=n,3500
            for w in [st,end]:
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
            while st!=end:
                #print(h,n,st,end)
                w=int((st+end)/2)
                if end-st==1:
                    end=w
                    st=w
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
                elif B>0:
                    end=w
                else:
                    st=w

        if flag:
            break
    if flag:
        break

print(h,n,w)
### BUGGY CODE ###

a = list(map(int, input().split()))
N = a[0]
K = a[1]
P = list(map(int, input().split()))

for i in range(len(P)):
    P[i] = (float)(P[i]+1)/2

max = 0

for i in range(len(P)-K+1):
    num = 0
    for j in range(K):
        num += P[i+j]

    if(max < num):
        max = num

print("{0:6f}".format(max))


### FIXED CODE ###

a = list(map(int, input().split()))
N = a[0]
K = a[1]
P = list(map(int, input().split()))

for i in range(len(P)):
    P[i] = (float)(P[i]+1)/2

S = []
for i in range(len(P)):
    if(i > 0):
        S.append(P[i]+S[i-1])
    else:
        S.append(P[0])
# print(S)

max = S[K-1]
for i in range(len(S)-K):
    a = S[i+K]-S[i]
    # print(a)

    if(a > max):
        max = a

# max = 0

# for i in range(len(P)-K+1):
#     num = 0
#     for j in range(K):
#         num += P[i+j]
#         # print(P[i+j],end=" ")
#     # print(num)
#     if(max < num):
#         max = num

print("{0:6f}".format(max))
### BUGGY CODE ###

# DP
def main():
    from builtins import int, map, max, min, range
    from sys import stdin
    readline = stdin.readline

    N, W = map(int, readline().split())

    dp = [-1] * (W + 1)
    dp[0] = 0
    max_w = 0
    for _ in range(N):
        w, v = map(int, readline().split())
        for j in range(min(max_w, W - w), -1, -1):
            dpj = dp[j]
            if dpj != -1:
                jw = j + w
                if dpj + v > dp[jw]:
                    dp[jw] = dpj + v
                if jw > max_w:
                    max_w = jw
    print(max(dp))


main()


### FIXED CODE ###

n, w = [int(e) for e in input().split()]
d = [[int(e) for e in input().split()] for i in range(n)]
t = {}
t[w] = 0
for i in range(n):
  keys = list(sorted(t.keys()))
  tw, tv = d[i]
  for j in keys:
    nw = j - tw
    if nw < 0:
      continue
    nv = t[j] + tv
    if nw in t:
      if nv > t[nw]:
        t[nw] = nv
    else:
      t[nw] = nv
print(max(t.values()))
### BUGGY CODE ###


import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions

import sys
def input():
	return sys.stdin.readline().strip()

S = input()

alpha = defaultdict(int)
N = len(S)
for i in range(N):
	alpha[S[i]] += 1

num = 0
for n in alpha:
	if alpha[n] % 2 == 1:
		num += 1

if num >= 2:
	print(-1)
	exit()

alpha_num = defaultdict(deque)
for i in range(N):
	alpha_num[S[i]].append(i)

loc_list = [-1]*N
num = 0
for i in range(N):
	if len(alpha_num[S[i]]) >= 2:
		x = alpha_num[S[i]].popleft()
		y = alpha_num[S[i]].pop()
		loc_list[x] = num
		loc_list[y] = N - 1 - num
		num += 1
	elif len(alpha_num[S[i]]) == 1:
		x = alpha_num[S[i]].popleft()
		loc_list[x] = N // 2

G = []
ans = 0
for i in range(N):
	x = bisect.bisect(G, loc_list[i])
	bisect.insort(G, loc_list[i])
	ans += i - x
print(ans)

### FIXED CODE ###


import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions

import sys
def input():
	return sys.stdin.readline().strip()

S = input()

alpha = defaultdict(int)
N = len(S)
for i in range(N):
	alpha[S[i]] += 1

num = 0
for n in alpha:
	if alpha[n] % 2 == 1:
		num += 1

if num >= 2:
	print(-1)
	exit()

alpha_num = defaultdict(deque)
for i in range(N):
	alpha_num[S[i]].append(i)

loc_list = [-1]*N
num = 0
for i in range(N):
	if len(alpha_num[S[i]]) >= 2:
		x = alpha_num[S[i]].popleft()
		y = alpha_num[S[i]].pop()
		loc_list[x] = num
		loc_list[y] = N - 1 - num
		num += 1
	elif len(alpha_num[S[i]]) == 1:
		x = alpha_num[S[i]].popleft()
		loc_list[x] = N // 2

class Bit:
	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i


bit = Bit(N)
ans = 0



for i, p in enumerate(loc_list):
	bit.add(p + 1, 1)
	ans += i + 1 - bit.sum(p + 1)

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

X = input()
N = len(X)//2
for _ in range(N):
    X = X.replace("ST", "")
print(len(X))

### FIXED CODE ###

X = input()
s = []
for x in X:
    if x=="T":
        if s==[] or s[-1]=="T":
            s.append(x)
        else:
            s.pop()
    else: # x=="S"
        s.append(x)
    #print(x, s)
print(len(s))
### BUGGY CODE ###

import numpy as np

n,k = map(int, input().split())
d = np.array(list(map(int, input().split())))
l = np.arange(n)
ans = np.array([0]*n)
cnt = 0

def func(x_left, x_right):
  for x_l,x_r in zip(x_left,x_right):
      ans[x_l:x_r] += 1

while True:
  if np.all(d==n):
    ans = d
    break

  if cnt == k:
    break

  ans *= 0
  x_left = l-d
  x_left[x_left < 0] = 0
  x_right = l+d+1
  x_right[x_left > n] = n
  func(x_left, x_right)
  cnt += 1
  d = ans.copy()

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


### FIXED CODE ###

import sys
import numpy as np
from numba import njit
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
@njit('(i8[::1],)', cache=True)
def update(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, x in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    B = np.cumsum(B)
    return B
 
N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)
 
K = min(K, 100)
for _ in range(K):
    A = update(A)
print(' '.join(A.astype(str)))
### BUGGY CODE ###

# ABC-143-D
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0

def binary_search(j, a_plus_b):
    left = j + 1
    right = N-1
    while right-left > 1:
        tmp = (left+right)//2
        if L[tmp] < a_plus_b:
            left = tmp
        else:
            right = tmp
    if L[(left+right)//2] >= a_plus_b:
        return j
    else:
        return (left+right)//2

for i in range(0, N-2):
    for j in range(i+1, N-1):
        a_plus_b = L[i] + L[j]
        #この部分をbinary_search関数でうまくできないかもっと考えたい
        if a_plus_b > L[-1]:
            ans += N - (j + 1)
        else:
            ans += binary_search(j, a_plus_b) - j

print(ans)

### FIXED CODE ###

N = int(input())
L_list = list(map(int, input().split()))
sum = 0

L_list.sort()

from bisect import bisect_left

for i in range(N):
    for j in range(i+1, N):
        t = L_list[i]+L_list[j]
        idx = bisect_left(L_list, t)
        sum += max(0, idx-(j+1))
        
print(sum)
### BUGGY CODE ###

import sys
import heapq as hp

class Edge:
    def __init__(self, end, cost):
        self.to = end
        self.cost = cost


class Dijkstra:
    def __init__(self, V):
        self._node = V
        self._graph = [[] for i in range(self._node)]
        self._inf = sys.maxsize
        self.dist = [self._inf for i in range(self._node)]

    def add_edge(self, st, ed, cost):
        self._graph[st].append(Edge(ed, cost))
    def solve(self, s):
        que = []
        self.dist[s] = 0
        hp.heappush(que, (0, s))
        while que:
            info = hp.heappop(que)
            cur_cost, cur_vertex = info
            if self.dist[cur_vertex] < cur_cost:
                continue
            for e in self._graph[cur_vertex]:
                if cur_cost + e.cost < self.dist[e.to]:
                    self.dist[e.to] = cur_cost + e.cost
                    hp.heappush(que, (self.dist[e.to], e.to))
                    hp.heapify(que)


if __name__ == '__main__':
    V, E, r = map(int, input().split())
    dk = Dijkstra(V)
    for i in range(E):
        s, t, d = map(int, input().split())
        dk.add_edge(s, t, d)
    dk.solve(r)
    for value in dk.dist:
        if value == sys.maxsize:
            print("INF")
        else:
            print(value)



### FIXED CODE ###

import sys
from heapq import heappush, heappop


class Dijkstra:
    class Edge:
        def __init__(self, end, cost):
            self.to = end
            self.cost = cost

    def __init__(self, node_size, inf):
        self._node = node_size
        self._graph = [[] for _ in range(self._node)]
        self.inf = inf
        self.dist = [self.inf for _ in range(self._node)]

    def add_edge(self, st, ed, cs):
        self._graph[st].append(self.Edge(ed, cs))

    def solve(self, start):
        que = []
        self.dist[start] = 0
        heappush(que, (0, start))
        while que:
            cur_cost, cur_vertex = heappop(que)
            if self.dist[cur_vertex] < cur_cost:
                continue
            for e in self._graph[cur_vertex]:
                if self.dist[e.to] > cur_cost + e.cost:
                    self.dist[e.to] = cur_cost + e.cost
                    heappush(que, (self.dist[e.to], e.to))


if __name__ == '__main__':
    V, E, r = map(int, sys.stdin.readline().split())
    dk = Dijkstra(V, 10 ** 10)
    for i in range(E):
        s, t, d = map(int, sys.stdin.readline().split())
        dk.add_edge(s, t, d)
    dk.solve(r)
    for value in dk.dist:
        if value == dk.inf:
            sys.stdout.write("INF\n")
        else:
            sys.stdout.write("%s\n" % value)
### BUGGY CODE ###

n = int(input())
num_list = []
for i in range(n):
    num_list.append(int(input()))

dp = [ [0, -1, -1] for i in range(n + 1) ] ## [length, sequence_top_num, sequence_second_num]

ans = 0
while sum( x==-2 for x in num_list) < n:
    longest_list = []
    for i in range(n):
        if dp[i][1] >= num_list[i]:
            if dp[i][2] < num_list[i]:
                longest_list.pop()
                longest_list.append(i)
                dp[i+1][0] = dp[i][0]
                dp[i+1][1] = num_list[i]
                dp[i+1][2] = dp[i][2]
            else:
                dp[i+1][0] = dp[i][0]
                dp[i+1][1] = dp[i][1]
                dp[i+1][2] = dp[i][2]
        else:
            dp[i+1][0] = dp[i][0] + 1
            dp[i+1][2] = dp[i][1]
            dp[i+1][1] = num_list[i]
            longest_list.append(i)
    
    for indx in longest_list:
        num_list[indx] = -2
    
    ans += 1

print(ans)

### FIXED CODE ###

import bisect

n = int(input())
num_list = []
for i in range(n):
    num_list.append(int(input()) * -1) 

dp = [1] * n 

for i in num_list:
    indx = bisect.bisect_right(dp, i)
    dp[indx] = min(dp[indx], i)

ans = sum(x < 1 for x in dp)

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

s = list(input())

flg = True
i = 0
cnt = 0

while flg:
    flg = False
    while i < len(s)-1:
        if s[i]+s[i+1] == '01' or s[i]+s[i+1] == '10':
            s.pop(i)
            s.pop(i)
            flg = True
            cnt += 2
        else:
            i += 1
    i = 0

print(cnt)

### FIXED CODE ###

s = list(input())

print(min(s.count('0'),s.count('1'))*2)
### BUGGY CODE ###

str = input()
num = int(str)
if num % 2 == 0:
  print('-1');
else:
  i = 1
  j = 7
  while j % num != 0:
    j = (j % num) * 10 + 7
    i += 1
  print(i);
  

### FIXED CODE ###

str = input()
num = int(str)
if num % 2 == 0:
  print('-1');
else:
  i = 1
  j = 7
  while j % num != 0 and i <= num:
    j = (j % num) * 10 + 7
    i += 1
  if i > num:
    print('-1');
  else:
    print(i);
### BUGGY CODE ###

s=input()
N=len(s)
t=input()
M=len(t)

alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

index={moji:[] for moji in alphabetlist}
for i in range(N):
    index[s[i]].append(i)

dp=[["" for i in range(0,N)] for j in range(0,M)]

for i in range(0,N):
    if index[t[0]]:
        if i>=index[t[0]][0]:
            dp[0][i]=t[0]

for i in range(0,M):
    for j in range(0,N):
        x=t[i]
        if index[x] and j>=index[x][0]:
            start=0
            end=len(index[x])-1
            while end-start>1:
                test=(end+start)//2
                if j>=index[x][test]:
                    start=test
                else:
                    end=test
            if j>=index[x][end]:
                next=index[x][end]-1
            else:
                next=index[x][start]-1
            if next>=0:
                if len(dp[i-1][j])>1+len(dp[i-1][next]):
                    dp[i][j]=dp[i-1][j]
                else:
                    dp[i][j]=dp[i-1][next]+t[i]
            else:
                if dp[i-1][j]=="":
                    dp[i][j]=t[i]
                else:
                    dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=dp[i-1][j]

print(dp[M-1][N-1])

### FIXED CODE ###

s=input()
N=len(s)
t=input()
M=len(t)

alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
def al(str):
    return alphabetlist.index(str)+1

dp=[[0 for i in range(0,M+1)] for i in range(0,N+1)]

for i in range(0,N):
    for j in range(0,M):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+1
        else:
            if dp[i+1][j]>dp[i][j+1]:
                dp[i+1][j+1]=dp[i+1][j]
            else:
                dp[i+1][j+1]=dp[i][j+1]

ans=[]
i=N
j=M
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans.append(s[i-1])
        i-=1
        j-=1

ans=ans[::-1]
print(''.join(ans))
### BUGGY CODE ###

from collections import deque

h,w = map(int,input().split())
field = [ list(input()) for _ in range(h) ]

d = [ [float("inf")]*w for _ in range(h) ]
q = deque()

for j in range(h):
    for i in range(w):
        a = field[j][i]
        if a=="#":
            q.append([j,i])
            d[j][i] = 0
        else:
            pass

m = 0
while q:
    y,x = q.popleft()
    for j,i in ([1,0],[0,-1],[-1,0],[0,1]):
        ny = y + j
        nx = x + i
        if ny==-1 or nx==-1 or ny==h or nx==w:
            pass
        elif field[ny][nx]=="#":
            pass
        elif d[ny][nx]!=float("inf"):
            pass
        else:
            field[ny][nx] = "#"
            d[ny][nx] = d[y][x] + 1
            m = max(m,d[ny][nx])
            q.append([ny,nx])
print(m)

### FIXED CODE ###

from collections import deque

h,w = map(int,input().split())
field = [ list(input()) for _ in range(h) ]

visited = [ [0]*w for _ in range(h) ]
q = deque()

for j in range(h):
    for i in range(w):
        a = field[j][i]
        if a=="#":
            q.append([j,i,0])
            visited[j][i] = 1
        else:
            pass

m = 0
while q:
    y,x,d = q.popleft()
    for j,i in ([1,0],[0,-1],[-1,0],[0,1]):
        ny = y + j
        nx = x + i
        if ny==-1 or nx==-1 or ny==h or nx==w:
            pass
        elif visited[ny][nx]==0:
            visited[ny][nx] = 1
            q.append([ny,nx,d+1])
            m = max(m,d+1)   
print(m)
### BUGGY CODE ###

from collections import OrderedDict

A, B, K = map(int, input().split())
L = []
res = []

if K > B-A:
    for i in range(A, B+1):
        print(i)
    exit()
else:
    for i in range(A, B+1):
        L.append(i)
    for i in range(0, K):
        res.append(L[i])
    for i in range(len(L)-K, len(L)):
        res.append(L[i])

res_unique = list(set(res))
res_unique.sort()

for i in res_unique:
    print(i)

### FIXED CODE ###

from collections import OrderedDict

A, B, K = map(int, input().split())
L = []
res = []

if K > B-A:
    for i in range(A, B+1):
        print(i)
    exit()
else:
    for i in range(A, A+K):
        res.append(i)
    for i in range(B-K+1, B+1):
        res.append(i)

res_unique = list(set(res))
res_unique.sort()

for i in res_unique:
    print(i)
### BUGGY CODE ###

# ABC141c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

sanka = [k]*n

for i in a:
    sanka[i-1] += 1
    for j in range(n):
        sanka[j] -= 1
# print(sanka)

for i in sanka:
    print('Yes' if i > 0 else 'No')

### FIXED CODE ###

# ABC141c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

sanka = [0]*n

for i in a:
    sanka[i-1] += 1
# print(sanka)

for i in sanka:
    print('Yes' if i+k-q > 0 else 'No')
### BUGGY CODE ###

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

mindiff = 10 ** 9 * 2 * 10 ** 5 + 1
for i in range(N-1):
    s1 = sum(a[0:i + 1])
    s2 = sum(a[i+1:])
    mindiff = min(mindiff, abs(s1 - s2))
    
print(mindiff)

### FIXED CODE ###

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

mindiff = 10 ** 9 * 2 * 10 ** 5 + 1
s1 = 0
s2 = sum(a)
for i in range(N-1):
    s1 += a[i]
    s2 -= a[i]
    mindiff = min(mindiff, abs(s1 - s2))
    
print(mindiff)