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

import sys
import heapq
sys.setrecursionlimit(10 ** 8)

H, W, K = map(int, sys.stdin.readline().strip().split())
xs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())

m = []
for _ in range(H):
    m.append(list(map(str, sys.stdin.readline().strip())))

M = [[float('inf')] * W for _ in range(H)]


def bfs(x1, y1, d):
    q = []
    heapq.heapify(q)
    heapq.heappush(q, (d, (x1, y1)))

    while q:
        d, u = heapq.heappop(q)
        x1 = u[0]
        y1 = u[1]

        M[x1][y1] = d

        if (x1 == xg - 1) and (y1 == yg - 1):
            break

        for dx, dy in [[0, 1], [1, 0], [0, -1], [-1, 0]]:
            k = 1
            while k <= K:
                x2 = x1 + dx * k
                y2 = y1 + dy * k
                if x2 < 0 or x2 >= H:
                    break
                if y2 < 0 or y2 >= W:
                    break
                if m[x2][y2] == '@':
                    break
                if M[x2][y2] != float('inf'):
                    break

                heapq.heappush(q, (d + 1, (x2, y2)))

                k += 1


if m[xs - 1][ys - 1] != '@':
    bfs(xs - 1, ys - 1, 0)

# for i in range(len(M)):
#     print(M[i])


ans = M[xg - 1][yg - 1]
if ans == float('inf'):
    print(-1)
else:
    print(ans)


### FIXED CODE ###

from collections import deque


def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        # queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。
        y, x = queue.popleft()  # queueに入っていたものを消す。
        if [y, x] == [gy, gx]:  # もしゴールについていたならば、そのときの手数を出す。
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            l = 1
            while True:
                new_y, new_x = y + j * l, x + k * l
                if (0 <= new_y < H) and (0 <= new_x < W):
                    if maze[new_y][new_x] == "@":
                        break
                    elif visited[new_y][new_x] == -1:  # まだ来たことない点だったという条件
                        visited[new_y][new_x] = visited[y][x] + 1
                        queue.append([new_y, new_x])  # 新しい点を足す。
                    elif visited[new_y][new_x] < visited[y][x] + 1:
                        break
                else:
                    break
                l += 1
                if l == K + 1:
                    break


H, W, K = map(int, input().split())
# K = min(K, max(H, W))
x1, y1, x2, y2 = map(int, input().split())
x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
C = [0] * H
for i in range(H):
    C[i] = str(input())
visited = [[-1] * W for i in range(H)]
bfs(C, visited, x1, y1, x2, y2)
# print(visited)
print(visited[x2][y2])
### BUGGY CODE ###

import numpy as np
import heapq
N,M = map(int, input().split())
works_array = np.array([tuple(map(int, input().split())) for k in range(N)])
rewards = []
reward_sum = 0
heapq.heapify(rewards)
for k in range(M+1):
    indices = np.where(works_array[:,0]==k)[0]
    if indices.shape[0] != 0:
        for index in indices:
            heapq.heappush(rewards, -works_array[index, 1])
    if len(rewards) != 0:
        reward_sum += - heapq.heappop(rewards)
print(reward_sum)

### FIXED CODE ###

import heapq
N,M = map(int, input().split())
works = {}
for _ in range(N):
    a, b = map(int, input().split())
    if a not in works:
        works[a] = [b]
    else:
        works[a].append(b)
rewards = []
reward_sum = 0
for k in range(M+1):
    if k in works:
        print()
        for j in works[k]:
            heapq.heappush(rewards, -j)
    if len(rewards) != 0:
        reward_sum -= heapq.heappop(rewards)
print(reward_sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    Q = int(input())
    # Query = [list(input().split()) for _ in range(Q)]
    reverse = 1
    for _ in range(0, Q):
        T = list(input().split())
        if T[0] == "1":
            if reverse == 1:
                reverse = 2
            else:
                reverse = 1
        elif T[0] == "2":
            if int(T[1]) == reverse:
                S = T[2] + S
            else:
                S = S + T[2]
    print(S) if reverse == 1 else print(S[::-1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    Q = int(input())
    Query = [list(input().split()) for _ in range(Q)]
    reverse = 1
    head = ""
    tail = ""
    for T in Query:
        if T[0] == "1":
            if reverse == 1:
                reverse = 2
            else:
                reverse = 1
        elif T[0] == "2":
            if int(T[1]) == reverse:
                head = T[2] + head
            else:
                tail = tail + T[2]
    S = head + S + tail
    print(S) if reverse == 1 else print(S[::-1])


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

int_n = int(input())
list_x = list(map(int, input().split()))

int_sum = 0
list_calc_minus_2 = list()

#print([max(list_x[0:len(list_x)-i]) for i in range(len(list_x))])

for i in range(len(list_x)):
  #list_calc_minus_2.insert(0, max(list_x[0:len(list_x)-i]))
  int_sum = int_sum + max(list_x[0:len(list_x)-i]) - list_x[len(list_x)-i-1]
#print(list_calc_minus_2)

#print(sum([x - y for (x, y) in zip(list_calc_minus_2, list_x)]))
print(int_sum)


### FIXED CODE ###

int_n = int(input())
list_a = list(map(int, input().split()))

#print(int_n, list_a)

int_tmp_highet = 0
int_count = 0
for i in list_a:
  if i > int_tmp_highet:
    int_tmp_highet = i
  else:
    int_count = int_count + int_tmp_highet - i
  #print(int_count)

print(int_count)
### BUGGY CODE ###

import math
N = int(input())
sum = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            sum += math.gcd(math.gcd(i,j),k)
print(sum)

### FIXED CODE ###

import math
N = int(input())
sum = 0
for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range(j,N+1):
            if i == j and j == k and k == i:
                sum += math.gcd(math.gcd(i,j),k)
            elif i != j and j != k and k != i:
                sum += 6 * math.gcd(math.gcd(i,j),k)
            else:
                sum += 3 * math.gcd(math.gcd(i,j),k)
print(sum)
### BUGGY CODE ###

N = int(input())
result = 0

def make_divisors(n):
    lower_divisors = []
    upper_divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)

    upper_divisors.reverse()
    return lower_divisors + upper_divisors

for num in range(1, N+1):
	result += len(make_divisors(num)) * num
print(result)

### FIXED CODE ###

N = int(input())
divisors = [1 for _ in range(N+1)]
result = 0

for n in range(2, N+1):
  for m in range(n, N+1, n):
    divisors[m] += 1
for i, d in enumerate(divisors):
  result += i * d
print(result)
### BUGGY CODE ###

import sys
import collections

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n = ri()
a = rl()
c = collections.Counter(a)
dp = [-1] * 2*10**5
for i in a:
    if dp[i-1] != -1:
        print(dp[i-1])
        continue
    ans = 0
    for k, v in c.items():
        ci = v
        if k == i:
            ci = max(0, v-1)
        ans += ci*(ci-1)//2
    dp[i-1] = ans
    print(ans)

### FIXED CODE ###

import sys
import collections
ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n = ri()
a = rl()
c = collections.Counter(a)
t = 0
for v in c.values():
    t += v*(v-1)//2

for i in a:
    print(t-c[i]+1)
### BUGGY CODE ###

a,b,n = map(int,input().split())
ans = -int(1e18)
for i in range(min(b, n+1)):
    ans = max(ans,(a*i//b)-a*(i//b))
print(ans)


### FIXED CODE ###

a,b,n = map(int,input().split())
# ans = -int(1e18)
# for i in range(min(b, n+1)):
#     ans = max(ans,(a*i//b)-a*(i//b))
ans = a*min(b-1, n)//b
print(ans)
### BUGGY CODE ###

import sys
from math import ceil

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

def check(k):
    tmp = list(h)
    for i in range(N):
        tmp[i] -= B*k
    if sum([int(i<=0) for i in tmp]) == N:
        return True

    lf = 0
    for i in tmp:
        if i > 0:
            lf += ceil(i/(A-B))

    if lf <= k:
        return True
    else:
        return False

N,A,B = map(int,input().split())
h = tuple(int(input()) for _ in range(N))
m = max(h)
s = sum(h)

left = -1
right = 1e9

while abs(left-right) > 1:

    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(int(right))


### FIXED CODE ###

import sys
from math import ceil

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

def check(k):
    tmp = list(h)
    for i in range(N):
        tmp[i] -= B*k
    if sum([int(i<=0) for i in tmp]) == N:
        return True

    lf = 0
    for i in tmp:
        if i > 0:
            lf += ceil(i/(A-B))

    if lf <= k:
        return True
    else:
        return False

N,A,B = map(int,input().split())
h = tuple(int(input()) for _ in range(N))

left = -1
right = 1e9

while abs(left-right) > 1:

    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(int(right))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N,Q = map(int,input().split())
to = [[] for _ in range(N+1)]
ans = [0 for _ in range(N+1)]

for _ in range(N-1):
    a,b=map(int,input().split())
    to[a].append(b)
    to[b].append(a)
for _ in range(Q):
    p,x = map(int,input().split())
    ans[p] += x

def dfs(v, p):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)
dfs(1, -1)
print(*ans[1:])


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N,Q = map(int,input().split())
to = [[] for _ in range(N+1)]
ans = [0 for _ in range(N+1)]

for _ in range(N-1):
    a,b=map(int,input().split())
    to[a].append(b)
    to[b].append(a)
for _ in range(Q):
    p,x = map(int,input().split())
    ans[p] += x

def dfs(v, p):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)
dfs(1, -1)
print(*ans[1:])
### BUGGY CODE ###

from heapq import heappush, heappop
n,q=map(int,input().split())
a=[]
for i in range(n):
  s,t,x=map(int,input().split())
  s-=x
  t-=x
  a.append([s,t,x])
a=sorted(a,reverse=True)
heap=[]
ans=[]
for i in range(q):
  d=int(input())
  while a and a[-1][0]<=d:
    e=a.pop()
    heappush(heap,(e[2],e[1]))
  while heap and heap[0][1]<=d:
    heappop(heap)
  if heap:
    ans.append(heap[0][0])
  else:
    ans.append(-1)

for i in ans:
  print(i)


### FIXED CODE ###

import sys
from heapq import heappush, heappop
n,q=map(int,input().split())
a=sorted(((s-x, t-x, x) for _ in range(n) for s, t, x in (map(int, sys.stdin.readline().split()),)), reverse=True)
heap=[]
ans=[]
for i in range(q):
  d=int(input())
  while a and a[-1][0]<=d:
    e=a.pop()
    heappush(heap,(e[2],e[1]))
  while heap and heap[0][1]<=d:
    heappop(heap)
  if heap:
    ans.append(heap[0][0])
  else:
    ans.append(-1)

print(*ans, sep='\n')
### BUGGY CODE ###


import heapq
h,w,k = list(map(int, input().split()))
x1,y1,x2,y2 = list(map(int, input().split()))
x1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1
c = [[]*w for _ in range(h)]
dp = [[0]*w for _ in range(h)]
que = []
for i in range(h):
  for j,s in enumerate(input()):
    c[i].append(s)
    if s != '.':
      dp[i][j] = -1

ans = 0
dp[x1][y1] = 1
heapq.heappush(que, (dp[x1][y1], [x1,y1]))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
flg = 0
while que:
  p= heapq.heappop(que)
  p = p[1]
  if (p[0] == x2) &( p[1] == y2):break
  for i in range(4):
    for ki in range(1,k+1):
      nx = p[0] + dx[i]*ki
      ny = p[1] + dy[i]*ki
      if (nx>=0) & (nx<=(h-1)) & (ny>=0) & (ny<=(w-1)):
        if dp[nx][ny] == -1:break
        if dp[nx][ny] == 0:
          dp[nx][ny] = dp[p[0]][p[1]] + 1
          if (nx == x2) &( ny == y2):exit( print(dp[x2][y2]-1))
          heapq.heappush(que, (dp[nx][ny], [nx,ny]))

if dp[x2][y2] != 0:
  print(dp[x2][y2]-1)
else:
  print(-1)

### FIXED CODE ###

#import heapq
from collections import deque
h,w,k = list(map(int, input().split()))
x1,y1,x2,y2 = list(map(int, input().split()))
x1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1
dp = [[-1]*w for _ in range(h)]
#que = []
que = deque()
c = [input() for _ in range(h)]

dp[x1][y1] = 0
#heapq.heappush(que, (dp[x1][y1], [x1,y1]))
que.append((x1,y1))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while que:
  x,y=que.popleft()
  if x==x2 and y==y2:
    exit(print(dp[x][y]))
  for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:
    for i in range(1,k+1):
      xx=x+dx*i
      yy=y+dy*i
      if not(0<=xx<h and 0<=yy<w) or c[xx][yy]=="@":break
      if 0<=dp[xx][yy]<=dp[x][y]:break
      if dp[xx][yy]==-1:que.append((xx,yy))
      dp[xx][yy]=dp[x][y]+1
print(-1)
### BUGGY CODE ###

N = int(input())
strX = input()

#10進数に変換
decX = int(strX,2)

#1の数をカウント
pop_c = strX.count('1')

# X % popcount+1
f_p = decX % (pop_c + 1)

# X % popcount-1(0になる時は0)
if pop_c == 1:
  f_m = 0
else:
  f_m = decX % (pop_c - 1)

#(2**i)÷popcountを保存するリストを作成
f_tp = [0] * N  
f_tm = [0] * N  

for i in range(0,N):
  f_tp[i] = (2**(N-1-i)) % (pop_c + 1) 
  if pop_c - 1 == 0:
    f_tm[i] = 0
  else:
    f_tm[i] = (2**(N-1-i)) % (pop_c - 1) 

  
for i in range(0,N):
  if strX[i] == '0':
    pop_a = (f_p + f_tp[i]) % (pop_c + 1) 
    Ans = 1
    
  elif strX[i] == '1' and pop_c == 1:
    pop_a = 0
    Ans = 0
    
  else:
    pop_a = f_m - f_tm[i]
    if pop_a < 0:
      pop_a = pop_a + pop_c - 1
    Ans = 1
  
  while pop_a > 0:
    wkpop = bin(pop_a).count('1')
    pop_a = pop_a % wkpop
    Ans += 1
  
  print(Ans)


### FIXED CODE ###

N = int(input())
strX = input()

#10進数に変換
decX = int(strX,2)

#1の数をカウント
pop_c = strX.count('1')

# X % popcount+1
f_p = decX % (pop_c + 1)

# X % popcount-1(0になる時は0)
if pop_c == 1:
  f_m = 0
else:
  f_m = decX % (pop_c - 1)

for i in range(0,N):
  if strX[i] == '0':
    pop_a = (f_p + pow(2,(N-1-i),(pop_c + 1))) % (pop_c + 1) 
    Ans = 1
    
  elif pop_c == 1:
    pop_a = 0
    Ans = 0
    
  else:
    pop_a = f_m - (pow(2,(N-1-i),(pop_c - 1)))
    if pop_a < 0:
      pop_a = pop_a + pop_c - 1
    Ans = 1
  
  while pop_a > 0:
    wkpop = bin(pop_a).count('1')
    pop_a = pop_a % wkpop
    Ans += 1
  
  print(Ans)
### BUGGY CODE ###

N = int(input())
print(sum(range(1,N)))

### FIXED CODE ###

N = int(input())
print(N*(N-1)//2)
### BUGGY CODE ###

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

mod=10**9+7
ans=0
cnt=[[0]*2 for _ in range(60)]

for x in A:
    for i in range(60):
        a=x%2
        x//=2
        cnt[i][a]+=1

for p,q in enumerate(cnt):
    i,j=q
    ans+=((i*j)%mod)*pow(2,p,mod)
    ans%=mod
    
print(ans)

### FIXED CODE ###

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

mod=10**9+7
ans=0
cnt=[[0]*2 for _ in range(60)]

for x in A:
    for i in range(60):
        a=x%2
        x//=2
        cnt[i][a]+=1

for p,q in enumerate(cnt):
    i,j=q
    ans+=((i*j)%mod)*pow(2,p,mod)
    ans%=mod
    
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
x0 = n
x1 = n
count = 0
while x0 >= 0 :
  x0 -= k
  count += 1
else:
  if min(x0+k,-x0) ==x0+k:
    print(x0+k)
  else :
    print(-x0)

### FIXED CODE ###

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

from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        for c in range(b+1, bisect_left(L,L[a]+L[b])):
            cnt += 1
print(cnt)

### FIXED CODE ###

from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        cnt += bisect_left(L,L[a]+L[b])-(b+1)
print(cnt)
### BUGGY CODE ###

temp = input().split()
n,total = int(temp[0]), int(temp[1])
find = False
for a in range(n+1):
    for b in range(n+1):
        for c in range(n+1):
            if a+b+c == n and a*10000 + b*5000 + c*1000 == total:
                print('{} {} {}'.format(a,b,c))
                find = True
                break
        else:
            continue
        break
    else:
        continue
    break

if not find:
    print('{} {} {}'.format(-1,-1,-1))

### FIXED CODE ###

temp = input().split()
n,total = int(temp[0]), int(temp[1])

find = False
for a in range(n+1):
    for b in range(n+1):
        c = (-a) + (-b) + n
        if c >= 0 and a*10000 + b*5000 + c*1000 == total:
            print('{} {} {}'.format(a,b,c))
            find = True
            break
    else:
        continue
    break

if not find:
    print('{} {} {}'.format(-1,-1,-1))
### BUGGY CODE ###

n = int(input())

for x in range(1, 10**6+1):
    if x**2 >= n:
        y = x
        break

i, j = y, y
while True:
    if i*j == n:
        ans = i + j - 2
        break
    elif i*j > n:
        i -= 1
    elif i*j < n:
        j += 1

print(ans)

### FIXED CODE ###

import math

n = int(input())

ans  = 10 ** 12 
for i in range(1, math.floor(math.sqrt(n)) + 1):
    if n%i != 0:
        continue
    j = int(n/i)
    ans = min(ans, i+j-2)

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

import bisect
import numpy as np
n, q = map(int, input().split())
s = input()
ac = 'AC'
args = []
for i in range(len(s) - 1):
    if s[i:i+2] == 'AC':
        args.append(i)
args = np.array(args)
for j in range(q):
    l, r = map(int, input().split())
    i_l = bisect.bisect_left(args, l-1)
    i_r = bisect.bisect_right(args, r-2)
    print(len(args[i_l:i_r]))

### FIXED CODE ###

import bisect
n, q = map(int, input().split())
s = input()
ac = 'AC'
args = []
for i in range(len(s) - 1):
    if s[i:i+2] == 'AC':
        args.append(i)
for j in range(q):
    l, r = map(int, input().split())
    i_l = bisect.bisect_left(args, l-1)
    i_r = bisect.bisect_right(args, r-2)
    print(i_r - i_l)
### BUGGY CODE ###

import heapq

def main():
    N, M = map(int, input().split())

    n_list = list(map(int, input().split()))
    heapq.heapify(n_list)

    for i in range(M):
        b, c = map(int, input().split())
        for i in range(b):
            n = heapq.heappop(n_list)
            if c > n:
                heapq.heappush(n_list, c)
            else:
                heapq.heappush(n_list, n)
                break

    print(sum(n_list))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import heapq

def main():
    N, M = map(int, input().split())
    n_list = map(int, input().split())
    n_dic = {}
    for n in n_list:
        n_dic.setdefault(n, 0)
        n_dic[n] += 1
    
    for i in range(M):
        b, c = map(int, input().split())
        n_dic.setdefault(c, 0)
        n_dic[c] += b
    
    com_list = []

    for score, num in n_dic.items():
        heapq.heappush(com_list, (-score, num))
    
    taken = 0
    result = 0

    while True:
        score, num = heapq.heappop(com_list)
        score = -score
        if N - taken > num:
            result += score * num
            taken += num
        else:
            result += score * (N - taken)
            break
    
    print(result)

main()
### BUGGY CODE ###

def mod_pow(x, n, mod):
    if n == 0:
        return 1
    if n % 2 == 1:
        return x * mod_pow(x, n - 1, mod) % mod
    else:
        return mod_pow(x, n // 2, mod) ** 2 % mod

def choose(n, m, mod):
    x, y = 1, 1
    for i in range(m):
        x *= (n - i) % mod
        y *= (i + 1) % mod
    return x * mod_pow(y, mod - 2, mod) % mod

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

ans = (mod_pow(2, n, mod) - 1 - choose(n, a, mod) - choose(n, b, mod)) % mod
print(ans)

### FIXED CODE ###

def choose(n, m, mod):
    x, y = 1, 1
    for i in range(m):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    return x * pow(y, mod - 2, mod) % mod

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

ans = (pow(2, n, mod) - 1 - choose(n, a, mod) - choose(n, b, mod)) % mod
print(ans)
### BUGGY CODE ###

import itertools

ans = 0

N, A = map(int, raw_input().split())

x = map(int, raw_input().split())

for i in range(N):
  for element in itertools.combinations(x, i + 1):
    if sum(element) / (i + 1.0) == A:
      ans += 1

print ans

### FIXED CODE ###

n, a = map(int, input().split())
x = [ int(i) for i in input().split() ]

dp = [ [[0] * 3000 for _ in range(55)] for __ in range(55) ]
dp[0][0][0] = 1

for j in range(n+1):
    for k in range(n+1):
        for s in range(2555):
            if j > 0 and x[j-1] > s:
                dp[j][k][s] = dp[j-1][k][s]
            elif j > 0 and k >= 1 and s >= x[j-1]:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]

ans = 0

for k in range(1, n+1):
    ans += dp[n][k][k*a]

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

import numpy as np
from functools import lru_cache


@lru_cache(maxsize=40000)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total += gcd(gcd(i, j), k)

print(total)


### FIXED CODE ###

import math as f

K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        ij = f.gcd(i, j)
        if ij == 1:
            total += K
            continue
        for k in range(1, K + 1):
            total += f.gcd(ij, k)

print(total)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

#output
import numpy as np
A = np.array(A)
F = np.array(F)

A = np.sort(A)[::-1]
F = np.sort(F)
B = np.sum(A)
M = max([a*f for a, f in zip(A, F)])

def is_possible(x):
    return B - np.minimum(A, x//F).sum() <= K

for i in range(M):
    if is_possible(i):
        print(i)
        break


### FIXED CODE ###

import sys
input = sys.stdin.readline

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

#output
import numpy as np
A = np.array(A)
F = np.array(F)

A = np.sort(A)[::-1]
F = np.sort(F)
B = np.sum(A)
M = max([a*f for a, f in zip(A, F)])

def is_possible(x):
    return B - np.minimum(A, x//F).sum() <= K

left = -1
right = M
while left + 1 < right:
    mid = (left + right)//2
    if is_possible(mid):
        right = mid
    else:
        left = mid

print(right)
### BUGGY CODE ###

dictionary = []
for making in range(int(input())) :
    action = input().split()
    if action[0] == 'insert' : dictionary.append(action[1])
    else : 
        if action[1] in dictionary : print('yes')
        else : print('no')

### FIXED CODE ###

from collections import deque
dictionary = set()
for making in range(int(input())) :
    action = input().split()
    if action[0] == 'insert' : dictionary.add(action[1])
    else : 
        if action[1] in dictionary : print('yes')
        else : print('no')
### BUGGY CODE ###

s = input()
ans = 0
for i in range(len(s) + 1):
    tmp, tmpb = 0, 0
    for j in range(len(s)):
        if i > j:
            if s[j] == '<':
                tmp += 1
            else:
                tmp = 0
        else:
            if s[j] == '>':
                tmpb += 1
            else:
                break
    ans += max(tmp, tmpb)

print(ans)
    

### FIXED CODE ###

s = input()
ans = 0
t = [0 for i in range(len(s) + 1)]
tmp = 0
for i in range(1, len(s) + 1):
    if s[i - 1] == '<':
        tmp += 1
    else:
        tmp = 0
    t[i] = tmp

ans += t[len(s)]
tmp = 0
for i in range(len(s) - 1, -1, -1):
    if s[i] == '>':
        tmp += 1
    else:
        tmp = 0
    ans += max(tmp, t[i])
    
print(ans)