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

S=list(input())
ans=len(S)
l=[]
f=0
while f==0 and len(S)>=2:
    a=S.pop()
    b=S.pop()
    while a==b:
        if len(S)==0:
            l.append(a)
            l.append(b)
            f=1
            break
        l.append(a)
        a,b=b,S.pop()
    while len(l):
        S.append(l.pop())
print(ans-len(S))

### FIXED CODE ###

S=input()
stack=[]
cnt=0
for s in S:
    if not stack: stack.append(s)
    elif stack[-1]!=s:
        stack.pop()
        cnt+=2
    else: stack.append(s)
print(cnt)
### BUGGY CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
t=[]
for i in range(m):
    for k in range(bc[i][0]):
        t.append(bc[i][1])
t.sort(reverse=True)
ans=0

for i in range(n):
    if i<len(t):
        ans+=max(a[i],t[i])
    else:
        ans+=a[i]
print(ans)


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
t=[]

for b,c in bc:
    a.extend([c]*b)
    if len(a)>2*n:
        break
a.sort(reverse=True)
print(sum(a[:n]))
### BUGGY CODE ###

N = int(input())
A = list(map(str, input().split())) 
for i in range(N): 
    print(A.count("{}".format(i+1)))

### FIXED CODE ###

import collections

N = int(input())
A = list(map(str, input().split())) 
c = collections.Counter(A)  
for i in range(N):
    print(c["{}".format(i+1)])
### BUGGY CODE ###

S = input()

max_S = 10**9 + 7

N_Q = 0
N_C = 0
for c in S:
    if(c == "?"):
        N_Q += 1
    elif(c == "C"):
        N_C += 1

AQ_0 = int(3**N_Q)
AQ_1 = AQ_0 // 3
AQ_2 = AQ_1 // 3

BQ_0 = AQ_0 // 3
BQ_1 = AQ_1 // 3
BQ_2 = AQ_2 // 3


t_A = 0
t_Q = 0
if(S[0:1] == "C"):
    t_C = N_C - 1
else:
    t_C = N_C

ans = 0
baac = 0
bqaq = 0
aqqc = 0
for i in range(1, len(S)):
    if(S[i - 1:i] == "A"):
        t_A += 1
    elif(S[i - 1:i] == "?"):
        t_Q += 1

    bA = t_A
    bQ = t_Q
    if(S[i:i + 1] == "?"):
        aQ = N_Q - t_Q - 1
    else:
        aQ = N_Q - t_Q
    if(S[i:i + 1] == "C"):
        t_C -= 1
    aC = t_C

    if(S[i:i + 1] == "A" or S[i:i + 1] == "C"):
        continue
    elif(S[i:i + 1] == "?"):
        Q_0 = BQ_0
        Q_1 = BQ_1
        Q_2 = BQ_2
    else:
        Q_0 = AQ_0
        Q_1 = AQ_1
        Q_2 = AQ_2

    # q_0
    baac += bA * aC * Q_0
    # q_2
    bqaq += bQ * aQ * Q_2
    # Q_1
    aqqc += (bA * aQ + bQ * aC) * Q_1

ans = (ans + baac) % max_S
ans = (ans + bqaq) % max_S
ans = (ans + aqqc) % max_S


print(ans)

### FIXED CODE ###

S = input()

d = [0, 0, 0, 1]

max_ans = 10**9 + 7

for c in reversed(S):
    # print(c, d)
    m = [c == "A", c == "B", c == "C", c == "?"]
    if(m[3] is True):
        tmp = 3
    else:
        tmp = 1

    for j in range(3):
        d[j] = (tmp * d[j] + int(m[j] or m[3]) * d[j + 1]) % max_ans
    d[3] = (tmp * d[3]) % max_ans

print(d[0])
### BUGGY CODE ###

A, B, C = map(int, input().split())
jyotai = 0
ans = 0
while True:
    if A == 0 and B == 0 and jyotai == 1:
        break
    if B == 0 and C == 0:
        break

    if jyotai == 0:
        if C != 0:
            ans += 1
            C -= 1
            jyotai += 1
        else:
            ans += 1
            B -= 1
            jyotai -= 1

    else:
        if B != 0:
            ans += 1
            B -= 1
        else:
            A -= 1
        jyotai -= 1

print(ans)

### FIXED CODE ###

A, B, C = map(int, input().split())
ans = 2 * B
C -= B
if A >= C:
    ans += C
else:
    ans += A + 1

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

import math
N = int(input())
result = 0
for i in range(1, N + 1):
    s = math.ceil(N / i)
    for j in range(1, s + 1):
        a = N - i * j
        if a > 0:
            result = result + 1
        else:
            break
print(result)


### FIXED CODE ###

N = int(input())
result = 0
for i in range(1, N + 1):
    s = int(N / i) + 1
    for j in range(s + 1, 0, -1):
        if N - i * j > 0:
            result = result + j
            break
print(result)
### BUGGY CODE ###

import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n = ni()
m = nl()
res = 1
for i in m:
    res *= i
print(res if not res > 10**18 else -1)

### FIXED CODE ###

import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n = ni()
m = nl()
res = 1
if 0 in m:
    print(0)
else:
    for i in m:
        res *= i
        if res > 10**18 :
            print(-1)
            break
    else:
        print(res)
### BUGGY CODE ###

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

def solve(sh,sw):
  if S[sh][sw]=="#":
    return 0
  h,w=sh,sw
  cnt=1
  for i in range(H):
    if h==0:
      break
    h-=1
    if S[h][w]=="#":
      break
    cnt+=1
  h=sh
  for i in range(H):
    if h==H-1:
      break
    h+=1
    if S[h][w]=="#":
      break
    cnt+=1
  h=sh
  for i in range(W):
    if w==0:
      break
    w-=1
    if S[h][w]=="#":
      break
    cnt+=1
  w=sw
  for i in range(W):
    if w==W-1:
      break
    w+=1
    if S[h][w]=="#":
      break
    cnt+=1
  return cnt

ans=0
for i in range(H):
  for j in range(W):
    ans=max(ans,solve(i,j))
print(ans)

### FIXED CODE ###

import numpy as np

H,W=map(int,input().split())
S=np.array([list(input()) for _ in range(H)]) == "."

ups=np.zeros((H,W),dtype=int)
downs=np.zeros((H,W),dtype=int)
rights=np.zeros((H,W),dtype=int)
lefts=np.zeros((H,W),dtype=int)

for i in range(1,H):
    ups[i,:]=(ups[i-1,:]+1)*S[i-1,:]

for i in range(H-2,-1,-1):
    downs[i,:]=(downs[i+1,:]+1)*S[i+1,:]

for i in range(1,W):
    rights[:,i]=(rights[:,i-1]+1)*S[:,i-1]

for i in range(W-2,-1,-1):
    lefts[:,i]=(lefts[:,i+1]+1)*S[:,i+1]

ans=((ups+downs+lefts+rights)*S).max()+1
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3

mod = 10**9+7

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

max_digit = 61

count_0 = [0 for _ in range(max_digit)]
count_1 = [0 for _ in range(max_digit)]

for i in range(len(a)):
    num_str = bin(a[i])[2:]
    # print(num_str)
    for j in range(len(num_str)):
        # print(num_str[-j-1])
        if num_str[-j-1] == "1":
            count_1[-j-1] += 1

for i in range(max_digit):
    count_0[i] = n-count_1[i]

ans = 0
count = 1
for i in range(61):
    tmp = count_0[-i-1]*count_1[-i-1]
    ans += tmp*count
    count = (count*2) % mod
print(ans % mod)

### FIXED CODE ###

#!/usr/bin/env python3

# mod = 10**9+7

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

# max_digit = 61

# count_0 = [0 for _ in range(max_digit)]
# count_1 = [0 for _ in range(max_digit)]

# for i in range(len(a)):
#     num_str = bin(a[i])[2:]
#     # print(num_str)
#     for j in range(len(num_str)):
#         # print(num_str[-j-1])
#         if num_str[-j-1] == "1":
#             count_1[-j-1] += 1

# # for i in range(max_digit):
# #     count_0[i] = n-count_1[i]

# ans = 0
# count = 1
# for i in range(61):
#     # tmp = count_0[-i-1]*count_1[-i-1]
#     tmp = count_1[-i-1]*(n-count_1[-i-1])
#     ans += tmp*count
#     count = (count*2) % mod
# print(ans % mod)


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

mod = 10**9+7
max_digit = 61

ans = 0
m = 1
for _ in range(max_digit):
    bit = sum(x&m for x in a)
    bit //= m
    non_bit = n - bit
    ans = (ans+bit*non_bit*m)%mod
    m <<= 1
print(ans)
### BUGGY CODE ###

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

LR = []
for i in range(K):
    L, R = map(int, input().split())
    LR.append([L, R])
    

S = []
for lr in sorted(LR, key=lambda x:x[0]):
    S += list(range(lr[0], lr[1]+1))

dp = [0] * N
dp[0] = 1

#S.sort()

for i in range(1, N):
    for s in S:
        if i - s < 0:break
        dp[i] += dp[i - s]

print(dp[-1] % 998244353)


### FIXED CODE ###

mod = 998244353
N, K = map(int, input().split())

S = []
for i in range(K):
    L, R = map(int, input().split())
    S.append((L, R))

dp = [0] * (N+1)
dpsum = [0] * (N+1)
dp[1] = 1
dpsum[1] = 1

for i in range(2, N+1):
    for s in S:
        l = i - s[1]
        r = i - s[0]
        if r < 1:continue
        l = max(1, l)

        dp[i] += dpsum[r] - dpsum[l-1]
        dp[i] %= mod

    dpsum[i] = (dpsum[i-1] + dp[i]) % mod

print(dp[-1])
### BUGGY CODE ###

while True:
    n = int(raw_input())
    if n == 0:
        break
    a = map(int, raw_input().split())
    b = list(set(a))
    flag = 0
    if len(b) < n/2.0:
        for i in b:
            if a.count(i) > n/2.0:
                ans = i
                flag = 1
                break
    print ans if flag == 1 else "NO COLOR"

### FIXED CODE ###

while 1:
    n = input()
    if n == 0: break
    A = map(int,raw_input().split())
    A.sort()
    c,l = A[0],0
    for i in A:
        if i == c:
            l += 1
            if l > n/2:
                print c
                break
        else:
            c = i
            l = 1
    else:
        print "NO COLOR"
### BUGGY CODE ###

from collections import deque
from collections import defaultdict
N,K,L=map(int, raw_input().split())

nl=[ [] for i in range(N+1) ]

c1=set()

for i in range(K):
	p,q=map(int, raw_input().split())
	nl[p].append(q)
	nl[q].append(p)
	c1.add(p)
	c1.add(q)

nl2=[ [] for i in range(N+1) ]
c2=set()

for i in range(L):
	p,q=map(int, raw_input().split())
	nl2[p].append(q)
	nl2[q].append(p)
	c2.add(p)
	c2.add(q)


road=[ None for i in range(N+1) ]
railway=[ None for i in range(N+1) ]

def bfs(start,nl,type):
	V=[ None for i in range(N+1)]
	q = deque([]) 
	V[start]=1
	if type=="road": road[start]=start
	elif type=="railway": railway[start]=start

	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in nl[v]:
			if V[i] is None:
				V[i]=1
				q.append(i)
				if type=="road": road[i]=start
				elif type=="railway": railway[i]=start					
	return V




for i in c1:
	if road[i] is None: bfs(i,nl,"road")


for i in c2:
	if railway[i] is None: bfs(i,nl2,"railway")



l1=defaultdict(lambda: [])
for i in range(1,N+1):
	if road[i] is not None:
		l1[road[i]].append(i)


l2=defaultdict(lambda: [])
for i in range(1,N+1):
	if railway[i] is not None:
		l2[railway[i]].append(i)


for idx,i in enumerate( zip(road,railway) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	if (x and y) is None:
		print 1,
	else:
		print len( set(l1[x]) & set(l2[y]) ),
	
	



### FIXED CODE ###

from collections import deque
from collections import Counter

N,K,L=map(int, raw_input().split())

nl=[ [] for i in range(N+1) ]

for i in range(K):
	p,q=map(int, raw_input().split())
	nl[p].append(q)
	nl[q].append(p)

nl2=[ [] for i in range(N+1) ]

for i in range(L):
	p,q=map(int, raw_input().split())
	nl2[p].append(q)
	nl2[q].append(p)


v1=[ None for i in range(N+1) ]
v2=[ None for i in range(N+1) ]


def bfs(start,nl,V,l):
	q = deque([]) 
	V[start]=1
	l[start]=start
	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in nl[v]:
			if V[i] is None:
				V[i]=1
				q.append(i)
				l[i]=start
			
	return V

l1=[ "" for i in range(N+1) ]
l2=[ "" for i in range(N+1) ]


for i in range(1,N+1):
	if v1[i] is None:
		bfs(i,nl,v1,l1)

for i in range(1,N+1):
	if v2[i] is None:
		bfs(i,nl2,v2,l2)


c=[]
for idx,i in enumerate( zip(l1,l2) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	c.append( (x,y) )


C=Counter(c)

for idx,i in enumerate( zip(l1,l2) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	print C[(x,y)],
### BUGGY CODE ###

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

n,m=map(int,input().split())
ro,co,w=[],[],[]
for i in range(m):
    a,b=map(int,input().split())
    ro.append(a-1)
    co.append(b-1)
    w.append(1)

g=csr_matrix((w,(ro,co)),shape=(n,n))
d=dijkstra(g,directed=False,indices=0)
if d[-1]==2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

### FIXED CODE ###

from collections import deque

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

sx=0
gx=n-1

tree=[[] for i in range(n)]
for i in l:
    tree[i[0]-1].append(i[1]-1)
    tree[i[1]-1].append(i[0]-1)

dist=[-1 for i in range(n)]
dist[sx]=0

que=deque()
que.append(sx)

while que:
    x=que.popleft()

    if x==gx and dist[gx]==2:
        print('POSSIBLE')
        exit()
    elif x==gx and dist[gx]!=2:
        print('IMPOSSIBLE')
        exit()

    for j in tree[x]:
        if dist[j]==-1:
            que.append(j)
            dist[j]=dist[x]+1

print('IMPOSSIBLE')
### BUGGY CODE ###

s = input()
n = len(s)
bits = dict()
bits[0] = 0
bit = 0
for i in range(n):
	x = ord(s[i])-97
	bit ^= (1<<x)
	for j in range(26):
		new_bit = bit ^ (1<<j)
		if new_bit in bits:
			#print(bin(bit)[2:], bin(new_bit)[2:])
			if bit in bits:
				bits[bit] = min(bits[bit], bits[new_bit] + 1)
			else:
				bits[bit] = bits[new_bit] + 1
			#print(bits[bit])
		#print("-----")
if bit not in bits:
	print(-1)
else:
	print(max(1, bits[bit]))

### FIXED CODE ###

s = input()
n = len(s)
bits = dict()
bits[0] = 0
bit = 0
for i in range(n):
	x = ord(s[i])-97
	bit ^= (1<<x)
	for j in range(26):
		new_bit = bit ^ (1<<j)
		if new_bit in bits:
			#print(bin(bit)[2:], bin(new_bit)[2:])
			if bit in bits:
				bits[bit] = min(bits[bit], bits[new_bit] + 1)
			else:
				bits[bit] = bits[new_bit] + 1
			#print(bits[bit])
		#print("-----")
if bit not in bits:
	print(-1)
else:
	print(max(1, bits[bit]))
### BUGGY CODE ###

W, H, x, y = map(int, input().split())
if x*y == 0 or (x-W)*(y-H) ==0 or (x == W/2 and y != H/2) or (x != W/2 and y == H/2) :
  print(str(W*H/2) + ' 0')
  exit()
else:
  for i in range(W+1):
    if x == i and y == H / W * x and x != W/2:
      print(str(W*H/2) + ' 0')
      exit()
    if x == i and y == W - H / W * x and x != W/2:
      print(str(W*H/2) + ' 0')
      exit()
print(str(W*H/2) + ' 1')


### FIXED CODE ###

W, H, x, y = map(int, input().split())
#if x*y == 0 or (x-W)*(y-H) ==0 or (x == W/2 and y != H/2) or (x != W/2 and y == H/2) :
#  print(str(W*H/2) + ' 0')
#  exit()
#elif y == H / W * x and x != W/2:
#  print(str(W*H/2) + ' 0')
#  exit()
#elif y == H - H / W * x and x != W/2:
#  print(str(W*H/2) + ' 0')
#  exit()
#print(str(W*H/2) + ' 1')

if x == W/2 and y == H/2:
  print(str(W*H/2) + ' 1')
  exit()
print(str(W*H/2) + ' 0')
### BUGGY CODE ###

from collections import deque
D,G = [int(i) for i in input().split()]
P = [0]*D
n = 0
for i in range(D):
    p,c = [int(j) for j in input().split()]
    P[i] = [int(k) * 100 * (i+1) for k in range(p+1)]
    P[i][-1] += c
    n += p
deq = deque()
ans = n
deq.append((0,0,0))
while(len(deq)>0):
    tmp = deq.pop()
    if tmp[0]+1 > len(P):
        break
    for i,j in enumerate(P[tmp[0]]):
        cand = (tmp[0]+1, tmp[1]+i, tmp[2]+j)
        if cand[2] < G:
            if cand[1] < ans:
                deq.appendleft(cand)
        else:
            if cand[1] < ans:
                ans = cand[1]      
print(ans)

### FIXED CODE ###

from collections import deque
D,G = [int(i) for i in input().split()]
P = [0]*D
n = 0
for i in range(D):
    p,c = [int(j) for j in input().split()]
    P[i] = [int(k) * 100 * (i+1) for k in range(p+1)]
    P[i][-1] += c
    n += p
deq = deque()
ans = n
deq.append((0,0,0))
dic = {}

while(len(deq)>0):
    tmp = deq.pop()
    if tmp[0]+1 > len(P):
        break
    for i,j in enumerate(P[tmp[0]]):
        cand = (tmp[0]+1, tmp[1]+i, tmp[2]+j)
        if cand[1] < ans:
            if cand[2] < G:
                if cand[1] not in dic:
                    dic[cand[1]] = cand[2]
                    deq.appendleft(cand)
                elif dic[cand[1]] <= cand[2]:
                    dic[cand[1]] = cand[2]
                    deq.appendleft(cand)
            else:
                ans = cand[1]
print(ans)
### BUGGY CODE ###

def inpl(): return list(map(int, input().split()))
n = int(input())
a = inpl()
#sa = sorted(a)
maximum = max(a)
c = 0
while True:
    if maximum//2-c in a:
        print(maximum, maximum//2-c)
        break
    elif maximum-maximum//2+c in a:
        print(maximum, maximum-maximum//2+c)
        break
    else:
        c += 1

### FIXED CODE ###

def inpl(): return list(map(int, input().split()))
n = int(input())
a = inpl()
maximum = max(a)
diff = maximum/2
a.remove(maximum)
min_num = [abs(i - diff) for i in a]
min_num = a[min_num.index(min(min_num))]
print(maximum, min_num)
### BUGGY CODE ###

from collections import Counter

def verify_counters(first, second):
    return first == second

N = int(input())
words = [Counter(input()) for _ in range(N)]
ans = 0
while True:
    if not words:
        break
    target = words.pop(0)
    same_word_index = []
    loop_sum = 0
    for i, word in enumerate(words):
        if verify_counters(target, word):
            same_word_index.append(i)
            loop_sum += 1
    # 同じやつをリストから消す
    if same_word_index:
        for index in reversed(same_word_index):
            words.pop(index)
    # 合計に加算
    ans += int((loop_sum * (loop_sum+1)) / 2)
    
    # 後ろからも
    if not words:
        break
    target = words.pop()
    same_word_index = []
    loop_sum = 0
    for i, word in enumerate(words):
        if verify_counters(target, word):
            same_word_index.append(i)
            loop_sum += 1
    # 同じやつをリストから消す
    if same_word_index:
        for index in reversed(same_word_index):
            words.pop(index)
    # 合計に加算
    ans += int((loop_sum * (loop_sum+1)) / 2)

print(ans)

### FIXED CODE ###

from collections import Counter

class hashabledict(dict):
    def __hash__(self):
        return hash(tuple(sorted(self.items())))

N = int(input())
words = [hashabledict(dict(Counter(input()))) for _ in range(N)]
ans = 0
counter_hash = {}
for counter in words:
    if counter not in counter_hash.keys():
        counter_hash[counter] = 1
    else:
        counter_hash[counter] += 1
 
for count in counter_hash.values():
    ans += int((count * (count-1)) / 2)
print(ans)
### BUGGY CODE ###

a,b,n = map(int,input().split())
p = (n+1)//b
c = p*b-1
if c < 0:
  print(a*n//b-a*(n//b))
  exit()
ans = 0
for i in range(c,n+1):
  ans = max(ans,a*i//b-a*(i//b))
print(ans)

### FIXED CODE ###

a,b,n = map(int,input().split())
p = (n+1)//b
c = p*b-1
if c < 0:
  print(a*n//b-a*(n//b))
  exit()
ans = max(a*n//b-a*(n//b),a*c//b-a*(c//b))
print(ans)
### BUGGY CODE ###

from math import ceil, floor
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = 10**9
m = (l+r)//2+1
for i in range(100):
    # print(l,m,r)
    cnt = 0
    for j in a:
        cnt += (ceil(j/m)-1)
    # print(cnt)
    # print(l,m,r,cnt)
    if cnt <= k:
        r = m
        m = ceil((l+r)/2)
    else:
        l = m
        m = ceil((l+r)/2)
print(m)


### FIXED CODE ###

from math import ceil, floor
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = 10**9
m = (l+r)//2+1
for i in range(100):
    # print(l,m,r)
    cnt = 0
    for j in a:
        cnt += (ceil(j/m)-1)
    # print(cnt)
    # print(l,m,r,cnt)
    if cnt <= k:
        r = m
        m = ceil((l+r)/2)
    else:
        l = m
        m = ceil((l+r)/2)
print(m)
### BUGGY CODE ###

def mygets():
    return list(map(int, input().strip().split()))

n, x = mygets()
a = mygets()

b1 = a.copy()
b2 = a.copy()

ans = sum(a)

for i in range(1, n):
    for j in range(n):
        k = (j + n - 1) % n
        if a[j] < b1[k]:
            b2[j] = a[j]
        else:
            b2[j] = b1[k]
    ans = min(ans, sum(b2) + i * x)
    b1, b2 = b2, b1

print(ans)

### FIXED CODE ###

def mygets():
    return list(map(int, input().strip().split(' ')))

n, x = mygets()
a = mygets()

b1 = a

ans = sum(a)

def f(k, u):
    j = k - 1
    if j < 0:
        j = n - 1
    w = b1[j]
    if u < w:
        return u
    return w

for i in range(1, n):
    b2 = [f(k, u) for k, u in enumerate(a)]
    ans = min(ans, sum(b2) + i * x)
    b1 = b2

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

import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))

ans=0
mod=10**9+7
for i in range(60):
    x=0
    for j in range(n):
        if (a[j] >>i&1) :x+=1

    now = x*(n-x) % mod

    for j in range(i):
        now = now*2 % mod
    ans += now
    ans %= mod

print(ans)

### FIXED CODE ###

# import numpy as np
n=int(input())
# a=np.array(list(map(int,input().split())))
a=list(map(int,input().split()))

ans=0
mod=10**9+7
for i in range(60):
    x=0
    for j in range(n):
        if (a[j] >>i&1) :x+=1

    now = x*(n-x) % mod

    for j in range(i):
        now = now*2 % mod
    ans += now
    ans %= mod

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

import numpy as np


A = list(map(int, input().split()))
K = A[0]
S = A[1]
counter = 0
for i in range(K+1):
	for j in range(K+1):
		for l in range(K+1):
			temp = i + j + l
			if(temp == S):
				counter = counter + 1

print(counter)
print("\n")

### FIXED CODE ###

import numpy as np


A = list(map(int, input().split()))
K = A[0]
S = A[1]
counter = 0
for i in range(K+1):
	for j in range(K+1):
		sa = S - (i + j)
		if 0 <= sa and sa <= K:
			counter = counter + 1
			
			
print(counter)
print("\n")
### BUGGY CODE ###

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

sum_A = [0] * (N+1)
mark_A = 0
for i,a in enumerate(A, 1):
    tmp =  sum_A[i-1] + a
    if tmp <= K:
        sum_A[i] = tmp
        mark_A = i
    else:
        break

sum_B = [0] * (M+1)
mark_B = 0
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B[i] = tmp
        mark_B = i
    else:
        break
        
import numpy as np
C = np.array([np.array(sum_A[:mark_A+1]) + x for x in sum_B[:mark_B+1]])
# C = np.tile(sum_A[:mark_A+1], (mark_B+1,1)) + np.array(sum_B[:mark_B+1]).reshape(-1, 1)
print(max(np.where(C <= K)[0] + np.where(C <= K)[1]))

### FIXED CODE ###

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

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
j = len(sum_B) - 1

for i,a in enumerate(sum_A):
    while sum_B[j] > K - a:
        j -= 1
        
    ans = max(ans, i+j)
    
print(ans)
### BUGGY CODE ###

#B
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

cost = [float('inf')]*n
for i in range(n):
    if i == 0:
        cost[i] = 0
        continue    
    for j in range(1,k+1):
        if i-j>=0:
            cost[i] = min(cost[i],cost[i-j]+abs(h[i]-h[i-j]))
print(cost[n-1])

### FIXED CODE ###

#B
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

dp = [float('inf')]*n
for i in range(n):
    if i == 0:
        dp[i] = 0
        continue    
    for j in range(1,k+1):
        if i-j>=0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])
### BUGGY CODE ###

X,Y,Z,K=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
SUM=[]
for a in A:
  for b in B:
    for c in C:
      SUM.append(a+b+c)
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])

### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
SUM=[]
for i in range(X):
  for j in range(Y):
    for k in range(Z):
      if (i+1)*(j+1)*(k+1)<=K:
        SUM.append(A[i]+B[j]+C[k])
      else:
        break
SUM.sort(reverse=True)
for i in range(K):
  print(SUM[i])
### BUGGY CODE ###

str = input()
while True:
       pos = str.find('ST')
       if pos != -1:
              str = str[0:pos]+str[pos+2:]
       else:
              break
print(len(str))


### FIXED CODE ###


str = input()
res=0
s=0
for e in str:
       if e == 'S':
              s=s+1
       elif s>0:
              res=res+1
              s=s-1
print(len(str)-res*2)