Harryxun/stf_run huggingface dataset:
from scipy.special import comb
from collections import Counter, deque

S = list(map(int, list(input())))
D = deque(S)
a = {}
value = 0
ten_mod = 1

for i in range(len(S)):
    value = value + D.pop() * ten_mod % 2019
    ten_mod = ten_mod * 10 % 2019
    if value % 2019 in a.keys():
        a[value % 2019] += 1
    else:
        a[value % 2019] = 1

b = [comb(i, 2, exact=True) for i in a.values() if i > 1]
print(sum(b))


### FIXED CODE ###

import sys
from collections import deque
def input():
    return sys.stdin.readline()[:-1]

S = deque(map(int, list(input())))
num = 0
dict = {}
dict[0] = 1
ans = 0

for i in range(len(S)):
    num += S.pop() * pow(10,i,2019)
    cand = num % 2019
    if cand in dict.keys():
        dict[cand] += 1
    else:
        dict[cand] = 1

for key in dict.keys():
    ans += dict[key] * (dict[key] - 1) // 2
print(ans)
from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
INF = 10**7
to = [ [] for _ in range(n) ]
dist = [ [INF]*n for _ in range(3) ]
for _ in range(m):
    u, v = map(int, input().split())
    to[u-1].append(v-1)
s, t = map(int, input().split())
s -= 1
t -= 1

dist[s][0] = 0
que = deque([(s, 0)])
while que:
    u, t = que.popleft()
    d = dist[t][u]
    w = (t+1) % 3
    if t == 2:
        d += 1
    for v in to[u]:
        if dist[w][v] != INF:
            continue
        que.append((v, w))
        dist[w][v] = d
print( dist[0][t] if dist[0][t] < INF else -1 )

### FIXED CODE ###

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

n, m = map(int, input().split())
INF = 10**9
to = [ [] for _ in range(n) ]
dist = [ [INF]*n for _ in range(3) ]
for _ in range(m):
    u, v = map(int, input().split())
    to[u-1].append(v-1)
s, t = map(int, input().split())
s -= 1; t -= 1

dist[0][s] = 0
que = deque([(s, 0)])
while que:
    u, prv = que.popleft()
    d = dist[prv][u]
    cur = (prv+1) % 3
    if prv == 2:
        d += 1
    for v in to[u]:
        if dist[cur][v] != INF:
            continue
        que.append((v, cur))
        dist[cur][v] = d
print( dist[0][t] if dist[0][t] < INF else -1 )
N = int(input())
*W, = map(int, input().split())

front = W[0]
back = sum(W) - W[0]
diff = abs(front, back)
for i in range(1, N):
  front += W[i]
  back -= W[i]
  diff = min(diff, abs(front, back))

print(diff)
  

### FIXED CODE ###

N = int(input())
*W, = map(int, input().split())

front = W[0]
back = sum(W) - W[0]
diff = abs(front - back)
for i in range(1, N):
  front += W[i]
  back -= W[i]
  diff = min(diff, abs(front - back))

print(diff)
N, K, S = map(int, input().split())
ans = [S] * K + [S//(N-K)+1] * (N-K)
print(ans)

### FIXED CODE ###

N, K, S = map(int, input().split())
ans = [S] * K 
if S != 10**9:
    ans += [S+1] * (N-K)
else:
    ans += [1] * (N-K)
print(' '.join([str(x) for x in ans]))
n = int(input())

first = 1
second = 1
for i in range(n):
    second, first = first + second, second
return val

### FIXED CODE ###

n = int(input())

first = 1
second = 1
for i in range(n-1):
    second, first = first + second, second
print(second)
import collections

N,X,Y=map(int,input().split())
if X > Y:
    exc=X
    X=Y
    Y=exc
L=[]
for i in range(N-1):
    for j in range(i+1,N):
        if i >= Y-1 or j <= X-1:
            L.append(j-i)
        elif j-i == 1:
            L.append(1)
        elif i <= X-1 and j >= Y-1:
            L.append(1+abs(X-1-i)+abs(Y-1-j))
        elif i >= X-1 and i-(X-1) > (Y-1)-i:
            L.append(j-i)            
        else:
            L1=j-i
            L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
            L.append(min(L1,L2))

c=collections.Counter(L)

for i in range(1,N):
    print(c[i])




### FIXED CODE ###

import numpy as np
import collections

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

a=np.array(A, dtype=np.float64)
asign=np.sign(A)
c = collections.Counter(asign)
ar = np.array(c[-1], dtype=np.float64)
ac = a * asign

if c[-1] % 2 == 0:
    print(int(sum(ac)))
else:
    print(int(sum(ac)-min(ac)*2))
line = input()
A, B, C,K = [int(u) for u in line.split()]
u=[A,B,C]
j = max(u)
u.remove(j)
u.append(j*2**K)
print(sum(u))

### FIXED CODE ###

line = input()
numbers = [int(n) for n in line.split()]
numbers.sort()
K = int(input())
N = numbers[-1]
for _ in range(K):
    N*=2
for num in numbers[:2]:
    N+=num
print(N)
A=int(input())
B=int(input())
if B%A==0:
    print(A+B)
else:
    print(B-A)


### FIXED CODE ###

DATA=input()
DATA=DATA.split(" ")
A=int(DATA[0])
B=int(DATA[1])

if B%A==0:
    print(A+B)
else:
    print(B-A)
A,B,C=map(int,input().split())
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]
  ans='YES'
print(ans)

### FIXED CODE ###

A,B,C=input().split()
ans='NO'
if A[-1]==B[0] and B[-1]==C[0]:
  ans='YES'
print(ans)
N, WW = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(N)]
W, V = zip(*l)
M = [[-1] * (WW + 1) for i in range(N + 1)]
def cal(i, w):
  if M[i][w] >= 0:
    return M[i][w]
  if i == N:
    v = 0
  elif w < W[i]:
    v = cal(i + 1, w)
  else:
    v = max(cal(i + 1, w), cal(i + 1, w - W[i]) + V[i])
  M[i][w] = v
  return v

print(cal(0, WW))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

N, WW = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(N)]
W, V = zip(*l)
M = [{} for i in range(N + 1)]
def cal(i, w):
  if w in M[i]:
    return M[i][w]
  if i == N:
    v = 0
  elif w < W[i]:
    v = cal(i + 1, w)
  else:
    v = max(cal(i + 1, w), cal(i + 1, w - W[i]) + V[i])
  M[i][w] = v
  return v

print(cal(0, WW))
A, B, C, D = map(int, input().split())
for _ in range(10000):
  C -= B
  if C <= 0:
    print("Yes")
    exit()
  A -= D
  if A <= 0:
    print("No")
    exit()

### FIXED CODE ###

A, B, C, D = map(int, input().split())
for _ in range(10000):
  C -= B
  if C <= 0:
    print("Yes")
    exit()
  A -= D
  if A <= 0:
    print("No")
    exit()
import sys
sys.setrecursionlimit(100000000)
n=int(input())
t=[int(i) for i in sys.stdin]
def gcd(x,y):
  if y==0:
    return x
  return gcd(y,x%y)
x=t[0]
for i in range(1,n):
  y=x*t[i]//gcd(x,t[i])
  x=y
print(y)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
n=int(input())
t=[int(i) for i in sys.stdin]
if n==1:
  print(t[0])
  exit()
def gcd(x,y):
  if y==0:
    return x
  return gcd(y,x%y)
x=t[0]
for i in range(1,n):
  y=x*t[i]//gcd(x,t[i])
  x=y
print(y)
h,w=map(int,input().split())
a=[list(input())+'.' for _ in range(h)]
d='.'*(w+1)
a.append(d)
x=1
i=0;j=0
while i!=h-1 or j!=w-1:
  if a[i+1][j]=='#':
    if a[i][j+1]=='#':
      x=0
      break
    else:
      i=i+1
      a[i][j]='.'
  else:
    if a[i][j+1]=='.':
      x=0
      break
    else:
      j=j+1
      a[i][j]='.'
if x==1:
  if '#' in a:
    x=0
print('Possible' if x==1 else 'Impossible')

### FIXED CODE ###

h,w=map(int,input().split())
a=[list(input()+'.') for _ in range(h)]
d=['.']*(w+1)
a.append(d)
x=1
i=0;j=0
a[0][0]='.'
while i!=h-1 or j!=w-1:
  if a[i+1][j]=='#':
    if a[i][j+1]=='#':
      x=0
      break
    else:
      i=i+1
      a[i][j]='.'
  else:
    if a[i][j+1]=='.':
      x=0
      break
    else:
      j=j+1
      a[i][j]='.'
if x==1:
  for k in range(h):
    if '#' in a[k]:
      x=0
      break
print('Possible' if x==1 else 'Impossible')
S = list(input())
for i in range(:len(S):2):
  if S[i] == 'R':
    print('No')
    exit()
for j in range(1:len(S):2):
  if S[j] == 'L':
    print('NO')
    exit()
print('Yes')

### FIXED CODE ###

S = list(input())
for i in range(0,len(S),2):
  if S[i] == 'L':
    print('No')
    exit()
for j in range(1,len(S),2):
  if S[j] == 'R':
    print('No')
    exit()
print('Yes')
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    vector<vector<int>> vec(100, vector<int>(100, 0));
    cin >> vec.at(99).at(99);
    long long num = vec.at(99).at(99);
    cout << pow(num, 3) << endl;
}


### FIXED CODE ###

y = int(input())
print(y*y*y)
n = int(input())
d = list(map(int,input().split()))
d.sort()
print(d[int(N/2)]-d[int(N/2)-1])

### FIXED CODE ###

N = int(input())
d = list(map(int,input().split()))
d.sort()
print(d[int(N/2)]-d[int(N/2)-1])
n = int(input())
a = list(mao(int,input().split()))
b = []
c = 0
for i in range(n):
  while a[i] % 2 == 0:
    a[i] /= 2
    c += 1
  b.append(c)
  c = 0
print(min(b))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = []
c = 0
for i in range(n):
  while a[i] % 2 == 0:
    a[i] /= 2
    c += 1
  b.append(c)
  c = 0
print(min(b))
n,k=map(int,input().split())
r=input()

c=0
for i in range(1,n):
  if r[i-1]==r[i]:
    c+=1
  
print(min(n-1,c+2*k))
  



### FIXED CODE ###

n=int(input())
sumNum=n*(n-1)//2
 
#print(r)
print(sumNum)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

COSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)


def main():
  remain, _ = list(map(int, input().split()))

  costs = list(map(int, input().split()))
  costs = [(c, COSTS[c]) for c in costs]
  costs.sort(key=lambda x:x[1])

  num, cost = costs[0]
  costs.sort(key=lambda x:-x[0])

  nums = [num] * (remain // cost)
  remain -= cost * len(nums)

  if remain != 0:
    new_costs = []
    exists = set([0])

    for n, c in costs:
      nc = c - cost

      if nc <= remain and nc not in exists:
        new_costs.append((n, nc))

    max_repeat = min(remain // min(v[1] for v in new_costs), len(nums))
    rep_nums_list = []

    for repeat in range(1, max_repeat + 1):
      for idxs in itertools.product(range(len(new_costs)), repeat=repeat):
        nc = sum(new_costs[i][1] for i in idxs)

        if nc != remain:
          continue

        rep_nums_list.append([new_costs[i][0] for i in idxs])

    #max_nums = [0] * len(nums)

    #for rep_nums in rep_nums_list:
    #  uns = [v for v in rep_nums if v > num]
    #  lns = [v for v in rep_nums if v < num]
    #  new_nums = nums[:]

    #  if len(uns) > 0:
    #    new_nums = uns + new_nums[len(uns):]

    #  if len(lns) > 0:
    #    new_nums = new_nums[:-len(lns)] + lns

    #  if new_nums > max_nums:
    #    max_nums = new_nums

    #nums = max_nums

  print(''.join(str(v) for v in nums), flush=True)


if __name__ == '__main__':
  main()



### FIXED CODE ###

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

COSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)


def gen(base_digit, base_cost, base_length, digits, remain):
  number = [base_digit] * base_length
  remain -= base_cost * base_length

  if remain == 0:
    print(''.join(str(d) for d in number), flush=True)
    return True

  digits = [(d, c - base_cost) for d, c in digits if d != base_digit and c - base_cost <= remain]

  if len(digits) == 0:
    return False

  max_repeat = min(remain // min(digits, key=lambda x: x[1])[1], len(number))
  numbers = []

  for repeat in range(1, max_repeat + 1):
    for idxs in itertools.product(range(len(digits)), repeat=repeat):
      if sum(digits[i][1] for i in idxs) != remain:
        continue

      replaces = [digits[i][0] for i in idxs]
      uppers = [d for d in replaces if d > base_digit]
      lowers = [d for d in replaces if d < base_digit]

      num = number[:]

      if len(uppers) > 0:
        num = uppers + num[len(uppers):]

      if len(lowers) > 0:
        num = num[:-len(lowers)] + lowers

      numbers.append(num)

  if len(numbers) == 0:
    return False

  number = max(numbers)

  print(''.join(str(d) for d in number), flush=True)

  return True


def main():
  remain, _ = list(map(int, input().split()))

  digits = {}

  for d in map(int, input().split()):
    if COSTS[d] not in digits or digits[COSTS[d]] < d:
      digits[COSTS[d]] = d

  digits = [(d, c) for c, d in digits.items()]
  base_digit, base_cost = min(digits, key=lambda x: x[1])

  for length in range(remain // base_cost, -1, -1):
    if gen(base_digit, base_cost, length, digits, remain):
      break


if __name__ == '__main__':
  main()
X,Y = map(int,input().split())
A = list(map(int,input().split()))
A = set(A[1:])
for i in range(X-1):
    A = list(map(int,input().split()))
    B = B & set(A[1:])
print(len(B))

### FIXED CODE ###

x,y = map(int,input().split())
a = list(map(int,input().split()))
b = set(a[1:])
for i in range(x-1):
    a = list(map(int,input().split()))
    b = b & set(a[1:])
print(len(b))
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
X_distance = [0]*(M-1)
for i in range(M-1):
    X_distance[i] = abs(X[i]-X[i+1])

if N == M:
    print(0)
else :
    for i in range(N-1):
        max_index = X_distance.index(max(X_distance))
        X_distance[max_index] = 0
    print(sum(X_distance))

### FIXED CODE ###

N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
X_distance = [0]*(M-1)
for i in range(M-1):
    X_distance[i] = abs(X[i]-X[i+1])
X_distance.sort(reverse=True)

if N >= M:
    print(0)
elif M == 1:
    print(0)
else :
    for i in range(N-1):
        X_distance[i] = 0
    print(sum(X_distance))
import numpy as np
N=int(raw_input())
AN=map(int, raw_input().split())
BN=[0 for i in xrange(N)]
for i in AN:
    BN[i-1] += 1
BN=[i for i in BN if i > 0]
BN.sort(reverse=True)

for K in xrange(1, N+1):
    x = np.zeros(K)
    for i in BN:
        x[x.argmin()] += i

    print (int(x.min()))


### FIXED CODE ###

A,B=raw_input().split()

a = int(A)
b = int(B)

c = a - 2 * b

print 0 if c < 0 else c
import sys
input = sys.stdin.readline
import numpy as np
import queue
sys.setrecursionlimit(1000000000)

N, Q = list(map(int, input().split()))
graph = [[] for i in range(N)]
# 最初にroot pointを定めて:
# graph構造に大して点を与える...
for i in range(N-1):
    a, b = list(map(int, input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

points = np.zeros(N, dtype=int)
for _ in range(Q):
    p, x = list(map(int, input().split()))
    points[p-1] += x

visited = np.zeros(N, dtype=bool)
tot_points = np.zeros(N, dtype=int)
tot_points[0] = points[0]
top_nodes = np.full(N, -1, dtype=int)

nodes = graph[0]
top_nodes[nodes] = 0
old_node = 0
visited[0] = True


def dfs(old_node, node):
    if visited[node]:
        return
    tot_points[node] = tot_points[old_node] + points[node]
    visited[node] = True
    nodes = queue.deque(graph[node])
    for _node in nodes:
        dfs(node, _node)
while _node in nodes:
    dfs(0, _node)
    

for x in tot_points.tolist():
    print(x, end=" ")
    
    

### FIXED CODE ###

import sys
from queue import deque
input = sys.stdin.readline

def main():
    N, Q = list(map(int, input().split()))
    graph = [[] for i in range(N)]
    # 最初にroot pointを定めて:
    # graph構造に大して点を与える...
    for i in range(N-1):
        a, b = list(map(int, input().split()))
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    
    points = [0] * N
    for _ in range(Q):
        p, x = list(map(int, input().split()))
        points[p-1] += x
    
    visited = [False] * N
    
    nodes = deque([0])

    while nodes:
        node = nodes.pop()
        visited[node] = True
        for _node in graph[node]:
            if visited[_node]:
                continue
            points[_node] += points[node]
            nodes.append(_node)
    
    print(*points)
    
main()
import sys
from operator import add

n = int(sys.stdin.readline().strip())
A = [ [0] for i in range(n)]
for i in range(n):
	temp = map(int ,sys.stdin.readline().strip().split(" "))
	A[i] = temp


weight = [None for i in range(n)]
mitayatu=[False for i in range(n)]

def min(array):
	temp = array[1]
	index=0
	for i in range(n):
		if array[i] is not None and mitayatu[i]==False:
			if temp>array[i]:
				temp == array[i]
				index = i
	return index

def owari():
	for i in mitayatu:
		if i is False:
			return False
	return True
# zero origin
def prim(nodeid):
	if owari() == True:
		return
	if mitayatu[nodeid]==True:
		return
	mitayatu[nodeid]=True
	for i in range(n):
		if A[nodeid][i]!=-1:
			if weight[i] is None:
				weight[i]=A[nodeid][i]
			elif weight[i]>A[nodeid][i]:
				weight[i]=A[nodeid][i]
	prim(min(weight))

weight[0]=0
prim(0)


print reduce(add, weight)

### FIXED CODE ###

import sys
from operator import add

n = int(sys.stdin.readline().strip())
A = [ [0] for i in range(n)]
for i in range(n):
	temp = map(int ,sys.stdin.readline().strip().split(" "))
	A[i] = temp


weight = [None for i in range(n)]
mitayatu=[False for i in range(n)]

def min(array):
	temp = 100000
	index= 0
	for i in range(n):
		if array[i] is not None and mitayatu[i]==False:
			if temp>=array[i]:
				temp = array[i]
				index = i
	return index

def owari():
	for i in mitayatu:
		if i is False:
			return False
	return True
# zero origin
def prim(nodeid):
	#print(nodeid)
	if owari() == True:
		return
	if mitayatu[nodeid]==True:
		return
	mitayatu[nodeid]=True
	for i in range(n):
		if A[nodeid][i]!=-1:
			if weight[i] is None:
				weight[i]=A[nodeid][i]
			elif weight[i]>A[nodeid][i] and mitayatu[i]==False:
				weight[i]=A[nodeid][i]
	prim(min(weight))

weight[0]=0
prim(0)

#print(weight)
print(reduce(add, weight))
s=input()
if s=='Sunny':
    print('Cloudy')
else if s=='Cloudy':
    print('Rainy')
else:
    print('Sunny')



### FIXED CODE ###

s=input()
if s=='Sunny':
    print('Cloudy')
elif s=='Cloudy':
    print('Rainy')
else:
    print('Sunny')
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 再帰的に解いて解く

    def solver(T):
        if T == "":
            print("YES")
            quit()
        if len(T) >= 5:
            if T[:5] == "dream" or T[:5] == "erase":
                solver(T[5:])
        if len(T) >= 6:
            if T[:6] == "eraser":
                solver(T[6:])
        if len(T) >= 7:
            if T[:7] == "dreamer":
                solver(T[7:])
        return

    solver(S)
    print("NO")
    return


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    # 後ろから貪欲に評価すればよい
    while True:
        if S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue
        elif S[-6:] == "eraser":
            S = S[:-6]
            continue
        elif S[-7:] == "dreamer":
            S = S[:-7]
            continue
        else:
            break
    if S == "":
        print("YES")
    else:
        print("NO")
    return


if __name__ == "__main__":
    main()
ciar = input().split()
W = int(ciar[0])
H = int(ciar[1])
x = int(ciar[2])
y = int(ciar[3])
r = int(ciar[4])
if (x + r) <= W and (x - r) >= 0 :
    if (y + r) <= H and (y - r) >= 0 :
        print("Yes")
    else    
        print("No")
else :
    print("No")

### FIXED CODE ###

ciar = input().split()
W = int(ciar[0])
H = int(ciar[1])
x = int(ciar[2])
y = int(ciar[3])
r = int(ciar[4])
if (x + r) <= W and (x - r) >= 0 :
    if (y + r) <= H and (y - r) >= 0 :
        print("Yes")
    else :
        print("No")
else :
    print("No")
n = int( raw_input() )
A = map( int , raw_input().split() )
q = int( raw_input() )
m = map( int , raw_input().split() )

for i in range( len(A) + 1 ):
  def solve(i, m)
    if m == 0:
      return yes
    if i >= n:
      return no
    res = solve( i+1 , m ) | solve( i+1 , m-A[i] )
    return res

### FIXED CODE ###

n = input()
A = map( int , raw_input().split() )
q = input()
mi = map( int , raw_input().split() )

def solve(i, m):
  if m == 0:
    return True
  elif i >= n or m > sum(A):
    return False

  res = solve( i+1 , m ) or solve( i+1 , m-A[i] )
  return res

for m in mi:
  if solve( 0 , m ): print "yes"
  else: print "no"
s = input()
x, y = list(map(int, input().split()))
F = [len(fs) for fs in s.split('T')]
Fx = F[0::2]
Fy = F[1::2]

xt2 = (sum(Fx)-x)
yt2 = (sum(Fy)-y)
if xt2%2==1 or yt2%2==1:
    print('No')
    exit()

xt = xt2//2
yt = yt2//2

M = 8000
dpx = [False]*M
dpx[0] = True
for f in Fx:
    for i in range(M-1, f-1, -1):
        if dpx[i-f]: dpx[i]=True

dpy = [False]*M
dpy[0] = True
for f in Fy:
    for i in range(M-1, f-1, -1):
        if dpy[i-f]: dpy[i]=True

print('Yes' if dpx[xt] and dpy[yt] else 'No')

### FIXED CODE ###

s = input()
x, y = list(map(int, input().split()))
F = [len(fs) for fs in s.split('T')]
x -= F[0]
Fx = F[2::2]
Fy = F[1::2]

xt2 = sum(Fx)-x
yt2 = sum(Fy)-y
if xt2%2==1 or yt2%2==1 or xt2<0 or yt2<0:
    print('No')
    exit()

xt = xt2//2
yt = yt2//2

dpx = [False]*(xt+1)
dpx[0] = True
for f in Fx:
    for i in range(xt, f-1, -1): dpx[i] |= dpx[i-f]

dpy = [False]*(yt+1)
dpy[0] = True
for f in Fy:
    for i in range(yt, f-1, -1): dpy[i] |= dpy[i-f]

print('Yes' if dpx[xt] and dpy[yt] else 'No')
N=int(input())
A=list(map(int,input().split(' ')))
import math
import collections
def nCr(n,r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n-r) if n>1 else 0
counter=collections.Counter(A)
penult=0
for i in range(1,N+1):
    penult=penult+nCr(counter[i],2)
for i in range(0,N):
    print(int(penult-(counter[A[i]]-1)))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split(' ')))
import math
import collections
import operator as op
from functools import reduce
def nCr(n,r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom if n>1 else 0
counter=collections.Counter(A)
penult=0
for i in range(1,N+1):
    penult=penult+nCr(counter[i],2)
for i in range(0,N):
    print(int(penult-(counter[A[i]]-1)))
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    min = 1000

    for i in range(1, 101):

        if i in p:
            continue

        elif min > abs(x - i):
            result = i
            min = abs(x - i)

    print(result)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    min = 1000

    for i in range(-50, 150):

        if i in p:
            continue

        elif min > abs(x - i):
            result = i
            min = abs(x - i)

    print(result)


if __name__ == "__main__":
    main()
import queue
import copy
 
def ngoin(bo,now):
    return 0 <= now[0] and now[0] < len(bo) and 0 <= now[1] and now[1] < len(bo[0])
 
def minido(bo,si,sj):
    tb = [[False for i in range(len(bo[0]))] for j in range(len(bo))]
    q = queue.Queue()
    q.put([si,sj,0])
    tb[si][sj] = True
    ret = 0
    while not q.empty():
        now = q.get()
        ret = now[2]
        if ngoin(bo,[now[0]-1,now[1]]):
            if bo[now[0]-1][now[1]] and not tb[now[0]-1][now[1]]:
                q.put([now[0]-1,now[1],now[2]+1])
                tb[now[0]-1][now[1]] = True
                
        if ngoin(bo,[now[0],now[1]+1]):
            if bo[now[0]][now[1]+1] and not tb[now[0]][now[1]+1]:
                q.put([now[0],now[1]+1,now[2]+1])
                tb[now[0]][now[1]+1] = True
                
        if ngoin(bo,[now[0]+1,now[1]]):
            if bo[now[0]+1][now[1]] and not tb[now[0]+1][now[1]]:
                q.put([now[0]+1,now[1],now[2]+1])
                tb[now[0]+1][now[1]] = True
                
        if ngoin(bo,[now[0],now[1]-1]):
            if bo[now[0]][now[1]-1] and not tb[now[0]][now[1]-1]:
                q.put([now[0],now[1]-1,now[2]+1])
                tb[now[0]][now[1]-1] = True
    return ret
            
 
h,w = map(int,input().split())
bo = [[True if x == '.' else False for x in input()] for i in range(h)]
grap = [[float('inf') for i in range(h*w)] for j in range(h*w)]
ans = 0
for i in range(h*w):
    grap[i][i] = 0
for si in range(h):
    for sj in range(w):
        if not bo[si][sj]:
            continue
        ans = max(ans,minido(bo,si,sj))
                
print(ans)


### FIXED CODE ###

a = input()
print(chr(ord(a)+1))
K, N = map(int, input().split())
A = list(map(int, input().split()))

dif = [A[i+1]-A[i] for i in range(N)]

dif.extend([K-A[N]])

print(K-max(dif))


### FIXED CODE ###

k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
c = a[0] + (k - a[n-1])
for i in range(1,n):
  c = max(c,a[i] - a[i-1])
print(k-c)