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

import sys
sys.setrecursionlimit(100000000)
def dfs(cur,par,d):
    dist[cur]=d
    for nx,nx_dist in G[cur]:
        if nx==par:continue
        dfs(nx,cur,d+nx_dist)

n=int(input())
G=[[] for i in range(n)]
dist=[0]*n
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append([b-1,c])
    G[b-1].append([a-1,c])
q,k=map(int,input().split())
k-=1
dfs(k,-1,0)
for i in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(dist[x]+dist[y])

### FIXED CODE ###

# ABC070 D - Transit Tree Path
import heapq
def dijkstra_heap(s):
    """
    始点sから各頂点への最短距離を返す

    Parameters
    ----------
    s : int
        視点とする頂点

    Returns
    -------
    d ：list
    始点sから各頂点への最短距離
    """
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #未使用の頂点の中から最小の距離のものを探す
        if not used[minedge[0]]:
            continue
        v = minedge[0]
        d[v] = minedge[1]
        used[v] = False
        for e in edge[v]:
            if used[e[0]]:
                heapq.heappush(edgelist,[e[0],e[1]+d[v]])
    return d

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

q,k=map(int,input().split())
k-=1
dist=dijkstra_heap(k)
for i in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(dist[x]+dist[y])
### BUGGY CODE ###

N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

tmp = []
for _ in range(M):
    b,c = [int(i) for i in input().split()]
    tmp += [c]*b

A += tmp
A.sort(reverse=True)
print(sum(A[:N]))


### FIXED CODE ###

N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
bc = [tuple(int(i) for i in input().split()) for _ in range(M)]

A.sort()
bc.sort(key=lambda t: t[1], reverse=True)

index = 0
count = 0
for i in range(N):
    if index >= M or A[i] >= bc[index][1]:
        break
    A[i] = bc[index][1]
    count += 1
    if bc[index][0] <= count:
        index += 1
        count = 0

print(sum(A))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    tmp = A[i]
    A[i] = NIL
    print(max(A))
    A[i] = tmp




# def main():

# if __name__ == '__main__':
#     main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N = int(input())
A = [int(input()) for _ in range(N)]

max_a = max(A)
max_idx = [i for i, x in enumerate(A) if x == max_a]

if len(max_idx) > 1:
    for i in range(N):
        print(max_a)
    exit()
else:
    for i in max_idx:
        A[i] = NIL
    second_max = max(A)

    for i in range(N):
        if i in max_idx:
            print(second_max)
        else:
            print(max_a)
### BUGGY CODE ###

#coding: utf-8

N, K = map(int,input().split())

if N % K == 0:
    print(0)
elif abs(N-K) < N:
    while True:
        N_ = abs(N-K)
        if N_ < N:
            N = N_
        else:
            break
    print(N)

elif abs(N-K) >= N:
    if N >= K:
        print(N%K)
    else:
        print(N)
else:
    print('jj')

### FIXED CODE ###

#coding: utf-8

N, K = map(int,input().split())

if N % K == 0:
    print(0)
elif abs(N-K) < N:
    N = N % K
    while True:
        N_ = abs(N-K)
        if N_ < N:
            N = N_
        else:
            break
    print(N)

elif abs(N-K) >= N:
    if N >= K:
        print(N%K)
    else:
        print(N)
### BUGGY CODE ###

import sys
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    dic = defaultdict(int)
    a.sort()
    ans = 0
    for i in range(n):
        x = a[i]
        if i < n-1 and a[i] == a[i+1]:
            dic[a[i]] = 1
            continue
        flag = 1
        for check in range(1,int(x**0.5)+1):
            if(x%check==0):
                if dic[check]:
                    flag = 0
                    break
                if dic[x//check]:
                    flag = 0
                    break
        if flag:
            ans += 1
        dic[a[i]] = 1
    print(ans)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
 
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 0
    N = max(a)+1
    tab = [1 for _ in range(N)]
    for i in range(n):
        x = a[i]
        if i < n-1 and a[i] == a[i+1]:
            tab[a[i]] = 0
        if tab[x]:
            ans += 1
        for i in range(N):
            if x*i >= N:
                break
            tab[x*i] = 0        
    print(ans)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n,k=map(int,input().split())
i=1
while True:
  if n-i*k<=0:
    m=min((i*k-n),(n-(i-1)*k))
    print(m)
    break
  i+=1

### FIXED CODE ###

n,k=map(int,input().split())
s=n//k
m=min((n-s*k),((s+1)*k-n))
print(m)
### BUGGY CODE ###

import heapq

num = int(input())
nums = [int(input()) for _ in range(num)]

for n in nums:
  maxs = heapq.nlargest(2, nums)
  if maxs[0] > n:
    print(maxs[0])
  else:
    print(maxs[1])


### FIXED CODE ###

import heapq

num = int(input())
nums = [int(input()) for _ in range(num)]

maxs = heapq.nlargest(2, nums)
for n in nums:
  if n == maxs[0]:
    print(maxs[1])
  else:
    print(maxs[0])
### BUGGY CODE ###


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

import math
from fractions import gcd

A, B = map(int, input().split())

# 最大公約数
g = gcd(A, B)

if g == 1:
    print(1)
    exit()


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

prime = get_sieve_of_eratosthenes(g)

a = []
count = 0
for p in prime:
    if A%p == 0 and B%p == 0:
        count += 1

print(count+1)

### FIXED CODE ###


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

from fractions import gcd

A, B = map(int, input().split())

# 最大公約数
g = gcd(A, B)

if g == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a

print(len(prime_factorize(g)) +1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

# C - Marks
N, K = map(int, input().split())
A = list(map(int, input().split()))
score = 1

for i in range(N):
	if i < K:
		score *= A[i]
	else:
		new_score = score * A[i] // A[i-K]
		
		if new_score > score:
			print('Yes')
		else:
			print('No')
		
		score = new_score

### FIXED CODE ###

import sys
input = sys.stdin.readline

# C - Marks
N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N):
	if i >= K:
		
		if A[i] > A[i - K]:
			print('Yes')
		else:
			print('No')
### BUGGY CODE ###

N = int(input())
X = input()

X_int = int(X, 2)
pcXi01 = bin(X_int).count('1') + 1
pcXi10 = bin(X_int).count('1') - 1
if pcXi10 < 1:
  pcXi10 = 1
Xmod01 = X_int % pcXi01
Xmod10 = X_int % pcXi10

tmp01 = [1]
tmp10 = [-1]
for i in range(N - 1):
  tmp01.append(tmp01[i]*2 % pcXi01)
  tmp10.append(tmp10[i]*2 % pcXi10)

init_n = [0] * N
next_n = [0] * N
for i in range(N):
  X_list = list(X)
  if X_list[i] == '0':
    X_list[i] = '1'
    Xi_str = ''.join(X_list)
    init_n[i] = int(Xi_str, 2)
    next_n[i] = (Xmod01 + tmp01[N - 1 - i]) % pcXi01
  else:
    X_list[i] = '0'
    Xi_str = ''.join(X_list)
    init_n[i] = int(Xi_str, 2)
    next_n[i] = (Xmod10 + tmp10[N - 1 - i]) % pcXi10

for i in range(N):
  fn = 0
  n = init_n[i]
  if n != 0:
    n = next_n[i]
    fn += 1
  while n != 0:
    n = n % bin(n).count('1')
    fn += 1
  
  print(fn)
  

### FIXED CODE ###

N = int(input())
X = input()

X_int = int(X, 2)
cnt1 = bin(X_int).count('1')
pcXi01 = cnt1 + 1
pcXi10 = cnt1 - 1
zero_idx = N + 5
if cnt1 == 1:
  for i in range(N):
    if X[i] == '1':
      zero_idx = i

if pcXi10 < 1:
  pcXi10 = 1
Xmod01 = X_int % pcXi01
Xmod10 = X_int % pcXi10

tmp01 = [1]
tmp10 = [-1]
for i in range(N - 1):
  tmp01.append(tmp01[i]*2 % pcXi01)
  tmp10.append(tmp10[i]*2 % pcXi10)

init_n = [0] * N
next_n = [0] * N
for i in range(N):
  if X[i] == '0':
    next_n[i] = (Xmod01 + tmp01[N - 1 - i]) % pcXi01
  else:
    next_n[i] = (Xmod10 + tmp10[N - 1 - i]) % pcXi10

for i in range(N):
  fn = 0
  if i == zero_idx:
    print(0)
    continue

  n = next_n[i]
  fn += 1
  while n != 0:
    n = n % bin(n).count('1')
    fn += 1
  
  print(fn)
### BUGGY CODE ###

import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7
from math import factorial
def comb(n,r):
    return factorial(n) // (factorial(r) * factorial(n - r))

n = INT()
l = MAP()

l.sort()
res=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]+l[j]<=l[k]:
                res+=n-k
                break
        else:
            break


print(comb(n,3)-res)

### FIXED CODE ###

import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n = INT()
l = MAP()

l.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        idx = bisect.bisect_left(l,l[i]+l[j])
        ans+=idx-j-1

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

N = int(input())
*A, = map(int, input().split())
C = [0]*4
for a in A:
    C[a] += 1

c1, c2, c3 = C[1:]
dp = [[[0]*301 for i in range(301)] for j in range(301)]
for c in range(c3+1):
    M1 = c2+c3-c
    for b in range(M1+1):
        M2 = N-b-c
        for a in range(M2==N, M2+1):
            r = N
            if a:
                r += a*dp[a-1][b][c]
            if b:
                r += b*dp[a+1][b-1][c]
            if c:
                r += c*dp[a][b+1][c-1]
            dp[a][b][c] = r / (a+b+c)
print("%.10f" % dp[c1][c2][c3])

### FIXED CODE ###

N = int(input())
*A, = map(int, input().split())
C = [0]*4
for a in A:
    C[a] += 1

c1, c2, c3 = C[1:]
dp = [[[0]*(c1+c2+c3+1) for i in range(c2+c3+2)] for j in range(c3+2)]
for c in range(c3+1):
    M1 = c2+c3-c
    T = dp[c-1]
    S = dp[c]
    for b in range(M1+1):
        M2 = N-b-c
        X = S[b-1]; Y = S[b]
        Z = T[b+1]
        for a in range(M2==N, M2+1):
            r = N
            if a:
                r += a*Y[a-1]
            if b:
                r += b*X[a+1]
            if c:
                r += c*Z[a]
            Y[a] = r / (a+b+c)
print("%.10f" % dp[c3][c2][c1])
### BUGGY CODE ###

import sys

S = input()


for i in range(2**(len(S)+1)):
    op_list = [""]*(len(S)+1)

    for j in range(len(op_list)):
        if (i>>j) & 1:
            op_list[j] = "A"

    s = ""

    for k in range(len(op_list)-1):
        s = s + op_list[k] + S[k]

    s = s + op_list[len(op_list)-1]

    if s=="AKIHABARA":
        print("YES")
        sys.exit()

print("NO")

### FIXED CODE ###

import sys

S = input()

if len(S)>=10:
    print("NO")
    sys.exit()

for i in range(2**(len(S)+1)):
    op_list = [""]*(len(S)+1)

    for j in range(len(op_list)):
        if (i>>j) & 1:
            op_list[j] = "A"

    s = ""

    for k in range(len(op_list)-1):
        s = s + op_list[k] + S[k]

    s = s + op_list[len(op_list)-1]

    if s=="AKIHABARA":
        print("YES")
        sys.exit()

print("NO")
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
sum = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        sum += (a[i] * a[j]) % (10**9 + 7)
        sum = sum % (10**9 + 7)
print(sum)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
sum = sum(a)
s = 0
c = 0
for i in range(n - 1):
    s += a[i]
    c = (c + (a[i] * (sum - s)))  % (10**9 + 7)
print(c)
### BUGGY CODE ###

N = int(input())
li = list(map(int, input().split()))
for i in range(1, N + 1):
  print(li.index(i) + 1, end = ' ')

### FIXED CODE ###

N = int(input())
li = list(map(int, input().split()))
ans = [0] * N
num = 1
for i in li:
    ans[i - 1] = num
    num += 1
print(*ans)
### BUGGY CODE ###

import collections
N = int(input())
stock = dict()
ans = 0
for i in range(N):
    s = list(input())
    s.sort()
    c = str(s)
    for k, v in stock.items():
        #print(sto)
        #print(c)
        #print(sto == c)
        if c == k:
            ans += v
            stock[k] += 1
            break
    else:
        stock[c] = 1
print(ans)

### FIXED CODE ###

import collections
N = int(input())
stock = dict()
ans = 0
for i in range(N):
    c="".join(sorted(input()))
    if c in stock:
        ans += stock[c]
        stock[c] += 1
    else:
        stock[c] = 1
print(ans)
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def all_group_members(self):
        return [set(self.members(r)) for r in self.roots()]

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n, m = map(int, input().split())
    P = {i : int(p) - 1 for i, p in enumerate(input().split())}
    uf = UnionFind(n)
    for _ in range(m):
        x, y = map(lambda x:int(x) - 1, input().split())
        uf.union(x, y)
    ans = 0
    for g in uf.all_group_members():
        Q = set([P[p] for p in g])
        ans += len(g & Q)
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def all_group_members(self):
        return [set(self.members(r)) for r in self.roots()]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n, m = map(int, input().split())
    P = list(map(lambda x:int(x) - 1, input().split()))
    uf = UnionFind(n)
    for _ in range(m):
        x, y = map(lambda x:int(x) - 1, input().split())
        uf.union(x, y)
    ans = 0
    for i, p in enumerate(P):
        if uf.same(i, p):
            ans += 1
    print(ans)

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

import bisect

n, m = map(int, input().split())
aaa = list(map(int, input().split()))
aaa.sort()

for i in range(m):
  a = aaa.pop(-1)
  a = a // 2
  insert_index = bisect.bisect_left(aaa, a)
  aaa.insert(insert_index, a)
  
print(sum(aaa))

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
aaa = [-1 * int(a) for a in input().split()]
heapq.heapify(aaa)

for i in range(m):
  a = -heapq.heappop(aaa) // 2
  heapq.heappush(aaa, -a)
  
print(-sum(aaa))
### BUGGY CODE ###

from collections import Counter
n,p=map(int,input().split())
s=input()
def U(x):
    return int(s[x:])
if p in [2,5]:
    keta=0
    ans=0
    for i in range(n):
        keta+=1
        if int(s[i])%p==0:
            ans+=keta
    print(ans)
    exit()


ikeru=[U(x)%p for x in range(n)]+[0]
ans=0
C=Counter(ikeru)
for t in C.values():
    if t ==0:continue
    ans+= t*(t-1)//2
print(ans)

### FIXED CODE ###

from collections import Counter
n,p=map(int,input().split())
A=list(map(int,input()))
def U(x):
    return int(A[x:])
if p in [2,5]:
    keta=0
    ans=0
    for i in range(n):
        keta+=1
        if int(A[i])%p==0:
            ans+=keta
    print(ans)
    exit()
    
acc = [0 for i in range(n)] 
cur = A[-1] % p
acc[-1] = cur
k = 1
for i in range(n-2, -1, -1):
    cur += pow(10, k, p) * A[i]
    cur %= p
    acc[i] = cur
    k += 1
acc = acc + [0]
 
C = Counter(acc)
ans = 0
for v in C.values():
    ans += v * (v-1) // 2
print(ans)
### BUGGY CODE ###

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

for i in range(1, len(a)+1):
    b = a[0:i-1]+a[i:len(a)]
    
    cnt = 0
    for j in range (1, len(a)):
        cnt += b.count(j)*(b.count(j)-1)/2
    print(int(cnt))

### FIXED CODE ###

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

num_list = [0]* (len(a)+1)

for i in range(len(a)):
#    num_list[i] = a.count(i)
    num_list[a[i]] += 1

total = 0

for j in range(len(num_list)):
    total += (num_list[j]* (num_list[j]-1))/2

#print(total)

for k in range(len(a)):
#    print(num_list[a[k]]) 
    print(int(total-(num_list[a[k]])+1))
"""
import math

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

cnt = flaot(0.0)

for i in range(1, len(a)+1):
    b = a[0:i-1]+a[i:len(a)]
    
    cnt = 0.0
    for j in range (1, len(a)):
        cnt += b.count(j)*(b.count(j)-1)/2
    print(int(cnt))
"""
### BUGGY CODE ###

import bisect
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
BC = [ list(map(int, input().split())) for _ in range(m) ]
BC.sort(key=lambda x:x[1], reverse=True)
for b, c in BC:
  d = bisect.bisect_left(A, c)
  t = min(d, b)
  for i in range(t):
    A[i] = c
  if b >= d:
    print(sum(A))
    exit()
  else:
    A = A[b:d] + A[:b] + A[d:]
print(sum(A))

### FIXED CODE ###

from operator import itemgetter
n, m = map(int, input().split())
A = [(1, i) for i in map(int, input().split())]
BC = [ tuple(map(int, input().split())) for _ in range(m) ]
XY = sorted(A + BC, reverse=True, key=itemgetter(1))
c = n
now = 0
ans = 0
while c > 0 and now < n+m:
  x, y = XY[now]
  t = min(c, x)
  ans += y*t
  c -= t
  now += 1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
ok = True
for i in a:
  ans *= i
  if ans > 1000000000000000000:
    ok = False
  if i == 0:
    print(0)
    exit()
if ok:
  print(ans)
else:
  print(-1)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
ok = True
for i in a:
  if ok == True:
    ans *= i
  if ans > 1000000000000000000:
    ok = False
  if i == 0:
    print(0)
    exit()
if ok:
  print(ans)
else:
  print(-1)
### BUGGY CODE ###

import numpy
H, W, D = map(int, input().split())
A = numpy.array([list(map(int, input().split())) for i in range(H)])
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]


for l, r in LR:
    ans = 0
    z = l
    while z != r:
        zahyo1 = numpy.where(A==z)
        x1, y1 = int(zahyo1[0]), int(zahyo1[1])
        zahyo2 = numpy.where(A==z+D)
        x2, y2 = int(zahyo2[0]), int(zahyo2[1])
        ans += (abs(x1-x2)+abs(y1-y2))
        z = z + D
    print(ans)

### FIXED CODE ###


H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]
d = [0] * ((H*W)+1)
num_dict = {}
y = 0
for aa in A:
    x = 0
    for a in aa:
        num_dict[a] = [x, y]
        x += 1
    y += 1

for i in range(D+1, H*W+1):
    d[i] = d[i-D] + abs(num_dict[i][0]-num_dict[i-D][0]) + abs(num_dict[i][1]-num_dict[i-D][1])
for l, r in LR:
    print(d[r]-d[l])
### BUGGY CODE ###

n = int(input())
s = input()
ans = 0
len_s = len(s)

for i in range(len_s):
    for j in range(i+1, len_s):
        if s[i] == s[j]:
            continue
        for k in range(j+1, len_s):
            if (s[i] != s[j] and s[i] != s[k] and s[j] != s[k]) and (j-i != k-j):
                ans += 1

print(ans)


### FIXED CODE ###

n = int(input())
s = input()
ans = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i+1, n-1):
        k = 2 * j - i
        if(k < n):
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ans -= 1

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

def warshall_floyd(d, n):
    # d: 隣接行列(正方行列)
    # n: 頂点数

    # i -> j の最短距離を計算する
    for k in range(n):
        for i in range(n):
            for j in range(n):
                # i -> k -> j と頂点kを挟む
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    return d


# -------------------------------------------------------------------#
import copy


def main():
    # n: 頂点数
    # w: 辺の数
    n, w = map(int, input().split())
    # v -> v ; cost: 0
    d = [[float("Inf")] * n for i in range(n)]
    for i in range(n):
        d[i][i] = 0

    # d[u][v] : 辺u-vのコスト(if not: inf)
    e = []
    for i in range(w):
        # edge: u -> v ; cost : z
        u, v = map(lambda x: int(x) - 1, input().split())
        e.append([u, v])
        # 無向グラフを想定
        d[u][v] = 1
        d[v][u] = 1

    ans = 0
    for (u, v) in e:
        dd = copy.deepcopy(d)
        dd[u][v] = float("Inf")
        dd[v][u] = float("Inf")

        wd = warshall_floyd(dd, n)

        for res in wd:
            if float("Inf") in res:
                ans += 1
                break

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import copy


def main():
    # n: 頂点数
    # w: 辺の数
    n, w = map(int, input().split())
    # v -> v ; cost: 0
    d = [[False] * n for i in range(n)]

    # d[u][v] : 辺u-vのコスト(if not: inf)
    e = []
    for i in range(w):
        # edge: u -> v ; cost : z
        u, v = map(lambda x: int(x) - 1, input().split())
        e.append([u, v])
        # 無向グラフを想定
        d[u][v] = True
        d[v][u] = True

    def dfs(graph, visited, x):
        if visited[x]:
            return
        visited[x] = True
        for i in range(n):
            if graph[x][i]:
                dfs(graph, visited, i)

    ans = 0
    for (u, v) in e:
        graph = copy.deepcopy(d)
        graph[u][v] = False
        graph[v][u] = False
        for i in range(n):
            visited = [False for _ in range(n)]
            dfs(graph, visited, i)
            if not all(visited):
                ans += 1
                break
    print(ans)


if __name__ == "__main__":
    main()