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

n ,x, y = map(int, input().split())
'''
degree_all = []
d = [float('inf')]*n
for i in range(n):
    degree_all.append(d)
for i in range(n-1):
    degree_all[i][i] = 0
    if i != n-1:
        degree_all[i][i+1] = 1
        #degree_all[i+1][i] = 1
'''
sub_degree = [0]*n
for i in range(n):
    for j in range(i+1, n):
        sub_degree[min(abs(j-i), abs(x-1-i)+1+abs(j-y+1), abs(y-1-i)+1+abs(j-x+1))-1]+=1
'''
for i in range(n-1):
    for j in range(i+1, n):
        sub_degree[degree_all[i][j]-1] +=1
        #print(degree_all[i][j])
#print("aaaa")
'''
for i in range(n-1):
    print(sub_degree[i])


### FIXED CODE ###

N,X,Y = map(int,input().split())

ans = [0]*N

for i in range(1,N):
    for j in range(i+1,N+1):
        road = min(abs(j-i),abs(X-i)+abs(j-Y)+1,abs(Y-i)+abs(j-X)+1)
        ans[road] += 1

for i in range(1,N):
    print(ans[i])
### BUGGY CODE ###

n = int(input())
a = list(map(str, input().split()))
A = list(set(a))
ans = ["0"]*n
for ai in A:
  ans[int(ai)-1] = str(a.count(ai))
print("\n".join(ans))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = ["0"]*n
for i in range(n-1):
  ans[a[i]-1] = str(int(ans[a[i]-1])+1)
print("\n".join(ans))
### BUGGY CODE ###

n,C,*H=map(int,open(0).read().split());
dp=[0];
P=[0];
def f(I,h):
    return dp[I]+H[I]*(H[I]-2*h)
for i in range(1,n):
    h=H[i]
    while len(P)>1 and f(P[0],h)>f(P[1],h):P.pop(0)
    dp+=[f(P[0],h)+h**2+C]
    while len(P)>1 and (H[P[-1]]-H[P[-2]])*(f(P[-1],0)-f(i,0))>(h-H[P[-1]])*(f(P[-2],0)-f(P[-1],0)):P.pop()
    P+=[i]
print(dp[-1])

### FIXED CODE ###

n,C,*H=map(int,open(0).read().split());
dp=[0];
P=[0];
def f(I,h):
    return dp[I]+H[I]*(H[I]-2*h)
def c(x,y,z):
    return (H[y]-H[x])*(f(y,0)-f(z,0))>(H[z]-H[y])*(f(x,0)-f(y,0))
for i in range(1,n):
    while len(P)>1 and f(P[0],H[i])>f(P[1],H[i]):P.pop(0)
    dp+=[f(P[0],H[i])+H[i]**2+C]
    while len(P)>1 and c(P[-2],P[-1],i):P.pop()
    P+=[i]
print(dp[-1])
### BUGGY CODE ###

R, C, K = map(int, input().split())
item = [[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    item[r][c] = v


dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

for i in range(R+1):
    for j in range(C+1):
        for k in range(4):
            here = dp[k][i][j]
            # 次の"行"に移動する場合（下に移動するので今まで獲得したアイテムの個数はリセットされる）
            if i + 1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][i+1][j] = max(dp[0][i+1][j], here)
                # 移動先のアイテムをとる場合
                dp[1][i+1][j] = max(dp[1][i+1][j], here+item[i+1][j])
            # 次の列に移動する場合（右に移動するのでその行で獲得したアイテムの個数は維持される）
            if j + 1 <= C:
                dp[k][i][j+1] = max(dp[k][i][j+1], here)
                # 現在のkが3未満のときのみ，移動先のアイテムをとることが可能
                if k < 3:
                    dp[k+1][i][j+1] = max(dp[k+1][i][j+1], here+item[i][j+1])

ans = 0
for k in range(4):
    ans = max(ans, dp[k][-1][-1])
print(ans)


### FIXED CODE ###

R, C, K = map(int, input().split())
item = [[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    item[r][c] = v


dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

for i in range(R+1):
    for j in range(C+1):
        for k in range(4):
            here = dp[k][i][j]
            # 次の"行"に移動する場合（下に移動するので今まで獲得したアイテムの個数はリセットされる）
            if i + 1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][i+1][j] = max(dp[0][i+1][j], here)
                # 移動先のアイテムをとる場合
                dp[1][i+1][j] = max(dp[1][i+1][j], here+item[i+1][j])
            # 次の列に移動する場合（右に移動するのでその行で獲得したアイテムの個数は維持される）
            if j + 1 <= C:
                dp[k][i][j+1] = max(dp[k][i][j+1], here)
                # 現在のkが3未満のときのみ，移動先のアイテムをとることが可能
                if k < 3:
                    dp[k+1][i][j+1] = max(dp[k+1][i][j+1], here+item[i][j+1])

ans = 0
for k in range(4):
    ans = max(ans, dp[k][-1][-1])
print(ans)
### BUGGY CODE ###

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

for i in range(n):
    if a[i] not in d.keys():
        d[a[i]] = 1
    else:
        d[a[i]] += 1

for i in range(q):
    b, c = list(map(int, input().split()))
    if b in d.keys():
        if c in d.keys():
            d[c] += d[b]
            del d[b]
        else:
            d[c] = d[b]
            del d[b]
    print(sum([k * v for k, v in d.items()]))

### FIXED CODE ###

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

for i in range(n):
    if a[i] not in d.keys():
        d[a[i]] = 1
    else:
        d[a[i]] += 1

s = sum([k * v for k, v in d.items()])

for i in range(q):
    b, c = list(map(int, input().split()))
    if b in d.keys():
        s += (c - b) * d[b]
        if c in d.keys():
            d[c] += d[b]
            d[b] = 0
        else:
            d[c] = d[b]
            d[b] = 0
    print(s)
### BUGGY CODE ###

N, M, K = map(int, input().split())
a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))
a_time = 0
b_time = 0
a_times = [0 for _ in range(N+1)]
b_times = [0 for _ in range(M+1)]
for i, a in enumerate(a_books):
  a_time += a
  a_times[i+1] = a_time
  
for i, b in enumerate(b_books):
  b_time += b
  b_times[i+1] = b_time
  
result = 0
l = 0
for i in range(N+1):
  if l == M:
    break
  for j in range(l, M+1):
    if a_times[N-i] + b_times[j] <= K:
      result = max(result, N-i+j)
    else:
      l = j
      break
print(result)

### FIXED CODE ###

N, M, K = map(int, input().split())
a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))
a_time = 0
b_time = 0
a_times = [0 for _ in range(N+1)]
b_times = [0 for _ in range(M+1)]
for i, a in enumerate(a_books):
  a_time += a
  a_times[i+1] = a_time
  
for i, b in enumerate(b_books):
  b_time += b
  b_times[i+1] = b_time
  
result = 0
l = 0
for i in range(N+1):
  if l == M:
    break
  while(l <= M):
    if a_times[N-i] + b_times[l] <= K:
      result = max(result, N-i+l)
      l += 1
    else:
      break
print(result)
### BUGGY CODE ###

n = int(input())
A = [int(x) for x in input().split()]

found = {}
for i, a in enumerate(A):
    if a in found:
        dup = a
        dup_1 = found[a]
        dup_2 = i
    found[a] = i

from functools import lru_cache

@lru_cache(maxsize=None)
def gfp_inv(x, p):
    return pow(x, p - 2, p)

@lru_cache(maxsize=None)
def fact(n, m, p):
    ret = 1
    for i in range(m, n + 1):
        ret = (ret * i) % p
    return ret

def comb(n, m):
    if m < 0 or n < m: return 0
    if n == m: return 1
    return fact(n, n - m + 1, p) * gfp_inv(fact(m, 1, p), p) % p

p = 10**9 + 7

intv = dup_2 - dup_1 - 1
for k in range(1, n + 2):
    ans = comb(n + 1, k)
    ans -= comb(n + 1 - intv - 2, k - 1)
    print(ans % p)

### FIXED CODE ###

n = int(input())
A = [int(x) for x in input().split()]

p = 10**9 + 7

found = {}
for i, a in enumerate(A):
    if a in found:
        dup = a
        dup_1 = found[a]
        dup_2 = i
    found[a] = i

from functools import lru_cache

@lru_cache(maxsize=None)
def gfp_inv(x, p):
    return pow(x, p - 2, p)

from itertools import chain, accumulate
memo_fact = list(chain([1], accumulate(range(1, 10**5 + 2), lambda a, x: a * x % p)))

def comb(n, m):
    if m < 0 or n < m: return 0
    if n == m: return 1
    return memo_fact[n] * gfp_inv(memo_fact[n - m], p) * gfp_inv(memo_fact[m], p) % p

intv = dup_2 - dup_1 - 1
for k in range(1, n + 2):
    ans = comb(n + 1, k)
    ans -= comb(n + 1 - intv - 2, k - 1)
    print(ans % p)
### BUGGY CODE ###

import itertools


def resolve():
	n,m=map(int,input().split())
	l=[]
	for i in range(n):
		x,y,z=map(int,input().split())
		l.append([x,y,z])
	lst=list(itertools.combinations(l,m))
	ms=0
	for i in lst:
		xx=abs(sum([p[0] for p in i]))
		yy=abs(sum([p[1] for p in i]))
		zz=abs(sum([p[2] for p in i]))
		ms=max(ms,xx+yy+zz)
	print(ms)
resolve()

### FIXED CODE ###

def resolve():
	ans=0
	n,m=map(int,input().split())
	xyz=[list(map(int,input().split())) for i in range(n)]
	t=[(1,1,1),(1,1,-1),(1,-1,1),(1,-1,-1),(-1,1,1),(-1,1,-1),(-1,-1,1),(-1,-1,-1)]
	for k in t:
		l=[k[0]*x+k[1]*y+k[2]*z for x,y,z in xyz ]
		l.sort(reverse=True)
		ans=max(ans,sum(l[:m]))
	print(ans)

resolve()
### BUGGY CODE ###

n, m = map(int, input().split())
hole_ids = [int(input()) - 1 for _ in range(m)]
X = 1000000007


def solve(n, hole_ids):
    nums = []
    for i in range(n):
        if i in hole_ids:
            nums.append(0)
            continue

        if i == 0:
            nums.append(1)
        elif i == 1:
            # 1つ前から1段上がるから2つ前から2個飛ばし
            nums.append(nums[-1] + 1)
        else:
            nums.append((nums[-1] + nums[-2]) % X)
    return nums[-1]


print(solve(n, hole_ids))


### FIXED CODE ###

n, m = map(int, input().split())
hole_ids = {int(input()) - 1: 0 for _ in range(m)}
X = 1000000007


def solve(n, hole_ids):
    # nums = []
    nums = [0] * n
    for i in range(n):
        if i in hole_ids:
            # nums.append(0)
            nums[i] = 0
            continue

        if i == 0:
            # nums.append(1)
            nums[i] = 1
        elif i == 1:
            # 1つ前から1段上がるから2つ前から2個飛ばし
            # nums.append(nums[-1] + 1)
            nums[i] = nums[i-1] + 1
        else:
            # nums.append((nums[-1] % X + nums[-2] % X) % X)
            nums[i] = (nums[i-1] + nums[i-2]) % X
    return nums[-1]


print(solve(n, hole_ids))
### BUGGY CODE ###

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

rlist = []
i = 0
while True :
    cur = i
    i += 1
    while A[i%N] != A[cur%N] :
        i += 1
    rlist.append(i-cur+1)
    if i % N == N - 1 :
        break
    i += 1

s = sum(rlist) 
m = N*K%s

ss = 0
for r in rlist :
    if ss + r < m :
        ss += r
    else :
        break     

ret = []
for a in A[ss % N:] :
    if not a in ret :
        ret.append(a)
    else :
        ret = ret[:ret.index(a)]
        
print(' '.join([str(i) for i in ret]))

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

last = dict()
v = [-1] * N

for i, a in enumerate(A + A) :
    if a in last and last[a] < N :
        v[last[a]] = i + 1
    
    last[a] = i

dist = [-1] * N
cur = 0
cycle = 0
while dist[cur] < 0 :
    dist[cur] = cycle 
    cycle += v[cur] - cur
    cur = v[cur] % N

NK = N * K

m = NK % cycle
cur = v[cur] % N
s = 0
while m > dist[cur] > 0 :
    s = dist[cur]
    cur = v[cur] % N
m -= s

ret = []
seen = set()
for a in A[N-m:] :
    if a in seen :
        p = ret.pop()
        seen.remove(a)
        while p != a :
            seen.remove(p)
            p = ret.pop()
    else :
        ret.append(a)
        seen.add(a)
        
print(' '.join([str(i) for i in ret]))
### BUGGY CODE ###

S = input()
S = S[::-1]

dp = [[0]*13 for _ in range(len(S)+1)]

dp[0][0]=1

q=1
for i in range(1,len(S)+1): #i文字目，1-index
  s = S[i-1]
  if s=='?':
    for j in range(13):
      for n in range(10):
      	dp[i][(j+n*q)%13] += dp[i-1][j]
    for j in range(12):
      dp[i][j] %= 10**9+7
  else:
    n = int(s)
    for j in range(13):
      dp[i][(j+n*q)%13] = dp[i-1][j]
  q = (10*q)%13
  
print(dp[len(S)][5])

### FIXED CODE ###

S = input()
S = S[::-1]

dp = [[0]*13 for _ in range(len(S)+1)]

dp[0][0]=1

q=1
for i in range(1,len(S)+1): #i文字目，1-index
  s = S[i-1]
  if s=='?':
    for j in range(13):
      for n in range(10):
      	dp[i][(j+n*q)%13] += dp[i-1][j]
    for j in range(12):
      dp[i][j] %= 10**9+7
  else:
    n = int(s)
    for j in range(13):
      dp[i][(j+n*q)%13] = dp[i-1][j]
  q = (10*q)%13
  
print(dp[len(S)][5])
### BUGGY CODE ###

S = input()
Q = int(input())

reverse = False
cnt = 0
for i in range(Q):
    inp = input().split()
    if len(inp) == 1:
        cnt += 1
        reverse = (cnt % 2 != 0)
        #S = S[::-1]
    else:
        f, c = inp[1:]
        if int(f) == 1:
            if reverse:
                S = S + c
            else:
                S = c + S
        else:
            if reverse:
                S = c + S
            else:
                S = S + c
print(S[::-1] if reverse else S)

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())

reverse = False
cnt = 0
for i in range(Q):
    inp = input().split()
    if inp[0] == "1":
        cnt += 1
        reverse = (cnt % 2 != 0)
        #S = S[::-1]
    else:
        f, c = inp[1:]
        if int(f) == 1:
            if reverse:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if reverse:
                S.appendleft(c)
            else:
                S.append(c)
S = "".join(S)
print(S[::-1] if reverse else S)
### BUGGY CODE ###

N, M = map(int,input().split())
A = list(map(int,input().split()))
for i in range(M):
  max_item = A.index(max(A))
  A[max_item] //= 2
print(sum(A))

### FIXED CODE ###

import heapq

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

#全要素に-1かける
for i in range(len(A)):
    A[i] *= -1 

heapq.heapify(A) 
for _ in range(M):
    x = heapq.heappop(A)
    heapq.heappush(A, (-x//2)*(-1))

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

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    x = [[B[i],C[i]] for i in range(M)]
    x = sorted(x, key=lambda x:x[1], reverse=True)

    D = []
    for i in range(M):
        D.extend([x[i][1]]*x[i][0])


    A.sort()

    for i in range(min(N, len(D))):
        if(A[i] < D[i]):
            A[i] = D[i]

    print(sum(A))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]" 
    C = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    x = [[B[i],C[i]] for i in range(M)]
    x = sorted(x, key=lambda x: -x[1])

    A.sort()

    dn = 0
    for b, c in x:
        for j in range(b):
            if(dn >= N):
                break
            if(A[dn] < c):
                A[dn] = c
                dn += 1
            else:
                break


    print(sum(A))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]" 
    C = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)

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

FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]
N = rri()
arr = rrm()
def solve(N, arr):
    memo = {}
    def find(status, cur_money, idx):
        if (status, cur_money, idx) in memo:
            return memo[(status, cur_money, idx)]
        if idx == N-1:
            if not status:
                return cur_money
            else:
                return cur_money+ status * arr[idx]
        ans = cur_money
        if status == 0:
            nxt_status = cur_money//arr[idx]
            nxt_money = cur_money % arr[idx]
            for i in range(idx+1, N):
                ans = max(find(nxt_status, nxt_money, i), ans)
                ans = max(ans, find(status, cur_money, i))
        else:
            nxt_status = 0
            nxt_money = cur_money+status*arr[idx]
            for i in range(idx+1, N):
                ans = max(find(nxt_status, nxt_money, i), ans)
                ans = max(ans, find(status, cur_money, i))
        memo[(status, cur_money, idx)] = ans;
        return ans
    return find(0, 1000, 0)
print(solve(N, arr))
        

### FIXED CODE ###

FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]
N = rri()
arr = rrm()
def solve(N, prices):
    ans = 1000
    for i in range(1, len(prices)):
        if prices[i]>prices[i-1]:
            ans += (prices[i]-prices[i-1])*(ans//prices[i-1])
    return ans
print(solve(N, arr))
### BUGGY CODE ###

import collections

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

path = [[False for i in range(N)] for j in range(N)]
detect_start = [[False for i in range(N)] for j in range(N)]
for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    detect_start[b][a] = True

start = []
for i in range(N) :
    if not sum(detect_start[i]) :
        start.append(i)

ans = 0

for i in range(len(start)) :
    q = collections.deque()
    q.append(start[i])
    dist = [0 for i in range(N)]
    
    while q :
        now = q.pop()
        for j in range(N) :
            if path[now][j] :
                q.append(j)
                dist[j] = max(dist[j], dist[now]+1)
    
    ans = max(ans, max(dist))

print(ans)


### FIXED CODE ###

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

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

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

"""
References
----------
[1]. kmjp. AtCoder ABC #144 : F - Fork in the Road, <http://kmjp.hatenablog.jp/entry/2019/10/28/0930>, kmjp's blog
[2]. physics0523. Fork in the Road(ABC144-F), <https://physics0523.hatenablog.com/entry/2019/10/27/235334>, physics0523's 精進ログ
"""
from copy import copy
INF = 10**9
def solve(n, m, s, t):
    E = {}
    for i in range(m):
        u, v = s[i], t[i]
        if not u in E:
            E[u] = []
        E[u].append(v)
    dp = [INF] * (n+1)
    dp[n] = 0
    for i in range(n-1, 0, -1):
        v = [dp[j] for j in E[i]]
        dp[i] = 1 + sum(v) / len(v)
    dp2 = copy(dp)
    res = dp[1]
    for i in range(n-1, 0, -1):
        if len(E[i]) == 1:
            continue
        v = [dp[e] for e in E[i]]
        dp2[i] = 1 + (sum(v) - max(v)) / (len(v) - 1)
        for j in range(i-1, 0, -1):
            v = [dp2[k] for k in E[j]]
            dp2[j] = 1 + sum(v) / len(v)
        res = min(res, dp2[1])
        dp2[:i+1] = copy(dp[:i+1])
    return res

n, m = map(int, input().split())
s = [0] * m
t = [0] * m
for i in range(m):
    s[i], t[i] = map(int, input().split())
print(solve(n, m, s, t))

### FIXED CODE ###

"""
References
----------
[0]. 解説(公式), https://img.atcoder.jp/abc144/editorial.pdf, AtCoder
    - O(NM)
[1]. kmjp. AtCoder ABC #144 : F - Fork in the Road, <http://kmjp.hatenablog.jp/entry/2019/10/28/0930>, kmjp's blog
    - O(NM)
[2]. physics0523. Fork in the Road(ABC144-F), <https://physics0523.hatenablog.com/entry/2019/10/27/235334>, physics0523's 精進ログ
    - O(M)
[3]. Genki Ogaki. BC144 F - Fork in the Road考察＋参戦記, <https://www.onakasuitacity.com/abc144-f>, おじさん、今日プロ始
めるってよ
    - O(M)
"""
def solve(n, m, s, t):
    edges = [[] for i in range(n)]
    for i in range(m):
        u, v = s[i], t[i]
        edges[u-1].append(v-1)
    p = [0] * n
    p[0] = 1
    for i in range(n):
        for j in edges[i]:
            p[j] += p[i] / len(edges[i])
    E = [0] * n
    for i in range(n-2, -1, -1):
        v = [E[j] for j in edges[i]]
        E[i] = 1 + sum(v) / len(v)
    res = E[0]
    for i in range(n):
        deg = len(edges[i])
        if deg <= 1:
            continue
        k = max((E[j], j) for j in edges[i])[1]
        v = [E[j] for j in edges[i] if j != k]
        res = min(res, E[0] + p[i] * (sum(v) / (deg-1) - E[k]) / deg)
    return res

n, m = map(int, input().split())
s = [0] * m
t = [0] * m
for i in range(m):
    s[i], t[i] = map(int, input().split())
print(solve(n, m, s, t))
### BUGGY CODE ###

a, b, x = map(int,input().split())
cnt = 0
for i in range(a,b + 1):
    if i % x == 0:
        cnt += 1
        
print(cnt)

### FIXED CODE ###

a, b, x = map(int,input().split())

if a != 0:
    print((b // x) - ((a - 1) // x))
else:
    print(b // x + 1)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
 
for i in range(n):
    print(max(max(a[0:i], a[i+1:n])))


### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
b_max = b[-1]
b.pop(-1)
b_2max = b[-1]

for i in a:
    if i == b_max:
        print(b_2max)
    else:
        print(b_max)
### BUGGY CODE ###

from itertools import groupby
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = input()

x,y = map(int,input().split())

d = [len(i) for i in s.split('T')]

x_li = d[2::2]
X = len(x_li)
y_li = d[1::2]
Y = len(y_li)

x -= d[0]

x_flag = False
y_flag = False

def x_kumi(n,now):
    global x_flag
    if n == X:
        if now == x:
            x_flag = True
    else:
        return x_kumi(n+1,now+x_li[n]),x_kumi(n+1,now-x_li[n])

def y_kumi(n,now):
    global y_flag
    if n == Y:
        if now == y:
            y_flag = True
    else:
        return y_kumi(n+1,now+y_li[n]),y_kumi(n+1,now-y_li[n])

x_kumi(0,0)
y_kumi(0,0)

if x_flag and y_flag:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

from itertools import groupby
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = input()

x,y = map(int,input().split())

d = [len(i) for i in s.split('T')]

x_li = d[2::2]
y_li = d[1::2]

now_x = [0]
now_y = [0]

x -= d[0]

for i in x_li:
    nx = set()
    for j in now_x:
        nx.add(j-i)
        nx.add(j+i)
    now_x = nx

for i in y_li:
    ny = set()
    for j in now_y:
        ny.add(j-i)
        ny.add(j+i)
    now_y = ny

if x in now_x and y in now_y:
    print("Yes")
else:
    print("No")