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

n = int(input())
ListP = [int(i) for i in input().split()]
#ListPosPのPositionは1からnまでの値
ListPosP = [ListP.index(i) for i in range(1, n+1)]
points = 0
for i in reversed(range(1, n)):
	ListDistPlus = sorted([j - ListPosP[i-1] for j in ListPosP[i:] if j - ListPosP[i-1] > 0])
	ListDistMinus = sorted([j - ListPosP[i-1] for j in ListPosP[i:] if j - ListPosP[i-1] < 0])
	#Plus側のiより大きい値を1つだけ含む部分配列
	if (len(ListDistPlus) == 1):
		ListDistPlus = ListDistPlus + [n+1-(ListPosP[i-1] + 1)]
	if (len(ListDistPlus) == 0):
		ListDistPlus = [n+1-(ListPosP[i-1] + 1), n+1-(ListPosP[i-1] + 1)]
	if (len(ListDistMinus) == 1):
		ListDistMinus = [-(ListPosP[i-1] + 1)] + ListDistMinus
	if (len(ListDistMinus) == 0):
		ListDistMinus = [-(ListPosP[i-1] + 1), -(ListPosP[i-1] + 1)]
	points += i * ((ListDistPlus[1] - ListDistPlus[0]) * (-ListDistMinus[-1]) + (ListDistMinus[-1] - ListDistMinus[-2]) * (ListDistPlus[0]))
	#print(points)デバッグ用
	#print(ListDistMinus[-1], ListDistMinus[-2], ListDistPlus[0], ListDistPlus[1])デバッグ用
print(points)

### FIXED CODE ###

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

pos_list = [0] * n
for ind, i in enumerate(p):
	pos_list[i-1] = ind

left_nextInd = list(range(-1, n-1)) + [-1, -1]
right_nextInd = list(range(1, n+1)) + [n, n]

answer = 0
for i in range(1, n):
	ind = pos_list[i-1]
	l1 = left_nextInd[ind]
	l2 = left_nextInd[l1]
	r1 = right_nextInd[ind]
	r2 = right_nextInd[r1]

	answer += i * ((ind-l1) * (r2-r1) + (r1-ind) * (l1-l2))

	left_nextInd[r1] = l1
	right_nextInd[l1] = r1
print(answer)
### BUGGY CODE ###

N=int(input())
A=input()
c=0
for i in range(N-2):
 B2=A[i+1]
 for j in range(i+1):
  B1=A[j]
  if B1!=B2:
   for k in range(N-i-2):
    B3=A[i+2+k]
    if B2==B3 or B1==B3 or i==j+k:
     continue
    else:
     c+=1
print(c)


### FIXED CODE ###

N=int(input())
A=input()
c=0
B1B=0
B1R=0
B1G=0
if A[0]=="B":
 B1B+=1
elif A[0]=="R":
 B1R+=1
else:
 B1G+=1
for i in range(N-2):
 B2=A[i+1]
 for k in range(N-i-2):
  B3=A[i+2+k]
  if (B2=="B" and B3=="R")or (B2=="R" and B3=="B"):
   c+=B1G
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="G":
     c-=1
  if (B2=="G" and B3=="R")or (B2=="R" and B3=="G"):
   c+=B1B
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="B":
     c-=1
  if (B2=="B" and B3=="G")or (B2=="G" and B3=="B"):
   c+=B1R
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="R":
     c-=1
 if B2=="B":
  B1B+=1
 elif B2=="R":
  B1R+=1
 else:
  B1G+=1
print(c)
### BUGGY CODE ###

import heapq


class Prim():
    # 無向グラフであるという前提に注意
    def __init__(self, N):
        self.edge = [[] for i in range(N)]
        self.N = N

    def add(self, u, v, d):
        """
        u = from, v = to, d = cost
        0-indexedであることに注意、graph.add(u-1, v-1)とする必要がある
        """
        self.edge[u].append([d, v])  # コスト、e_toとなっていることに注意
        self.edge[v].append([d, u])

    def delete(self, u, v):
        self.edge[u] = [_ for _ in self.edge[u] if _[0] != v]
        self.edge[v] = [_ for _ in self.edge[v] if _[0] != u]

    def Prim(self):
        """
        return: 最小全域木のコストの和
        """
        used = [True] * self.N  # True:不使用
        edgelist = []
        for e in self.edge[0]:
            heapq.heappush(edgelist, e)
        used[0] = False
        res = 0
        while len(edgelist) != 0:
            minedge = heapq.heappop(edgelist)
            if not used[minedge[1]]:
                continue
            v = minedge[1]
            used[v] = False
            for e in self.edge[v]:
                if used[e[1]]:
                    heapq.heappush(edgelist, e)
            res += minedge[0]
        return res

N = int(input())
data = [list(map(int,input().split())) for i in range(N)]

G = Prim(N)

for i in range(G.N-1):
    for j in range(i+1,G.N):
        G.add(i,j,min(abs(data[i][0]-data[j][0]),abs(data[i][1]-data[j][1])))

print(G.Prim())

### FIXED CODE ###

class Kruskal():
    def __init__(self,n):
        self.e = []
        self.par = [i for i in range(n+1)]  #親のノード番号
        self.rank = [0]*(n+1)
    def add(self,u,v,d):  #クラスカル法で考えるのは無向グラフ
        self.e.append([u,v,d])
    def find(self,x):  #xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self,x,y):  #x,yが同じグループか否か
        return self.find(x) == self.find(y)
    def unite(self,x,y):  #x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[y] = x
            self.rank[x] += 1
    def Kruskal(self):
        edges = sorted(self.e,key=lambda x: x[2])  #距離でソート
        a = 0
        for e in edges:
            if not self.same_check(e[0],e[1]):
                self.unite(e[0],e[1])
                a += e[2]
        return a

N = int(input())
A = [list(map(int,input().split())) for i in range(N)]

G = Kruskal(N)

X = []
Y = []
for i in range(N):
    X.append((A[i][0], i))
    Y.append((A[i][1], i))

X = sorted(X)
Y = sorted(Y)

# 辞書順で隣り合うものだけ考えれば良い

for i in range(N - 1):
    G.add(X[i][1], X[i + 1][1], X[i + 1][0] - X[i][0])
    G.add(Y[i][1], Y[i + 1][1], Y[i + 1][0] - Y[i][0])

print(G.Kruskal())
### BUGGY CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
graph = [[] for _ in range(n)]
for u, v in LIR(m):
    graph[u - 1] += [v - 1]


s, t = LI()
dist = [[INF for _ in range(3)] for _ in range(n)]
dist[s - 1][0] = 0
que = deque([(s - 1, 0)])
while que:
    cur, cost = que.pop()
    for nxt in graph[cur]:
        if cost + 1 < dist[nxt][(cost + 1) % 3]:
            dist[nxt][(cost + 1) % 3] = cost + 1
            que += [(nxt, cost + 1)]



if dist[t - 1][0] == INF:
    print(-1)
else:
    print(dist[t - 1][0] // 3)

### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
graph = [[] for _ in range(n)]
for u, v in LIR(m):
    graph[u - 1] += [v - 1]


s, t = LI()
dist = [[INF for _ in range(3)] for _ in range(n)]
dist[s - 1][0] = 0
que = deque([(s - 1, 0)])
while que:
    cur, cost = que.popleft()
    for nxt in graph[cur]:
        if cost + 1 < dist[nxt][(cost + 1) % 3]:
            dist[nxt][(cost + 1) % 3] = cost + 1
            que += [(nxt, cost + 1)]



if dist[t - 1][0] == INF:
    print(-1)
else:
    print(dist[t - 1][0] // 3)
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(357,n+1):
    a = str(i)
    if (a[0] == '3' or a[0] == '5' or a[0] == '7') and ('3' in a and '5' in a and '7' in a):
        sa = set(a)
        if len(sa) == 3 and '3' in sa and '5' in sa and '7' in sa:
            ans += 1
print(ans)

### FIXED CODE ###

import itertools
n = int(input())
a = [3,5,7]
b = list(itertools.product(a,a,a)) + list(itertools.product(a,a,a,a)) + list(itertools.product(a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a,a)) + list(itertools.product(a,a,a,a,a,a,a,a,a))
ans = 0
for i in range(len(b)):
    sb = set(b[i])
    if len(sb) == 3 and 3 in sb and 5 in sb and 7 in sb:
        c = ''.join(map(str,b[i]))
        c = int(c)
        if c <= n:
            ans +=1
        else:
            break
print(ans)
### BUGGY CODE ###

def merge(A,left,mid,right):
    n1=mid-left
    n2=right-mid
    L=[0]*(n1+1)
    R=[0]*(n2+1)
    for i in range(n1):
        L[i]=A[left+i]
    for i in range(n2):
        R[i]=A[mid+i]
    L[n1]=float("inf")
    R[n2]=float("inf")
    i=0
    j=0
    for k in range(left,right):
        global cnt
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i=i+1
        else:
            A[k]=R[j]
            j=j+1

def mergeSort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)

n=int(input())
S=list(input().split())
for i in range(n):
    S[i]=int(S[i])
cnt=0
mergeSort(S,0,n)
for i in range(n):
    if i==n-1:
        print(S[i])
    else:
        print(S[i],end=" ")
print(cnt)


### FIXED CODE ###

def merge(A,left,mid,right):
    n1=mid-left
    n2=right-mid
    L = A[left:mid]
    R = A[mid:right]
    L.append(float("inf"))
    R.append(float("inf"))
    """
    L=[0]*(n1+1)
    R=[0]*(n2+1)
    for i in range(n1):
        L[i]=A[left+i]
    for i in range(n2):
        R[i]=A[mid+i]
    L[n1]=float("inf")
    R[n2]=float("inf")
    """
    i=0
    j=0
    for k in range(left,right):
        global cnt
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i=i+1
        else:
            A[k]=R[j]
            j=j+1

def mergeSort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)

n=int(input())
S=list(input().split())
for i in range(n):
    S[i]=int(S[i])
cnt=0
mergeSort(S,0,n)
for i in range(n):
    if i==n-1:
        print(S[i])
    else:
        print(S[i],end=" ")
print(cnt)
### BUGGY CODE ###

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
from functools import lru_cache

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

setrecursionlimit(10000)

def main():
	MOD = 10**9 + 7
	k, d = int(rl()), int(rl())
	ans = 0

	@lru_cache(None)
	def dfs(x, tight, i, tot):
		if i == len(x):
			return 1 if tot % d == 0 else 0
		start = 0 if i > 0 else 1
		maxdig = x[i] if tight else 9
		cnt = 0
		for dig in range(start, maxdig + 1):
			ntight = 1 if tight and dig == x[i] else 0
			cnt += dfs(x, ntight, i + 1, tot + dig)
		return cnt % MOD

	def totup(num):
		ans = deque()
		while num:
			num, dig = divmod(num, 10)
			ans.appendleft(dig)
		return tuple(ans)

	tupk = totup(k)
	ans += dfs(tupk, 1, 0, 0)
	for i in range(1, len(tupk)):
		bndry = 10**i-1
		ans += dfs(totup(bndry), 1, 0, 0)
		ans %= MOD

	print(ans % MOD)

	stdout.close()

if __name__ == "__main__":
	main()

### FIXED CODE ###

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
from functools import lru_cache

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

setrecursionlimit(100000)

def main():
	MOD = 10**9 + 7
	k, d = int(rl()), int(rl())
	ans = 0

	def totup(num):
		ans = deque()
		while num:
			num, dig = divmod(num, 10)
			ans.appendleft(dig)
		return tuple(ans)

	x = totup(k)

	dp = [[[0]*2 for j in range(d)] for i in range(len(x)+1)]
	dp[0][0][1] = 1
	for i in range(len(x)):
		for digsum in range(d):
			for tight in range(2):
				for dig in range(x[i]+1 if tight else 10):
					ns = (digsum + dig) % d 
					ntight = 1 if tight and dig == x[i] else 0
					dp[i+1][ns][ntight] += dp[i][digsum][tight]
					dp[i+1][ns][ntight] %= MOD

	ans = (dp[len(x)][0][0] + dp[len(x)][0][1] - 1) % MOD
	print(ans)
	stdout.close()

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

n=int(input())
S=set()
for i in range(n):
  a=int(input())
  S=S^set([a])
print(len(S))

### FIXED CODE ###

n=int(input())
S=set()
for i in range(n):
  S^=set([input()])
print(len(S))
### BUGGY CODE ###

N = int(input())

start = 0
end = N

print(0)
s0 = input()
if s0 == 'Vacant':
    exit()

ni = (start+end)//2
print(ni, flush=True)
s = input()

while s != 'Vacant':
    if not((s == s0) ^ (s % 2 == s0 % 2)):
        start = ni
    else:
        end = ni

    s0 = s

    ni = (start+end)//2
    print(ni, flush=True)
    s = input()

exit()


### FIXED CODE ###

N = int(input())


def ask(i):
    print(i, flush=True)
    resp = input()
    if resp == 'Vacant':
        exit()
    return resp


def test(l, r, l_resp, r_resp):
    if l % 2 == r % 2:
        return l_resp == r_resp
    else:
        return l_resp != r_resp


resp = ask(0)

l = 0
r = N
l_resp = resp
r_resp = resp

for _ in range(19):
    m = (l+r)//2
    m_resp = ask(m)
    if test(l, m, l_resp, m_resp):
        l, l_resp = m, m_resp
    else:
        r, r_resp = m, m_resp
### BUGGY CODE ###

n = int(input())
 
str = input()
sum = 0
ans = []
for i in range(n):
  if str[i] == "R":
    ans.append(2)
  elif str[i] == "G":
    ans.append(3)
  else:
    ans.append(5)

for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if ans[i] == ans[j]:
        break
      elif ans[i] * ans[j] * ans[k] == 30 and j - i != k - j:
        sum += 1
print(sum)

### FIXED CODE ###

n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)
### BUGGY CODE ###

import heapq
import sys
n, m, s, t = [int(i) for i in input().split()]
s -= 1
t -= 1
snuuk_dict = dict()
yen_dict = dict()
snuuk_que = []
yen_que = []
for i in range(m):
    u, v, a, b = [int(i) for i in sys.stdin.readline().split()]
    u -= 1
    v -= 1
    if snuuk_dict.get(u) is None:
        snuuk_dict[u] = []
        yen_dict[u] = []
    if snuuk_dict.get(v) is None:
        snuuk_dict[v] = []
        yen_dict[v] = []
    snuuk_dict[u].append([b, u, v])
    snuuk_dict[v].append([b, v, u])
    yen_dict[u].append([a, u, v])
    yen_dict[v].append([a, v, u])

for i in snuuk_dict[t]:
    heapq.heappush(snuuk_que, i)
for i in yen_dict[s]:
    heapq.heappush(yen_que, i)
snuuk_ls = [-1 for i in range(n)]
yen_ls = [-1 for i in range(n)]
yen_ls[s] = 0
snuuk_ls[t] = 0
while len(yen_que) > 0:
    a, u, v = heapq.heappop(yen_que)
    if yen_ls[v] != -1:
        continue
    yen_ls[v] = a
    for i in yen_dict[v]:
        heapq.heappush(yen_que, [i[0] + yen_ls[v], i[1], i[2]])
while len(snuuk_que) > 0:
    b, v, u = heapq.heappop(snuuk_que)
    if snuuk_ls[u] != -1:
        continue
    snuuk_ls[u] = b
    for i in snuuk_dict[u]:
        heapq.heappush(snuuk_que,  [i[0] + snuuk_ls[u], i[1], i[2]])
sum_ls = [10** 15 - (i + j) for i, j in zip(snuuk_ls, yen_ls)]
for i in range(n):
    print(max(sum_ls[i:]))

### FIXED CODE ###

import heapq
import sys
n, m, s, t = [int(i) for i in input().split()]
s -= 1
t -= 1
snuuk_dict = dict()
yen_dict = dict()
snuuk_que = []
yen_que = []
for i in range(m):
    u, v, a, b = [int(i) for i in sys.stdin.readline().split()]
    u -= 1
    v -= 1
    if snuuk_dict.get(u) is None:
        snuuk_dict[u] = []
        yen_dict[u] = []
    if snuuk_dict.get(v) is None:
        snuuk_dict[v] = []
        yen_dict[v] = []
    snuuk_dict[u].append([b, u, v])
    snuuk_dict[v].append([b, v, u])
    yen_dict[u].append([a, u, v])
    yen_dict[v].append([a, v, u])

for i in snuuk_dict[t]:
    heapq.heappush(snuuk_que, i)
for i in yen_dict[s]:
    heapq.heappush(yen_que, i)
snuuk_ls = [-1 for i in range(n)]
yen_ls = [-1 for i in range(n)]
yen_ls[s] = 0
snuuk_ls[t] = 0
while len(yen_que) > 0:
    a, u, v = heapq.heappop(yen_que)
    if yen_ls[v] != -1:
        continue
    yen_ls[v] = a
    for i in yen_dict[v]:
        if yen_ls[i[2]] == -1:
            heapq.heappush(yen_que, [i[0] + yen_ls[v], i[1], i[2]])
while len(snuuk_que) > 0:
    b, v, u = heapq.heappop(snuuk_que)
    if snuuk_ls[u] != -1:
        continue
    snuuk_ls[u] = b
    for i in snuuk_dict[u]:
        if snuuk_ls[i[2]] == -1:
            heapq.heappush(snuuk_que,  [i[0] + snuuk_ls[u], i[1], i[2]])
sum_ls = [10** 15 - (i + j) for i, j in zip(snuuk_ls, yen_ls)]
_max = 0
for i in range(n):
    _max = sum_ls[-1-i] if sum_ls[-1-i] > _max else _max
    sum_ls[-i-1] = _max
for i in range(n):
    print(sum_ls[i])
### BUGGY CODE ###

# -*-coding: utf-8 -*-
import numpy as np

N, M = map(int, input().split())
A = list(map(int, input().split()))
np_A = np.array(A)
for i in range(M):
    num = np_A.argmax()
    np_A[num] = np_A[num] // 2

print(sum(np_A))

### FIXED CODE ###

# -*-coding: utf-8 -*-
import heapq
def main():
    N, M = map(int, input().split())
    A = list(map(lambda x: int(x)*(-1), input().split()))
    heapq.heapify(A)

    for _ in range(M):
        tmp_min = heapq.heappop(A)
        heapq.heappush(A, (-1)*(-tmp_min//2))
    
    print(-sum(A))
if __name__ == '__main__':
    main()
### BUGGY CODE ###

nm = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for i in range(nm[1])]


a = [{j for j in range(lr[i][0], lr[0][1]+1)} for i in range(nm[1])]
b = set()
for i in range(len(a)):
    if b == set():
        b = a[i]
    b = b & a[i]
print(len(b))

### FIXED CODE ###

nm = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for i in range(nm[1])]

l = [i[0] for i in lr]
r = [i[1] for i in lr]
print(len(range(max(l), min(r)+1)))
### BUGGY CODE ###

s=input()
n=len(s)
dp=[list(0 for i in range(13)) for j in range(n)]
MOD=10**9+7
if s[0]=="?":
    for k in range(0,10):
        dp[0][k]+=1
else:
    dp[0][int(s[0])]+=1
for i in range(0,n-1):
    for k in range(13):
        if s[i+1]=="?":
            for j in range(10):
                ct=(k*10+j)%13
                dp[i+1][ct]+=dp[i][k]
                dp[i+1][ct]%=MOD
        elif s[i+1]!="?":
            tmp=(int(s[i+1])+k*10)%13
            dp[i+1][tmp]+=dp[i][k]
            dp[i+1][tmp]%=MOD
print(dp[n-1][5])



### FIXED CODE ###

s=input()
n=len(s)
dp=[list(0 for i in range(13)) for j in range(n)]
MOD=10**9+7
if s[0]=="?":
    for k in range(0,10):
        dp[0][k]+=1
else:
    dp[0][int(s[0])]+=1
for i in range(0,n-1):
    for k in range(13):
        if s[i+1]=="?":
            for j in range(10):
                ct=(k*10+j)%13
                dp[i+1][ct]+=dp[i][k]
                dp[i+1][ct]%=MOD
        elif s[i+1]!="?":
            tmp=(int(s[i+1])+k*10)%13
            dp[i+1][tmp]+=dp[i][k]
            dp[i+1][tmp]%=MOD
print(dp[n-1][5])
### BUGGY CODE ###

n = input()
n = int(n)
lin = input().split()
# 要素の個数を求める
dic_s = {}
for c in lin:
  dic_s.setdefault(c, 0)
  dic_s[c] += 1
dic_tot = {}
for c in lin:
  if dic_tot.get(c):
    print(int(dic_tot[c]))
  else:
    tot = 0
    for key,value in dic_s.items():
      v = value
      if key == c:
        v -= 1
      if v > 1:
        tot += v * (v - 1) / 2
    dic_tot.setdefault(c,tot)
    print(int(tot))

### FIXED CODE ###

n = input()
n = int(n)
lin = input().split()
# 要素の個数を求める
dic_s = {}
for c in lin:
  dic_s.setdefault(c, 0)
  dic_s[c] += 1
# ペアの総数
tot = 0
for key,value in dic_s.items():
  v = value
  tot += v * (v - 1) / 2
# print(int(tot))
# 指定位置のペアを除く
for c in lin:
  if tot > 0:
    v = dic_s[c]
    print(int(tot-(v-1)))
  else:
    print(0)
### BUGGY CODE ###

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

x=[0]*(n+1)
for i in range(n-1):
    if a[i]<0:
        a[i]=-1*a[i]
        a[i+1]=-1*a[i+1]
        x[i+1]=max(sum(a),x[i])


print(max(max(x),sum(a)))


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
    if a[i]<0:
        c+=1
        a[i]=-1*a[i]
aa=list(map(abs,a))
if c%2==0:
    print(sum(aa))
else:
    print(sum(aa)-2*min(aa))
### BUGGY CODE ###

N,M = map(int,input().split())
ls = [[]]*M
for p in range(M):
    ls[p] = input().split()
ans = 0
for q in range(1,N+1):
    an = True
    for a,b in ls:
        if an:
            if int(a) <= q <= int(b):
                an = True
            else:
                an = False
    if an:
       ans += 1
print(ans)

### FIXED CODE ###

N,M = map(int,input().split())
ls_a = []
ls_b = []
for p in range(M):
    L,R  = map(int,input().split())
    ls_a.append(L)
    ls_b.append(R)
ans = min(ls_b)-max(ls_a)+1
if ans < 0:
    print(0)
else:
    print(ans)