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

def main():
    N, Q = (int(i) for i in input().split())
    C = [int(i) for i in input().split()]
    Query = [([int(i) for i in input().split()], j) for j in range(Q)]
    Query.sort(key=lambda p: p[0][1])
    lastappend = [0]*(N+1)

    def sum(tree, i):
        s = 0
        while i > 0:
            s += tree[i]
            i -= i & -i
        return s

    def add(tree, i, x):
        while i <= N:
            tree[i] += x
            i += i & -i
    bit = [0]*(N+1)

    for i, a in enumerate(C, start=1):
        if i <= Query[0][0][1]:
            lastappend[a] = i
    for la in lastappend[1:]:
        if la != 0:
            add(bit, la, 1)
    pre = Query[0][0][1]
    ans = []
    for (le, ri), j in Query:
        if pre <= N and pre < ri:
            for i in range(pre+1, ri+1):
                pre_i = lastappend[C[i-1]]
                if pre_i != 0:
                    add(bit, pre_i, -1)
                lastappend[C[i-1]] = i
                add(bit, i, 1)
            pre = ri
        ans.append((j, sum(bit, ri) - sum(bit, le-1)))
    ans.sort()
    for _, a in ans:
        print(a)


if __name__ == '__main__':
    main()


### FIXED CODE ###

SHIFT = 1 << 20


def main():
    N, Q = (int(i) for i in input().split())
    C = [int(i) for i in input().split()]
    Query = []
    for j in range(Q):
        le, ri = (int(i) for i in input().split())
        Query.append(ri << 40 | le << 20 | j)
    Query.sort()

    # Query復元
    for i in range(Q):
        j = Query[i] % (SHIFT)
        Query[i] >>= 20
        le = Query[i] % (SHIFT)
        Query[i] >>= 20
        ri = Query[i]
        Query[i] = (le, ri, j)
    Query.append((-1, -1, -1))

    def sum(tree, i):
        s = 0
        while i > 0:
            s += tree[i]
            i -= i & -i
        return s

    def add(tree, i, x):
        while i <= N:
            tree[i] += x
            i += i & -i

    lastappend = [-1] * (N + 1)
    bit = [0] * (N + 1)
    idx = 0  # Queryのindex
    ans = [0]*Q

    for i, a in enumerate(C, start=1):
        if lastappend[a] != -1:
            add(bit, lastappend[a], -1)
        lastappend[a] = i
        add(bit, i, 1)
        while i == Query[idx][1]:
            (le, ri, j) = Query[idx]
            ans[j] = sum(bit, ri) - sum(bit, le-1)
            idx += 1

    print(*ans, sep="\n")


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

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
#import bisect
#from collections import deque
import math

#############################
#         59 58 57     1
# Ai = 0xbi bi bi ... bi
# 
#############################

#############################
#   N-1 N
#   Σ   Σ     (Ai xor Aj)
#   i=1 j=i+1
#
#   59  N-1 N       d      d
# = Σ   Σ   Σ     (bi xor bj) * 2^(d-1)
#   d=1 i=1 j=i+1
#############################

#############################
#   N-1 N       d      d
#   Σ   Σ     (bi xor bj)
#   i=1 j=i+1
#
# = (bx のうち 1 の数) * (bx のうち 0 の数)
#############################

def input():
    return sys.stdin.readline().rstrip('\n')

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

s = 0 #sum

for d in range(60):
    B = [1 & (a >> d) for a in A]
    s += B.count(1) * B.count(0) * (2**d)
    #print(d,B,B.count(1),B.count(0),2**(d-1),s)

#print(s)
print(s % (10**9+7))


### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
#import bisect
#from collections import deque
import math

#############################
#         59 58 57     1
# Ai = 0xbi bi bi ... bi
# 
#############################

#############################
#   N-1 N
#   Σ   Σ     (Ai xor Aj)
#   i=1 j=i+1
#
#   59  N-1 N       d      d
# = Σ   Σ   Σ     (bi xor bj) * 2^(d-1)
#   d=1 i=1 j=i+1
#############################

#############################
#   N-1 N       d      d
#   Σ   Σ     (bi xor bj)
#   i=1 j=i+1
#
# = (bx のうち 1 の数) * (bx のうち 0 の数)
#############################

def input():
    return sys.stdin.readline().rstrip('\n')

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

s = 0 #sum

for d in range(60):
    B = [1 & (a >> d) for a in A]
    s += B.count(1) * B.count(0) * (2**d)
    #print(d,B,B.count(1),B.count(0),2**(d-1),s)

#print(s)
print(s % (10**9+7))
### BUGGY CODE ###

import numpy as np
def rem():
  mod=10**9+7
  s=input()
  dp=np.zeros((len(s)+1,13),dtype=int)
  dp[0][0]=1
  r=[i%13 for i in range(130)]

  for i in range(len(s)):
    if s[i]=='?':
      for j in range(13):
        for k in range(10):
          dp[i+1][r[j*10+k]]+=dp[i][j]
    else:
      t = int(s[i])
      for j in range(13):
        dp[i+1][r[j*10+t]] += dp[i][j]

    for k in range(13):
      dp[i+1][k] %= mod

  print(dp[len(s)][5])

rem()

### FIXED CODE ###

mod=10**9+7
s=input()
dp=[[0]*13 for _ in range(len(s)+1)]
dp[0][0]=1
r=[i%13 for i in range(130)]

for i in range(len(s)):
  if s[i]=='?':
    for j in range(13):
      for k in range(10):
        dp[i+1][r[j*10+k]]+=dp[i][j]
  else:
    t = int(s[i])
    for j in range(13):
      dp[i+1][r[j*10+t]] += dp[i][j]

  for k in range(13):
    dp[i+1][k] %= mod

print(dp[len(s)][5])
### BUGGY CODE ###

def solve(aaa):
    l = 1
    r = 200000
    while l < r:
        m = (l + r) // 2
        if check(m, aaa):
            r = m
        else:
            l = m + 1
    return r


def check(d, aaa):
    if d == 1:
        return all(a1 < a2 for a1, a2 in zip(aaa, aaa[1:]))
    l = 0
    word = {}
    for a in aaa:
        if l >= a:
            if not carry(d, word, a):
                return False
            for i in list(word.keys()):
                if a < i:
                    del word[i]
        l = a
    return True


def carry(d, word, i):
    while i > 0:
        if i in word:
            if word[i] < d:
                word[i] += 1
                return True
            del word[i]
        else:
            word[i] = 2
            return True
        i -= 1
    return False


n = int(input())
aaa = list(map(int, input().split()))
print(solve(aaa))


### FIXED CODE ###

def solve(aaa):
    l = 1
    r = 200000
    while l < r:
        m = (l + r) // 2
        if check(m, aaa):
            r = m
        else:
            l = m + 1
    return r


def check(d, aaa):
    if d == 1:
        return all(a1 < a2 for a1, a2 in zip(aaa, aaa[1:]))
    l = 0
    word = {}
    for a in aaa:
        if l >= a:
            if not carry(d, word, a):
                return False
            for i in list(word.keys()):
                if a < i:
                    del word[i]
        l = a
    return True


def carry(d, word, i):
    while i > 0:
        if i in word:
            if word[i] < d:
                word[i] += 1
                return True
            del word[i]
        else:
            word[i] = 2
            return True
        i -= 1
    return False


n = int(input())
aaa = list(map(int, input().split()))
print(solve(aaa))
### BUGGY CODE ###

N = int(input())

k = 1
for i in range(1, N+1):
  k *= i

ans = k % (10**9 +7)
print(ans)

### FIXED CODE ###

N = int(input())

ans = 1
for i in range(1, N+1):
  ans *= i
  ans %= (10**9 + 7)

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

K = int(input())
x = 7
count = 1

if K%2 == 0 or K%5 == 0:
  print("-1")
  exit(0)
for i in range(100000):
  if x % K == 0:
    print(count)
    exit(0)
  else:
    x = 10*x + 7
    count += 1
print("-1")

### FIXED CODE ###

def calc(k):
    cur = 0
    for i in range(1, 10 ** 7):
        cur *= 10
        cur += 7
        cur %= k
        if cur == 0:
            return i

    return -1


k = int(input())
print(calc(k))
### BUGGY CODE ###

def main():
    S = input()
    N, result, work, temp, _int = len(S), 0, [0] * 2019, 0, int
    work[0] += 1
    for i in range(N):
        temp += _int(S[N - i - 1]) * 10**i
        work[temp % 2019] += 1
    for w in work: result += w*(w-1)//2
    print(result)
main()

### FIXED CODE ###

def main():
    S = input()
    work, temp = [0] * 2019, 0
    work[0] = 1
    a = 1
    for s in S[::-1]:
        temp += int(s) * a
        work[temp%2019] += 1
        a *= 10
        a %= 2019
    print(sum([w*(w-1)//2 for w in work]))
main()
### BUGGY CODE ###

from copy import deepcopy
h, w = map(int, input().split())
data = []
for n in range(h):
    data.append(list(input().rstrip()))


def data_have_dot():
    # print(data)
    for row in data:
        if row.count('.') > 0:
            return True
    return False


count = 0
while data_have_dot():
    count += 1
    copy = deepcopy(data)
    for l in range(h):
        for r in range(w):
            if copy[l][r] == '#':
                if l > 0:
                    data[l - 1][r] = '#'
                if l < h - 1:
                    data[l + 1][r] = '#'
                if r > 0:
                    data[l][r - 1] = '#'
                if r < w - 1:
                    data[l][r + 1] = '#'

print(count)


### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
que = deque()
data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0
while len(que) > 0:
    count += 1
    next = deque()
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in [(row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)]:
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que = next

print(count - 1)
### BUGGY CODE ###

import math

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

for i in reversed(range(n+1)):
    if i<b:
        print(math.floor(a*i/b))
        break



### FIXED CODE ###

import math

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

# for i in reversed(range(b)):
#     if i<=n:
#         print(math.floor(a*i/b))
#         break

if b <= n:
    print(math.floor(a*(b-1)/b))
else:
    print(math.floor(a*n/b))
### BUGGY CODE ###

import numpy as np
N, M = map(int, input().split())
LRC = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: (x[0], x[1]))
 
inf = float('inf')
dp = np.full(N+1, inf)
dp[1] = 0
for l, r, c in LRC:
    dp[l:r+1] = np.minimum(dp[l:r+1], dp[l] + c)
 
if dp[-1] < inf:
    print(int(dp[-1]))
else:
    print(-1)

### FIXED CODE ###

N, M = map(int, input().split())
LRC = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: (x[0], x[1]))

inf = float('inf')
dp = [inf] * N
dp[0] = 0

for l, r, c in LRC:
    for i in range(r, l, -1):
        if dp[i-1] > dp[l-1] + c:
            dp[i-1] = dp[l-1] + c
        else:
            break

if dp[-1] < inf:
    print(dp[-1])
else:
    print(-1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Thu May  7 00:07:17 2020

@author: shinba
"""
import collections

def conbination(n):
    return int(n*(n-1)/2)

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

B = collections.Counter(A)

key = []
val = []

for i,j in B.items():
    key.append(i)
    val.append(j)

for i in range(len(B)):
    W = 0
    for j in range(len(B)):
        if i == j:
            val[j] -= 1
            s = j
        W += conbination(val[j])
    B[key[i]] = W
    val[s] += 1

for i in A:
    print(B[i])

    

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Thu May  7 01:30:29 2020

@author: shinba
"""
import collections

def conbination(n):
    return int(n*(n-1)/2)

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

B = collections.Counter(A)

W = 0
for i in B.values():
    W += conbination(i)

for i in A:
    print(W-B[i]+1)
### BUGGY CODE ###

# match matching
import bisect
import sys
input = sys.stdin.readline
compare = [10**i for i in range(5*10**3+1)]
N, M = map(int, input().split())
ok = list(map(int, input().split()))
a = [i for i in range(1, 10)]
b = [2, 5, 5, 4, 5, 6, 3, 7, 6]
data = {a[i]: b[i] for i in range(9)}
how = {i: [] for i in range(2, 8)}
for n in ok:
    how[data[n]].append(n)
new = []
for i in range(2, 8):
    if len(how[i]) > 0:
        new.append(max(how[i]))
new.sort()
ok = new
dp = [[0 for i in range(N+1)] for j in range(M+1)]


def find(X):
    return bisect.bisect_right(compare, X)


for i in range(M):
    for cnt in range(N+1):
        for num in ok[:i+1]:
            cost = data[num]
            if cnt > cost:
                K = dp[i+1][cnt-cost]
                if K > 0:
                    dp[i+1][cnt] = max(K + num*10 ** find(K), dp[i+1][cnt])
                    continue
                else:
                    dp[i+1][cnt] = max(K, dp[i+1][cnt])
                    continue
            elif cnt == cost:
                dp[i+1][cnt] = max(num, dp[i+1][cnt])
                continue
            else:
                dp[i+1][cnt] = max(dp[i][cnt], dp[i+1][cnt])
                continue
ans = dp[M][N]
print(ans)

### FIXED CODE ###

matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

n, m = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort(reverse=True)

dp = [-1 for _ in range(n + 1)]
dp[0] = 0
for a in alist:
    match = matches[a]
    for i in range(n - match + 1):
        if dp[i] == -1: continue
        dp[i + match] = max(dp[i + match], dp[i] * 10 + a)

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

from heapq import heappop, heappush


def solve(n, m, s):
    q = [(0, 0)]
    curr = None
    for i in range(1, n + 1):
        if s[i] == '1':
            continue
        left_limit = max(0, i - m)
        while q and q[0][-1] < left_limit:
            heappop(q)
        if not q:
            return (-1,)
        prev = q[0]
        dice = i - prev[-1]
        curr = (prev[0] + 1,) + prev[1:-1] + (dice, i)
        heappush(q, curr)

    return curr[1:-1]


n, m = map(int, input().split())
s = input()
print(*solve(n, m, s))


### FIXED CODE ###

from heapq import heappop, heappush


def solve(n, m, s):
    curr = n
    l = max(0, n - m)
    r = n
    ans = []
    while r > 0:
        for i, c in enumerate(s[l:r], start=l):
            if c == '0':
                dice = curr - i
                ans.append(dice)
                curr = i
                l = max(0, i - m)
                r = i
                break
        else:
            return (-1,)

    return reversed(ans)


n, m = map(int, input().split())
s = input()
print(*solve(n, m, s))
### BUGGY CODE ###

dice = list(map(int, input().split()))
mask = {
    'N': (1, 5, 2, 3, 0, 4),
    'R': (0, 2, 4, 1, 3, 5)
    }

for i in range(int(input())):
    a, b = map(int, input().split())

    while dice[0] != a:
        dice = [dice[x] for x in mask['N']]
    while dice[1] != b:
        dice = [dice[x] for x in mask['R']]
    print(dice[2])



### FIXED CODE ###

dice = list(map(int, input().split()))
mask = {
    'N': (1, 5, 2, 3, 0, 4),
    'R': (0, 2, 4, 1, 3, 5)
    }


for i in range(int(input())):
    a, b = map(int, input().split())

    lim = 0
    while dice[0] != a:
        dice = [dice[x] for x in mask['N']]
        lim += 1
        if lim == 4:
            dice = [dice[x] for x in mask['R']]
            lim = 0
    while dice[1] != b:
        dice = [dice[x] for x in mask['R']]
    print(dice[2])
### BUGGY CODE ###

from functools import reduce

n = int(input())
a = [int(_) for _ in input().split()]
#mul = 0

#for i in range(n):
mul = reduce(lambda x,y: x*y, a)

if mul > 10**18:
  print(-1)
else:
  print(mul)


### FIXED CODE ###

n = int(input())
a = [int(_) for _ in input().split()]

if 0 in a:
  print(0)
  exit()

mul = 1
for i in a:
  mul *= i
  if mul > 10**18:
    print(-1)
    exit()

print(mul)
### BUGGY CODE ###

N,M = tuple(map(int,input().split()))
# matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
# friendlist = [0 for i in range(N)]
gplist = [[-1]]
def match(ab):
    a,b=ab
    igpa = 0
    igpb = 0
    for i,gp in enumerate(gplist):
        if a in gp:
            igpa = i
            if b in gp:
                return
        elif b in gp:
            igpb = i
        if bool(igpa) and bool(igpb):
            break
    if not bool(igpa) and not bool(igpb):
        gplist.append([a,b])
    elif bool(igpa) and not bool(igpb):
        gplist[igpa].append(b)
    elif not bool(igpa) and bool(igpb):
        gplist[igpb].append(a)
    else:
        gplist[igpa].extend(gplist[igpb])
        gplist.remove(gplist[igpb])


# print(gplist)
for i in range(M):
    # match(matchlist[i])
    match(tuple(map(lambda x:int(x)-1,input().split())))
    # print(gplist)
print(max([len(item) for item in gplist]))

### FIXED CODE ###

N,M = tuple(map(int,input().split()))
# matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = list(range(N))
# [所属先,[所属メンバー]]
gplist = [[i] for i in range(N)]

def getgroup(a):
    A = friendlist[a]
    if A == a:
        return a
    else:
        return getgroup(A)

def match(ab):
    A = getgroup(ab[0])
    B = getgroup(ab[1])
    if A==B:
        return
    elif len(gplist[A])<len(gplist[B]):
        gplist[B].extend(gplist[A])
        friendlist[A] = B
    else:
        gplist[A].extend(gplist[B])
        friendlist[B] = A

for i in range(M):
    # print(friendlist)
    # print(gplist)
    match(tuple(map(lambda x:int(x)-1,input().split())))

# print(friendlist)
# print(gplist)

print(max([len(item) for item in gplist]))
### BUGGY CODE ###

N = int(input())
edge_list = [list(map(int, input().split())) for i in range(N-1)]
colors = [[0 for j in range(N)] for i in range(N)]
reached = [False for i in range(N)]
edges = [[] for j in range(N)]
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    edges[a].append(b)
    edges[b].append(a)

color_num = 0
for i in range(N):
    if len(edges[i]) > color_num:
        color_num = len(edges[i])


color_stack = [[]]
node_stack = [0]
while len(node_stack) > 0:
    current = node_stack.pop()
    reached[current] = True
    used_colors = color_stack.pop()
    nodes = edges[current]
    can_color = [i+1 for i in range(color_num)]
    for color in used_colors:
        can_color.remove(color)
    for node in nodes:
        if reached[node]:
            continue
        color = can_color.pop()
        node_stack.insert(0, node)
        color_stack.insert(0, [color])
        colors[current][node] = color
        colors[node][current] = color

print(color_num)
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    print(colors[a][b])



### FIXED CODE ###

from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

    mat[a].append((i, b))
    mat[b].append((i, a))

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)
### BUGGY CODE ###

import math
import sys
import collections
def main():
    N=int(input())
    Tr=tuple(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
       if Tr[i]=="G":
           G.append(i)
       if Tr[i]=="B":
           B.append(i)
    cnt=len(R)*len(G)*len(B)
    for i in R:
        for j in G:
            if max(i,j)+abs(i-j) in B:
                cnt-=1
            if min(i,j)-abs(i-j) in B:
                cnt-=1
            if (i+j)%2==0 and (i+j)//2 in B:
                cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()

### FIXED CODE ###

import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import numpy as np
N = int(input())
a_s = input().split()
for i in range(N):
    a_s[i] = int(a_s[i])
a_s = np.array(a_s)

a_unique = np.unique(a_s)
a_counts = []
for i,a in enumerate(a_unique):
    a_counts.append(sum(a_s==a))

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if i>0:
        if a_unique[i-1]+1==a_unique[i]:
            val += a_counts[i-1]
            
    if i<len(a_unique)-1:
        if a_unique[i+1]-1==a_unique[i]:
            val += a_counts[i+1]
            
    if val > ans:
        ans = val
        
    if ans > sum(a_counts[i:]):
        break
        
print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
a_s = input().split()
a_s = [int(a_s[i]) for i in range(N)]

c = Counter(a_s)
c = sorted(c.items(), key=lambda x:x[0])
a_unique, a_counts = zip(*c)

ans = 0
for i,a in enumerate(a_unique):
    val = a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a):
            val += a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a):
            val += a_counts[i+1]
    
    if val > ans:
        ans = val
        
print(ans)
### BUGGY CODE ###

import bisect
import numpy as np
N,M=map(int, input().split())
A=list(map(int, input().split()))
A=sorted(A)

L=[]
for i in range(M):
    b,c=map(int, input().split())
    L.append([b,c])

L=sorted(L,reverse=True, key=lambda x: x[1])
X=[]
for l in L:
    b=l[0]
    c=l[1]
    n=min(b,N-len(X))
    X=X+[c]*n
    if len(X)==N:
        break
#print(X)
ans=0
for i in range(N):
    if len(X)>i:
        ans+=max(X[i],A[i])
    else:
        ans+=A[i]

print(ans)

### FIXED CODE ###

N, M=map(int, input().split())
A=list(map(int, input().split()))
bc=[]
for i in range(M):
  b, c=map(int, input().split())
  bc.append((c,b))
for i in range(N):
  bc.append((A[i], 1))
  
bc=sorted(bc, key=lambda x : x[0], reverse=True)

ans=0
res=N
for x in bc:
  c=x[0]
  b=min(x[1], res)
  ans+=c*b
  res-=b
  if res==0:
    break
    
print(ans)
### BUGGY CODE ###

def sakuzyo(li):
    ct = 0
    found = 1
    while found:
        found = 0
        for i in range(len(li)-1):
            if (li[i] == "0" and li[i+1] == "1") or (li[i] == "1" and li[i+1] == "0"):
                li.pop(i)
                li.pop(i)
                ct += 2
                found = 1
                break
    return ct
li = list(input())
print(sakuzyo(li))



### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = ns()
n = len(s)
b = s.count('0')
r = n - b
print(2 * min(b, r))