Harryxun/stf_run huggingface dataset:
n , m = map(int,input().split())

g = [[] for i in range(n)]

for _ in range(m):
  v1, v2 = map(int,input().split())
  v1-=1 ; v2-=1
  g[v1].append(v2)

def dfs(i):
  temp = 0
  for neighbour in g[i]:
    temp = max(temp, dfs(neighbour) + 1)
  return temp
  
res = 0
for i in range(n):
  res = max(res, dfs(i))

print(res)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
n , m = map(int,input().split())

g = [[] for i in range(n)]

dp = [-1] * n
for _ in range(m):
  v1, v2 = map(int,input().split())
  v1-=1 ; v2-=1
  g[v1].append(v2)

def dfs(i):
  if dp[i]!=-1:
    return dp[i]
  temp = 0
  for neighbour in g[i]:
    temp = max(temp, dfs(neighbour) + 1)
  dp[i]=temp
  return temp
  
res = 0
for i in range(n):
  res = max(res, dfs(i))

print(res)
import math
N = int(input())
print(int((2 * N) // math.gcd(2, N)))

### FIXED CODE ###

N = int(input())
if(N % 2 == 0):
    print(N)
else:
    print(N * 2)
C = []
for _ in range(3):
    c = list(map(int,input().split()))
    C.append(c)

if((C[0][0]-C[1][0]==C[0][1]-C[1][1]==C[0][2]-C[1][2])                    
        and(C[0][0]-C[2][0]==C[0][1]-C[2][1]==C[0][2]-C[2][2]):                   
    print("Yes")
else:
    print("No")


### FIXED CODE ###

C = []
for _ in range(3):
    c = list(map(int,input().split()))
    C.append(c)

if((C[0][0]-C[1][0]==C[0][1]-C[1][1])and(C[0][0]-C[1][0]==C[0][2]-C[1][2])
        and(C[0][0]-C[2][0]==C[0][1]-C[2][1])and(C[0][0]-C[2][0]==C[0][2]-C[2][2])
        and(C[0][0]-C[0][1]==C[1][0]-C[1][1])and(C[0][0]-C[0][1]==C[2][0]-C[2][1])
        and(C[0][0]-C[0][2]==C[1][0]-C[1][2])and(C[0][0]-C[0][2]==C[2][0]-C[2][2])):
    print("Yes")
else:
    print("No")
import re
n = int(input())
s = input()
if not '#' in s:
    print(0)
else:
    s = s.rsplit('.#', 1)[0] + '.#' if '.#' in s else  s
    ptn = re.search(re.compile('\.#+?$'), s)
    if ptn:
        s = s[:ptn.start()]
    print(min(s.count('.'), s.count('#')))

### FIXED CODE ###

a,b,c = map(int, input().split())
lst = list(range(min(a,b), max(a,b)+1))
if c in lst:
    print('Yes')
else:
    print('No')
s = input()
s.sort()
if s[0] != s[1] or s[1] != s[2]:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s = input()
if len(set(s))==2:
    print("Yes")
else:
    print("No")
n=int(input())
a=sorted(list(map(int,input().split())))
i=0
ans=0
while i<n:
  h=a.count(a[i])
  i+=h
  ans=ans+h-a[i]
print(ans)

### FIXED CODE ###

import collections
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
c=collections.Counter(a)
i=0
ans=0
while i<n:
    h=c[a[i]]
    if h>=a[i]:
        ans+=h-a[i]
    else:
        ans+=h
    i+=h
print(ans)
#-*- coding: utf-8 -*-#
test = input()
a, b, c = map(int, test.split())  # 変数a,b,cにそれぞれN、A、Bをint型にして入力する　
x = []
e = []
for i in range(1,a+1):  # list型の変数xに１からNまでの要素を入れる
    x.append(i)
len_x = len(x)  # リスト型の変数xの要素数を獲得
d = 0  # リストの各行の和を入れるための変数
f = []  # 各行がA以上B以下の要素を入れるための変数
x = map(str, x)  # リストxの各要素をstr型に変換
e_number = 0
for i in range(len_x):
    e = x[i]           # xのi番目の要素を抽出
    e = list(e)  # xのi番目の要素を一文字ずつのstr型としてリスト型の変数に入れる
    e = map(int, e)  # xのi番目の要素をint型に変換
    e_number = len(e)   # リスト型の変数eの要素数を取得
    d = 0              # 位の合計の判定用の変数
    for g in range(e_number):
        d += e[g-1]  # 位の合計
    if b <= d <= c:  # 位の合計がA以上B以下ならリストfに要素を追加
        f.append(x[i])
answer = 0  # 条件位合う要素の合計を入れる変数
f = map(int, f)
for h in f:
    answer += h  # 要素に合う要素の合計
print(answer)



### FIXED CODE ###

# coding: utf-8
# Your code here!
#-*- coding: utf-8 -*-#
test = input()
a, b, c = map(int, test.split())  # 変数a,b,cにそれぞれN、A、Bをint型にして入力する　
x = []
e = []
for i in range(1,a+1):  # list型の変数xに１からNまでの要素を入れる
    x.append(i)
len_x = len(x)  # リスト型の変数xの要素数を獲得
d = 0  # リストの各行の和を入れるための変数
f = []  # 各行がA以上B以下の要素を入れるための変数
x = map(str, x) # リストxの各要素をstr型に変換
x = list(x)
e_number = 0
for i in range(len_x):
    e = x[i]           # xのi番目の要素を抽出
    e = list(e)  # xのi番目の要素を一文字ずつのstr型としてリスト型の変数に入れる
    e = map(int, e)# xのi番目の要素をint型に変換
    e = list(e)
    e_number = len(e)   # リスト型の変数eの要素数を取得
    d = 0              # 位の合計の判定用の変数
    for g in range(e_number):
        d += e[g-1]  # 位の合計
    if b <= d <= c:  # 位の合計がA以上B以下ならリストfに要素を追加
        f.append(x[i])
answer = 0  # 条件位合う要素の合計を入れる変数
f = map(int, f)
for h in f:
    answer += h  # 要素に合う要素の合計
print(answer)
N = int(input())
check = []
k = int()
for i in range(2,N):
    if N % i == 0:
        k = int( N / i )
        check.append(i + k - 2)
        
print(min(check))

### FIXED CODE ###

N = int ( input() )
check_list = []
for i in range( 1, int( N**( 1/2 )+1 ) ):
    check = 0
    if N % i == 0:
        check = i + int( N / i ) - 2
        check_list.append(check)

print( min(check_list) )
mport numpy as np
N,M = map(int,raw_input().split())
a = []
c = []
for i in range(N):
    a.append(map(int,raw_input().split()))
#print a
for j in range(M):
    c.append(map(int,raw_input().split()))
a = np.array(a)
c = np.array(c)
#print a.shape
#print c.shape
min = 100
index = np.zeros(N)
for i in range(N):
    for j in range(M):
        if min > np.abs(a[i][0]-c[j][0])+np.abs(a[i][1]-c[j][1]):
            min = np.abs(a[i][0]-c[j][0])+np.abs(a[i][1]-c[j][1])
            index[i] = j
        elif min == np.abs(a[i][0]-c[j][0])+np.abs(a[i][1]-c[j][1]):
            if j < index[i]:
                index[i] = j
index = index.astype(np.int32)
for i in range(N):
    print index[i]+1

### FIXED CODE ###

import numpy as np

def manhattan(x,y):
    return np.abs(x[0]-y[0]) + np.abs(x[1]-y[1])

N,M = map(int,raw_input().split())
students = np.zeros((N,2))
checkpoints = np.zeros((M,2))
for i in range(N):
    students[i][0],students[i][1] = map(int,raw_input().split())
#print a
for j in range(M):
    checkpoints[j][0],checkpoints[j][1] = map(int,raw_input().split())

index = np.zeros(N)
for i in range(N):
    min = 200000000
    for j in range(M):
        d = manhattan(students[i],checkpoints[j])
        if min > d:
            min = d
            index[i] = j
    print (index[i]+1).astype(np.int32)
def getlist_pattern( offset, rstr, N, step ):
  aap = []
  if(N<=0):
    return aap
  
  for i,ch in enumerate(rstr):
    if( ch == "o" ):
      ap = getlist_pattern( offset+i+step+1, rstr[i+step+1:], N-1,step )
      
      if( ap==[] ):
        ap = [[offset+i]]
      else:
      	for j in range(len(ap)):
          ap[j].append(offset+i)
      aap.extend(ap)
  return aap    

n,k,c = map(int, input().split(" "))

vstr = input()

pp = getlist_pattern( 0, vstr, k, c )

#print(pp)
base = []
for p in pp:
  if(len(p) == k):
    base = p
    break

base.sort()

for ind in base:
  err_flag = 0
  for p in pp:
    if(len(p) == k):
      if( not( ind in p )):
        err_flag = 1
        break
  if( err_flag==0):
  	print( ind+1 )



### FIXED CODE ###

k,y,c = map( int, input().split(" "))
ss = input()

asc = []
dsc = []

cnt = 0
err_flg = 0
while( True ):
  if(len(ss) <= cnt):
    err_flg = 1
    break
  if( ss[cnt] == "o"):
    asc.append( cnt )
    cnt += c+1
  else:
    cnt += 1
    
  if( len(asc)==y ):
    break

cnt = 0
ss = ss[::-1]
while( True ):
  if(len(ss) <= cnt):
    err_flg = 1
    break
  if( ss[cnt] == "o"):
    dsc.append( cnt )
    cnt += c+1
  else:
    cnt += 1
    
  if( len(dsc)==y ):
    break
    
for i in range(len(dsc)):
  dsc[i] = len(ss) - dsc[i] - 1
  
dsc.reverse()
#print(asc)
#print(dsc)

if( err_flg == 0 ):
  for i in range(len(asc)):
    if( asc[i] == dsc[i] ):
      print(asc[i]+1)
import sys
sys.setrecursionlimit(10 ** 9)
                      
h,w,k = map(int,input().split())
x1,y1,x2,y2 = map(int,input().split())
c = []
for i in range(h):
  c.append(list(input()))

def dfs(x,y,kk,d,a):
  #print(kk,d)
  if c[x][y] == '.':
    c[x][y] = a
  else:
    c[x][y] = min(c[x][y],a)
  for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
    if 0 <= x+dx < h and 0 <= y+dy < w and (c[x+dx][y+dy] == '.' or (c[x+dx][y+dy] != '@' and c[x+dx][y+dy] > a)):
      if kk == -1:
        kk = k-1
        a = 1
      elif kk == 0 or d != (dx,dy):
        kk = k
        a += 1
      else:
        kk -= 1
      dfs(x+dx,y+dy,kk,(dx,dy),a)

q = [(0,x1-1,y1-1,-1,())]
while(q):
  qq = []
  for a,x,y,kk,d in q:
    #print(x,y,c[x][y])
    if c[x][y] == '.':
      c[x][y] = a
    else:
      c[x][y] = min(c[x][y],a)
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
      if 0 <= x+dx < h and 0 <= y+dy < w and (c[x+dx][y+dy] == '.' or (c[x+dx][y+dy] != '@' and c[x+dx][y+dy]>a):
        if kk == -1:
          kk = k-1
          a = 1
        elif kk == 0 or d != (dx,dy):
          kk = k
          a += 1
        else:
          kk -= 1
        qq.append((a,x+dx,y+dy,kk,(dx,dy)))
  q = qq[:]
  q.sort()

print(-1 if c[x2-1][y2-1] == '.' else c[x2-1][y2-1])
print(c)


### FIXED CODE ###

h,w,k = map(int,input().split())
x1,y1,x2,y2 = map(int,input().split())
c = []
for i in range(h):
  c.append(list(input()))

q = [(1,x1-1,y1-1)]
c[x1-1][y1-1] = 0
while(q):
  qq = []
  for a,x,y in q:
    for dx,dy in ((0,-1),(0,1),(-1,0),(1,0)):
      for kk in range(1,k+1):
        xx = x+dx*kk
        yy = y+dy*kk
        if not (0 <= xx < h) or not (0 <= yy < w) or c[xx][yy] == '@' or (c[xx][yy] != '.' and c[xx][yy] < a):
          break
        if c[xx][yy] == '.' or (c[xx][yy] != '.' and c[xx][yy] > a):
          c[xx][yy] = a
          qq.append((a+1,xx,yy))
  #print(qq)
  q = qq[:]

print(-1 if c[x2-1][y2-1] == '.' else c[x2-1][y2-1])
#print(c)
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)
a = list(a)
kaisa = deque()
ans = deque()
double_kaisa = deque()
for i in range(len(a)):
    if i == 0:
        continue
    diff = a[i] - a[i - 1]
    kaisa.append(diff)


for i in range(n):
    ans = kaisa.copy()
    new_num = kaisa[i] + kaisa[i + 1]
    ans.remove(kaisa[i])
    ans.remove(kaisa[i + 1])
    ans.insert(i, new_num)
    print(sum([abs(n) for n in ans]))


### FIXED CODE ###

from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)

sum = sum([abs(a[i + 1] - a[i]) for i in range(len(a) - 1)])
ans = 0

for i in range(n):
    ans = sum
    ans = ans - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i])
    print(ans)
list = [int(input()) for i in range(5)]
t = 0
cnt_l = []
for i in range(5):
    cnt = 0
    while list[i] % 10 != 0:
        list[i] += 1
        cnt += 1
    t += list[i]
    if cnt != 0:
        cnt_l.append(cnt)
print(t - max(cnt_l))

### FIXED CODE ###

list = [int(input()) for i in range(5)]
t = 0
cnt_l = []
for i in range(5):
    cnt = 0
    while list[i] % 10 != 0:
        list[i] += 1
        cnt += 1
    t += list[i]
    if cnt != 0:
        cnt_l.append(cnt)
if not cnt_l:
    cnt_l.append(0)
print(t - max(cnt_l))
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
a0 = a[0]
a1 = a[1]
r = 0
while True:
  r = a1 % a0
  if r == 0:
    b0 = a0
    break
  elif r > a0:
    a1, a0 = r, a0
  else:
    a1, a0 = a0, r
a1 = a[1]
a2 = a[2]
r = 0
while True:
  r = a2 % a1
  if r == 0:
    b1 = a1
    break
  elif r > a1:
    a2, a1 = r, a1
  else:
    a2, a1 = a1, r
a0 = a[0]
a2 = a[2]
r = 0
while True:
  r = a2 % a0
  if r == 0:
    b2 = a0
    break
  elif r > a0:
    a2, a0 = r, a0
  else:
    a2, a0 = a0, r
max_a = max(b0,b1,b2)
for j in range(max_a,1,-1):
  c = list(map(lambda x: x % j,a))
  c_ng = [i for i in c if i > 0]
  #print("j=",j,"c=",c,"c_ng=",c_ng)
  if len(c_ng) <= 1:
    ans = j
    break
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
if n == 2:
  print(max(a))
else:
  a0 = a[0]
  a1 = a[1]
  r = 0
  while True:
    r = a1 % a0
    if r == 0:
      b0 = a0
      break
    elif r > a0:
      a1, a0 = r, a0
    else:
      a1, a0 = a0, r
  a1 = a[1]
  a2 = a[2]
  r = 0
  while True:
    r = a2 % a1
    if r == 0:
      b1 = a1
      break
    elif r > a1:
      a2, a1 = r, a1
    else:
      a2, a1 = a1, r
  a0 = a[0]
  a2 = a[2]
  r = 0
  while True:
    r = a2 % a0
    if r == 0:
      b2 = a0
      break
    elif r > a0:
      a2, a0 = r, a0
    else:
      a2, a0 = a0, r
  max_a = max(b0,b1,b2)
  kouho = []
  for j in range(max_a,1,-1):
    if max_a % j == 0:
      c = list(map(lambda x: x % j,a))
      c_ng = [i for i in c if i > 0]
    #print("j=",j,"c=",c,"c_ng=",c_ng)
      if len(c_ng) <= 1:
        ans = j
        break
  print(ans)
n=int(input())
A=list(map(int,input().split()))
ans=10**9
sumA=sum(A)

for i in range(n-1):
  x+=A[i]
  ans=min(ans,abs(sumA-x*2))

print(ans)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=10**20
sumA=sum(A)
x=0
for i in range(n-1):
  x+=A[i]
  ans=min(ans,abs(sumA-x*2))

print(ans)
n = int(input())
for i in range(1,10)
    if 2**i > n:
        print(2**(i-1))


### FIXED CODE ###

n = int(input())
for i in range(1,10):
    if 2**i > n:
        print(2**(i-1))
        break
n,m = map(int,input().split())
a = n
while a % m != 0:
    a += n
l = ['0'] * a
s = input()
t = input()
for i in range(n):
    l[a//n*i] = s[i]
for i in range(m):
    if l[a//m*i] != '0':
        if l[a//m*i] != t[i]:
            print(-1)
            exit(0)
    else:
        l[a//m*i] = t[i]
print(a)

### FIXED CODE ###

from math import gcd
n,m = map(int,input().split())
z = n * m // gcd(n,m)
s = input()
t = input()
n = z // n
m = z // m
x = 0
y = 0
i = 0
j = 0
while x < z and y < z:
    if x > y:
        y += m
        j += 1
    elif x < y:
        x += n
        i += 1
    else:
        if s[i] != t[j]:
            print(-1)
            exit(0)
        x += n
        y += m
        i += 1
        j += 1
print(z)
H,N=map(int,input().split())
L=list(map(int,input().split()))
a=sum(L)
if H>L:
  print('No')
else:
  print('Yes')
       

### FIXED CODE ###

H,N=map(int,input().split())
L=list(map(int,input().split()))
a=sum(L)
if H>a:
  print('No')
else:
  print('Yes')
n=int(input())
h=list(map(int,input().split()))

dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[2])

for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])

### FIXED CODE ###

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

dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))


H,K=input2()
h=input_array()

for _ in range(K):
	max_h=max(h)
	h.remove(max_h)
attacks=sum(h)

print(attacks)

### FIXED CODE ###

#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))


H,K=input2()
h=input_array()

if K>=H:
	print(0)
elif K<=0:
	print(sum(h))
else:
	sorted_h=sorted(h)
	print(sum(sorted_h[:-K]))
def warshall_floyd(n, dist):
    min_dist = dist.copy()
    for k in range(n):
        for i in range(n):
            for t in range(n):
                min_dist[i][t] = min(min_dist[i][t], min_dist[i][k] + min_dist[k][t])
        
    return min_dist
    
n, m, r = map(int, input().split())
r = list(map(int, input().split()))
edge = [[0] * n for _ in range(n)]

for _ in range(m):
    a, b, c = map(int, input().split())
    edge[a-1][b-1] = c
    edge[b-1][a-1] = c

dist = warshall_floyd(n, edge)

ans = float('inf')
for pr in permutations(r):
    temp = 0
    for i in range(len(r)-1):
        temp += dist[pr[i]-1][pr[i+1]-1]
        if temp >= ans: break
    
    ans = min(ans, temp)
    
print(ans)

### FIXED CODE ###

import heapq
from itertools import permutations
def dijkstra(n, tc_edges, s):
    
    min_dist = [float('inf')] * n
    min_dist[s] = 0
    next_v = []
    heapq.heappush(next_v, (0, s))
    
    while True:
        if len(next_v) == 0: break
        d, v = heapq.heappop(next_v)
        
        for u, d in tc_edges[v]:
            if min_dist[u] > min_dist[v] + d:
                min_dist[u] = min_dist[v] + d
                heapq.heappush(next_v, (min_dist[u], u))
                
    return min_dist
    
n, m, r = map(int, input().split())
r = list(map(int, input().split()))
edge = [[] for _ in range(n)]

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

dist = [dijkstra(n, edge, i) for i in range(n)]

ans = float('inf')
for pr in permutations(r):
    temp = 0
    for i in range(len(r)-1):
        temp += dist[pr[i]-1][pr[i+1]-1]
        if temp >= ans: break
    
    ans = min(ans, temp)
    
print(ans)
x, n = map(int, input().split())
s = []
if n == 0:
  print(x)
else:
  a = sorted([i for i in list(map(int, input().split())) if i != x])
  for i in range(n):
    s.append(abs(a[i] - x))
  b = a[s.index(min(s))]
  print(b)

### FIXED CODE ###

x, y = map(int, input().split())
a = []
for i in range(0, x+1):
  a.append(2 * i + 4 * (x - i))
print("Yes" if y in a else "No")
X = input()
# X = 'SSTTST'
# X = 'TSSTTTSS'

# naive case
# len_prev = -1
# while len_prev != len(X):
#     len_prev = len(X)
#     X = X.replace('ST', '')
# print(len(X))


i = 0
cnt = []
X += " "
cur = 1
for i in range(len(X) - 1):
    if X[i] == X[i + 1]:
        cur += 1
    else:
        cnt.append((X[i], cur))
        cur = 1

total = 0
for i in range(len(cnt) - 1):
    if cnt[i][0] == 'S':
        if cnt[i][1] > cnt[i + 1][1]:
            if i + 2 < len(cnt):
                cnt[i + 2][1] += cnt[i][1] - cnt[i + 1][1]
        total += min(cnt[i][1], cnt[i + 1][1])
print(len(X) - 1 - 2 * total)


### FIXED CODE ###

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

x = input()
n = len(x)

s, t = 0, 0
cnt = 0
for i in range(n):
    if x[i] == 'T':
        if s > 0:
            s -= 1
            cnt += 2
    elif x[i] == 'S':
        s += 1

# i = 0
# s = 0
# t = 0
# cnt = 0
# while i < n:
#     while i < n and x[i] == 'T':
#         i += 1
#         t += 1
#     tmp = min(t, s)
#     cnt += tmp * 2
#     if t - tmp == 0:
#         s -= tmp
#     else:
#         s = 0
#         t = 0

#     while i < n and x[i] == 'S':
#         i += 1
#         s += 1
print(n - cnt)
a = {1, 2, 3}
a.remove(int(input()))
a.remove(int(input()))
print(list(a)[2])

### FIXED CODE ###

val = {1, 2, 3}
val.remove(int(input()))
val.remove(int(input()))
print(list(val)[0])
s = input()
q = int(input())
for i in range(q):
  a = input()
  if " " in a:
    l = list(a.split())
    if l[1] == "1":
      s = l[2] + s
    else:
      s += l[2]
  else:
    s.reverse()
print(s)

### FIXED CODE ###

s = input()
q = int(input())
s1 = ""
s2 = ""
c = 1
for i in range(q):
  a = input()
  if " " in a:
    l = list(a.split())
    c2 = 3-2*int(l[1])
    if c*c2 == 1:
      s1 = s1 + l[2]
    else:
      s2 = s2 + l[2]
  else:
    c = -c
s = s1[::-1] + s + s2
if c == 1:
  print(s)
else:
  print(s[::-1])
# -*- coding: utf-8 -*-
INF=10**20

def main():
    
    n=int(input())
    array=[int(input()) for i in range(n)]
    
    answer=INF
    
    for a in range(-100,101):
        temp=0
        for b in array:
            temp+=(a-b)**2
        if temp<answer:
            answer=temp
    print(answer)
            

if __name__=="__main__":
    main()
    

### FIXED CODE ###

# -*- coding: utf-8 -*-
INF=10**10

def main():
    
    n=int(input())
    array=list(map(int,input().split()))
    
    answer=INF
    
    for a in range(-100,101):
        temp=0
        for b in array:
            temp+=(a-b)**2
        if temp<answer:
            answer=temp
    print(answer)
            

if __name__=="__main__":
    main()
import numpy as np
N=int(input())
A=list(map(int,input().split()))
maxA=max(A)
lim=int(np.sqrt(maxA))
d=[i+1 for i in range(2,maxA,2)]
D=[2]*(maxA+1)
D[0]=D[1]=-1
while True:
    p=d[0]
    if lim<p:
        for x in d:
            D[x]=x
        break
    D[p]=p
    d2=[]
    for x in d:
        if x%p!=0:
            d2.append(x)
        else:
            D[x]=p
    d=d2

count=[0]*(maxA+1)
for x in A:
    pre=x+1
    while x>1:
        if pre!=D[x]:
            count[D[x]]+=1
            pre=D[x]
        x//=D[x]
maxc=max(count)
if maxc==N:
    print('not coprime')
elif maxc==1:
    print('pairwise coprime')
else:
    print('setwise coprime')

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
maxA=max(A)
count=[0]*(maxA+1)
for x in A:
    count[x]+=1
maxc=0
for i in range(2,maxA+1):
    maxc = max(maxc,sum(count[i::i]))

if maxc==N:
    print('not coprime')
elif maxc<=1:
    print('pairwise coprime')
else:
    print('setwise coprime')
def bfs(h,w):
    if l[h][w]!=".":
        return 
    if h+1<H:
        if l[h+1][w]=="." and h+1<H:
            dp[h+1][w]+=dp[h][w]
            dp[h+1][w]%=(10**9+7)
            que.append([h+1,w])
    if w+1<W:
        if l[h][w+1]==".":
            dp[h][w+1]+=dp[w][h]
            dp[h][w+1]%=(10**9+7)
            que.append([h,w+1])
    l[h][w]="!"
    return

H,W=map(int,input().split())
l=[]
dp=[[0]*W for i in range(H)]

for _ in range(H):
    l.append(list(input()))

que=[[0,0]]
dp[0][0]=1
while True:
    
    if len(que)==0:
        break
    temp=que.pop(0)
    bfs(temp[0],temp[1])
    """
    for item in dp:
        print(item)
    print(temp)
    print("===================================")
    """
#print(l)
#print(dp)
print(dp[-1][-1]%(10**9+7))

### FIXED CODE ###

# coding: utf-8
# Your code here!
H,W=map(int,input().split())

A=[]
for _ in range(H):
    A.append(list(input()))

dp=[[0 for j in range(W+1)] for i in range(H+1)]
dp[1][1]=1

for h in range(H):
    for w in range(W):
        if A[h][w]==".":
            dp[h+1][w+1]+=dp[h][w+1]+dp[h+1][w]
            dp[h+1][w+1]%=(10**9+7)

print(dp[-1][-1])
def search(v, A, B, flg, p, c, s):
  if c > 2:
    print("v=", v, "flg=", flg, "p=", p, "cnt=", c)
  if flg[v-1] == 1:
    return c
  flg[v-1] = 1
  p.append(v)
  c += 1
  for idx in range(len(A)):
    if v == A[idx]:
      cnt = search(B[idx], A, B, flg, p, c, s)
      if cnt != 0:
        return cnt
      else:
        flg[idx] = 0
        return 0
  for idx in range(len(B)):
    if v == B[idx]:
      cnt = search(A[idx], A, B, flg, p, c, s)
      if cnt != 0:
        return cnt
      else:
        flg[idx] = 0
        return 0
  return c

#
# Main Routine
#
str = input()
NM = list(map(int,str.split()))
print(NM)
ANS = 1
AB = []
C = []
A = []
B = []
for i in range(0,int(NM[1])):
  str = input()
  AB.append(list(map(int,str.split())))
  A.append(AB[i][0])
  B.append(AB[i][1])
#  print("A=", A, "B=", B)
#
# Start path finding
#
for i in range(0,int(NM[1])):  # Choose start vertex
  flg = [] # Clear the flag list
  for j in range(0,int(NM[0])):
    flg.append(0)
  v = AB[i][0]  # current vertex
  s = v   # start vertex
  p = []
  cnt = search(v, A, B, flg, p, 0, s)
  for idx in range(len(A)):
    if s == A[idx] and B[idx] == 1:
      cnt = 0	# Start vertex doesn't satisfy the condition.
  for idx in range(len(B)):
    if s == B[idx] and A[idx] == 1:
      cnt = 0	# Start vertex doesn't satisfy the condition.
  if cnt != 0:
    print(cnt)	# If all the conditions are met, output the result and stop.
    print(p)
    for i in p:
      print(i)
    break

### FIXED CODE ###

N = input()
state = 0
max = 0
min = 0
prev = 0
len = 0
ANS = 1
S = input()
A = list(map(int,S.split()))
 
for i in range(0,int(N)):
  len = len + 1
  if state in {0}:	# Initial state
      prev = A[i]
      state = 1
  elif state in {1}: # Newtral state
    if A[i] > prev:
      state = 2
    elif A[i] < prev:
      state = 3
  elif state in {2}: # Acsending state
    if A[i] < prev:
      state = 1
      ANS = ANS + 1
      len = 0
  elif state in {3}: # Descending state
    if A[i] > prev:
      state = 1
      ANS = ANS + 1
      len = 0
  prev = A[i]
#  print('s=', state, 'in=', A[i], 'prev=', prev, 'ANS=', ANS, 'len=', len)
print(ANS)