Harryxun/stf_run huggingface dataset:
N,M=[int(x) for x in input().split()]
I=[[] for n in range(N)]
G=[n for n in range(N)]
W=[1 for n in range(N)]
E=[]

result=[]
ans = int(N * (N-1) / 2)

def union(i,g):
    if(G[i]!=g):
        G[i]=g
        for n in I[i]:
            union(n,g)

for m in range(M):
    A,B=[int(x) for x in input().split()]
    E.append((A-1,B-1))

for m in range(M):
    result.append(ans)
    if(ans>0):
        A,B=E.pop()
        Ga,Gb=G[A],G[B]
        Wa,Wb=W[Ga],W[Gb]
        if (Wb>Wa):
            union(Ga,Gb)
            W[Gb]=Wa+Wb
        else:
            union(Gb,Ga)
            W[Ga]=Wa+Wb
        ans=ans-(Wa*Wb)
        I[A].append(B)
        I[B].append(A)

for r in reversed(result):
    print(r)


### FIXED CODE ###

N,M=[int(x) for x in input().split()]
G=[-1] * N
W=[0] * N
E=[]

result=[]
ans = int(N * (N-1) / 2)

def union(i,j):
    gi=find(i)
    gj=find(j)

    if(gi!=gj):
        if W[gi] > W[gj]:
            G[gi]+=G[gj]
            G[gj]=gi
        else:
            G[gj]+=G[gi]
            G[gi]=gj
            if W[gi]==W[gj]:
                W[gj]+=1

def find(i):
    if G[i]<0:
        return i;
    else:
        G[i]=find(G[i])
        return G[i]

for m in range(M):
    A,B=[int(x) for x in input().split()]
    E.append((A-1,B-1))

for m in range(M):
    result.append(ans)
    if(ans>0):
        A,B=E.pop()
        ga,gb=find(A),find(B)
        if (ga!=gb):
            ans=ans-(G[ga]*G[gb])
            union(A,B)

for r in reversed(result):
    print(r)
gridNumber = []
numbers = []
for i in range(3):
    gridNumber.append(list(map(int, input().split())))

a1=0
b1=gridNumber[0][0] - a1
b2=gridNumber[1][0] - a1
b3=gridNumber[2][0] - a1

a2=gridNumber[2][0] - b1
a3=gridNumber[3][0] - b1

numbers.append([a1+b1, a1+b2, a1+b3])
numbers.append([a2+b1, a2+b2, a2+b3])
numbers.append([a3+b1, a3+b2, a3+b3])

for i in range(3):
    for j in range(3):
        if not(numbers[i][j] == gridNumber[i][j]):
            print("No")
            quit()
        else:
            pass

print("Yes")


### FIXED CODE ###

gridNumber = []
numbers = []
for i in range(3):
    gridNumber.append(list(map(int, input().split())))

a1=0
b1=gridNumber[0][0] - a1
b2=gridNumber[0][1] - a1
b3=gridNumber[0][2] - a1

a2=gridNumber[1][0] - b1
a3=gridNumber[2][0] - b1

numbers.append([a1+b1, a1+b2, a1+b3])
numbers.append([a2+b1, a2+b2, a2+b3])
numbers.append([a3+b1, a3+b2, a3+b3])

for i in range(3):
    for j in range(3):
        if not(numbers[i][j] == gridNumber[i][j]):
            print("No")
            quit()
        else:
            pass

print("Yes")
def main():
    a, b, c = map(int,input().split())

    count = b / a
    if count < c :
        print(count)
    else:
        print(c)

if __name__ == '__main__'
    main()

### FIXED CODE ###

def main():
    a, b, c = map(int,input().split())

    count = int(b / a)
    if count < c :
        print(count)
    else:
        print(c)

if __name__ == '__main__':
    main()
def pickup(S,ans):
    l = len(S)
    if l<2:
        return ans
    check_dif = False
    #print(S)
    for i in range(l-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            #print(S)
            check_dif = True
            ans += pickup(S,ans)
            break
    if not check_dif:
        return ans
    else:
        return ans+2
    
S=input()
l = len(S)
S_list = [S[i] for i in range(l)]
ans =0
print(pickup(S_list,ans))

### FIXED CODE ###

S=input()
num_one=S.count('1')
num_zero=S.count('0')
ans = 2*min(num_one,num_zero)
print(ans)
import numpy as np
K = input()
N = int(K[0])
M = int(K[1])

hairetu = np.ones((N+2, M+2))

for i in range(M+2):
    hairetu[0][i] = 0
    hairetu[N+1][i] = 0
for i in range(N+2):
    hairetu[i][0] = 0
    hairetu[i][M+1] = 0

for i in range(1, N+1):
    for j in range(1, M+1):
        for k in range(-1, 2):
            for l in range(-1, 2):
                hairetu[i+k][j+l] = (-1) * hairetu[i+k][j+l]


count = 0

for i in range(1, N+1):
    for j in range(1, M+1):
        if hairetu[i][j] == -1:
            count += 1


print(count)

### FIXED CODE ###

K = input().split()
N = int(K[0])
M = int(K[1])

if N >= 2 and M >= 2:
    print((N-2)*(M-2))
elif N == 1 and M >= 2:
    print(M-2)
elif N >= 2 and M == 1:
    print(N-2)
elif N == 1 and M == 1:
    print(1)
N = int(input())
T,A = map(int, input().split())
H = [int(i) for i in input().split]

dif = float("inf")

for i in range(N):
    temp = T - H[i] * 0.006
    dif2 = abs(A-temp)
    if dif2 < dif:
        dif = dif2
        ans = i

print(ans)

### FIXED CODE ###

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

dif = float("inf")

for i in range(N):
    temp = T - H[i] * 0.006
    dif2 = abs(A-temp)
    if dif2 < dif:
        dif = dif2
        ans = i

print(ans+1)
H, W = map(int, input().split())
s = [input() for i in range(H)]

dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
for i in range(H):
    for j in range(W):
        flag = False
        for k in range(4):
            if s[i][j] == '#':
                nx = i + dx[k]
                ny = j + dy[k]
                if nx < 0 or nx >= W or ny < 0 or ny >= H:
                    continue
                if s[nx][ny] == '#':
                    flag = True
            else:
                flag = True
        if flag == False:
            print('No')
            exit()        

print('Yes')

### FIXED CODE ###

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

dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
for i in range(H):
    for j in range(W):
        flag = False
        for k in range(4):
            if s[i][j] == '#':
                nx = j + dx[k]
                ny = i + dy[k]
                if nx < 0 or nx >= W or ny < 0 or ny >= H:
                    continue
                if s[ny][nx] == '#':
                    flag = True
            else:
                flag = True
        if flag == False:
            print('No')
            exit()        

print('Yes')
def ispossible(list1):
  if list1.count("5") == 2 and list1.count("7") == 1:
    return "YES"
  else:
    return "NO"

list1 = input().split()
print(ispposible(list1))

### FIXED CODE ###

def ispossible(list1):
  if list1.count("5") == 2 and list1.count("7") == 1:
    return "YES"
  else:
    return "NO"

list1 = input().split()
print(ispossible(list1))
a,b = map(int, raw_input().split())
print a/b a%b "%.6f" % (a/float(b))

### FIXED CODE ###

a, b = map(int, raw_input().split())
print "%d %d %f" % ((a/b), (a%b), (float(a)/b))
#!/usr/bin/env python3
N, M = map(int, input().split())
g = [[] for _ in range(N)]
rg = [[] for _ in range(N)]
for _ in range(N - 1 + M):
    A, B = map(lambda x: int(x) - 1, input().split())
    g[A].append(B)
    rg[B].append(A)


def dfs1(s):
    global ans
    for t in rg[s]:
        return dfs1(t)
    else:
        ans[s] = 0
        return s


def dfs2(s):
    global ans
    for t in g[s]:
        if ans[t] is None:
            ans[t] = s + 1
            dfs2(t)


ans = [None] * N
s = dfs1(0)
dfs2(s)

for x in ans:
    print(x)


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(100000)
N, M = map(int, input().split())
g = [[] for _ in range(N)]
rg = [[] for _ in range(N)]
for _ in range(N - 1 + M):
    A, B = (int(x) - 1 for x in input().split())
    g[A].append(B)
    rg[B].append(A)


def dfs(s):
    global ts
    global used
    used[s] = True
    for t in g[s]:
        if not used[t]:
            dfs(t)
    ts.append(s)


def tsort():
    global ts
    for i in range(N):
        dfs(i)
    ts = ts[::-1]


used = [False] * N
ts = []
tsort()

mp = [None] * N
for i, x in enumerate(ts):
    mp[x] = i

ans = [0] * N
for t in ts[1:]:
    if rg[t]:
        ans[t] = ts[max(mp[s] for s in rg[t])] + 1

for x in ans:
    print(x)
import math
a, b = map(float, input().split())
times = 0
a = int(a)
b = round(math.float(100 * b))
times = a * b
new_times = times / 100
print(new_times)

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=float(b)*1000
b=int(b)
print(int((a*b)//1000))
from bisect import bisect_left
import sys
sys.setrecursionlimit(1000000)


def dfs(v, p):
    i = bisect_left(dp, a[v])
    dp[i], old = a[v], dp[i]
    ans[v] = i
    if p != -1:
        ans[v] = max(ans[v], ans[p])
    for u in to[v]:
        if u == p:
            continue
        dfs(u, v)
    dp[i] = old

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    to = [[] for _ in range(n)]
    ans = [None]*n
    INF = 10**10
    for _ in range(n-1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        to[u].append(v)
        to[v].append(u)
    dp = [INF]*n
    dp[0] = -INF
    dfs(0, -1)
    print("\n".join(list(map(str, ans))))

### FIXED CODE ###

from bisect import bisect_left
import sys
sys.setrecursionlimit(1000000)


def dfs(v, p):
    i = bisect_left(dp, a[v])
    dp[i], old = a[v], dp[i]
    ans[v] = bisect_left(dp, INF)-1
    for u in to[v]:
        if u == p:
            continue
        dfs(u, v)
    dp[i] = old

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    to = [[] for _ in range(n)]
    ans = [0]*n
    INF = 10**20
    for _ in range(n-1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        to[u].append(v)
        to[v].append(u)
    dp = [INF]*(n+1)
    dp[0] = -INF
    dfs(0, -1)
    print("\n".join(list(map(str, ans))))
a,b = int(input())
print(a*b)
print(2*(a+b))


### FIXED CODE ###

a,b = map(int,input().split())
print(a*b,2*(a+b))
from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        continue
    if a*b != 0:
        g=gcd(a,b)*b//abs(b)
    elif a != 0:
        g=a
    else:
        g=b
        
    x=a//g,b//g
    count[x]=count.get(x,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    if (-1*x//abs(x)*y,abs(x)) in mem:
        continue
    mem.add((x,y))
    ans*=pow(2,z)+pow(2,count.get((-1*x//abs(x)*y,abs(x))),0)-1
    ans%=mod

print((ans-1)%mod)

### FIXED CODE ###

from math import gcd 
n=int(input())
mod = 10**9+7
count = {}

num=0
for _ in range(n):
    a,b = map(int,input().split())
    if a==0 and b==0:
        num+=1
        continue
    if a*b != 0:
        g=gcd(a,b)*(b//abs(b))
    elif a != 0:
        g=a
    else:
        g=b
        
    l=a//g,b//g
    count[l]=count.get(l,0)+1
        
mem=set()
ans=1
for (x,y),z in count.items():
    if x*y==0:
        k=(y,x)
    else:
        k=(-1*x//abs(x)*y,abs(x))
    if k in mem:
        continue
    mem.add((x,y))
    ans*=(pow(2,z)+pow(2,count.get(k,0))-1)
    ans%=mod

print((ans+num-1)%mod)
import bisect

A, B, Q = map(int, input().split())
S = []
for i in range(A):
    S.append(int(input()))
T = []
for i in range(B):
    T.append(int(input()))
X = []
for i in range(Q):
    X.append(int(input()))

for x in X:
    sxi, txi = bisect.bisect_right(S, x), bisect.bisect_right(T, x)
    print(min(abs(s-t)+min(abs(s-x), abs(t-x))
              for s in S[sxi-1:sxi+1] for t in T[txi-1:txi+1]))


### FIXED CODE ###

y, m, d = map(int, input().split("/"))
if y > 2019:
    print("TBD")
elif y == 2019:
    if m > 4:
        print("TBD")
    else:
        print("Heisei")
else:
    print("Heisei")
def comb(n, r):
    return f(n) / (f(n - r) * f(r)) 
 
def f(n):
    if n == 0:
        return 1
    else:
        return n * f(n - 1)
 
n = input()
a = map(int, raw_input().split())
 
a.sort()
a.reverse()
max = 0
ai = 0
aj = 0
for i in range(0, len(a)):
    for j in range(i + 1, len(a)):
        c = comb(a[i], a[j])
        if c > max:
            max = c
            ai = a[i]
            aj = a[j]
print(str(ai) + " " + str(aj))

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split(" ")]
m = max(a)
abs_min = m
abs_i = 0

for i in range(0, n):
    ab = abs((m + 1)//2 - a[i])
    if a[i] != m and abs_min > ab:
        abs_min = ab
        abs_i = i
        
print(m, a[abs_i])
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def baisu(x,a):
    if x%a ==0:
        return int(x//a)
    else:
        x -=1
        return baisu(x,a)

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

to_a = a - baisu(a,c) - baisu(a,d) + baisu(a,c*d/gcd(c,d))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d/gcd(c,d))


print(int(to_b-to_a+1))


### FIXED CODE ###

s = input()
count= 0

for i in range(3):
    if s[i] == s[i+1]:
        count += 1
    else:
        pass
if count>0:
    print("Bad")
else:
    print("Good")
n = int(input())
mod = 10 ** 9 + 7
import numpy as np
a = np.array(map(int, input().split())
s=0
ss=0
for i in range(n):
  ss += a[i]%mod
  s += ss * a[i] % mod
print(s)

### FIXED CODE ###

n = int(input())
mod = 10 ** 9 + 7
import numpy as np
a = list(map(int, input().split()))
s=0
ss=0
for i in range(n):
    if i > 0:
        ss += a[i-1]%mod
    s += ss * a[i] % mod
print(s%mod)
N = int(input())
*A, = map(int,input().split())

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3:
        ans = False
        1/0
    elif l==2:
        ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        a,b,c = B
        ans = ans and (A.count(a)==A.count(b)==A.count(c)==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

### FIXED CODE ###

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

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3:
        ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        if l==3:
            a,b,c = B
            l,m,n = (A.count(x) for x in (a,b,c))
        if l==2:
            a,b = B
            l,m = (A.count(x) for x in (a,b))
            if l>=m:
                c=a
                n=l//2
                l-=n
            else:
                c=b
                n=m//2
                m-=n
        ans = ans and (l==m==n==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")
n, k = map(int,input().split())
a = list(map(int,input().split()))
def trans(v):
  l = [0]*(k+1)
  for i in range(k+1):
    l[i] = (v&1)
    v >>= 1
  return l

a.sort()
lef = [1]*n
rig = [1]*n
mask = (1 << (k+1)) - 1
for i in range(n-1):
  lef[i+1] = lef[i] | (lef[i] << a[i]) & mask
  rig[-i-2] = rig[-i-1] | (rig[-i-1] << a[-i-1]) & mask
ok = -1
ng = n
while ng - ok > 1:
  mid = (ng + ok) // 2
  lc = lef[mid]
  rc = rig[mid]
  cov = ((1 << k) - 1) ^ ((1 << (k - a[mid])) - 1)
  for i in range(k+1):
    if lc & 1 and rc & cov:
      ng = mid
      break
    lc >>= 1
    cov >>= 1
  else:
    ok = mid
print(ok + 1)

### FIXED CODE ###

n, k = map(int,input().split())
a = [k+1 if x > k else x for x in map(int,input().split())]
a.sort()
lef = [1]*n
rig = [1]*n
mask = (1 << (k+1)) - 1
for i in range(n-1):
  lef[i+1] = lef[i] | (lef[i] << a[i]) & mask
  rig[-i-2] = rig[-i-1] | (rig[-i-1] << a[-i-1]) & mask
ok = -1
ng = n
while ng - ok > 1:
  mid = (ng + ok) // 2
  if a[mid] >= k:
      ng = mid
      continue
  lc = lef[mid]
  rc = rig[mid]
  cov = ((1 << k) - 1) ^ ((1 << (k - a[mid])) - 1)
  for i in range(k):
    if lc & 1 and rc & cov:
      ng = mid
      break
    lc >>= 1
    cov >>= 1
  else:
    ok = mid
print(ok + 1)
import sys
sys.setrecursionlimit(100000)

N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)


a=X[0][0]
b=X[0][1]

def f(a,b,i):
  c=X[i+1][0]
  d=X[i+1][1]

  x=ceil(a/c)
  y=ceil(b/d)
  ans=1000000000000
  if i!=N-2:
    if c*y-a>=0:
      a=c*y
      b=d*y
      ans=min(ans,f(a,b,i+1))
    
    if d*x-b>=0:
      z=f(c*x,d*x,i+1)
      if z<ans:
        a=c*x
        b=d*x
        ans=z

  elif i==N-2:
    
    if c*y-a>=0:
      a=c*y
      b=d*y
      ans=min(ans,a+b)
    
    if d*x-b>=0:
      a=c*x
      b=d*x
      ans=min(ans,a+b)

  return ans



print(f(a,b,0))





### FIXED CODE ###

N=int(input())
 
X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])
 
 
a=X[0][0]
b=X[0][1]
 
for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
 

  x= (a + (c - 1)) // c
  y= (b + (d -1)) // d
  
  a1=1000000000000000000
  b1=1000000000000000000
  a2=1000000000000000000
  b2=1000000000000000000
  if d*x-b>=0:
    a1=c*x
    b1=d*x
 
  
  if c*y-a>=0:
    a2=c*y
    b2=d*y
  if (a1+b1)<(a2+b2):
    a=a1
    b=b1
  else:
    a=a2
    b=b2
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" a1 = "+str(a1)+" b1 = "+str(b1)+" a2 = "+str(a2)+" b2 = "+str(b2)+" c = "+str(c)+" d = "+str(d))
  
 
 
 
 
  
print(a+b)
n,m = map(int,input().split())
a = map(int,input().split())
bc =[list(map(int,input().split()))for _ in [0]*m]

a.sort()
bc.sort(key=lambda x:-x[1])
i =0
for b,c in bc:
    for j in range(i,min(n,i+b)):
        if a[j]< c:a[j]=c
    i = i+b
print(sum(a))

### FIXED CODE ###

n,m = map(int,input().split())
*a, = map(int,input().split())
bc =[list(map(int,input().split()))for _ in [0]*m]
 
a.sort()
bc.sort(key=lambda x:-x[1])
i =0
for b,c in bc:
    for j in range(i,min(n,i+b)):
        if a[j]< c:a[j]=c
    i = i+b
print(sum(a))
N = int(input())

total = 0
for i in range(1,n+1):
    total += N[i]

    if N % total == 0:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

def f(n):
  return sum(map(int, str(n)))

X = int(input())

if X % f(X) == 0: 
  print("Yes")
else:
  print("No")
# coding: utf-8
# Your code here!

import fractions
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

L = lcm(N, M)

dp = [-1] * (L + 10)
for i, s in enumerate(S):
    dp[i*L//N] = s
'''   
for i, t in enumerate(T):
    if dp[i*L//M] != -1:
        if dp[i*L//M] != t:
            print(-1)
            sys.exit()
print(L)
'''

### FIXED CODE ###

# coding: utf-8
# Your code here!

import fractions
import sys
from collections import defaultdict

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

L = lcm(N, M)

dp = defaultdict(lambda: -1)

for i, s in enumerate(S):
    dp[i*L//N] = s

for i, t in enumerate(T):
    if dp[i*L//M] != -1:
        if dp[i*L//M] != t:
            print(-1)
            sys.exit()
print(L)
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n = int(input())
    if n == 1: print(0); exit()
    k = list(range(1, n+1))
    list1 = [i+1 for i in range(2, n)]
    a = [1] + list1[:] + [2]
    b = [2] + list1[:] + [1]
    ans = 0
    for row in (a, b):
        r = 0
        for x, y in zip(k, row):
            r += x % y
        ans = max(ans, r)
    print(ans)



main()

### FIXED CODE ###

def main():
    n = int(input())
    x = (n *(n-1))//2
    print(x)

main()
s=input()
t=input()
ls=len(s)
lt=len(t)
if ls<lt:
  print("UNRESTORABLE")
  exit()
for i in range(ls-lt,-1,-1):
  for j in range(i,i+lt):
    if s[j]==t[j] or s[j]=="?":
      continue
    else:
      break
  else:
    for k in range(i,i+lt):
      s[k]=t[k]
    for l in range(ls):
      if s[l]=="?":
        s[l]="a"
    print(s)
    exit()
else:
  print("UNRESTORABLE")

### FIXED CODE ###

s=list(input())
t=list(input())
ls=len(s)
lt=len(t)
if ls<lt:
  print("UNRESTORABLE")
  exit()
for i in range(ls-lt,-1,-1):
  for j in range(i,i+lt):
    if s[j]==t[j-i] or s[j]=="?":
      continue
    else:
      break
  else:
    for k in range(i,i+lt):
      s[k]=t[k-i]
    for l in range(ls):
      if s[l]=="?":
        s[l]="a"
    print(*s,sep="")
    exit()
else:
  print("UNRESTORABLE")
from fractions import gcd

i = list(map(int,input().split()))
A = i[0]
B = i[1]

ans = (A * B) // gcd(A, B)

print(ans)

### FIXED CODE ###

a = [int(input()) for i in range(2)]
A = a[0]
B = a[1]

ans = 6 - (A + B)
print(ans)
x, a, b = input().split()
 
if abs(x-a) > abs(x-b):
  print(B)
else:
  print(A)

### FIXED CODE ###

x, a, b = map(int, input().split())
 
if abs(x-a) > abs(x-b):
  print("B")
else:
  print("A")
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

x = STR()
l = len(x)
a = x[0]
st = []
tmp = 1
for i in range(1, l):
    if a[i] == a[i-1]:
        tmp += 1
    else:
        st.append(tmp)
        tmp = 1
st.append(tmp)

ll = len(st)
ans = l
if a == 'S':
    if ll % 2 == 1:
        ll -= 1
    for i in range(0, ll, 2):
        ans -= min(st[i], st[i+1]) * 2
    print(ans)
else:
    if ll % 2 == 0:
        ll -= 1
    for i in range(1, ll, 2):
        ans -= min(st[i], st[i+1]) * 2
    print(ans)


### FIXED CODE ###

x = str(input())
n = len(x)
stack = []
for i in range(n):
    if x[i] == 'S':
        stack.append('S')
    elif len(stack) == 0 or stack[len(stack) - 1] == 'T':
        stack.append('T')
    else:
        stack.pop()
print(len(stack))
import numpy as np

x,n = [int(i) for i in input().split()]
if n >0:
  table = [int(i) for i in input().split()]
  min = min(table)
  b = table
  a = np.array(table)
  a = a - x
  a = np.abs(a)
  a = np.sort(a)
    #print(a)

  for i in range(n):
    if a[0] > 0:
      print(x)
      break
    elif a[i+1]-a[i]>1 and i < n:
      if i == 0:
        if x-a[i]-1 in b or x-a[i]-1 < min:
          print(x+a[i]+1)
          break
        else:
          print(x-a[i]-1)
          break
      elif i > 0 and a[i] == a[i-1]:
        if x-a[i]-1 in b or x-a[i]-1 < min:
          print(x+a[i]+1)
          break
        else:
          print(x-a[i]-1)
          break
      else:
        if x-a[i] in b or x-a[i] < min:
          print(x+a[i])
          break
        else:
          print(x+a[i])
          break
else:
  print(x)


      
    




### FIXED CODE ###

def main():
  x,n = [int(i) for i in input().split()]
  table = list(map(int, input().split()))
  
  for i in range(101):
    if x - i not in table:
      print(x-i)
      exit()
    elif x + i not in table:
      print(x+i)
      exit()
    	
if __name__ == "__main__":
  main()
N = input()
print(int(N*N*N))

### FIXED CODE ###

N =input()
print(int(N)**3)
n=int(input())
a=list(map(int,input().split()))
a.sort()
negative=[]
positive=[]
for ele in a:
    if ele<0:
        negative.append(ele)
    else:
        positive.append(ele)
if len(negative)==0:
    print(sum(a))
else:
    if len(negative)%2==0:
        print(-sum(negative)+sum(positive))
    else:
        if -negative[0]>positive[0]:
            print(-sum(negative)+sum(positive[1:])-positive[0])
        else:
            print(-sum(negative[1:])+sum(positive)+negative[0])




### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
negative=[]
positive=[]
for ele in a:
    if ele<0:
        negative.append(ele)
    else:
        positive.append(ele)
if len(negative)==0:
    print(sum(a))
else:
    if len(negative)%2==0:
        print(-sum(negative)+sum(positive))
    else:
        if len(positive)==0:
            print(-sum(negative)+2*negative[-1])
        elif -negative[-1]>positive[0]:
            print(-sum(negative)+sum(positive[1:])-positive[0])
        else:
            print(-sum(negative[:-1])+sum(positive)+negative[-1])