Harryxun/stf_run huggingface dataset:
import sys
import numpy as np

i8 = np.int64
i4 = np.int32
mod = 10**9 + 7


def solve(now, from_, K, pa, b):
    if from_ == -1:
        can_num = K - 1
    else:
        can_num = K - 2
    if K < pa[now + 1] - pa[now]:
        return 0
    case_num = i8(1)
    for i in range(pa[now], pa[now + 1]):
        if b[i] != from_:
            case_num *= can_num
            can_num -= 1
            case_num %= mod
    for i in range(pa[now], pa[now + 1]):
        if b[i] != from_:
            case_num *= solve(b[i], now, K, pa, b)
            case_num %= mod
    return case_num


def main():
    pin = np.fromstring(sys.stdin.buffer.read(), dtype=i4, sep=' ')
    N = pin[0]
    K = pin[1]
    ab = pin[2:2 * N].reshape(N - 1, 2).T
    ab = ab - 1
    ab = np.hstack((ab, ab[[1, 0]]))
    ab = ab[:, np.argsort(ab[0])]
    pa = np.unique(ab[0], return_index=True)[1]
    pa = np.append(pa, 2 * (N - 1))
    ans = K * solve(0, -1, K, pa, ab[1])
    print(ans % mod)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
mod = 10**9 + 7


def solve(now, from_, K, ab):
    if from_ == -1:
        can_num = K - 1
    else:
        can_num = K - 2
    if K < len(ab[now]):
        return 0
    case_num = 1
    for i in ab[now]:
        if i != from_:
            case_num *= can_num
            can_num -= 1
            case_num %= mod
    for i in ab[now]:
        if i != from_:
            case_num *= solve(i, now, K, ab)
            case_num %= mod
    return case_num


def main():
    N, K = map(int, input().split())
    if N == 1:
        print(K)
        exit(0)
    ab = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        ab[a - 1].append(b - 1)
        ab[b - 1].append(a - 1)
    ans = K * solve(0, -1, K, ab)
    print(ans % mod)


if __name__ == "__main__":
    main()
_input = [i for i in open(0).read().split('\n') if i]
n, k = [int(i) for i in _input[0].split()]
edge = [[int(p) for p in i.split()] for i in _input[1:n]]
 
import collections
 
colored  = {}
edge_map = collections.defaultdict(list)
for e in edge:
    edge_map[e[0]].append(e[1])
    edge_map[e[1]].append(e[0])
 
root = edge[0][0]

### FIXED CODE ###

import sys
sys.setrecursionlimit(4100000)

_input = [i for i in open(0).read().split('\n') if i]
n, k = [int(i) for i in _input[0].split()]
edge = tuple([tuple([int(p) for p in i.split()]) for i in _input[1:n]])

factorial = [0] * (k + 1)
inverse = [0] * (k + 1)
MOD = 1000000007

# Ref: http://keita-matsushita.hatenablog.com/entry/2016/12/05/175024
def mod_pow1(n, k, mod):
    a = 1
    while k:
        if (k & 1) == 1:
            a = (a * n) % mod
        n = (n * n) % mod
        k >>= 1
    return a

# Ref: https://www.smartbowwow.com/2018/10/mod1097.html
def mod_pow2(n, k, mod):
    if k == 0:
        return 1
    if k % 2 == 0:
        a = mod_pow2(n, k // 2, mod)
        return (a * a) % mod
    else:
        return (n * mod_pow2(n, k - 1, mod)) % mod

#mod_pow = mod_pow1
# It's better to use built-in function for speed.
mod_pow = pow

def mod_factorial_inverse(k, mod):
    factorial[0] = 1
    inverse[0] = 1

    # Ref: http://keita-matsushita.hatenablog.com/entry/2016/12/05/184011
    for i in range(1, k + 1):
        factorial[i] = ((i * factorial[i - 1]) % mod) # factrial[i]
        inverse[i] = mod_pow(factorial[i], mod - 2, mod) # inverse[i]
 
total = 1

if not edge:
    print(k)
else:
    all_edge = tuple([[] for _ in range(n + 1)])
    for e in edge:
        all_edge[e[0]].append(e[1])
        all_edge[e[1]].append(e[0])
    all_edge = [set(v) for v in all_edge]

    if [v for v in all_edge if len(v) >= k]:
        print(0)
    else:
        mod_factorial_inverse(k, MOD)

        root = edge[0]
        total = (factorial[k] * inverse[k - len(all_edge[root[0]]) - 1]) % MOD

        def dfs(current, from_):
            global total
            child = all_edge[current]
            if len(child) - 1 > 0:
                total = (total * factorial[k - 2] * inverse[k - 2 - (len(child) - 1)]) % MOD
            for c in child:
                if c != from_:
                    dfs(c, current)
        for c in all_edge[root[0]]:
            dfs(c, root[0])
        print(total)
def dp(idx,f,a,cache):
    if idx==len(a):
        return 0
    if cache[idx][f]!=-1:
        return cache[idx][f]
    ans=0
    for i in range(3):
        if i==f:
            continue
        ans=max(ans,dp(idx+1,i,a,cache))
    ans+=a[idx][f]
    cache[idx][f]=ans
    return ans
a=[]
n=int(input())
for i in range(n):
    a.append(list(map(int,input().split())))
cache=[[-1,-1,-1] for i in range(n)]
print(max(dp(0,0,a,cache),dp(0,1,a,cache),dp(0,2,a,cache)))

### FIXED CODE ###

inf = float("inf") 
n=int(input())
a=list(map(int ,input().split()))
dp=[inf]*n
k=2
dp[0]=0
for i in range(1,n):
   for j in range(i-1,max(0,i-k)-1,-1):
       dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]))
print(dp[n-1])
import sys
import numpy as np

read = sys.stdin.buffer.read

H,W,M = list(map(int, input().split()))

hw = np.zeros((3*10**5,3*10**5),dtype=np.int64)
w = np.zeros(3*10**5,dtype=np.int64)
h = np.zeros(3*10**5,dtype=np.int64)
 
for i in range(M):
    h_i, w_j = map(int, input().split())
    hw[h_i-1, w_j-1] = 1
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 0
for i in np.where(h==h.max())[0]:
    for j in np.where(w==w.max())[0]:
        mxh_v = h[i]
        mxw_v = w[j]
        d = hw[i, j]
        # print(i,j,a, mxh_v , mxw_v , d)
        a = max(a, mxh_v + mxw_v - d)
    if d == 0:
        break
print(a)

### FIXED CODE ###

H,W,M = list(map(int, input().split()))

hw = set()
w = [0] * 3*10**5
h = [0] * 3*10**5

for i in range(M):
    h_i, w_j = map(int, input().split())
    hw.add((h_i-1) + (w_j-1)*3*10**6)
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 1
mxh_v = max(h)
mxw_v = max(w)

x = [i for i,j in enumerate(h) if j == mxh_v]
y = [i for i,j in enumerate(w) if j == mxw_v]

for i in x:
    for j in y:
        if not(i + j*3*10**6 in hw):
            print(mxh_v+mxw_v)
            exit()
print(mxh_v+mxw_v-d)
n=int(input())
x=input()

def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
x0,x1=0,0
for i in range(n):
  if x[i]=='1':
    x0+=pow(2,n-1-i,pcx-1)
    x0%=pcx-1
    x1+=pow(2,n-1-i,pcx+1)
    x1%=pcx+1
for i in range(n):
  ans=0
  if x[i]=='1':
    xx=x0-pow(2,n-1-i,pcx-1)
    xx%=pcx-1
    print(func(xx)+1)
  else:
    xx=x1+pow(2,n-1-i,pcx+1)
    xx%=pcx+1
    print(func(xx)+1)


### FIXED CODE ###

n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)
import math
N=int(input())
list=[]#素因数の格納
for i in range(1,int(math.sqrt(N))):
    if N//i==N/i:
        list.append(N//i+i)
print(min(list)-2)

### FIXED CODE ###

import math
N=int(input())
list=[]#素因数の格納
for i in range(1,int(math.sqrt(N))+2):
    if N//i==N/i:
        list.append(N//i+i)
print(min(list)-2)
import sys
while True:
    x = sys.stdin.readline().strip()
    if x == "0 0":
        break
    a = list(map(int, x.strip()))
    sharp = "#" * a[1]
    for i in range(a[0]):
        print(sharp)
    print("\n")

### FIXED CODE ###

while True:
    a = list(map(int, input().split()))
    if a[0] == a[1] == 0:
        break
    sharp = "#" * a[1]
    for i in range(a[0]):
        print(sharp)
    print()
N = int(input())
X = list(input())

def popcount(a):
    cnt = 0
    while True:
        y = bin(a).count("1")
        a %= y
        cnt += 1
        if n == 0:
            print(cnt)
            break

ans = 0
for i in range(len(X)):
    if X[i] == "1":
        X[i] = "0"
        Flag = True
    else:
        X[i] = "1"
        Flag = False
        
    x = "".join(X)
    n = int(x, 2)
    popcount(n)
            
    if Flag is True:
        X[i] = "1"
    else:
        X[i] = "0"

### FIXED CODE ###

def goes_to_zero(n):
    cnt = 0
    while(n > 0):
        n %= bin(n).count('1')
        cnt += 1
    return cnt

N = int(input())
X = input()

XC = X.count('1')
XI = int(X, 2)
XCP = XC + 1
XCM = XC - 1
XTP = XI % XCP
XTM = XI % XCM if XCM != 0 else 0

for i in range(N):
    if X[i] == "0":
        print(goes_to_zero((XTP + pow(2, N - 1 - i, XCP)) % XCP) + 1)
    else:
        if XCM == 0:
            print(0)
        else:
            print(goes_to_zero((XTM - pow(2,N - 1 - i, XCM)) % XCM) + 1)
M,D = input().strip().split()
count = 0
for m in range(2,M+1):
    for d in range(22, D+1):
        if m = (d / 10) % 10 * (d % 10):
            count += 1
print(count)


### FIXED CODE ###

M,D = list(map(int, input().strip().split()))
count = 0
for m in range(2,M+1):
    for d in range(11, D+1):
        if ((d%10) >= 2) and (int(d/10) >= 2) and (m == int(d/10) * (d%10)):
            count+=1
print(count)
import math
def cmb(n, r):
    return math.factorial(n)/(math.factorial(r)*math.factorial(n-r) )

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

for i in range(1, k+1):
    if n-k+1 >= i:
        ans =  cmb(n-k+1,i)*cmb(k-1,i-1)%(10**9+7)
    else:
        ans = 0
    print(ans)

### FIXED CODE ###

import math
def cmb(n, r):
  n_ = math.factorial(n)
  n_r_ = math.factorial(n-r) 
  r_ = math.factorial(r)
  return n_//(r_*n_r_)

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

for i in range(1, k+1):
  if n-k+1 >= i:
    ans =  cmb(n-k+1,i)*cmb(k-1,i-1)%(10**9+7)
  else:
    ans = 0
  print(ans)
=int(input())
P=list(map(int,input().split()))
count=0
if P[0]!=1:
    count=count+1
elif P[N-1
       ]!=N:
    count=count+1
for i in range(N-1):
    if P[i]+1!=P[i+1]:
        count=count+1
if count<5:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
count=0
for i in range(N):
    if P[i]!=i+1:
        count=count+1
if count<3:
    print('YES')
else:
    print('NO')
from collections import Counter

S = Counter(list(input()))
T = Counter(list(input()))
s,t = list(S.values()),list(T.values())
print(["No", "Yes"][(s.sort() == t.sort() or  len(s) % 2 != 0])

### FIXED CODE ###

from collections import Counter

S = Counter(list(input()))
T = Counter(list(input()))
s,t = list(S.values()),list(T.values())
print(["No", "Yes"][Counter(s) == Counter(t)])
while True:
	try:
		A=[int(j) for j in input().split()]
		a=A[3]/A[0]
		for i in range(3):
			A[i]*=a
		for i in range(3):
			A[i]=A[i]-A[i+3]
		y=A[2]/A[1]
		x=(A[5]-A[4]*y)/A[3]
		print("%f %f"%(x+0,y+0))
	except EOFError:
		break

### FIXED CODE ###

while True:
    try:
        l=list(map(int, input().split()))
        x=(l[1]*l[5]-l[2]*l[4])/(l[1]*l[3]-l[0]*l[4])
        y=(l[2]-l[0]*x)/l[1]
        if x == 0: x = 0
        print( "{0:.3f} {1:.3f}".format(x,y))
    except:
        break
# 3
import math

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

def f(m,a):
    ans=0
    for i in a:
        ans+=m%i
    return ans

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

def lcm_list(numbers):
    ans=numbers[0]
    for i in range(1,len(numbers)):
        ans=lcm_base(ans,numbers[i])
    return ans

m= lcm_list(a)-1
print(f(m,a))

### FIXED CODE ###

# 3
import math

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

def f(m,a):
    ans=0
    for i in a:
        ans+=m%i
    return ans

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

def lcm_list(numbers):
    ans=numbers[0]
    for i in range(1,len(numbers)):
        ans=lcm_base(ans,numbers[i])
    return ans

m= lcm_list(a)-1
print(f(m,a))
N=int(input())
A=list(map(int, input().split()))
B=[]
B.append(A[0])
for i in range(1,N):
    if A[i]!=B[-1]: B.append(A[i])
i=1
length=len(B)
while i<length-1:
    if B[i]>B[i-1] and B[i]<B[i+1] or B[i]<B[i-1] and B[i]>B[i+1]:
        B.pop(i)
        length-=1
    else:
        i+=1
yen=1000
kabu=0
for i in range(len(B)):
    if B[0]<B[1]:
        if i%2==0 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        else:
            yen=yen+kabu*B[i]
    else:
        if i%2==1 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        else:
            yen=yen+kabu*B[i]
print(yen)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
B=[]
B.append(A[0])
for i in range(1,N):
    if A[i]!=B[-1]: B.append(A[i])
i=1
length=len(B)
while i<length-1:
    if B[i]>B[i-1] and B[i]<B[i+1] or B[i]<B[i-1] and B[i]>B[i+1]:
        B.pop(i)
        length-=1
    else:
        i+=1
yen=1000
kabu=0
for i in range(len(B)):
    if len(B)>=2 and B[0]<B[1]:
        if i%2==0 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        elif i%2==1:
            yen=yen+kabu*B[i]
    else:
        if i%2==1 and i<len(B)-1:
            kabu=yen//B[i]
            yen=yen%B[i]
        elif i%2==0:
            yen=yen+kabu*B[i]
print(yen)
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]



def check(string):
    for s, c in SC:
        if string[s - 1] != str(c):
            return False
    return True 



if N == 1:
    for i in range(10 ** i):
        if check(str(i)):
            print (i)
            exit()
    print (-1)
    exit()
else:
    for i in range(10 ** (N - 1), 10 ** (N)):
        if check(str(i)):
            print (i)
            exit()
    print (-1)
    exit()
       

### FIXED CODE ###

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

def check(string):
    for s, c in SC:
        if string[s - 1] != str(c):
            return False
    return True 

if N == 1:
    for i in range(10 ** 1):
        if check(str(i)):
            print (i)
            exit()
    print (-1)
    exit()
else:
    for i in range(10 ** (N - 1), 10 ** (N)):
        if check(str(i)):
            print (i)
            exit()
    print (-1)
    exit()
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**i)
sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if N <= i:
    N=N-i
    count+=1
      if N==0:
        print(count)

### FIXED CODE ###

N=int(input())

A=[1]

i = 1
while True:
    if 6**i <= 100000:
        A.append(6**i)
    else:
        break
    i += 1

i = 1
while True:
    if 9**i <= 100000:
        A.append(9**i)
    else:
        break
    i += 1

A.sort()

dp = [N]*(N+1)
dp[0] = 0
for i in range(1, N+1):
    for j in range(len(A)):
        if i - A[j] >= 0:
            dp[i] = min(1+dp[i-A[j]], dp[i])

print(dp[-1])
s = input()

if s % 1.08 < 0.1:
  print(':(')
else:
  x = s // 1.08
  x = int(x)
  print(x)

### FIXED CODE ###

import math

s = int(input())

te = s % 1.08
if te < 0.1:
  print(':(')
else:
  x = s / 1.08
  print(math.ceil(x))
A,B= list(input().split())
a = int(B[0])
b = int(B[2])
c = int(B[3])
if int(A) > 1000:
   e = int(A[-2])
   f = int(A[-1])
   d = (int(A)- 10 * e - f)/100
   error = 10 * (c * e + b * f) + c * f
   error = int(error/100)
   ans = int(A) * a + 10 * d * b + e * b + c * d + error
   print(ans)
else:
   print(int(int(A)*float(B))

### FIXED CODE ###

A,B= list(input().split())
a = int(B[0])
b = int(B[2])
c = int(B[3])
if int(A) > 1000:
   e = int(A[-2])
   f = int(A[-1])
   d = int((int(A)- 10 * e - f)/100)
   error = 10 * (c * e + b * f) + c * f
   error = int(error/100)
   ans = int(A) * a + 10 * d * b + e * b + c * d + error
   print(int(ans))
else:
   print(int(int(A)*float(B)))
n = int(input())
A = list(map(int,input().split()))
counter = 0
end_judge = 0
while 1:
  
  for i in range(n):
  	if A[i]%2 == 1:
      end_judge = 1
    else:
      A[i] = A[i] % 2    
  counter += 1
  if end_judge == 1:
    break

print(counter)

### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
 
counter = 0
end_judge = 0
while 1:
  
  for i in range(n):
    if A[i]%2 == 1 or A[i]==0:
      end_judge = 1
    A[i] = A[i] / 2    
      
  if end_judge == 1:
    break    
  counter += 1
  
print(counter)
N = int(input())
Atmp = [0] + list(map(int, input().split()))
A = {}

for i,a in enumerate(Atmp):
    A[i] = a

#print(A)

X = {}

def umeru(X, M, last):
    #print('---')
    for i in reversed(list(range(N//(M+1)+1, N//M+1))):
        if M == 1:
            X[i] = A[i]
        else:
            Xsum = 0
            j = 2
            while(i*j < N):
                Xsum += X[i*j]
                j += 1
                continue
            odd = Xsum % 2
            #print(M, i, odd, A[i])
            if odd == A[i]:
                X[i] = 0
            else:
                X[i] = 1
    #print(N,M,X)
    if last:
        return
    if N//(M+1) == 0:
        umeru(X, M+1, True)
    else:
        umeru(X, M+1, False)

umeru(X, 1, False)
#print(X)

M = 0
for i in range(1, N+1):
    if X[i] == 1:
        M += 1

print(M)

for i in range(1, N+1):
    if X[i] == 1:
        print(i, end=' ')


print()


### FIXED CODE ###

import sys

N = int(input())
Atmp = [0] + list(map(int, input().split()))
A = {}

for i,a in enumerate(Atmp):
    A[i] = a

#print(A)

X = {}

for i in reversed(list(range(1,N+1))):
    Xsum = 0
    j = 2
    while(i*j <= N):
        Xsum += X[i*j]
        j += 1
        continue
    odd = Xsum % 2
    if odd == A[i]:
        X[i] = 0
    else:
        X[i] = 1
    
M = 0
for i in range(1, N+1):
    if X[i] == 1:
        M += 1

print(M)
if M == 0:
    sys.exit()

xxx = []
for i in range(1, N+1):
    if X[i] == 1:
        xxx.append(str(i))

print(' '.join(xxx))
# -*- coding: utf-8 -*-
N = int(input())
A = [int(v) for v in input().split(' ')]

# 負の数が偶数 -> 全部+にできる
# 負の数が奇数 -> どれか一つが-になる
# 負の数の偶奇チェック
sign = 1
for a in A:
    sign *= a/abs(a)
    
if sign > 0:
    print(sum(A))
else:
    print(sum(A)-min(A))

### FIXED CODE ###


N = int(input())
A = [ int(v) for v in input().split() ]

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < -1e9 and v < 1e9: raise()

abs_list = [abs(v) for v in A]

total = sum( abs_list )
num_of_minus = sum([ True for v in A if v < 0 ])

if num_of_minus % 2 == 1:
    print(total - min( abs_list ) * 2)
else:
    print(total)
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return ''.join(sm)

def jfws(s):
    print(s)
    fws=fnw(5,s)
    # print(fws)
    if fws=='dream':
        fws=fnw(2,s)
        if fws=='er':
            if s[0]=='a':
                s.extendleft(deque(reversed(list(fws))))
        else:
            s.extendleft(deque(reversed(list(fws))))
        return False
    elif fws=='erase':
        fws=fnw(1,s)
        if fws!='r':
            s.appendleft(fws)
        return False
    else:
        return True 

def main(s):
    while bool(s):
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))



### FIXED CODE ###

from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return sm

def jfws(s):
    # print(s)
    sm=fnw(5,s)
    # print(sm)
    if ''.join(sm)=='dream':
        sm=fnw(2,s)
        if ''.join(sm)=='er':
            if bool(s):
                if s[0]=='a':
                    s.extendleft(deque(reversed(list(sm))))
        else:
            s.extendleft(deque(reversed(list(sm))))
        return False
    elif ''.join(sm)=='erase':
        sm=fnw(1,s)
        if ''.join(sm)!='r':
            s.extendleft(sm)
        return False
    else:
        return True 

def main(s):
    while len(s)>0:
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))
X = input()

cache = 0
ans = len(X)

for c in X:
    if c == 'S'
        cache += 1
    else:
        if cache > 0:
            cache -= 1
            ans -= 2

print(ans)

### FIXED CODE ###

X = input()

cache = 0
ans = len(X)

for c in X:
    if c == 'S':
        cache += 1
    else:
        if cache > 0:
            cache -= 1
            ans -= 2

print(ans)
s,t = [i for i in input().split()]
list(s).sort()
list(t).sort(reverse = True)
if s < t :
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = list(input())
t = list(input())
s.sort()
t.sort(reverse = True)
if ''.join(s) < ''.join(t) :
  print('Yes')
else:
  print('No')
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n+1):
	for x in [1,-1]:
		y = n + x*i
		if y not in a:
			print(y)
			exit(1)

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n+1):
	for x in [-1,+1]:
		y = n + x*i
		if y not in a:
			print(y)
			exit(0)
inputStr = input().split(' ')
a = int(inputStr[0])
b = int(inputStr[1])
c = int(inputStr[2])
if(a < b && b < c):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

inputStr = input().split(' ')
a = int(inputStr[0])
b = int(inputStr[1])
c = int(inputStr[2])
if a < b & b < c:
  print("Yes")
else:
  print("No")
import sys
argv = sys.argv
x = int(argv[1])
y = int(argv[2])
print x*y,
print 2*x+2*y

### FIXED CODE ###

num = map(int, raw_input().split())
print num[0]*num[1], 2*(num[0] + num[1])
7
1 2 3 4 5 6 7

### FIXED CODE ###

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

cnt=0
for i in range(N):
    if i+1!=p[i]:
        cnt+=1
if cnt==0 or cnt==2:
    print("YES")
else:
    print("NO")
n=input()
flag=0
for i in n:
    if i=='7':
        flag=1
if flag==1:
    print('Yes')
else
    print('No')

### FIXED CODE ###

n=input()
n=list(n)
flag=0
for i in n:
    if i=='7':
        flag=1
if flag==1:
    print('Yes')
else:
    print('No')
n=input()
l=list(range(1,n))
m=0
def c(n):
  return n/2
while any(i%2==0 for i in l):
       l=map(c,l)
       m+=1
print(2**m)

### FIXED CODE ###

N=int(input())
c=0
n=range(1,N)
while any(i%2==0 for i in n):
          N=int(N/2)
          n=range(1,N+1)
          c+=1
print(2**c)
a,b,c,d = 0,0,0,0
while 1:
	lng=list(int(input().split()))
	lng.sort()
	if lng[0] + lng[1] <= lng[2]:
		print('%d %d %d %d' % (a,b,c,d))
		break
	else:
		a += 1
		if lng[0]**2 + lng[1]**2 == lng[2]**2:
			b += 1
		elif lng[0]**2 + lng[1]**2 >= lng[2]**2:
			d += 1
		else:
			c += 1


### FIXED CODE ###

a,b,c,d = 0,0,0,0
while 1:
	lng=list(map(int,input().split()))
	lng.sort()
	if lng[0] + lng[1] <= lng[2]:
		print('%d %d %d %d' % (a,b,c,d))
		break
	else:
		a += 1
		if lng[0]**2 + lng[1]**2 == lng[2]**2:
			b += 1
		elif lng[0]**2 + lng[1]**2 <= lng[2]**2:
			d += 1
		else:
			c += 1
import math

# 組み合わせ算出
def combinations_count(n, r):
    if n == 1:
        return 0
    if n == 0:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if __name__ == '__main__':

    N= int(input())

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

    for i in range(N):
        total = 0

        b = a[:i] + a[i+1:]

        c = collections.Counter(b)

        for j in set(a):

            total = total + combinations_count(c[j], 2)

        print(total)

### FIXED CODE ###

import collections
import math


if __name__ == '__main__':
    N= int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    result = 0
    for i in set(a):
        # c[i]の中から2個選ぶ
        result += (c[i]*(c[i]-1))/2

    for i in a:
        d = c[i]
        print(int(result - (d*(d-1))/2 + ((d-1)*(d-2))/2))
l=list(int(input()) for _ in range(5))
s=list(10-i%10 for i in l)
for i in range(s.count(10)):
  s.remove(10)
s.remove(max(s))
print(sum(l)+sum(s))

### FIXED CODE ###

l=list(int(input()) for _ in range(5))
s=list(10-i%10 for i in l)
for i in range(s.count(10)):
  s.remove(10)
if len(s)>0:
  s.remove(max(s))
print(sum(l)+sum(s))