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

def LI(): return list(map(int,input().split()))
A,B,N = LI()
ans = 0
for i in range(max(N-N%B-A,1),N+1):
    temp = (A*i//B)-A*(i//B)
    ans = max(ans,temp)
print(ans)

### FIXED CODE ###

def LI(): return list(map(int,input().split()))
A,B,N = LI()
ans = 0
if B<=N:
    print(int((A/B*(B-1))//1))
else:
    print(int((A/B)*(N%B)//1))
### BUGGY CODE ###

K,S = list(map(int,input().split()))

x=0
count = 0

if S>K: n=K+1
else: n=S+1
for i in range(n):
	y=0
	while S-x>=0 and S-x<=2*K:
		if S-x-y>=0 and S-x-y<=K: count+=1
		y+=1
		if y>K: break
	x+=1
	if x>K: break

print(count)


### FIXED CODE ###

K,S = list(map(int,input().split()))

count = 0

if K>S: n=S
else: n=K
x=0
for i in range(n+1):
	if K>S-x: m=S-x
	else: m=K
	y=0
	for j in range(m+1):
		if S-x-y<=K: count +=1
		y+=1
	x+=1

print(count)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
b = []
for a in A:
    b.append(a)
    b = b[::-1]
print(*b)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A_oddList = A[::2]
A_evenList = A[1::2]
A_oddList = A_oddList[::-1]
A_evenList = A_evenList[::-1]

if N % 2 == 1:
    A_evenList = A_evenList[::-1]
    print(*A_oddList , end = " ")
    print(*A_evenList)
else:
    A_oddList = A_oddList[::-1]
    print(*A_evenList , end = " ")
    print(*A_oddList)
### BUGGY CODE ###

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

L.sort(reverse=True)
# print(L)
ans = 0
for i in range(N-2):
    A = L[i]
    for j in range(i+1,N-1):
        B = L[j]
        for k in range(j+1,N):
            C = L[k]
            if A < B + C and B < C + A and C < A + B:
                ans += 1
                # print(A,B,C)
            else:
                break

print(ans)


### FIXED CODE ###

from enum import Enum
from queue import Queue
import collections
import bisect

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

L.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        key = bisect.bisect_left(L,L[j]-L[i]+1)
        ans += max([0,i-key])

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

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
C = list(map(int, input().split()))
LRST = []
for i in range(Q):
    l, r = map(int, input().split())
    LRST.append((l-1, 0, r-1, i))


class FenwickTree(object):
    def __init__(self, n):
        self._bit = [0] * (n+1)
        self.n = n+1
    
    def add(self, i, a):
        i += 1
        while i < self.n:
            self._bit[i] += a
            i += i & -i
    
    def sum(self, i):
        i += 1
        ret = 0
        while i > 0:
            ret += self._bit[i]
            i -= i & -i
        return ret


def solve():
    memo = [-1] * N
    for i, c in enumerate(C):
        if memo[c-1] >= 0:
            LRST.append((memo[c-1], 1, i, -1))
        memo[c-1] = i
    LRST.sort(reverse=True)
    ans =[0 for _ in range(Q)]
    ft = FenwickTree(N+1)
    for sl, typ, tr, q in LRST:
        if typ == 1:
            ft.add(tr, 1)
        else:
            ans[q] = tr - sl + 1 - ft.sum(tr)
    return ans

if __name__ == "__main__":
    print('\n'.join(map(str, solve())))


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
C = list(map(int, input().split()))
LR = []
for i in range(Q):
    l, r = map(int, input().split())
    LR.append((l-1, r-1, i))


class FenwickTree(object):
    def __init__(self, n):
        self._bit = [0] * (n+1)
        self.n = n+1
    
    def add(self, i, a):
        i += 1
        while i < self.n:
            self._bit[i] += a
            i += i & -i
    
    def sum(self, i):
        i += 1
        ret = 0
        while i > 0:
            ret += self._bit[i]
            i -= i & -i
        return ret


def solve():
    memo = [-1] * N
    ST = []
    nst = 0
    for i, c in enumerate(C[::-1]):
        if memo[c-1] >= 0:
            ST.append((N-i-1, memo[c-1]))
            nst += 1
        memo[c-1] = N-i-1
    # ST.sort(reverse=True)
    LR.sort(reverse=True, key=lambda x:x[0])
    ans =[0 for _ in range(Q)]
    ft = FenwickTree(N+1)
    j = 0
    for l, r, i in LR:
        while j < nst and ST[j][0] >= l:
            ft.add(ST[j][1], 1)
            j += 1
        ans[i] = r - l + 1 - ft.sum(r)
    return ans

if __name__ == "__main__":
    print('\n'.join(map(str, solve())))
### BUGGY CODE ###

N = int(input())

l = [None] * N

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

def d(_a, _b):
    return abs(_a[0]-_b[0])+abs(_a[1]-_b[1])

print(max([d(p0,p1) for p0 in l for p1 in l]))




### FIXED CODE ###

N = int(input())

l = [None] * N

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

minX = min([e[0] for e in l])
minY = min([e[1] for e in l])
maxX = max([e[0] for e in l])
maxY = max([e[1] for e in l])

def d(_a, _b):
    return abs(_a[0]-_b[0])+abs(_a[1]-_b[1])

s0 = min([d([minX,minY], e) for e in l])
s1 = min([d([maxX,maxY], e) for e in l])
 
t0 = min([d([maxX,minY], e) for e in l])
t1 = min([d([minX,maxY], e) for e in l])
 

print(d([minX,minY], [maxX,maxY]) - min(s0+s1, t0+t1))
### BUGGY CODE ###

N = int(input())
L = []
count = 0
for i in range(N):
    S = input()
    if not S in L:
        L.append(S)
        count += 1
print(count)
    


### FIXED CODE ###

N = int(input())
L = set({})
for i in range(N):
    L.add(input())
print(len(L))
### BUGGY CODE ###

N = int(input())
arr = [int(input()) for i in range(N)]

swap_cnt = 0
i = 0
while True:
    swap_flg = False
    for j in range(N - 1, i + 1, -1):
        if (arr[j] < arr[j - 1]):
            arr[j], arr[j - 1] = arr[j - 1], arr[j]
            swap_cnt += 1
            swap_flg = True
    if (swap_flg):
        break



### FIXED CODE ###

N = int(input())
arr = [int(n) for n in input().split()]

swap_cnt = 0
swap_flg = True
i = 0
while swap_flg:
    swap_flg = False
    for j in range(N - 1, i, -1):
        if (arr[j] < arr[j - 1]):
            arr[j], arr[j - 1] = arr[j - 1], arr[j]
            swap_cnt += 1
            swap_flg = True
    i += 1

print(' '.join(map(str, arr)))
print(swap_cnt)
### BUGGY CODE ###

a,b,c,k = map(int,input().split())
if a == b:
    print(0)
    exit()
for i in range(k):
    a_o = a
    b_o = b
    c_o = c
    a = b_o + c_o
    b = a_o + c_o
    c = a_o + b_o
    if abs(a-b) > 10**18:
        print("Unfair")
        break
print(a-b)


### FIXED CODE ###

a,b,c,k = map(int,input().split())
ans = a - b
if k % 2 == 0:
    print(ans)
else:
    print(-ans)
### BUGGY CODE ###

n = input()

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

MAX = 10**18

ans = 1
for num in nums:
    ans = ans*num

if ans > MAX:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = input()
 
nums = list(map(int, input().split()))
 
MAX = 10**18

if min(nums) == 0:
    print(0)
    exit()

ans = 1
for num in nums:
    ans = ans*num 
    if ans > MAX:
        print(-1)
        exit()

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

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k = I()
    r = k * k
    for a in range(2, k+1):
        for b in range(1, k+1):
            g = fractions.gcd(a, b)
            if g == 1:
                r += k
                continue
            for c in range(1, k+1):
                r += fractions.gcd(g, c)

    return r


print(main())





### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k = I()
    r = 0
    for a,b,c in itertools.product(range(1,k+1), repeat=3):
        r += math.gcd(math.gcd(a,b), c)

    return r


print(main())
### BUGGY CODE ###

import sys
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(m)]
data=[[] for i in range(n+1)]
for u in abc:
    a,b,c=u
    data[a].append([b,c])
inf=float("inf")
lst=[-inf]*(n+1)
lst[1]=0
que=[1]
count=0
z=0
a,b,c,d=-inf,-inf,-inf,-inf
while que:
    h=[]
    for u in que:
        for v in data[u]:
            w,c=v
            lst[w]=max(lst[w],lst[u]+c)
            h.append(w)
    que=h
    count+=1
    if count==m:
        a=lst[n]
    if count==2*m+5:
        b=lst[n]
        break
    if len(que)>n:
        c=lst[n]
        z=10
    if z>=10:
        z+=1
        if z==15:
            d=lst[n]
            break
else:
    print(lst[n])
    sys.exit()
if b>a or d>c:
    print("inf")
else:
    print(lst[n])

### FIXED CODE ###

n,m=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(m)]

inf=float("inf")
data=[-inf]*(n+1)
data[1]=0
for i in range(n):
    for a,b,c in abc:
        if data[a]!=inf:
            data[b]=max(data[b],data[a]+c)

lst=data[:]
for i in range(n):
    for a,b,c in abc:
        if data[a]!=inf:
            data[b]=max(data[b],data[a]+c)

que=[]
for i in range(1,n+1):
    if lst[i]!=data[i]:
        que.append(i)
        
flag=[0]*(n+1)
for u in que:
    flag[u]=1

li=[[] for i in range(n+1)]
for a,b,c in abc:
    li[a].append(b)

while que:
    h=que.pop()
    for u in li[h]:
        if flag[u]==0:
            flag[u]=1
            que.append(u)

if flag[n]==1:
    print("inf")
else:
    print(data[n])
### BUGGY CODE ###

n,m = map(int,input().split( ))
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(m):
    p,y = map(int,input().split( ))
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    ls_b[i].sort()
for i in range(m):
    print(str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6))

### FIXED CODE ###

N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)] #定義終了
 
PY.sort(key= lambda x:x[1])
num=[0]*N
w=[""]*M
 
for p,y,i in PY:
	num[p-1]+=1
	w[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for i in range(M):
  	print(w[i])
### BUGGY CODE ###

import numpy as np
n=input().split(' ')
a=[int(i) for i in input().split(' ')]
n=np.array(a)

x=0
m = n.max()
mx= n.argmax()
k = n.min()
kx= n.argmin()
e=[]
if abs(m) > abs(k) and m > 0:
  for i in range(len(a)-1):
    while n[i] > n[i+1]:
      n[i+1] = n[i+1] + m
      e.append([mx+1 ,i+1 +1])
      x+=1
    m =n.max()
    mx= n.argmax()
else:
  for i in range(len(a)-1,0,-1):
    while n[i-1] > n[i]:
      n[i-1] = n[i-1] + k
      e.append([kx+1 ,i])
      x+=1
    k =n.max()
    kx= n.argmax()
    
print(x)
for j in e:
  print(" ".join([str(i) for i in j]))

### FIXED CODE ###

import numpy as np

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

if abs(max(a)) >= abs(min(a)):
  ma  = max(a)
  ma_i= np.argmax(a)
  mi  = 0
  mi_i= 0
else:
  mi  = min(a)
  mi_i= np.argmin(a)
  ma  = 0
  ma_i= 0

xa=[]
if ma == 0:
  for i in range(n):
    if a[i] > 0:
      a[i] = a[i] + mi
      xa.append([mi_i+1, i+1])
  for i in reversed(range(1,n)):
    if a[i-1] > a[i]:
      a[i-1] = a[i-1] + a[i]
      xa.append([i+1, i-1+1])
else:
  for i in range(n):
    if a[i] < 0:
      a[i] = a[i] + ma
      xa.append([ma_i+1, i+1])
  for i in range(1,n):
    if a[i-1] > a[i]:
      a[i] = a[i] + a[i-1]
      xa.append([i-1+1,i+1])

print(len(xa))
for i in range(len(xa)):
  print(xa[i][0],xa[i][1])
### BUGGY CODE ###

import numpy as np
S = input()
mod = 10 ** 9 + 7

n = len(S)
a = S[-1]
x = np.zeros(13, int)
l = [[i * j % 13 for j in range(0, 10)] for i in [1, 10, 9, 12, 3, 4]]
if a == "?":
    x[0:10] += 1
else:
    x[int(a)] += 1
for s, i in zip(S[-2::-1], range(1, n)):
    l_ = l[i % 6]
    x_ = x
    if s == "?":
        x = sum(np.roll(x_, v) for v in l_)
    else:
        v = l_[int(s)]
        x = np.roll(x_, v)
    x %= mod
print(x[5])

### FIXED CODE ###

#!python3

LI = lambda: list(map(int, input().split()))

# input
S = input()

MOD = 10 ** 9 + 7


def main():
    n = len(S)
    m = 5
    w = []
    p = 1
    for i in range(n):
        s = S[-1 - i]
        if s == "?":
            w.append(p)
        else:
            m = (m - int(s) * p) % 13
        p = p * 10 % 13

    n = len(w)
    l1 = [0] * 13
    l1[0] = 1
    for i in range(1, n + 1):
        l2 = [0] * 13
        for j in range(10):
            x = w[i - 1] * j % 13
            for k in range(13):
                t = (x + k) % 13
                l2[t] += l1[k]
        l1 = [y % MOD for y in l2]
    
    ans = l1[m]
    print(ans)


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

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

all_max = max(nums)
for num in range(N):
    if nums[num] == all_max:
        new_nums = list(nums)
        new_nums.pop(num)
        print(max(new_nums))
    else:
        print(all_max)


### FIXED CODE ###

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

all_max = max(nums)

new_nums = list(nums)
new_nums.remove(all_max)

second_max = max(new_nums)  # max関数はfor文の中にいれずに、先に2番目の最大値をもとめておく

for num in range(N):
    if nums[num] == all_max:
        print(second_max)
    else:
        print(all_max)
### BUGGY CODE ###

import itertools

n, l = map(int, input().split())
s = [input() for i in range(n)]

s_marge = []
for v in itertools.permutations(s, n):
  s_marge.append(''.join(v))
  
d = sorted(s_marge)
print(d[0])

### FIXED CODE ###

import itertools

n, l = map(int, input().split())
s = [input() for i in range(n)]

print(''.join(sorted(s)))
### BUGGY CODE ###

import itertools
n, cs = map(int, input().split())
d = [list(map(int, input().split())) for i in range(cs)]
c = [list(map(int, input().split())) for i in range(n)]
for i, j in itertools.product(range(n), repeat=2):
  c[i][j] -= 1
ans = 10**20
for i, j, k in itertools.permutations(range(cs), 3):
  s = 0
  for l, m in itertools.product(range(n), repeat=2):
    if (l + m) % 3 == 0:
      s += d[c[l][m]][i]
    elif (l + m) % 3 == 1:
      s += d[c[l][m]][j]
    else:
      s += d[c[l][m]][k]
  ans = min(ans, s)
print(ans)


### FIXED CODE ###

import itertools
n, cs = map(int, input().split())
d = [list(map(int, input().split())) for i in range(cs)]
c = [list(map(int, input().split())) for i in range(n)]
color_count = [[0] * cs for i in range(3)]
for i, j in itertools.product(range(n), repeat=2):
  color_count[(i + j) % 3][c[i][j] - 1] += 1
ans = 10**20
for t in itertools.permutations(range(cs), 3):
  s = 0
  for l in range(3):
    for m in range(cs):
      s += color_count[l][m] * d[m][t[l]]
  ans = min(ans, s)
print(ans)
### BUGGY CODE ###

n, k, q = map(int, input().split())
a = []
for i in range(q):
  a.append(int(input()))
  
for i in range(n):
  if k-q+a.count(i+1) > 0:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

n, k, q = map(int, input().split())
point = [k]*n
for i in range(q):
  point[int(input())-1] += 1
for i in range(n):
  if point[i]-q > 0:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

n = int(input())

nums = [0]*n
m = n//6
for i in range(1,m+1):
  if i**2//6 >= n: continue
  for j in range(i, m+1):
    if i**2 + j**2 + i*j >= n//2: break
    for k in range(j, m+1):
      t = i**2 + j**2 + k**2 + i*j + j*k + i*k
      if t <= n:
        if i == j and i == k: nums[t-1] += 1
        else: nums[t-1] += 3
        
print(*nums, sep="\n")

### FIXED CODE ###

from itertools import product
n = int(input())

nums = [0]*(n+1)
for i in product(range(1, int(n**0.5)+1),repeat=3):
  t = i[0]**2 + i[1]**2 + i[2]**2 + i[0]*i[1] + i[1]*i[2] + i[0]*i[2]
  if t <= n: nums[t] += 1

for i in range(1,n+1): print(nums[i])
### BUGGY CODE ###


n = int(input())
s = list(map(int, input()))
cnt = 0
for i1 in range(10):
    for i2 in range(10):
        for i3 in range(10):
            for i in range(n):
                if s[i]==i1: 
                    for j in range(i+1, n):
                        if s[j]==i2:
                            for k in range(j+1, n):
                                if s[k]==i3:
                                    cnt += 1
                                    #print(i1, i2, i3)
                                    break
                            break
                    break

print(cnt)



### FIXED CODE ###

n = int(input())
s = list(map(int, input()))
cnt = 0
for i1 in range(10):
    for i2 in range(10):
        for i3 in range(10):
            for i in range(n):
                if s[i]==i1: 
                    for j in range(i+1, n):
                        if s[j]==i2:
                            for k in range(j+1, n):
                                if s[k]==i3:
                                    cnt += 1
                                    #print(i1, i2, i3)
                                    break
                            break
                    break

print(cnt)
### BUGGY CODE ###

n=int(input())
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans=[]
for num,cnt in factorization(n):
  for _ in range(cnt):
    ans.append(num)
out=float('inf')
tmp=[]
for i in range(2**len(ans)):
  tmp1,tmp2=1,1
  for j in range(len(ans)):
    if i>>j&1:
      tmp1*=ans[j]
    else:
      tmp2*=ans[j]
  out=min(out,tmp1-1+tmp2-1)
print(out)

### FIXED CODE ###

import math
n=int(input())

def make_divisors(n):
  divisors=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      divisors.append(i)
      if i!=n//i:
        divisors.append(n//i)
  divisors.sort()
  return divisors
a=make_divisors(n)
if len(a)%2==1:
  print(2*int(math.sqrt(n))-2)
if len(a)%2==0:
  b=a[len(a)//2-1]
  c=a[len(a)//2]
  print(b+c-2)
### BUGGY CODE ###

import sys
a,b,c=map(int,input().split())

for i in range(10**9):
  if (a*i)%b==c:
    print("YES")
    sys.exit()
print("NO")

### FIXED CODE ###

import sys
a,b,c=map(int,input().split())

for i in range(10**5):
  if (a*i)%b==c:
    print("YES")
    sys.exit()
print("NO")
### BUGGY CODE ###

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

dp=[[-10**12]*(n+1) for i in range(n+1)]
#dp[i][j]:=A[j:j+i+1]
if n%2==0:
  for i in range(n):
    dp[0][i]=-1*A[i]
  for i in range(1,n+1):
    for j in range(n-i):
      if i%2==1:
        if j+i==n:
          dp[i][j]=dp[i-1][j+1]+A[j]
        else:
          dp[i][j]=max(dp[i-1][j]+A[j+i],dp[i-1][j+1]+A[j])
      else:
        if j+i==n:
          dp[i][j]=dp[i-1][j+1]-A[j]
        else:
          dp[i][j]=min(dp[i-1][j]-A[j+i],dp[i-1][j+1]-A[j])
else:
  for i in range(n):
    dp[0][i]=A[i]
  for i in range(1,n+1):
    for j in range(n-i):
      if i%2==0:
        if j+i==n:
          dp[i][j]=dp[i-1][j+1]+A[j]
        else:
          dp[i][j]=max(dp[i-1][j]+A[j+i],dp[i-1][j+1]+A[j])
      else:
        if j+i==n:
          dp[i][j]=dp[i-1][j+1]-A[j]
        else:
          dp[i][j]=min(dp[i-1][j]-A[j+i],dp[i-1][j+1]-A[j])
print(dp[n-1][0])

### FIXED CODE ###

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

dp=[[-10**12]*(n+1) for i in range(n+1)]
#dp[i][j]:=A[j:j+i+1]
if n%2==0:
  for i in range(n):
    dp[0][i]=-1*A[i]
  for i in range(1,n+1):
    for j in range(n-i):
      if i%2==1:
        if j+i==n:
          dp[i][j]=dp[i-1][j+1]+A[j]
        else:
          dp[i][j]=max(dp[i-1][j]+A[j+i],dp[i-1][j+1]+A[j])
      else:
        if j+i==n:
          dp[i][j]=dp[i-1][j+1]-A[j]
        else:
          dp[i][j]=min(dp[i-1][j]-A[j+i],dp[i-1][j+1]-A[j])
else:
  for i in range(n):
    dp[0][i]=A[i]
  for i in range(1,n+1):
    for j in range(n-i):
      if i%2==0:
        if j+i==n:
          dp[i][j]=dp[i-1][j+1]+A[j]
        else:
          dp[i][j]=max(dp[i-1][j]+A[j+i],dp[i-1][j+1]+A[j])
      else:
        if j+i==n:
          dp[i][j]=dp[i-1][j+1]-A[j]
        else:
          dp[i][j]=min(dp[i-1][j]-A[j+i],dp[i-1][j+1]-A[j])
print(dp[n-1][0])
### BUGGY CODE ###

import fractions

k = int(input())
ans = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += fractions.gcd(fractions.gcd(a, b), c)

print(ans)

### FIXED CODE ###

import math
 
k = int(input())
ans = 0
 
for a in range(1, k+1):
    for b in range(1, k+1):
        tmp = math.gcd(a,b)
        for c in range(1, k+1):
            ans += math.gcd(tmp, c)
 
print(ans)
### BUGGY CODE ###

L, R = map(int, input().split())
mods = []

for i in range(L, R):
  for j in range(i+1, R+1):
    mods.append(i*j%2019)

print(min(mods))

### FIXED CODE ###

L, R = map(int, input().split())
mods = []

if 2019 <= R - L:
  print('0')
  exit(0)
    
for i in range(L, R):
  for j in range(i+1, R+1):
    mods.append(i*j%2019)
print(min(mods))
### BUGGY CODE ###

s = input()
n = len(s)

a = [0]*n
ans = [0]*n

for i in range(n):
    x = 0
    if s[i] == 'R':
        while s[i+x] == 'R':
            x += 1
    if s[i] == 'L':
        while s[i+x] == 'L':
            x -= 1
    a[i] = x

    if a[i] == 1 or a[i] == -1:
        ans[i] += 1
    elif a[i] % 2 == 0:
        ans[i+ a[i]] += 1
    elif a[i] > 0:
        ans[i+ a[i] - 1] += 1
    elif a[i] < 0:
        ans[i+ a[i] + 1] += 1
        
ans = [str(i) for i in ans]
print(' '.join(ans))

### FIXED CODE ###

s = input()
n = len(s)

a = [0]*n
ans = [0]*n

for i in range(n):
    x = 0
    if s[i] == 'R':
        if i > 0 and a[i-1] > 0:
            x = a[i-1] - 1
        else:
            while s[i+x] == 'R':
                x += 1
    if s[i] == 'L':
        if i > 0 and a[i-1] < 0:
            x = a[i-1] - 1
        else:
            while s[i+x] == 'L':
                x -= 1
    a[i] = x

    if a[i] == 1 or a[i] == -1:
        ans[i] += 1
    elif a[i] % 2 == 0:
        ans[i+ a[i]] += 1
    elif a[i] > 0:
        ans[i+ a[i] - 1] += 1
    elif a[i] < 0:
        ans[i+ a[i] + 1] += 1
        
ans = [str(i) for i in ans]
print(' '.join(ans))
### BUGGY CODE ###

from itertools import accumulate
MOD = 10**9+7
n = int(input())
S = input()
dp = [1]*n
for s in S:
  if s == "<":
    dp = list(accumulate(dp[::-1][:-1]))[::-1]
  else:
    dp = list(accumulate(dp[:-1]))
ans = dp[0]%MOD
print(ans)

### FIXED CODE ###

MOD = 10**9+7
n = int(input())
S = input()
dp = [[0]*(n+1) for _ in range(n+1)]
for j in range(n):
  dp[1][j] = 1
for i, s in enumerate(S, 1):
  if s == "<":
    dp[i+1][n-(i+1)] = dp[i][n-i]
    for j in range(n-i-2, -1, -1):
      dp[i+1][j] = dp[i+1][j+1] + dp[i][j+1]
      dp[i+1][j] %= MOD
  else:
    dp[i+1][0] = dp[i][0]
    for j in range(1, n-i):
      dp[i+1][j] = dp[i+1][j-1] + dp[i][j]
      dp[i+1][j] %= MOD
ans = dp[n][0]
print(ans)