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

N, Q = map(int, input().split())
S = input()
t = [0] * (N-1)
for n in range(N-1):
    if S[n:n+2] == "AC":
        t[n] = 1
for q in range(Q):
    l, r = map(int, input().split())
    print(sum(t[l-1:r-1]))


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N)
for n in range(N-1):
    add = 1 if S[n:n+2] == "AC" else 0
    t[n+1] = t[n] + add
for q in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

n,k=map(int,input().split())
td=sorted([list(map(int,input().split())) for i in range(n)],reverse=True,key=lambda x:x[1])
#print(td)
ans=0
kinds=dict()
for i in range(k):
    ans+=td[i][1]
    if td[i][0] in kinds:
        kinds[td[i][0]].append(td[i][1])
    else:
        kinds[td[i][0]]=[td[i][1]]
ans+=(len(kinds)**2)
#kindsの中はソートされている状況
#print(kinds)
ans_=[ans]
for i in range(k,n):
    if td[i][0] not in kinds:
        mi=[1000000000,1000000000]
        for j in kinds:
            if len(kinds[j])>1:
                if mi[1]>kinds[j][-1]:
                    mi=[j,kinds[j][-1]]
        if mi==[1000000000,1000000000]:
            break
        else:
            ans=ans-len(kinds)**2+(len(kinds)+1)**2-mi[1]+td[i][1]
            kinds[mi[0]].pop(-1)
            kinds[td[i][0]]=[td[i][1]]
            ans_.append(ans)
#print(kinds)
print(max(ans_))

### FIXED CODE ###

n,k=map(int,input().split())
td=sorted([list(map(int,input().split())) for i in range(n)],reverse=True,key=lambda x:x[1])

ans=0
kl=dict()
for i in range(k):
    ans+=td[i][1]
    if td[i][0] in kl:
        kl[td[i][0]]+=1
    else:
        kl[td[i][0]]=1
l=len(kl)
ans+=(l**2)
ans_=ans
now=k-1
for i in range(k,n):
    if td[i][0] not in kl:
        #最小を求めるのをもっと早く
        while now>=0:
            if kl[td[now][0]]>1:
                mi=td[now]
                kl[mi[0]]-=1
                now-=1
                break
            now-=1
        if now==-1:
            break
        else:
            ans=ans+2*l+1-mi[1]+td[i][1]
            kl[td[i][0]]=1
            ans_=max(ans,ans_)
            l+=1

print(ans_)
### BUGGY CODE ###

K,S=map(int,input().split())
count=0
for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            count+=S==X+Y+Z

print(count)


### FIXED CODE ###

K,S=map(int,input().split())
count=0
for X in range(K+1):
    for Y in range(K+1):
        count+=X+Y<=S<=X+Y+K

print(count)
### BUGGY CODE ###

from itertools import permutations

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
# conf = [[int(x) for x in input().split()] for _ in range(n)]
conf = sorted([[int(x) for x in input().split()] for _ in range(n)], reverse=True)

maxres = 0
for cc in permutations(conf, min(m, len(conf))):
  res = 0
  for i, c in enumerate(cc):
    if i + c[0] <= m:
      res = res + c[1]
    else:
      break
  if res > maxres:
    maxres = res
print(maxres)


### FIXED CODE ###


import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = collections.deque([])
for i in range(n):
  conditions.append([int(x) for x in input().split()])

conditions = sorted(conditions)

cnt, ans = 0, 0
candidates = []
for reversed_day in range(1, m + 1):
  while cnt < len(conditions) and conditions[cnt][0] <= reversed_day:
    heapq.heappush(candidates, -conditions[cnt][1])
    cnt += 1

  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

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

from collections import deque

s = input()
q = int(input())

d = deque(s)

for _ in range(q):
  Q = list(input().split())
  
  if Q[0]=='1':
    d = deque(reversed(d))
  elif Q[0]=='2':
    if Q[1]=='1':
      d.appendleft(Q[2])
    elif Q[1]=='2':
      d.append(Q[2])

print(*d, sep='')

### FIXED CODE ###

from collections import deque

s = input()
q = int(input())

d = deque(s)
inv = 0

for _ in range(q):
  Q = list(input().split())
  
  if Q[0]=='1':
    inv += 1
  elif Q[0]=='2':
    if Q[1]=='1':
      if inv%2==0:
        d.appendleft(Q[2])
      else:
        d.append(Q[2])
    elif Q[1]=='2':
      if inv%2==0:
        d.append(Q[2])
      else:
        d.appendleft(Q[2])

if inv%2==0:
  print(*d, sep='')
else:
  print(*deque(reversed(d)), sep='')
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC137 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def Bellman_Ford(edges,num_v, start):
    #start → iの最短距離
    #start:始点, num_v:頂点数, edges:[辺の始点, 辺の終点, 辺のコスト]
    dist = [-float('inf') for _ in range(num_v)]
    #dist[i] := s→iの最短距離
    dist[start] = 0
    flg = 0
    for _ in range(10000):
        update = False
        for i in range(num_v):
            for edge in edges:
                e_from, e_to, e_cost = edge
                if e_from != -float('inf') and dist[e_to] < dist[e_from] + e_cost:
                    dist[e_to] = dist[e_from] + e_cost
                    update = True
        if not update:
            flg = 1
            break
    return dist, flg

n,m,p = LI()
edge = []
for _ in range(m):
    a,b,c = LI()
    edge.append([a-1,b-1,c-p])
d,f = Bellman_Ford(edge,n,0)
if d[-1] < 0:
    print(0)
elif not f:
    print(-1)
else:
    print(d[-1])


### FIXED CODE ###

#!/usr/bin/env python3
#ABC137 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def Bellman_Ford(edges,num_v, start):
    #start → iの最短距離
    #start:始点, num_v:頂点数, edges:[辺の始点, 辺の終点, 辺のコスト]
    dist = [-float('inf') for _ in range(num_v)]
    #dist[i] := s→iの最短距離
    dist[start] = 0
    flg = 0
    for i in range(num_v):
        update = False
        for edge in edges:
            e_from, e_to, e_cost = edge
            if e_from != -float('inf') and visited[e_to] and dist[e_to] < dist[e_from] + e_cost:
                dist[e_to] = dist[e_from] + e_cost
                update = True
        if not update:
            flg = 1
            break
    return dist, flg

n,m,p = LI()
edge = []
f = defaultdict(dict)
for _ in range(m):
    a,b,c = LI()
    edge.append([a-1,b-1,c-p])
    f[b-1][a-1] = 1
visited = [False]*n
def dfs(x):
    visited[x] = True
    for t in f[x].keys():
        if not visited[t]:
            dfs(t)
dfs(n-1)
d,f = Bellman_Ford(edge,n,0)
if not f:
    print(-1)
else:
    print(max(0,d[-1]))
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()

ss = [0] * (n+1)

for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        for j in range(i, n):
            ss[j+1] += 1


for i in range(q):
    l, r = map(int, input().split())
    print(ss[r-1] - ss[l-1])



### FIXED CODE ###

n, q = map(int, input().split())
s = input()

ss = [0] * (n+1)

for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        ss[i+1] = 1

sss = [0] * (n+1)
cnt = 0
for i in range(n+1):
    cnt += ss[i]
    sss[i] = cnt


for i in range(q):
    l, r = map(int, input().split())
    print(sss[r-1] - sss[l-1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    assert N == len(p)
    answer = 0
    means = list(map(lambda x: (1+x)/2, p))
    for i in range(N-K+1):
        check = sum(means[i:i+K])
        if answer <= check:
            answer = check
    print(answer)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    answer = sum(p[0:K])
    r = answer
    for i in range(N-K):
        answer = answer - p[i] + p[i+K]
        r = max(r, answer)
    print((r+K)/2)


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

import bisect
N = int(input())
a = list(map(int,input().split()))
a_left = sorted(a[:N])
a_right = sorted(a[N:])
sum_left = sum(a_left)
sum_right = sum(a_right[:N])
res = sum_left - sum_right

len_left = N
for elem in a[N:2*N]:
    le = bisect.bisect_left(a_right, elem)
    a_right.remove(elem)
    if le < N:
        sum_right = sum(a_right[:N])
    ri = bisect.bisect_left(a_left, elem)
    if ri >= len_left - N:
        a_left.insert(ri, elem)
        len_left += 1
        sum_left = sum(a_left[len_left-N:])
    res = max(res, sum_left-sum_right)
print(res)


### FIXED CODE ###

import bisect
import heapq
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
a_left = sorted(a[:N])
a_right = sorted(a[2*N:])
sum_left = sum(a_left)
sum_right = sum(a_right)
#res = sum_left - sum_right
res = sum_left - sum(sorted(a[N:])[:N])
a_right = [-elem for elem in a_right]
heapq.heapify(a_right)
heapq.heapify(a_left)
sr = [0]*(N+1)
sr[0] = sum_right

for i,elem in enumerate(reversed(a[N:2*N])):
    now = -heapq.heappop(a_right)
    if now > elem:
        heapq.heappush(a_right, -elem)
        sum_right += (elem-now)
    else:
        heapq.heappush(a_right, -now)
    sr[i+1] = sum_right

for i,elem in enumerate(a[N:2*N]):
    now = heapq.heappop(a_left)
    if now < elem:
        heapq.heappush(a_left, elem)
        sum_left += (elem-now)
    else:
        heapq.heappush(a_left, now)
    res = max(res, sum_left-sr[N-i-1])
print(res)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 16:22:35 2019
 
@author: Owner
"""
import numpy as np
 
N, K = map(int, input().split())
 
h = [0]*N
h[:] = map(int, input().split())
 
dp = [np.inf]*N
 
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        temp = np.inf
        for k in range(1,K+1):
            if n-k >= 0:
                temp = min(temp, dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
        dp[n] = temp
    #print(dp)
print(dp[N-1])

### FIXED CODE ###

# -*- coding: utf-8 -*-

import numpy as np

N, K = map(int, input().split())
 
h = np.array(list(map(int, input().split())))
 
dp = np.zeros(N)
 
for n in range(1, N):
    k = min(K, n)
    temp = np.min(dp[n-k:n] + np.abs(h[n]-h[n-k:n]))
    dp[n] = temp
print(int(dp[-1]))
### BUGGY CODE ###

from operator import itemgetter
import bisect

N,Q = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(N)]
D = [int(input()) for _ in range(Q)]

ans = [-1]*Q
L.sort(key=itemgetter(2))

K = []
for i in range(N):
    l = L[i][0]-0.5-L[i][2]
    r = L[i][1]-0.5-L[i][2]
    idx_l = bisect.bisect_left(D, l)
    idx_r = bisect.bisect_right(D, r)
    for j in range(len(K)):
        if idx_r < K[j][0]:
            K.append([idx_l, idx_r])
            break
        if idx_l <= K[j][0] < idx_r <= K[j][1]:
            idx_r = K[j][0]
            K[j][0] = idx_l
            break
        if K[j][0] <= idx_l <= K[j][1] <= idx_r:
            idx_l = K[j][1]
            K[j][1] = idx_r
            break
        if j == len(K)-1 and K[j][1] < idx_l:
            K.append([idx_l, idx_r-1])
    if i == 0:
        K.append([idx_l, idx_r-1])
    K.sort()
    for j in range(idx_l, idx_r):
        if ans[j] >= 0:
            continue
        ans[j] = L[i][2]
        
for i in range(Q):
    print(ans[i])

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)
### BUGGY CODE ###

n = int(input())
odd = []
even = []
arr = list(map(int, input().split()))
for i, e in enumerate(arr):
    if i % 2 == 0:
        # odd
        res = False
        for x in odd:
            if x[0] == e:
                x[1] += 1
                res = True
                break
        if not res:
            odd.append([e, 1])
    else:
        # even
        res = False
        for x in even:
            if x[0] == e:
                x[1] += 1
                res = True
                break
        if not res:
            even.append([e, 1])
odd.sort(key=lambda x: x[1])
even.sort(key=lambda x: x[1])
if odd[-1][0] == even[-1][0]:
    if len(odd) == 1:
        ans = n - even[-1][1]
    elif len(even) == 1:
        ans = n - odd[-1][1]
    elif odd[-2][1] > even[-2][1]:
        ans = n - even[-1][1] - odd[-2][1]
    else:
        ans = n - even[-2][1] - odd[-1][1]
else:
    ans = n - odd[-1][1] - even[-1][1]
print(ans)


### FIXED CODE ###

n = int(input())
odd = [[i, 0] for i in range(100000)]
even = [[i, 0] for i in range(100000)]
arr = list(map(int, input().split()))
odd_e = True
even_e = True
for i, e in enumerate(arr):
    if i % 2 == 0:
        odd[e - 1][1] += 1
        if odd_e and arr[0] != e:
            odd_e = False
    else:
        even[e - 1][1] += 1
        if even_e and arr[1] != e:
            even_e = False
odd.sort(key=lambda z: z[1])
even.sort(key=lambda z: z[1])
if odd[-1][0] == even[-1][0]:
    if odd_e or even_e:
        ans = n - even[-1][1]
    elif odd[-2][1] > even[-2][1]:
        ans = n - even[-1][1] - odd[-2][1]
    else:
        ans = n - even[-2][1] - odd[-1][1]
else:
    ans = n - odd[-1][1] - even[-1][1]
print(ans)
### BUGGY CODE ###

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

Frends = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a < b:
        Frends[a].append(b)
    else:
        Frends[b].append(a)

Blocked = [[] for _ in range(N)]
for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if c < d:
        Blocked[c].append(d)
    else:
        Blocked[d].append(c)

# process
# 友人グループを作成
fg = []
for i in range (N):
    fs = Frends[i]
    for f in fs:
        flg = False
        for g in fg:
            if i in g and f in g:
                flg = True
                continue
            elif not (i in g or f in g):
                continue
            else:
                if i in g:
                    g.add(f)
                else:
                    g.add(i)
                
                flg = True
                break
            
        if not flg:
            fg.append(set([i, f]))

for i in range(len(fg)-1):
    for j in range(i+1, len(fg)):
        if fg[i] & fg[j] != set():
            fg[i] = fg[i] | fg[j]
            fg[j].clear()

#print(fg)

# 友人候補を抽出
cand = []
for i in range(N):
    for g in fg:
        if i in g:
            for f in g:
                if i < f and not f in Frends[i] and not f in Blocked[i]:
                    cand.append((i, f,))

# 友人候補をカウント
ans = [0 for _ in range(N)]
for c in cand:
    a, b = c
    ans[a] += 1
    ans[b] += 1

# output
print(" ".join(map(str, ans)))


### FIXED CODE ###

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

Friends = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    Friends[a].add(b)
    Friends[b].add(a)

Blocked = [set() for _ in range(N)]
for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    Blocked[c].add(d)
    Blocked[d].add(c)

# process
# 友人グループを作成
checked = set()
ans = [0]*N

for i in range (N):
    if i in checked:
        continue
    
    fg = set()

    stack = list(Friends[i])
    while stack:
        f = stack.pop()
        if f in checked:
            continue

        checked.add(f)
        fg.add(f)
        stack.extend(Friends[f])

    for f in fg:
        ans[f] += len(fg)-1-len(fg&(Friends[f]|Blocked[f]))

# output
print(" ".join(map(str, ans)))
### BUGGY CODE ###

def main():
    S = input()
    N = len(S)
    S = int(S)
    result, work, temp = 0, [0] * 2019, 0
    for i in range(N+1): work[(S % 10**i) % 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 ###

n,m = map(int, input().split())
li = []
countA = 1 
countB = 0

for i in range(m):
    li.append(list(map(int, input().split())))

for item in li:
    for i in range(m):
        if item[0] == li[i][0] and item[1] == li[i][1]:
            countB = 0
        elif item[0] == li[i][0]: 
            if item[1] > li[i][1]:
                countA += 1
    pr_id = str(1000000+item[0])[1:7]
    ci_id = str(1000000+countA)[1:7]
    countA = 1
    print(pr_id + ci_id)

### FIXED CODE ###

n,m = map(int,input().split())
py = [list(map(int,input().split())) + [_] for _ in range(m)]
py.sort()
result = ['' for _ in range(m)] #ここで先にリストを作るから後から飛び飛びのインデックス指定で値を埋めていける

a = 1 #県のインデックスを表す変数
b = 1 #市の県の中でのインデックスを表す変数
for i in range(m):
    if py[i][0] != a:
        b=1
        a = py[i][0] 
        result[py[i][2]] = str(a).zfill(6) + str(b).zfill(6)
        b+=1
    else:
        result[py[i][2]] = str(a).zfill(6) + str(b).zfill(6)
        b+=1

for i in range(m):
    print(result[i])
### BUGGY CODE ###

S = list(input())
Q = int(input())
rev = False
F = []

for i in range(Q):
    X = list(input().split(" "))

    if X[0] == "1" and rev is False:
        rev = True
    elif X[0] == "1" and rev is True:
        rev = False
    elif X[0] == "2" and X[1] == "1" and rev is False:
        F.insert(0, X[2])
    elif X[0] == "2" and X[1] == "1" and rev is True:
        S.append(X[2])
    elif X[0] == "2" and X[1] == "2" and rev is False:
        S.append(X[2])
    elif X[0] == "2" and X[1] == "2" and rev is True:
        F.insert(0, X[2])

F.extend(S)

if rev is True:
    F.reverse()

print(*F, sep="")


### FIXED CODE ###

S = list(input())
Q = int(input())
rev = False
F = []

for i in range(Q):
    X = list(input().split(" "))

    if X[0] == "1" and rev is False:
        rev = True
    elif X[0] == "1" and rev is True:
        rev = False
    elif X[0] == "2" and X[1] == "1" and rev is False:
        F.append(X[2])
    elif X[0] == "2" and X[1] == "1" and rev is True:
        S.append(X[2])
    elif X[0] == "2" and X[1] == "2" and rev is False:
        S.append(X[2])
    elif X[0] == "2" and X[1] == "2" and rev is True:
        F.append(X[2])

F.reverse()
F.extend(S)

if rev is True:
    F.reverse()

print(*F, sep="")
### BUGGY CODE ###

T = list(input())
P = input()
for i in range(len(T)-len(P)+1):
    t = "".join(T[i : i+len(P)])
    if t == P:
        print(i)

### FIXED CODE ###

T = input()
P = input()
lenp = len(P)
for i in range(len(T)-len(P)+1):
    t = T[i : i+lenp]
    if t == P:
        print(i)
### BUGGY CODE ###

from collections import deque


def bfs(start, end):
    Q = deque()
    Q.append(start)
    dist[start] = 0

    while Q:
        v = Q.popleft()

        for nv in G[v]:
            if dist[nv] != -1:
                continue
            Q.append(nv)
            dist[nv] = dist[v] + 1

            if nv == end:
                return dist[nv]


N, X, Y = map(int, input().split())
G = [[] for _ in range(N)]
res = [0] * N

for i in range(N - 1):
    G[i].append(i + 1)
    G[i + 1].append(i)

if abs(X - Y) != 1:
    G[X - 1].append(Y - 1)
    G[Y - 1].append(X - 1)

for i in range(N - 1):
    for j in range(i + 1, N):
        dist = [-1] * N
        res[bfs(i, j)] += 1

for i in range(1, N):
    print(res[i])


### FIXED CODE ###

N,X,Y=map(int,input().split())
ans=[0 for i in range(1,N)]
 
for i in range(1,N):
    for j in range(i+1,N+1):
        k=min(abs(j-i),abs(X-i)+1+abs(Y-j),abs(Y-i)+1+abs(X-j))
        ans[k-1]+=1
 
for i in ans:
    print(i)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

n, q = list(map(int, input().split()))
# 双方向に張る
tree = [[] for _ in range(n)]
for i in range(n-1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

# queryのスコア表を作る
total = [0 for _ in range(n)]
for i in range(q):
    p, x = list(map(int, input().split()))
    total[p - 1] += x

# dfs
ans = [0 for _ in range(n)]
def dfs(v, p, value):
    value += total[v]
    ans[v] = value
    for c in tree[v]:
        if c == p: continue
        dfs(c, v, value)

dfs(0, -1, 0)
print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

readline = sys.stdin.readline
n, q = list(map(int, readline().split()))
# 双方向に張る
tree = [[] for _ in range(n)]
for i in range(n-1):
    a, b = list(map(int, readline().split()))
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

# queryのスコア表を作る
total = [0 for _ in range(n)]
for i in range(q):
    p, x = list(map(int, readline().split()))
    total[p - 1] += x

# dfs
ans = [0 for _ in range(n)]
def dfs(v, p, value):
    value += total[v]
    ans[v] = value
    for c in tree[v]:
        if c == p: continue
        dfs(c, v, value)

dfs(0, -1, 0)
print(*ans)
### BUGGY CODE ###

import numpy as np


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    for w in range(W+1):
        if w - w_v[i][0] < 0:
            dp[i][w] = dp[i-1][w]
        else:
            dp[i][w] = max(dp[i-1][w], dp[i-1][w - w_v[i][0]] + w_v[i][1])
 
print(dp[N-1][W])

### FIXED CODE ###

import numpy as np


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    key = w_v[i][0]
    dp[i][:key] = dp[i-1][:key]
    dp[i][key:] = np.maximum(dp[i-1][key:], dp[i-1][:-key] + w_v[i][1])

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

# -*- coding: utf-8 -*-
# 整数の入力
n,m= map(int, input().split())
x=list(map(int, input().split()))
y=list(map(int, input().split()))
yoko=0
tate=0
for i in range (0,len(x)-1):
  for j in range (i+1,len(x)):
    yoko+=x[j]-x[i]
for i in range (0,len(y)-1):
  for j in range (i+1,len(y)):
    tate+=y[j]-y[i]

print(yoko*tate%(10**9+7))

### FIXED CODE ###

# -*- coding: utf-8 -*-
# 整数の入力
n,m= map(int, input().split())
x=list(map(int, input().split()))
y=list(map(int, input().split()))
yoko=0
tate=0
for i in range (0,len(x)):
  yoko+=(n-2*i-1)*x[i]
for i in range (0,len(y)):
  tate+=(m-2*i-1)*y[i]

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

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

now = 0

for i in range(n-k+1):
  now = max(sum(l[i:i+k]), now)
  
print((now + k) / 2)

### FIXED CODE ###

n, k = map(int, input().split())
l = list(map(int, input().split()))
 
tmp = sum(l[:k])
now = tmp
 
for i in range(n-k):
  tmp -= l[i]
  tmp += l[i+k]
  now = max(tmp, now)
  
print((now + k) / 2)
### BUGGY CODE ###

s = input()
n = len(s)
count = 0

while True:
    if '10' in s:
        s = s.replace('10','',1)
        count += 2
    elif '01' in s:
        s = s.replace('01','',1)
        count += 2
    else:
        break

print(count)


### FIXED CODE ###

s = input()
print(min(s.count('0'),s.count('1'))*2)