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

N=int(input())
L=list(map(int,input().split()))
Left=[sum(L[:i]) for i in range(N+1)]
Right=[sum(L[i:N]) for i in range(N+1)]
print(sum(Right[i+1:].count(Right[0]-Left[i]) for i in range(N+1)))

### FIXED CODE ###

N=int(input())
L=list(map(int,input().split()))
Left=[[0,0]]
Right=[[0,N]]
for i in range(N):
    Left.append([Left[i][0]+L[i],i+1])
for i in range(N):
    Right.append([Right[i][0]+L[i*(-1)-1],N-i-1])
Right=list(reversed(Right))
Left=sorted(Left, key=lambda x: x[0])
_sum_=Right[0][0]
Left=sorted(Left, key=lambda x: x[0],reverse=True)
Right=sorted(Right, key=lambda x: x[0])
Left.append([0,0])
Right.append([0,0])
 
j=0
s=0
ans=0
for i in range(N+1):
    if i != 0:
        if Left[i][0]!=Left[i-1][0]:
            s=0
    while(Left[i][0]+Right[j][0]<_sum_ and j<=N):
        j+=1
    if j>N:
        break
    elif Left[i][0]+Right[j][0]>_sum_:
        continue
    else:
        while(Left[i][0]+Right[j][0]==_sum_ and j<=N):
            if Left[i][1]>=Right[j][1]:
                j+=1
            else:
                s+=1
                ans+=s
                break
print(ans)
### BUGGY CODE ###

n, m, l = map(int, input().split())

edge_lst = []
for i in range(m):
    a,b,c = map(int ,input().split())
    if c <= l:
        edge_lst.append((a,b,c))
        edge_lst.append((b,a,c))
        
d_matrix = [[(-1, 10**10)] * (n+1) for _ in range(n+1)]
for i in range(n):
    d = [(-1, 10**10)] * (n+1)
    d[i+1] = (l, 0)
    while True:
        update = False
        for abc in edge_lst:
            a, b, c = abc
            if d[a][1] != 10**10:
                if d[a][0] < c:
                    cnt = d[a][1] + 1
                    f = l - c
                else:
                    cnt = d[a][1]
                    f = d[a][0] - c
                if d[b][1] == cnt:
                    if d[b][0] < f:
                        d[b] = (f, cnt)
                        update = True
                if d[b][1] > cnt:
                    d[b] = (f, cnt)
                    update = True
        if not update:
            break
        d_matrix[i+1] = d

q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    print(d_matrix[s][t][1]) if d_matrix[s][t][1] != 10**10 else print(-1)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
INF = float('inf')
VD = [[INF] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    VD[a][b] = c
    VD[b][a] = c
for i in range(N):
    VD[i][i] = 0
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if VD[i][j] > VD[i][k] + VD[k][j]:
                VD[i][j] = VD[i][k] + VD[k][j]
 
WD = [[INF] * N for _ in range(N)]
for i in range(N):
    WD[i][i] = 0
    for j in range(i+1,N):
        d = VD[i][j]
        if d <= L:
            WD[i][j] = 1
            WD[j][i] = 1
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if WD[i][j] > WD[i][k] + WD[k][j]:
                WD[i][j] = WD[i][k] + WD[k][j]
 
Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1)
### BUGGY CODE ###


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

for i in range(n):
    memo = x.pop(i)
    b = sorted(x)
    print(b[int(n/2) - 1])
    x.insert(i, memo)

### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
b = sorted(x)
m_left = b[int(n//2) -1]
m_right = b[int(n//2)]

for i in range(n):
    if x[i] <= m_left:
        print(m_right)
    elif x[i] >= m_right:
        print(m_left)
### BUGGY CODE ###

import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])

min_num = 100000000000

for x in range(-(max(a)), max(a) + 1):
  min_sum = sum(abs(a - np.ones(len(a)) * x - np.array(range(1, n + 1))))
  #print(abs(a - np.array(range(1, n + 1))))
  if min_sum < min_num:
    min_num = min_sum

print(int(min_num))

### FIXED CODE ###

import numpy as np
import statistics

n = int(input())
inputs = [int(i) for i in input().split()]
a = np.array(inputs)

z = a - np.array(range(1, n + 1))
nums = list(set(inputs))

print(int(sum(abs(z - np.ones(len(a)) * statistics.median(z)))))
### BUGGY CODE ###

N = int(input())

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

P = [0] + P
     
count = 0
for i in range(1, N+1):
    for j in range(1, i+1):
        #print(i, P[i], j , P[j])
        if P[i] > P[j]:
            #print("out", i)
            break
    else:
        #print("ok", i)
        count += 1
        
    if P[i] == 1:
        break

print(count)

### FIXED CODE ###

N = int(input())

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

P = [0] + P
     
count = 0
min = 10000000000000
for i in range(1, N+1):
    if min > P[i]:
        min = P[i]
    elif min < P[i]:
        continue
    """
    for j in range(1, i+1):
        #print(i, P[i], j , P[j])
        if P[i] > P[j]:
            #print("out", i)
            break
    else:
        #print("ok", i)
        count += 1
    """
    count += 1
        
    if P[i] == 1:
        break

print(count)
### BUGGY CODE ###

A,B,N=map(int,input().split())
result=0
for x in range(0,N+1):
	a=int(A*x/B)-A*int(x/B)
	if a>result:
		result=a
print(result)

### FIXED CODE ###

A,B,N=map(int,input().split())
if B!=1:
	p=(N+1)//B
	result=0
	if p!=0:
		for a in range(1,p+1):
			x=a*B-1
			s=(A*x)//B - A*(a-1)
			if result < s:
				result=s
	else:
		result=A*N//B -A*(N//B)
	print(result)
else:
	print(0)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
seen = set()
same = set()
ans = 0
for i in a:
    if i in seen:
        same.add(i)
        continue
    for j in seen:
        if i%j==0:
            break
    else:
        ans += 1
        seen.add(i)
print(ans-len(same))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[0]==1:
    if n==1 or a[1]>1:
        print(1)
    else:
        print(0)
    exit(0)
ok = [True]*(10**6+1)
ans = 0
pre = -1
for i in a:
    if not ok[i]:
        continue
    if i==pre:
        ok[i] = False
        continue
    pre = i
    for j in range(i*2, 10**6+1, i):
        ok[j] = False
for i in a:
    if ok[i]:
        ans += 1
print(ans)
### BUGGY CODE ###

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

    def dijkstra(s,edge):
        #始点sから各頂点への最短距離
        d = [10**20] * n
        used = [True] * n #True:未確定
        d[s] = 0
        used[s] = False
        edgelist = []
        for a,b in edge[s]:
            heapq.heappush(edgelist,a*(10**6)+b)
        while len(edgelist):
            minedge = heapq.heappop(edgelist)
            #まだ使われてない頂点の中から最小の距離のものを探す
            if not used[minedge%(10**6)]:
                continue
            v = minedge%(10**6)
            d[v] = minedge//(10**6)
            used[v] = False
            for e in edge[v]:
                if used[e[1]]:
                    heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
        return d

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

    edge = [[] for i in range(n)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for i in range(n-1):
        edge[i].append((1,i+1))
        edge[i+1].append((1,i))
    edge[x-1].append((1,y-1))
    edge[y-1].append((1,x-1))

    for i in range(n):
        edge[i] = tuple(edge[i])
    edge = tuple(edge)

    ans = [0 for _ in range(n)]
    for i in range(n):
        #dijkstra(始点,edge)
        res = dijkstra(i,edge)
        for j in range(i+1,n):
            ans[res[j]] += 1

    for i in range(1,n):
        print(ans[i])

if __name__ == '__main__':
    main()


### FIXED CODE ###

from scipy.sparse.csgraph import dijkstra
import sys
def main():
	input = sys.stdin.readline

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

	route = [[0 for _ in range(n)]for _ in range(n)]
	for i in range(n-1):
		route[i][i+1] = 1

	route[x-1][y-1] = 1
	route[y-1][x-1] = 1
	route = tuple(route)
	#res = shortest_path(route, unweighted=False,directed=False)
	res = tuple(dijkstra(route, directed=False))

	ans = [0 for _ in range(n)]
	for i in range(n):
		for j in range(i,n):
			ans[int(res[i][j])] += 1

	for i in range(1,n):
		print(ans[i])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

circum = circum_total[0]
total = circum_total[1]

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

def dist_from_node_forward(node_index, distances):
    forward_distances = distances[node_index:]
    forward_distances.extend([n + circum for n in distances[:node_index]])
    #print(forward_distances)
    dist = 0
    for index in range(1,len(forward_distances)):
        dist += forward_distances[index] - forward_distances[index-1]
    #print(dist)
    return(dist)

def dist_from_node_backward(node_index, distances):
    before = [distances[node_index]]
    before.extend(list(reversed(distances[:node_index])))
    before.append(0)
    #print(before)
    after = list(distances[node_index:])
    after.pop(0)
    #print(after)
    before.extend(list(reversed([n - circum for n in after])))
    #print(before)
    dist = 0
    for index in range(1,len(before)):
        dist += before[index-1] - before[index]
    #print(dist)
    return(dist)

def mindist(node_index, distances):
    return min(dist_from_node_forward(node_index,distances),dist_from_node_backward(node_index,distances))

minimum = circum

for i in range(len(distances)):
    minimum = min(minimum,mindist(i,distances))

print(minimum)


### FIXED CODE ###

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

circum = circum_total[0]
total = circum_total[1]

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

mindist = circum
for index in range(len(distances)):
    if index == len(distances) - 1:
        rightdist = distances[0] + circum - distances[index]
    else:
        rightdist = distances[index+1] - distances[index]
    if index == 0:
        leftdist = distances[index] - distances[index-1] + circum
    else:
        leftdist = distances[index] - distances[index-1]
    maxdist = max(rightdist,leftdist)
    mindist = min(mindist, circum - maxdist)

print(mindist)
### BUGGY CODE ###

#conding utf-8
N,Q=map(int,input().split())
S=input()
lr=[[int(i) for i in input().split()] for i in range(Q)]

AC=[0 for i in range(N)]

for i in range(N-1):
  if S[i:i+2]=="AC":
    AC[i]=1
    i=i+1

for i in range(Q):
  print(sum(AC[lr[i][0]-1:lr[i][1]-1]))


### FIXED CODE ###

#conding utf-8
N,Q=map(int,input().split())
S=input()
lr=[[int(i) for i in input().split()] for i in range(Q)]

AC=[0]
tmp=0
for i in range(N-1):
  if S[i:i+2]=="AC":
    tmp=tmp+1
  AC.append(tmp)

for i in range(Q):
  print(AC[lr[i][1]-1]-AC[lr[i][0]-1])
### BUGGY CODE ###

def mod_inv(a, MOD):
    """ 前提: aとMODが互いに素であること """
    b = MOD
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        u -= t * v
        a, b = b, a
        u, v = v, u
    u %= MOD
    return u


def prime_factorize(n):
    i = 2
    res = {}
    while i * i <= n:
        if n % i != 0:
            i += 1
            continue
        res[i] = 0
        while n % i == 0:
            res[i] += 1
            n //= i
        i += 1
    if n != 1:
        res[n] = 1
    return res


def solve(n):
    pf = prime_factorize(n)
    l = len(pf)
    pfk = []
    for i, p in enumerate(pf):
        pfk.append(p ** pf[p])

    ans = 10 ** 18

    for bit in range(1 << l):
        a = 1
        for d in range(l):
            if bit & (1 << d):
                a *= pfk[d]
        b = n // a

        if a == 1:
            k = n - 1
        elif b == 1:
            k = n
        else:
            m = mod_inv(b, a)
            k = b * m - 1
        # print(a, b, m, k)

        if k > 0 and k * (k + 1) // 2 % n == 0:
            ans = min(ans, k)
        else:
            ans = min(ans, k + n)

    return ans


n = int(input())
ans = solve(n)
print(ans)

# import random
#
# for n in range(1, 10000):
#     a = solve(n)
#     i = -1
#     for i in range(1, 2 * n + 1):
#         if i * (i + 1) // 2 % n == 0:
#             break
#     # print(n, a, i)
#     assert a == i


### FIXED CODE ###

def mod_inv(a, MOD):
    """ 前提: aとMODが互いに素であること """
    b = MOD
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        u -= t * v
        a, b = b, a
        u, v = v, u
    u %= MOD
    return u


def prime_factorize(n):
    i = 2
    res = {}
    while i * i <= n:
        if n % i != 0:
            i += 1
            continue
        res[i] = 0
        while n % i == 0:
            res[i] += 1
            n //= i
        i += 1
    if n != 1:
        res[n] = 1
    return res


def solve(n):
    pf = prime_factorize(n)
    l = len(pf)
    pfk = []
    for i, p in enumerate(pf):
        pfk.append(p ** pf[p])

    ans = 10 ** 18

    for bit in range(1 << l):
        a = 1
        for d in range(l):
            if bit & (1 << d):
                a *= pfk[d]
        b = n // a

        if a == 1:
            k = n - 1
        elif b == 1:
            k = n
        else:
            m = mod_inv(b, a)
            k = b * m - 1
        # print(a, b, m, k)

        if k > 0 and k * (k + 1) // 2 % n == 0:
            ans = min(ans, k)
        else:
            ans = min(ans, k + n)

    return ans


n = int(input())
ans = solve(n)
print(ans)

# import random
#
# for n in range(1, 10000):
#     a = solve(n)
#     i = -1
#     for i in range(1, 2 * n + 1):
#         if i * (i + 1) // 2 % n == 0:
#             break
#     # print(n, a, i)
#     assert a == i
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)

MOD = 998244353
A,B,C,D= map(int,input().split())

memo = {(A,B):1}
for Y in range(A,C+1):
    memo[(Y,1)] = 1
for X in range(B,D+1):
    memo[(1,X)] = 1

def cnt(C,D):
    if (C,D) in memo:
        return memo[(C,D)]
    res = 0
    if C > A:
        res += D * cnt(C-1,D)
    if D > B:
        res += C * cnt(C,D-1)
    if C > A and D > B:
        res -= cnt(C-1,D-1)*(C-1)*(D-1)
    res %= MOD
    memo[(C,D)] = res 
    return res

print(cnt(C,D))






### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

MOD = 998244353
A,B,C,D= map(int,input().split())
#A,B,C,D = 1,1,3000,3000

def dpinit(ps, val=0):
    res = [val for i in [0]*ps[-1]]
    for i in ps[:-1][::-1]:
        res = [res[:] for k in [0]*i]
    return res

memo = dpinit((C+1,D+1))

memo[A][B] = 1
for Y in range(A,C+1):
    memo[Y][B] = pow(B,Y-A,MOD)
for X in range(B,D+1):
    memo[A][X] = pow(A,X-B,MOD)

for y in range(A+1,C+1):
    for x in range(B+1,D+1):
        memo[y][x] = (x*memo[y-1][x] + y*memo[y][x-1] - (x-1)*(y-1)*memo[y-1][x-1]) % MOD

print(memo[C][D])
### BUGGY CODE ###

import sys

read = sys.stdin.buffer.read

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

hw = []
# w = np.zeros(3*10**5,dtype=np.int64)
# h = np.zeros(3*10**5,dtype=np.int64)
w = [0] * 3*10**5
h = [0] * 3*10**5

for i in range(M):
    h_i, w_j = map(int, input().split())
    hw.append([h_i-1, w_j-1])
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 1
mxh_v = max(h)
mxw_v = max(w)

x = [i for i,j in enumerate(h) if j == mxh_v]
y = [i for i,j in enumerate(w) if j == mxw_v]

for i in x:
    for j in y:
        if not([i,j] in hw):
            d = 0
    if d == 0:
        break
print(mxh_v+mxw_v-d)

### FIXED CODE ###

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

hw = set()
w = [0] * 3*10**5
h = [0] * 3*10**5

for i in range(M):
    h_i, w_j = map(int, input().split())
    hw.add((h_i-1) + (w_j-1)*3*10**6)
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 1
mxh_v = max(h)
mxw_v = max(w)

x = [i for i,j in enumerate(h) if j == mxh_v]
y = [i for i,j in enumerate(w) if j == mxw_v]

for i in x:
    for j in y:
        if not(i + j*3*10**6 in hw):
            print(mxh_v+mxw_v)
            exit()
print(mxh_v+mxw_v-d)
### BUGGY CODE ###

import itertools
n,a,b = map(int,input().split())
print((2**n-len(list(itertools.combinations(range(n),a)))-len(list(itertools.combinations(range(n),b)))-1)%(10**9+7))

### FIXED CODE ###

def mod_power(x,y,p):
    if y == 1:
        return x % p
    elif y % 2 == 0:
        return (mod_power(x,y/2,p)**2) % p
    else:
        return (mod_power(x,y-1,p) * x ) % p

def mod_inv(x,p):
    return mod_power(x,p-2,p)

def mod_nCa(n,a,p):
    num = 1
    den = 1
    for i in range(a):
        num = (num * (n-i)) % p
        den = (den * (a-i)) % p
    return (num * mod_inv(den,p)) % p


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

m = 10**9 + 7

print((mod_power(2,n,m) - mod_nCa(n,a,m) - mod_nCa(n,b,m) - 1) % m)
### BUGGY CODE ###

# "#"と"."だけで行き来できるエリアを"島"とする
# 島にある"#"から"."には必ず行けるので、
# "#"の数 * "."がその島の場合の数。これをすべて足し合わせる

# visitedになっていない点をすべて捜査する。
# 進めなかった（"#"もしくは"."が連続した）マスはvisitedにしない。

H,W = map(int,input().split())
grid = [None] * H
for i in range(H):
  grid[i] = input()
  
visited = [[False] * W for i in range(H)]

def get_next_unvisited(checked_y):
  for i in range(checked_y,H):
    for j in range(W):
      if not visited[i][j]:
        return i,j
  return -1,-1 # 候補なし
  
from collections import deque
ans = 0
cases = ((0,1),(0,-1),(1,0),(-1,0))
checked_y = 0
while True:
  y,x = get_next_unvisited(checked_y)
  if y == -1 and x == -1:
    print(ans)
    exit(0)
  checked_y = y
  # y,x,親,親マスの文字
  q = deque([[y,x,-1,-1,"N"]])
  black = 0
  white = 0
  
  while q:
    y,x,parent_y,parent_x,parent = q.pop()
    if visited[y][x]:
      continue
    point = grid[y][x]
    if point == parent:
      continue
    visited[y][x] = True
    if point == "#":
      black += 1
    if point == ".":
      white += 1
    for c in cases:
      if y + c[0] == parent_y and x + c[1] == parent_x:
        continue
      if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
        q.append([y + c[0],x + c[1],y,x, point])
  ans += black * white


### FIXED CODE ###

# "#"と"."だけで行き来できるエリアを"島"とする
# 島にある"#"から"."には必ず行けるので、
# "#"の数 * "."がその島の場合の数。これをすべて足し合わせる

# visitedになっていない点をすべて捜査する。
# 進めなかった（"#"もしくは"."が連続した）マスはvisitedにしない。

H,W = map(int,input().split())
grid = [None] * H
for i in range(H):
  grid[i] = input()
  
visited = [[False] * W for i in range(H)]

def get_next_unvisited(checked_y):
  for i in range(checked_y,H):
    for j in range(W):
      if not visited[i][j]:
        return i,j
  return -1,-1 # 候補なし
  
from collections import deque
ans = 0
cases = ((0,1),(0,-1),(1,0),(-1,0))
checked_y = 0
while True:
  y,x = get_next_unvisited(checked_y)
  if y == -1 and x == -1:
    print(ans)
    exit(0)
  checked_y = y
  # y,x,親,親マスの文字
  q = deque([[y,x,-1,-1,"N"]])
  black = 0
  white = 0
  
  while q:
    y,x,parent_y,parent_x,parent = q.pop()
    if visited[y][x]:
      continue
    point = grid[y][x]
    if point == parent:
      continue
    visited[y][x] = True
    if point == "#":
      black += 1
    if point == ".":
      white += 1
    for c in cases:
      if y + c[0] == parent_y and x + c[1] == parent_x:
        continue
      if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
        q.append([y + c[0],x + c[1],y,x, point])
  ans += black * white
### BUGGY CODE ###

def cost_culc(spot_list):
    cost = 0
    for i in range(1,len(spot_list)):
        cost += abs(spot_list[i]-spot_list[i-1])
    cost += abs(spot_list[0])+abs(spot_list[len(spot_list)-1])
    return cost

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

for i in range(len(spot_list)):
    deleted_list = spot_list[:i]+spot_list[i+1:]
    cost = cost_culc(deleted_list)
    print(cost)


### FIXED CODE ###


n = int(input())
spot_list = list(map(int,input().split()))
max_cost = 0

#maxの計算
for i in range(1,len(spot_list)):
    max_cost += abs(spot_list[i]-spot_list[i-1])
max_cost += abs(spot_list[0])+abs(spot_list[len(spot_list)-1])

spot_list = [0] + spot_list + [0]
for i in range(1,len(spot_list)-1):
    d_pay = abs(spot_list[i-1]-spot_list[i+1]) - (abs(spot_list[i]-spot_list[i-1])+abs(spot_list[i+1]-spot_list[i]))
    print(max_cost+d_pay)
### BUGGY CODE ###

from collections import deque
N, K = map(int, input().split())
P = list(map(int, input().split()))

dq = deque(maxlen=K)
ans = 0
for p in P:
    dq.append(1/p * p * (1 + p) /2)
    ans = max(ans, sum(dq))

print(ans)

### FIXED CODE ###

import numpy as np

N, K = map(int, input().split())
E = list(map(lambda x: (int(x)+1)/2, input().split()))
E_cumsum = np.cumsum(E)

ans = E_cumsum[K-1]
for i in range(0, N-K):
    e = E_cumsum[i+K] - E_cumsum[i]
    ans = max(ans, e)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def I(): return int(input())

result = -1
num = 7
K = I()

if K % 2 == 0 or K %  5 == 0:
    print(-1)
    sys.exit()

for i in range(10**6):
    if num % K == 0:
        print(i+1)
        sys.exit()
    else:
        num += 7*10**(i+1)
print(-1)

### FIXED CODE ###

import sys
input = sys.stdin.readline
def I(): return int(input())


def main():
    K = I()
    if K % 2 == 0 or K %  5 == 0:
        print(-1)
        exit()
    if K % 7 == 0:
        K = 9*K//7
    else:
        K = 9*K
    amari = 1
    for i in range(10**6):
        amari = amari*10 % K
        if amari == 1:
            print(i+1)
            exit()
    print(-1)

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

#!/usr/bin/env python
# coding: utf-8

# In[6]:


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


# In[7]:


ans = (10**9)*N
for i in range(1,N):
    x = sum(a[:i])
    y = sum(a[i:])
    ans = min(ans,abs(x-y))
print(ans)


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[11]:


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


# In[12]:


ans = (10**9)*N
x = 0
y = sum(a)
for i in range(N-1):
    x += a[i]
    y -= a[i]
    ans = min(ans,abs(x-y))
    if ans < 2:
        break
print(ans)


# In[ ]:
### BUGGY CODE ###

from collections import deque
s = deque(i for i in input())
n = int(input())
l = [[i for i in input().split()] for _ in range(n)]

for i in l:
    if i[0] == '1':
        s.reverse()
    elif i[1] == '1':
        s.appendleft(i[2])
    else:
        s.append(i[2])
            

print(*s,sep = '')

### FIXED CODE ###

from collections import deque
s = deque(i for i in input())
n = int(input())
l = [[i for i in input().split()] for _ in range(n)]

front = True

for i in l:
    if i[0] == '1':
        front = not front
    else:
        if front ^ (int(i[1]) == 1):
            s.append(i[2])
        else:
            s.appendleft(i[2])
            
ans = ''.join(s)

if front:
    print(ans)
else:
    ans = ans[::-1]
    print(ans)
### BUGGY CODE ###

import collections

N = int(input())
A = list(map(int, input().split()))
#A = [1, 2, 1, 4, 2, 1, 4, 1]

c = collections.Counter(A)
#print(c)

count_dic = {}
for i in c.keys():
    count = 0
    c_copy = c.copy()
    c_copy[i] = c[i]-1
    #print(c_copy)
    for k in c.keys():
        count += int(c_copy[k]*(c_copy[k]-1)/2)
        count_dic[i] = count
        #print(count)
    #print(count_dic)

for i in range(N):
    print(count_dic[A[i]])

### FIXED CODE ###


from collections import Counter
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
A_set = np.unique(A)
count_dict= Counter(A)
count_sum = np.sum([count_dict[i]*(count_dict[i]-1)/2 for i in A_set])

out = [int(count_sum-count_dict[i]+1) for i in A]
for i in out:
    print(i)
### BUGGY CODE ###

N = int(input())
per = [0] + [int(i) for i in input().split()]
res = 0
for i in range(1, N+1):
  flag = True
  for j in range(1, i+1):
    if per[i] > per[j]: 
      flag = False
      break
  
  if flag: res += 1
print(res)

### FIXED CODE ###

N = int(input())
per = [0] + [int(i) for i in input().split()]
res = 0
min_per = per[1]
for i in range(1, N+1):
  min_per = min(min_per, per[i])
  flag = True
  if per[i] > min_per: 
    pass
  else: 
    res += 1
print(res)