Harryxun/stf_run huggingface dataset:
from collections import deque

d = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def bfs(n):
    global pos_x, pos_y
    while len(que) != 0:
        x, y = que.popleft()
        for dx, dy in d:
            if 0 <= x + dx < W and 0 <= y + dy < H:
                if meiz[x + dx][y + dy] == str(n):
                    pos_x = x + dx
                    pos_y = y + dy
                    # print(distance)
                    return distance[x][y] + 1
                elif meiz[x + dx][y + dy] != "X" and distance[x + dx][y + dy] == float("inf"):
                    distance[x + dx][y + dy] = distance[x][y] + 1
                    # print(distance)
                    que.append((x + dx, y + dy))


if __name__ == '__main__':
    H, W, N = list(map(int, input().split()))
    meiz = [input() for i in range(H)]

    pos_x = 0
    for tmp in meiz:
        if tmp.find("S") != -1:
            pos_y = tmp.find("S")
            break
        pos_x += 1

    ans = 0
    for i in range(1, N + 1):
        distance = [[float("inf") for i in range(W)] for i in range(H)]
        distance[pos_x][pos_y] = 0
        que = deque()
        que.append((pos_x, pos_y))
        # print(que)
        ans += bfs(i)

    print(ans)

### FIXED CODE ###

from collections import deque

INF = 100000000
H, W, N = list(map(int, input().split()))
maze = [list(input()) for i in range(H)]

x = -1
for letters in maze:
    x += 1
    y = -1
    for letter in letters:
        y += 1
        if letter == "S":
            sx = x
            sy = y
        elif letter == str(N):
            gx = x
            gy = y

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def bfs():
    count = 0
    backup = []
    for tmp_goal in range(1, N + 1):
        d = [[INF for i in range(W)] for j in range(H)]
        if tmp_goal == 1:
            q = deque([[sx, sy]])
            d[sx][sy] = 0
        else:
            q = deque([backup])
            d[backup[0]][backup[1]] = count

        while len(q) != 0:
            tmp_x, tmp_y = q.popleft()
            if maze[tmp_x][tmp_y] == str(tmp_goal):
                count = d[tmp_x][tmp_y]
                backup = [tmp_x, tmp_y]
                q.clear()
                break
            for j in range(0, 4):
                nx = tmp_x + dx[j]
                ny = tmp_y + dy[j]
                if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] != "X" and d[nx][ny] == INF:
                    q.append([nx, ny])
                    d[nx][ny] = d[tmp_x][tmp_y] + 1
    return count


if __name__ == '__main__':
    ans = bfs()
    print(ans)
from math import gcd

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



# L[0] = 0
# L[i] (i=1, ..., N)にはA_1, ..., A_iの最大公約数が格納されている

L = []
L.append(A[0])

for i in range(N):
    L.append(gcd(L[i], A[i]))

#  for i in range(N+1):
    #  print(L[i])


# R[N+1] = 0
# R[i] (i=N, N-1, ..., 1)にはA_i, ..., A_Nの最大公約数が格納されている

R = [0] * (N+2)
# R = [0, 0, 0, ... , 0] (0がN+2個)
R[N+1] = A[N-1]

for i in range(N, 0, -1):
    R[i] = gcd(A[i-1], R[i+1])

#  for i in range(N+1, -1, -1):
    #  print(R[i])



# M[i] (i=0, ..., N-1)にはA_(i+1)を除いた整数の最大公約数が格納されている

M = []
for i in range(N):
    M.append(gcd(L[i], R[i+2]))

print(max(M))


### FIXED CODE ###

from fractions import gcd

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



# L[0] = 0
# L[i] (i=1, ..., N)にはA_1, ..., A_iの最大公約数が格納されている

L = []
L.append(0)

for i in range(N):
    L.append(gcd(L[i], A[i]))

#  for i in range(N+1):
    #  print(L[i])


# R[N+1] = 0
# R[i] (i=N, N-1, ..., 1)にはA_i, ..., A_Nの最大公約数が格納されている

R = [0] * (N+2)
# R = [0, 0, 0, ... , 0] (0がN+2個)

for i in range(N, 0, -1):
    R[i] = gcd(A[i-1], R[i+1])

#  for i in range(N+1, -1, -1):
    #  print(R[i])



# M[i] (i=0, ..., N-1)にはA_(i+1)を除いた整数の最大公約数が格納されている

M = []
for i in range(N):
    M.append(gcd(L[i], R[i+2]))

print(max(M))
import numpy as np
from math import gcd

def LGcd(l):
    a = l[0]
    for i in range(1,len(l)):
        a = gcd(a,l[i])
    return a
N, X = map(int,input().split())
k = np.array(input().split())
k = k.astype(np.int32)
k -= X
if N == 1:
    print(str(abs(k[0])))
else:
    print(str(LGcd(k)))

### FIXED CODE ###

# 正の数を受け取るように定義
def gcd(a,b):
    if b == 0:
        return a 
    return gcd(b,a % b)

N, X = map(int,input().split())
k = [abs(int(x) - X) for x in input().split()] # リスト内包表記で入力の受け取り
a = k[0]
for i in range(1,N):
    a = gcd(a,k[i])
print(str(a))
from fractions import gcd

d = int(input())
nums = list(map(int, input().split(' ')))

def lcm_base(x, y):
  return (x * y) // gcd(x, y)


lcm_num = 1
for i in range(len(nums)):
  lcm_num = lcm_base(lcm_num, nums[i])

ans = 0
for n in nums:
  ans += int(lcm_num / n)
print(ans % (10**9 + 7))

### FIXED CODE ###

from fractions import gcd

def lcm_base(x, y):
  return x * y // gcd(x, y)

d = int(input())
nums = list(map(int, input().split(' ')))

lcm_num = 1
for n in nums:
  lcm_num = lcm_base(lcm_num, n)

ans = 0
mod = 10**9 + 7
for n in nums:
  ans += lcm_num//n
print(ans % mod)
import sys
sys.setrecursionlimit(10000)

N = int(input())
COR = [tuple((map(int, input().split()))) for _ in range(N)]


class Group:
    
    def __init__(self):
        self.n = 0
        self.x = []
        self.y = []
        
    def new_cor_n(self):
        return len(self.x) * len(self.y) - self.n
    
    
def grouping(group, x, xcor, ycor):
    xcor[x][1] = True
    group.x.append(x)
    for y in xcor[x][0]:
        if ycor[y][1]:
            continue
        group.n += 1
        ycor[y][1] = True
        group.y.append(y)
        for x_ in ycor[y][0]:
            if xcor[x_][1]:
                continue
            group.n += 1
            grouping(group, x_, xcor, ycor)
            
if N <= 2:
    print(0)
else:
    xcor, ycor = {}, {}
    for xi, yi in COR:
        if xi in xcor:
            xcor[xi][0].append(yi)
        else:
            xcor[xi] = [[yi], False]
        if yi in ycor:
            ycor[yi][0].append(xi)
        else:
            ycor[yi] = [[xi], False]
    group_list = []
    for x, v in xcor.items():
        if v[1]:
            continue
        group = Group()
        group_list.append(group)
        grouping(group, x, xcor, ycor)
    s = 0
    for group in group_list:
        s += group.new_cor_n()
    print(s)


### FIXED CODE ###

# import sys
# sys.setrecursionlimit(20000)


N = int(input())
COR = [tuple((map(int, input().split()))) for _ in range(N)]


class Group:
    
    def __init__(self):
        self.n = 0
        self.x = 0
        self.y = 0
        self.xy = {}
        
    def new_cor_n(self):
        return self.x * self.y - self.n
        

def grouping(group, x, xcor, ycor):
    x_list = []
    group.x += 1
    for y in xcor[x][0]:
        if (x, y) not in group.xy:
            group.n += 1
            group.xy[(x, y)] = None
        if ycor[y][1]:
            continue
        ycor[y][1] = True
        group.y += 1
        for x_ in ycor[y][0]:
            if (x_, y) not in group.xy:
                group.n += 1
                group.xy[(x_, y)] = None
            if xcor[x_][1]:
                continue
            xcor[x_][1] = True
            x_list.append(x_)
    return x_list

if N <= 2:
    print(0)
else:
    xcor, ycor = {}, {}
    for xi, yi in COR:
        if xi in xcor:
            xcor[xi][0].append(yi)
        else:
            xcor[xi] = [[yi], False]
        if yi in ycor:
            ycor[yi][0].append(xi)
        else:
            ycor[yi] = [[xi], False]
    group_list = []
    for i, v in xcor.items():
        if v[1]:
            continue
        group = Group()
        group_list.append(group)
        xcor[i][1] = True
        x_list = [i]
        while True:
            new_x_list = []
            for x in x_list:
                new_x_list += grouping(group, x, xcor, ycor)
            if new_x_list == []:
                break
            x_list = new_x_list
    s = 0
    for group in group_list:
        s += group.new_cor_n()
    print(s)
a=[ord(c)-ord('a') for c in input()]
K=int(input())

for i in range(len(a)):
    if a[i]>0 and 26-a[i]<=K:
        K-=26-a[i]
        a[i]=0
a[-1]+=K
l=[chr(ord('a')+ai) for ai in a]

print(''.join(l))

### FIXED CODE ###

s=input()
K=int(input())
ans=''
for c in s:
    if c!='a' and ord('z')+1-ord(c)<=K:
        ans+='a'
        K-=ord('z')+1-ord(c)
    else:
        ans+=c
if K>0:
    ans=ans[:-1]+chr(ord(ans[-1])+K%26)

print(ans)
n,m = map(int,input().split())
if m == n-1:
  print(0)
  exit()
if 2*(n-m-1) > n:
    print("Impossible")
    exit()

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

u = Unionfind(n)
a = list(map(int,input().split()))
for i in range(m):
    x,y = map(int,input().split())
    u.union(x,y)
count = 2*(n-m-1)
l = [[] for i in range(n)]
for i in range(n):
    x = u.find(i)
    if x < 0:
        l[i].append(a[i])
    else:
        l[x].append(a[i])

ans = 0
h = []
for i in range(n):
    if l[i]:
        l[i].sort()
        ans += l[i][0]
        count -= 1
        for j in l[i][1:]:
            h.append(j)
h.sort()
ans += sum(h[:count])
print(ans)


### FIXED CODE ###

x,y = map(int,input().split())
if x % y:
    print(x)
else:
    print(-1)
x = int(input())
if a == 3 or a == 5 or a == 7:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

x = int(input())
if x == 3 or x == 5 or x == 7:
  print("YES")
else:
  print("NO")
Weather = [Sunny, Cloudy, Rainy, Sunny]
S = input()
print(Weather[Weather.index(S)+1])

### FIXED CODE ###

Weather = ["Sunny", "Cloudy", "Rainy", "Sunny"]
S = input()
print(Weather[Weather.index(S)+1])
N, K = map(int, input().split())
As = list(map(int, input().split()))

history = {}
cycle = []
pos = 1
isEnd = False
for i in range(2*N):
    if pos in history:
        for j in range(len(cycle)):
            if cycle[j] == pos:
                head = cycle[:j]
                cycle = cycle[j:]
                isEnd = True
                break

    if isEnd:
        break

    history[pos] = 1
    cycle.append(pos)
    pos = As[pos-1]


#print(cycle)

if K <= len(head):
    print(head[K])
else:
    mod = (K-len(head)) % len(cycle)
    print(cycle[mod])


### FIXED CODE ###

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

history = {}
cycle = []
pos = 1
isEnd = False
for i in range(2*N):
    if pos in history:
        for j in range(len(cycle)):
            if cycle[j] == pos:
                head = cycle[:j]
                cycle = cycle[j:]
                isEnd = True
                break

    if isEnd:
        break

    history[pos] = 1
    cycle.append(pos)
    pos = As[pos-1]


#print(cycle)

if K < len(head):
    print(head[K])
else:
    mod = (K-len(head)) % len(cycle)
    print(cycle[mod])
N = input()

ans = chr(ord('N'+1))

print(ans)
          

### FIXED CODE ###

a = input()
print(chr(ord(a) + 1))
from collections import Counter

n = int(input())
b = [input() for _ in range(n)]
m = int(input())
r = [input() for _ in range(m)]

db, dr = [Counter(x) for x in (b, r)]
print(max(*[v-dr[k] for k, v in db.items()]+[0]))


### FIXED CODE ###

a, b, c = map(int, input().split())
print('Yes' if a+b >= c else 'No')
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n-1):
    b[a[i]-1]+=1
for i in range(n+1):
    print(b[i])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n-1):
    b[a[i]-1]+=1
for i in range(n):
    print(b[i])
import collections

n = int(input());
A = list(map(int, input().split()));

ans = [0] * n;

c = collections.Counter(A)
key = list(c.keys());
value = list(c.values());

for i in key:
  ans[i-1] = value[i-1];
  
for a in ans:
  print(a);

### FIXED CODE ###

import collections

n = int(input());
A = list(map(int, input().split()));

ans = [0] * n;

c = collections.Counter(A)
key = list(c.keys());
value = list(c.values());

for i in range(len(key)):
    ans[key[i]-1] = value[i];
  
for a in ans:
  print(a);
(a, b) = (int(tok) for tok in input().split())
print("Possible" if any(s % 3 == 0 for s in [a, b, a + b] else "Impossible")

### FIXED CODE ###

(a, b) = (int(tok) for tok in input().split())
print("Possible" if any(s % 3 == 0 for s in [a, b, a + b]) else "Impossible")
import heapq 
N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K) #KがNより大きい場合を防ぐ
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        A1 = A[:i] #前から取る
        A3 = A[N-j:] #後ろから取る
        new_A = A1+A3
        new_A.sort()
        h = K - len(new_A)
        while h >0:
            if new_A[-1] > 0:
                break
            else:
                new_A.pop()
                h-=1
        M = max(M,sum(new_A))
print(M)

### FIXED CODE ###

n,k = map(int,input().split())
v = list(map(int,input().split()))

m=[]
for i in range(k+1):
 for j in range(min(k,n)-i+1):
  # print(i,j)
  t=sorted(v[:i]+v[:~j:-1])
  while t and(k-i-j)*t[0]<0:t.pop(0);j+=1
  m+=sum(t),
print(max(m))
n=int(input())
l=[int(input()) for _ in range(n)]
ans=0
if l[0]!=0:
  print(-1)
  exit()
for i in range(n-1):
  if l[i+1]-l[i]>1:
    print(-1)
    exit()
  elif (l[i]+1==l[i+1]):
    ans+=1
  else:
	ans+=l[i+1]
print(ans)


### FIXED CODE ###

n=int(input())
l=[int(input()) for _ in range(n)]
ans=0
if l[0]!=0:
  print(-1)
  exit()
for i in range(n-1):
  if l[i+1]-l[i]>1:
    print(-1)
    exit()
  elif (l[i]+1==l[i+1]):
    ans+=1
  else:
    ans+=l[i+1]
print(ans)
#! /usr/bin/python
# -*- coding: utf-8 -*-

from bisect import *

while 1:
    (N, M) = map(int, raw_input().split())
    if N == 0: break
    r = int(raw_input())
    used = [0]*(N+1)
    imos = [[0]*1301 for i in range(1001)]
    for i in range(r):
        (t, n, m, s) = map(int, raw_input().split())
        if s == 1 and used[n] == 0:
            used[n] = m
            imos[m][t] = 1
        if s == 0 and used[n] == m:
            used[n] = 0
            imos[m][t] = -1

    q = int(raw_input())
    for i in range(q):
        (qs, qe, user) = map(int, raw_input().split())
        tmp = 0
        ans = 0
        for j in range(540, 1261):
            #if imos[user][j] == 1:
            #    tmp += 1
            if tmp > 0 and j > qs and j <= qe:
                ans += 1
            tmp += imos[user][j]
            #if imos[user][j] == -1:
            #    tmp -= 1
        print ans
                

### FIXED CODE ###

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

from bisect import *

while 1:
    (N, M) = map(int, raw_input().split())
    if N == 0: break
    r = int(raw_input())
    used = [0]*(N+1)
    imos = [[0]*1301 for i in range(M+1)]
    for i in range(r):
        (t, n, m, s) = map(int, raw_input().split())
        if s == 1 and used[n] == 0:
            used[n] = m
            imos[m][t] += 1
        if s == 0 and used[n] == m:
            used[n] = 0
            imos[m][t] -= 1
            #if imos[m][t] > 0:
            #    imos[m][t] -= 1
            #else:
            #    imos[m][t] = -1

    q = int(raw_input())
    for i in range(q):
        (qs, qe, user) = map(int, raw_input().split())
        tmp = 0
        ans = 0
        for j in range(540, 1261):
            #if imos[user][j] == 1:
            #    tmp += 1
            if tmp > 0 and j > qs and j <= qe:
                ans += 1
            tmp += imos[user][j]
            #if imos[user][j] == -1:
            #    tmp -= 1
        print ans
def larger(x, y):
	if x > y: return x
	return y

A, B = map(int, input().split())
p = A + B
m = A - B
t = A * B
print(larger(p. larger(m, t)))

### FIXED CODE ###

def larger(x, y):
	if x > y: return x
	return y

A, B = map(int, input().split())
p = A + B
m = A - B
t = A * B
print(larger(p, larger(m, t)))
def main():
    K, N = [int(_) for _ in input().split()]
    A = list(map(int, input().split()))
    mx = 0

    for i in range(N-1):
        dis = A[i+1]-A[i]
        if dis > mx:
            mx = dis
    se = A[N-1] - A[0]
    if (K-(se)) > mx:
        mx = K - se
    print(mx)
main()

### FIXED CODE ###

def main():
    s = input()
    if s[2]==s[3] and s[4]==s[5]:
            print('Yes')
    else:
        print('No')

main()
import math as m
from fractions import gcd
D,G = map(int,input().split())
info = [list(map(int,input().split())) for i in range(D)]
a = info[0][0]
L = []
for i in range(1,D):
    b = info[i][0]
    lcm = (a * b) // gcd(a,b)
    a = lcm
for i in range(1,D+1):
    p = info[i-1][0]
    c = info[i-1][1]
    L.append([lcm*100*i + c, i, p, c])
goal = G
count = 0
# 見かけの点数でソート
L.sort()
# 見かけの点数が大きい順から問題を解いていく
# i番目を全問解いた見かけのiscoreについて　
# goal - iscore >= 0 ならば i番目を解くことは確定
for i in range(D-1,-1,-1):
    iscore = 100 * L[i][1] * L[i][2] + L[i][3]
    if goal - iscore >= 0:
        goal -= iscore
        count += L[i][2]
        if goal == 0:
            break
# goal - iscore < 0 ならば　
# i番目をj問解いたscore_jが goal - score_j <= 0 となるような 最小のjをメモ
# まだ解いていない他の問題についても同様にjをメモ(存在しない場合もあり)　これらのうち最小のjを採用する
    elif goal - iscore < 0:
        adopt = 100
        for k in range(i,-1,-1):
            score = 100 * L[k][1] * L[k][2] + L[k][3]
            if goal - score <= 0:
                j = min(m.ceil(goal/(100 * L[k][1])),L[k][2])
                if j < adopt:
                    adopt = j
        count += adopt
        break
print(count)

### FIXED CODE ###

import math as m
D,G = map(int, input().split())
info = [list(map(int, input().split())) for i in range(D)]
def bfs(list_hoge=[[0,[]]],depth=0):
    queue = []
    for e in list_hoge:
        for b in [0,1]:
            if b == 0:
                score = e[0]
                copy = e[1][:]
                queue.append([score,copy])
            elif b == 1:
                score = e[0] + 100*(depth+1)*info[depth][0] + info[depth][1]
                copy = e[1][:]
                copy.append(depth)
                queue.append([score,copy])
    list_hoge = queue[:]
    if depth == len(info)-1:
        return list_hoge
    return bfs(list_hoge,depth+1)
res = bfs()
ans = float("inf")
for e in res:
    solved = 0
    for i in range(len(e[1])):
        solved += info[e[1][i]][0]
    if e[0] >= G:
        if solved < ans:
            ans = solved
        continue
    for i in range(D-1,-1,-1):
        if not i in e[1]:
            nec = G-e[0]
            haiten = 100*(i+1)
            add_solve = m.ceil(nec/haiten)
            total_solved = solved + m.ceil(nec/haiten)
            if add_solve >= info[i][0]:
                break
            if total_solved < ans:
                ans = total_solved
print(ans)
A, B, X = input(int, input().split())

if A <= X <= A+B:
    print("YES")
else:
    print("No")

### FIXED CODE ###

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

if A <= X <= A+B:
    print("YES")
else:
    print("NO")
a, b = input().split()
if a = 'H' and b ='H':
    print('H')
elif a = 'H' and b ='D':
    print('D')
elif a = 'D' and b = 'H':
    print('D')
elif a = 'D' and b = 'D':
    print('H')

### FIXED CODE ###

a, b = input().split()
if a == 'H' and b =='H':
    print('H')
elif a == 'H' and b == 'D':
    print('D')
elif a == 'D' and b == 'H':
    print('D')
elif a == 'D' and b == 'D':
    print('H')
s=sorted(list(set(list(input()))))
if len(s)==26:
    print("None")
alph=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
for i in range(26):
    if s[i]!=alph[i]:
        print(alph[i])

### FIXED CODE ###

S=sorted(list(set(list(input()))))
alph=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
sum=0
A="None"
for i in range(len(S)):
    if S[i]!=alph[i]:
        A=alph[i]
        break
if A=="None" and len(S)<26:
    A=alph[i+1]

print(A)
n = int(input())
li = []

for x in range(n):
  for y in range(n):
    if x * y == n:
      li.append(x+y-2)

result = min(li) 
print(result)

### FIXED CODE ###

n = int(input())
li = []

for x in range(1, int(n ** 0.5)+1):
  if n % x == 0:
    y = n/x
    li.append(x+y-2)  
     
result = min(li) 
print(int(result))
def get_gcd(A, B):
    r = A%B
    if r == 0:
        return B
    else:
        return get_gcd(B, r)

           
if __name__ == '__main__':
    N = int(input())
    T = [int(input()) for _ in range(N)]
    
    for n in range(N-1):
        gcd = get_gcd(T[n], T[n+1])
        T[n+1] = int(T[n]/gcd)*T[n+1]
        
    print(T[N-1])

### FIXED CODE ###

import sys

sys.setrecursionlimit = 10000000

def get_gcd(A, B):
    r = A%B
    if r == 0:
        return B
    else:
        return get_gcd(B, r)
           
if __name__ == '__main__':
    N = int(input())
    T = [int(input()) for _ in range(N)]
    
    ans = 1
    for t in T:
        gcd = get_gcd(ans, t)
        ans = t//gcd*ans
        
    print(ans)
n=int(input())
s=input()
afters={}
for i in range(n):
    afters.setdefault(s[i],0)
    afters[s[i]] += 1

befores = {'R':0, 'B':0, 'G':0}
befores[s[0]]+=1
afters[s[0]]-=1

ans=0
for i in range(1,n-1):
    head=s[0:i]
    last=s[i+1::]
    afters[s[i]]-=1
    if s[i]=='R':
        ans += befores['G'] * afters['B'] + befores['B'] * afters['G'] 
        bad =[['G','B'],['B','G']]
    elif s[i]=='B':
        ans += befores['G'] * afters['R'] + befores['R'] * afters['G'] 
        bad = [['G','R'],['R','G']]
    else:
        ans += befores['B'] * afters['R'] + befores['R'] * afters['B'] 
        bad = [['B','R'],['R','B']]
    for j in range(min(i-0, n-i-1)):
        if [s[i-j-1], s[i+j+1]] in bad:
            ans -= 1
    befores[s[i]]+=1
    

print(ans)
        

### FIXED CODE ###

n=int(input())
s=input()
afters={'R':0, 'B':0, 'G':0}
for i in range(n):
    afters[s[i]] += 1

befores = {'R':0, 'B':0, 'G':0}
befores[s[0]]+=1
afters[s[0]]-=1

ans=0
for i in range(1,n-1):
    head=s[0:i]
    last=s[i+1::]
    afters[s[i]]-=1
    if s[i]=='R':
        ans += befores['G'] * afters['B'] + befores['B'] * afters['G'] 
        bad =[['G','B'],['B','G']]
    elif s[i]=='B':
        ans += befores['G'] * afters['R'] + befores['R'] * afters['G'] 
        bad = [['G','R'],['R','G']]
    else:
        ans += befores['B'] * afters['R'] + befores['R'] * afters['B'] 
        bad = [['B','R'],['R','B']]
    for j in range(min(i-0, n-i-1)):
        if [s[i-j-1], s[i+j+1]] in bad:
            ans -= 1
    befores[s[i]]+=1
    

print(ans)
x, n = map(int, input().split())
p = list(map(int, input().split()))
if x not in p:
    print(x)
else:
    a, b = 1, 1
    while True:
        if (x + a) not in p:
            break
        else:
            a += 1

    while True:
        if (x - b) not in p:
            break
        else:
            b += 1

    if a >= b:
        print(x - b)
    else:
        print(x + a)

### FIXED CODE ###

#ABC170-A
X = list(input().split())
for i in range(5):
  if X[i] == "0":
    print(i + 1)
N, M = [int(i) for i in input().split(" ")]

for i in range(0,N)
	lst.append(input().split(" "))

for i in range(1,N+1)
	print(lst.count(i))

### FIXED CODE ###

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

for i in range(0,M):
	lst.extend(input().split(" "))
for i in range(1,N+1):
	print(lst.count("{}".format(i)))
import sys
N = int(sys.stdin.readline())
nums = [int(x) for x in sys.stdin.readline().split]

ans = 0
_min = float('inf')
for num in nums:
  if _min >= num:
    ans += 1
  _min = min(_min, num)
print(ans)

### FIXED CODE ###

import sys
N = int(sys.stdin.readline())
nums = [int(x) for x in sys.stdin.readline().split()]
 
ans = 0
_min = float('inf')
for num in nums:
  if _min >= num:
    ans += 1
  _min = min(_min, num)
print(ans)
nxt = input().split()
#print(nxt)
N = int(nxt[0]) 
X = int(nxt[1])
T = int(nxt[2])
#print(N,X,T)
tmp = N/X - int(N/X)
if tmp == 0:
    counter = int(N/X)
else:
    counter = int(N/X) + 1
#print(counter)
print(counter * T)

### FIXED CODE ###

nxt = input().split()
# print(nxt)
N = int(nxt[0])
X = int(nxt[1])
T = int(nxt[2])
# print(N,X,T)
tmp = N/X - int(N/X)
if tmp == 0:
    counter = int(N/X)
else:
    counter = int(N/X) + 1
# print(counter)
print(counter * T)