Harryxun/stf_run huggingface dataset:
from collections import deque

def bfs(s):
    global dist, visit
    q = deque()
    q.append(s)
    dist[s] = 0
    visit[s] = s
    x = 0
    y = deque()
    while q:
        p = q.popleft()
        for g in G[p]:
            if dist[g[0]] == a:
                dist[g[0]] = dist[p] + g[1] + x
                y.append(dist[g[0]])
                visit[g[0]] = s
                q.append(g[0])
            else:
                if not dist[g[0]] == dist[p] + g[1] + x:
                    if visit[g[0]] == s:
                        print("No")
                        exit()
                    else:
                        if x == 0:
                            x = dist[g[0]] - (dist[p] + g[1])
                            while y:
                                z = y.popleft()
                                dist[z] += x
                        else:
                            print("No")
                            exit()
                    

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(m):
    l, r, d = map(int, input().split())
    G[l].append([r, d])
a = -pow(10, 9)
dist = [a] * (n + 1)
visit = [0] * (n + 1)
for i in range(1, n + 1):
    if dist[i] == a:
        bfs(i)
print("Yes")

### FIXED CODE ###

from collections import deque

def bfs():
    visit = [0] * (n + 1)
    e = [0] * (m + 1)
    x = [0] * (n + 1)
    q = deque()
    for i in range(1, n + 1):
        if not visit[i]:
            q.append(i)
            visit[i] = 1
            while q:
                j = q.popleft()
                for g in G[j]:
                    if not e[g[2]]:
                        #print(e, visit, q, x, j)
                        e[g[2]] = 1
                        if not visit[g[0]]:
                            x[g[0]] = g[1] + x[j]
                            visit[g[0]] = 1
                            q.append(g[0])
                        else:
                            #print(x[g[0]], g[1] + x[j])
                            if not x[g[0]] == g[1] + x[j]:
                                return False
    return True

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for i in range(m):
    l, r, d = map(int, input().split())
    G[l].append([r, d, i])
    G[r].append([l, -d, i])
print("Yes" if bfs() else "No")
mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 1
t1 = 0 if 1 in l else 1

for i in range(2,n+1):
  t0 = 0 if i in l else (t2+t1)%mod
  t2 = t1
  t1 = t0

print(t0)

### FIXED CODE ###

mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 0
t1 = 1

for i in range(1,n+1):
  if l == [] or i != l[0]:
    t0 = (t2+t1)%mod
  else:
    l.pop(0)
    t0 = 0
  t2 = t1
  t1 = t0

print(t0)
a = int(input())
b = int(input())
print(max(0,a-2*b))



### FIXED CODE ###

a,b = map(int,input().split())
print(max(0,a-2*b))
N, Y = map(int, input().split())
sum = 0
is_exist = False
for i in range(N+1):
  for j in range(N+1):
    k = N - i - j
    sum = i * 10000 + j * 5000 + k * 1000
    if sum == Y and i + j + k == N:
      printf(str(i) + " " + str(j) + " " + str(k))
      is_exist = True
      break
if is_exist == False:
  print("-1 -1 -1")

### FIXED CODE ###

def find(n, y):
  for i in range(n+1):
    for j in range(n+1-i):
      if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
        return i, j, n-i-j
  return -1, -1, -1
N, Y = map(int, input().split())
i, j, k = find(N, Y)
print("{} {} {}".format(i, j, k))
a,b = map(int input().split())
b = b / 2
result = a + b
print(result)

### FIXED CODE ###

a, b = map(int, input().split())
if 1 > a or b%2 != 0 or b > 100:
  SystemExit
print(int(a+b/2))
S = input()
T = input()
slide_num = len(S) - len(T)
if slide_num < 0:
    pass
for slide in range(slide_num+1):
    for j in range(len(S)-slide):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        print((S[:2] + T + S[2+len(T):]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')

### FIXED CODE ###

S = input()
T = input()
L = []
slide_num = len(S) - len(T)
if slide_num < 0:
    print('UNRESTORABLE')
    exit()
for slide in range(slide_num+1):
    for j in range(len(T)):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        L.append((S[:slide] + T + S[slide+len(T):]).replace('?', 'a'))

if L:
    print(L.pop())
else:
    print('UNRESTORABLE')
a, b , c ,d = map(int, input().split())


if b < c:
    print("0")
    exit()

if c<b and b<d:
    print((d-c)-(d-b))
elif a<c adn d<b:
    print(d-c)
else:
    print("0")



### FIXED CODE ###

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



mi = min(b,d )
ma = max(a,c)

print(max(0,mi - ma))
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    bitboard = 0
    for _ in range(m):
        hi, wi = map(int, read().split())
        bitboard += 1 << (w * (hi - 1) + (wi - 1))
    ans = 0
    for hi in range(h):
        for wi in range(w):
            b = bitboard & (((2**w - 1) << hi * w) | (sum(1 << (w * i) for i in range(h)) << wi))
            ans = max(bin(b).count("1"), ans)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = set()
    row = [0] * h
    col = [0] * w
    for _ in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target.add((hi, wi))
        row[hi] += 1
        col[wi] += 1
    row_max = max(row)
    r = [i for i in range(h) if row[i] == row_max]
    col_max = max(col)
    c = [i for i in range(w) if col[i] == col_max]
    for ri in r:
        for ci in c:
            if (ri, ci) not in target:
                print(row_max + col_max)
                return
    print(row_max + col_max - 1)


if __name__ == '__main__':
    main()
import math

n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += math.gcd(i, gcd(j,k))

print(ans)

### FIXED CODE ###

import math

n = int(input())
ans = 0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans += math.gcd(i, math.gcd(j,k))

print(ans)
S = input()
if len(S) <= K:
    print(S)
else:
    print(S[0:K]+'...')

### FIXED CODE ###

K = int(input())
S = input()
if len(S) <= K:
    print(S)
else:
    print(S[0:K]+'...')
#!/usr/bin/env python

main():
    N = int(input())
    A = tuple(map(int, input().split()))
    s = set()
    for a in A:
        if a in s:
            print("NO")
            exit()
        else:
            s.add(a)
    print("YES")

if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    s = set()
    for a in A:
        if a in s:
            print("NO")
            exit()
        else:
            s.add(a)
    print("YES")

if __name__ == '__main__':
    main()
import itertools

n = input()

p_list = list(int, input().split())
q_list = list(int, input().split())

num_list = [i+1 for i in range(n)]

a = 0
b = 0

for i, v in enumerate(itertools.permutations(num_list, n)): 
    print(v) 
    if(list(v) == p_list):
        a = i
    if(list(v) == q_list):
        b = i
print(abs(a - b))

### FIXED CODE ###

import itertools

n = int(input())

p_list = [int(i) for i in input().split()]
q_list = [int(i) for i in input().split()]

num_list = [i+1 for i in range(n)]

a = 0
b = 0

for i, v in enumerate(itertools.permutations(num_list, n)): 
    if(list(v) == p_list):
        a = i
    if(list(v) == q_list):
        b = i
print(abs(a - b))
a,b,c = map(input().split())
y=0
for x in(a,b+1):
    if c%x==0:
    y+=1
    print(y)

### FIXED CODE ###

a,b,c = map(int,input().split())
d=0
for x in range(a,b+1):
    if c%x==0:d+=1
print(d)
s = list(input())

if s[1] == '+':
  print(s[0]+s[2])
else:
  print(s[0]-s[2])

### FIXED CODE ###

s = list(input().split())

if s[1] == '+':
    print(int(s[0])+int(s[2]))
else:
    print(int(s[0])-int(s[2]))
A,B = map(input().split())
A = int(A)
B = B.replace(".","")
B = int(B)
ans = int((A * B)//100)
print(str(ans))

### FIXED CODE ###

A,B = input().split()
A = int(A)
B = B.replace(".","")
B = int(B)
ans = int((A * B)//100)
print(str(ans))
import numpy as np
h, w, m = map(int, input().split())
arr = np.zeros([h,w])
for _ in range(m):
    c_h, c_w = map(int, input().split())
    arr[c_h-1, c_w-1] = 1
    
row_sum = np.sum(arr, axis=1)
col_sum = np.sum(arr, axis=0)
row_max_pos = np.argwhere(row_sum == np.max(row_sum))
col_max_pos = np.argwhere(col_sum == np.max(col_sum))

### FIXED CODE ###

h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()

for i in range(m):
    _h, _w = map(int, input().split())
    h_cnt[_h-1] += 1
    w_cnt[_w-1] += 1
    bomb.add(((_h-1),(_w-1))) #爆破対象の位置を判断

h_max = max(h_cnt)
w_max = max(w_cnt)

max_h = []
max_w = []

for i in range(h):
    if h_cnt[i] == h_max:
        max_h.append(i)

for i in range(w):
    if w_cnt[i] == w_max:
        max_w.append(i)

flg = True

for i in max_h:
    for j in max_w:
        if (i,j) not in bomb:
            flg = False
            break
print(h_max+w_max-1 if flg else h_max+w_max)
n = int(input())
ans = 0
for i in range(10):
    for j in range(i+1):
        if i*j == n:
            ans += 1
if ans == 1:
    print("Yes")
elif n == 2,4,16,25,36,49,64:
  print("Yes")
else:
    print("No")

### FIXED CODE ###

n = int(input())
list = []

for i in range(1,10):
    for j in range(1,10):
        c = i*j
        list.append(c)
if n in list:
    print("Yes")
else:
    print("No")
import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline
n = int(rl())
li = []
for _ in range(n):
  lis = list(map(int, rl().split()))
  li.append(lis)
t = 0
for i in collections.permutations(n):
  for k in range(n-1):
    s = (li[i[k]][0] - li[i[k+1]][0])**2 + (li[i[k]][1] - li[i[k+1]][1])**2
    t += s**0.5
print(t/math.factorial(n))
  
  
  

### FIXED CODE ###

import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline
n = int(rl())
li = []
for _ in range(n):
  lis = list(map(int, rl().split()))
  li.append(lis)
t = 0
for i in list(itertools.permutations(range(n))):
  for k in range(n-1):
    s = (li[i[k]][0] - li[i[k+1]][0])**2 + (li[i[k]][1] - li[i[k+1]][1])**2
    t += s**0.5
print(t/math.factorial(n))
r1,c1,r2,c2 = map(int,input().split())
mod = 10**9+7
fact = [1]*(2*10**6+1)

for n in range(2*10**6):
    fact[n+1] = ((n+1)*fact[n])%mod

factinv = [1]*(2*10**6+1)
for n in range(10**6+1):
    factinv[n] = pow(fact[n],mod-2,mod)

def comb(n,k):
    return (fact[n]*factinv[n-k]*factinv[k])%mod

def fs(r,c):
    res = 0
    for i in range(1,c+1):
        res += comb(i+1+r,r)-1
    return res

ans = fs(r2,c2)-fs(r1-1,c2)-fs(r2,c1-1)+fs(r1-1,c1-1)
ans %= mod
print(ans)

### FIXED CODE ###

r1,c1,r2,c2 = map(int,input().split())
mod = 10**9+7
fact = [1]*(2*10**6+11)

for n in range(2*10**6+10):
    fact[n+1] = ((n+1)*fact[n])%mod

factinv = [1]*(2*10**6+10)
for n in range(10**6+10):
    factinv[n] = pow(fact[n],mod-2,mod)

def comb(n,k):
    return (fact[n]*factinv[n-k]*factinv[k])%mod

def fs(r,c):
    res = 0
    for i in range(1,c+1):
        res += comb(i+1+r,r)-1
    return res

ans = fs(r2,c2)-fs(r1-1,c2)-fs(r2,c1-1)+fs(r1-1,c1-1)
ans %= mod
print(ans)
N,K = map(int,input().split())
A = [int(input()) for _ in range(N)]
A.sort()
m=A[K-1]-A[0]
for i in range(N-K):
    if m > A[K+i]-A[i+1]:
        m = A[K+1]-A[i+1]
print(m)

### FIXED CODE ###

N,K = map(int,input().split())
A = [int(input()) for _ in range(N)]
A.sort()
m = []
for i in range(N-K+1):
    m.append(A[K-1+i]-A[i])
print(min(m))
s = int(input())
p = [1]*(s+1)
mod = 10**9 + 7

p[1] = 0
p[2] = 0

for i in range(3,s+1):
	p[i] = (sum(p[:i-2]))%mod
print(p[s])

### FIXED CODE ###

s = int(input())
p = [0]*(s+1)
mod = 10**9 + 7
p[0] = 1

if s >= 3:
	for i in range(3,s+1):
		p[i] = (sum(p[:i-2]))%mod
print(p[s])
S = input()
T = input()
ind = 0
w = ""
for i in range(len(S)):
  if S[i] == "?" or S[i] == T[ind]:
    ind += 1
    if ind == len(T):
      w += T
      for j in range(i+1,len(S)):
        w += S[j]
      break
  else:
    for k in range(ind, 0 , -1):
      w += S[i-k]
    ind = 0
    w += S[i]
if ind < len(T):
  print("UNRESTORABLE")
else:
  for i in range(len(w)):
    if w[i] == "?":
      ans = w.replace("?", "a")
  print(ans)   

### FIXED CODE ###

def main():
    s = input()
    t = input()
    T = len(t)
    candidate = []
    for i in range(len(s)-T+1):
        buf = s[i:i+T]
        flag = True
        for b, tc in zip(buf, t):
            if b == "?" or b == tc:
                continue
            else:
                flag = False
                break
        if flag == True:
            candidate.append(i)
    if len(candidate) == 0:
        print("UNRESTORABLE")
    else:
        print((s[:candidate[-1]] + t + s[candidate[-1]+T:]).replace("?", "a"))
if __name__ == '__main__':
    main()
import functools
import operator

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

i = 2
res = []
i_2 = i**N
while i * i<=P:
  while P%i_2==0:
    P/=i_2
    res.append(i)
  else:
    i += 1
    
res.append(1)
result = functools.reduce(operator.mul, res)
print(result)

### FIXED CODE ###

N = map(str,input())
M = [M for M in N]
print(M.count("2"))
N=int(input())
T=list(map(int,input().split()))
A=list(map(int,input().split()))

if T[N-1]!=A[0]:
    print(0)
elif N==1:
    print(1)
else:
    
    L=[[T[0],0]]
    for i in range(1,N):
        if T[i]==T[i-1]:
            L.append([T[i],1])
        else:
            L.append([T[i],0])
    #print(L)
            
    if L[len(L)-1][0]>A[len(L)-1]:
        L[len(L)-1]=[A[len(L)-1],0]
    else:
        L[len(L)-1][1][0]
    
    for i in range(1,N):
        if L[len(L)-1-i][0]>=A[len(L)-1-i]:
            L[len(L)-1-i][0]=A[len(L)-1-i]
            if A[len(L)-1-i]==A[len(L)-i]:
               pass
            else:
                L[len(L)-1-i][1]=0
            if L[len(L)-1-i][0]>L[len(L)-i][0]:
                L[len(L)-1-i][1]=0
    #print(L)
    ans=1
    for i in range(len(L)):
        if L[i][1]==1:
            ans*=L[i][0]
            ans%=(10**9+7)
    print(ans)

### FIXED CODE ###

N=int(input())
T=list(map(int,input().split()))
t=[1]
for i in range(1,N):
    if T[i]!=T[i-1]:
        t.append(1)
    else:
        t.append(T[i])
    if T[i]<T[i-1]:
        print(0)
        exit()
A=list(map(int,input().split()))
A=A[::-1]
a=[1]
for i in range(1,N):
    if A[i]!=A[i-1]:
        a.append(1)
    else:
        a.append(A[i])
    if A[i]<A[i-1]:
        print(0)
        exit()
A=A[::-1]
a=a[::-1]
#print(t)
#print(a)
M=max(A)

for i in range(N):
    if T[i]==M:
        if A[i]==M:
            break
        else:
            print(0)
            exit()

for i in range(N):
    if A[N-1-i]==M:
        if T[N-1-i]==M:
            break
        else:
            print(0)
            exit()
ans=1
mod=(10**9+7)
for i in range(N):
    ans*=min(t[i],a[i])
    ans%=mod
print(ans)
S=int(input())
x_1=10**9
y_1=10**9
x_2=10**9
y_3=10**9

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)

if S % S**(1/2):
    a = divisors(S)
    x=a[len(a)//2 - 1:len(a)//2  + 1]
else:
    x=[S**(1/2),S**(1/2)]



print(x_1,y_1,x_2,(10**9)-x[0],(10**9)-x[1],y_3)

### FIXED CODE ###

S=int(input())
x_1=0
y_1=0
x_2=10**9
y_2=1

if S%10**9==0:
    x_3=0
    y_3=S//10**9
else:
    x_3=10**9-S%10**9
    y_3=1+S//10**9

print(x_1,y_1,x_2,y_2,x_3,y_3)
STABLE = 'Stable'
UNSTABLE = 'Not stable'


def main():
  card_num = int(input())
  cards = input().split()

  bubble_sorted = bubble_sort(cards, card_num)
  select_sorted = select_sort(cards, card_num)

  stability = True
  for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
  stability = STABLE if stability else UNSTABLE

  print(bubble_sorted)
  print(STABLE)

  print(select_sorted)
  print(stability)

  return 0


def order(card_sym):
  return int(card_sym[1])


def select_sort(elements, element_num):
  elements = list(elements)

  for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < order(min_val):
        min_val = elements[j]
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

  return elements


def bubble_sort(elements, element_num):
  elements = list(elements)

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

  return elements


if __name__ == '__main__':
  main()

### FIXED CODE ###

STABLE = 'Stable'
UNSTABLE = 'Not stable'


def main():
  card_num = int(input())
  cards = input().split()

  bubble_sorted = bubble_sort(cards, card_num)
  select_sorted = select_sort(cards, card_num)

  stability = True
  for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
  stability = STABLE if stability else UNSTABLE

  print(' '.join(bubble_sorted))
  print(STABLE)

  print(' '.join(select_sorted))
  print(stability)

  return 0


def order(card_sym):
  order = int(card_sym[1])
  return order


def select_sort(elements, element_num):
  elements = list(elements)

  for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

  return elements


def bubble_sort(elements, element_num):
  elements = list(elements)

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

  return elements


if __name__ == '__main__':
  main()
N, M, K = map(int,input().split())
class UnionFind:
    def __init__(self, N):
        self.par = [-1 for i in range(N+1)]
        self.rank = [1]*(N+1)
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] > self.rank[y]:
            self.par[x] += self.par[y]
            self.par[y] = x
        else:
            self.par[y] += self.par[x]
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

UF = UnionFind(N)
friendlist = [[] for _ in range(N+1)]
for n in range(M):
    A, B = map(int,input().split())
    friendlist[A].append(B)
    friendlist[B].append(A)
    if not UF.same_check(A,B):
        UF.union(A, B)
blocklist = [[] for _ in range(N+1)]
for n in range(K):
    C, D = map(int, input().split())
    blocklist[C].append(D)
    blocklist[D].append(C)

for person in range(1,N+1):
    root = UF.find(person)
    ans = -UF.par[root]-1
    ans -= len(friendlist[person])
    for l in blocklist[person]:
        if UF.same_check(person,l):
            ans -= 1
    print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5+10)
N, M, K = map(int,input().split())
class UnionFind:
    def __init__(self, N):
        self.par = [-1 for i in range(N+1)]
        self.rank = [1]*(N+1)
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] > self.rank[y]:
            self.par[x] += self.par[y]
            self.par[y] = x
        else:
            self.par[y] += self.par[x]
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

UF = UnionFind(N)
friendlist = [[] for _ in range(N+1)]
for n in range(M):
    A, B = map(int,input().split())
    friendlist[A].append(B)
    friendlist[B].append(A)
    if not UF.same_check(A,B):
        UF.union(A, B)
blocklist = [[] for _ in range(N+1)]
for n in range(K):
    C, D = map(int, input().split())
    blocklist[C].append(D)
    blocklist[D].append(C)

for person in range(1,N+1):
    root = UF.find(person)
    ans = -UF.par[root]-1
    ans -= len(friendlist[person])
    for l in blocklist[person]:
        if UF.same_check(person,l):
            ans -= 1
    print(ans)
A,B,C,X,Y=map(int,input().split())

def dp(num_a,num_b):
    if num_a<=0 and num_b<=0:return 0
    elif num_b!=0:
        if B<2*C:return B+dp(num_a,num_b-1)
        else :return C*2+dp(num_a-1,num_b-1)
    else:
        if A<2*C:return A+dp(num_a-1,num_b)
        else: return C*2+dp(num_a-1,num_b-1)
print(dp(X,Y))

### FIXED CODE ###

A,B,C,X,Y=map(int,input().split())

def dp(num_a,num_b):
    """
    if num_a<=0 and num_b<=0:return 0
    elif num_b>0:
        if B<2*C:return B+dp(num_a,num_b-1)
        else :return C*2+dp(num_a-1,num_b-1)
    else:
        if A<2*C:return A+dp(num_a-1,num_b)
        else: return C*2+dp(num_a-1,num_b-1)
    """
    if A+B>2*C:
        if min(num_a,num_b)>0:
            if num_a > num_b:
                return num_b*2*C+dp(num_a-num_b,0)
            else :
                return num_a*2*C+dp(0,num_b-num_a)
        elif num_a==0 and num_b>0:
            if B<2*C:
                return num_b*B
            else :
                return C*2*num_b
        elif num_a>0 and num_b==0:
            if A<2*C:
                return A*num_a
            else :
                return 2*C*num_a
        else :
            return 0
    else :
        return num_a*A+num_b*B
print(dp(X,Y))
t = int(input())
point_l = [0 for i in range(t)]
for i in range((t*(t-1))/2):
    input_line = input()
    tmp = [int(x) for x in input_line.rstrip().split(' ')]
    if tmp[2] > tmp[3]:
        point_l[tmp[0]-1] += 3
    elif tmp[3] > tmp[2]:
        point_l[tmp[1]-1] += 3
    elif tmp[2] == tmp[3]:
        point_l[tmp[0]-1] += 1
        point_l[tmp[1]-1] += 1

rank_l = [0 for i in range(t)]
rank = 1
for l in sorted(point_l, reverse=True):
    dup = point_l.count(l)
    for j in range(dup):
        rank_l[point_l.index(l)] += rank
        point_l[point_l.index(l)] = -1
    rank += dup

for l in rank_l:
    print(l)

### FIXED CODE ###

t = int(input())
point_l = [0 for i in range(t)]
for i in range(int(t*(t-1)/2)):
    tmp = [int(x) for x in input().split()]
    if tmp[2] > tmp[3]:
        point_l[tmp[0]-1] += 3
    elif tmp[3] > tmp[2]:
        point_l[tmp[1]-1] += 3
    elif tmp[2] == tmp[3]:
        point_l[tmp[0]-1] += 1
        point_l[tmp[1]-1] += 1

rank_l = [0 for i in range(t)]
rank = 1
for l in sorted(point_l, reverse=True):
    dup = point_l.count(l)
    for j in range(dup):
        rank_l[point_l.index(l)] += rank
        point_l[point_l.index(l)] = -1
    rank += dup

for l in rank_l:
    print(l)
n = int(input())
s = []

for num in range(2, n//2):
    a = num
    b = n - num
    a_s = sum(list(map(int, str(a))))
    b_s = sum(list(map(int, str(b))))
    c = a_s + b_s
    s.append(c)

print(min(s))


### FIXED CODE ###

n = int(input())
s = []

for num in range(1, n//2+1):
    a = num
    b = n - num
    a_s = sum(list(map(int, str(a))))
    b_s = sum(list(map(int, str(b))))
    c = a_s + b_s
    s.append(c)

print(min(s))
s=input()
a=[]
for i in s:
	if i == 'B':
      if a:
		a.pop()
	else:
		a.append(i)
print(''.join(a))

### FIXED CODE ###

s=input()
a=[]
for i in s:
	if i == 'B':
		if a:
			a.pop()
		else:
			pass
	else:
		a.append(i)
print(''.join(a))