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

#%%
def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp

def combination(n, x, mod=10**9+7):
    # nCx, a=n!, b=x!, c=(n-x)!
    # 組み合わせ
    # ex) combination(5, 2) = 10
    tmp = factorial(n)
    tmp = (tmp * pow(factorial(x), mod-2, mod)) % mod
    tmp = (tmp * pow(factorial(n-x), mod-2, mod)) % mod
    return tmp

n, k = map(int, input().split())
mod = 10**9+7
a = list(map(int, input().split()))
a.sort()

b = combination(n, k)

l = [b] * (n-1)

for i in range(n-1):
    tmp = 0
    x = i+1
    y = (n-1)-i
    if x >= k:
        tmp += combination(x, k)
    if y >= k:
        tmp += combination(y, k)
    l[i] -= tmp

ll = [0] * (n-1)
for i in range(n-1):
    ll[i] = a[i+1] - a[i]
    ll[i] %= mod


ans = 0
for i in range(n-1):
    tmp = l[i] * ll[i]
    tmp %= mod
    ans += tmp
    ans %= mod

if ans < 0:
    ans += mod

print(ans)


### FIXED CODE ###

#%%
kai = [1]
tt = 1
mod = 10**9+7
for i in range(1, 10**5+1):
    tt *= i
    tt %= mod
    kai.append(tt)
#print(kai)


def combination(n, x, kai, mod=10**9+7):
    # nCx, a=n!, b=x!, c=(n-x)!
    # 組み合わせ
    # ex) combination(5, 2) = 10
    tmp = kai[n]
    tmp = (tmp * pow(kai[x], mod-2, mod)) % mod
    tmp = (tmp * pow(kai[n-x], mod-2, mod)) % mod
    return tmp

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

b = combination(n, k, kai)

l = [b] * (n-1)

for i in range(n-1):
    tmp = 0
    x = i+1
    y = (n-1)-i
    if x >= k:
        tmp += combination(x, k, kai)
    if y >= k:
        tmp += combination(y, k, kai)
    l[i] -= tmp

ll = [0] * (n-1)
for i in range(n-1):
    ll[i] = a[i+1] - a[i]
    ll[i] %= mod


ans = 0
for i in range(n-1):
    tmp = l[i] * ll[i]
    tmp %= mod
    ans += tmp
    ans %= mod

if ans < 0:
    ans += mod

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

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0] * n
    
    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            self.rank[x] += (self.rank[x] == self.rank[y])
            
def kruskal(n, **args):
    uf = UnionFind(n)
    mst_edge = []
    
    edge = []
    if "dist" in args:
        for i in range(n):
            for t in range(i+1, n):
                edge.append((args["dist"][i][t], i, t))
    elif "edge" in args:
        edge = args["edge"]

    edge.sort(key=lambda x:x[0])
    for i in range(len(edge)):
        d, v, u = edge[i]
        
        if uf.find(v) != uf.find(u):
            uf.union(v, u)
            mst_edge.append((v, u, d))
    
    return mst_edge  
  
n = int(input())
x, y = [None]*n, [None]*n
dist = [[0] * n for _ in range(n)]

for i in range(n):
    a, b = map(int, input().split())
    x[i] = (a, i)
    y[i] = (b, i)

x.sort(key=lambda x:x[0])
y.sort(key=lambda y:y[0])

edge_x = []
edge_y = []
for i in range(n-1):
    edge_x.append((x[i+1][0]-x[i][0], x[i][1], x[i+1][1]))
    edge_y.append((y[i+1][0]-y[i][0], y[i][1], y[i+1][1]))

mst = kruskal(n, edge=edge_x+edge_y)
print(sum([i[2] for i in mst]))

### FIXED CODE ###

import heapq
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0] * n
    
    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            self.rank[x] += (self.rank[x] == self.rank[y])

def kruskal(n, edge):
    ans = 0
    uf = UnionFind(n)
    while True:
        d, v, u = heapq.heappop(edge)
        
        if uf.find(v) != uf.find(u):
            uf.union(v, u)
            n -= 1
            ans += d
        if n < 2: return ans
    return ans

n = int(input())
x, y = [None]*n, [None]*n

for i in range(n):
    a, b = map(int, input().split())
    x[i] = (a, i)
    y[i] = (b, i)

x.sort(key=lambda x:x[0])
y.sort(key=lambda y:y[0])

edge = []
for i in range(n-1):
    heapq.heappush(edge, (x[i+1][0]-x[i][0], x[i][1], x[i+1][1]))
    heapq.heappush(edge, (y[i+1][0]-y[i][0], y[i][1], y[i+1][1]))

del x, y
print(kruskal(n, edge))
### BUGGY CODE ###

import bisect
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
A = p[:X]+q[:Y]
A.sort()
for n in r:
    if A[0] < n:
        index = bisect.bisect_left(A,n)
        A.insert(index,n)
        A.pop(0)
    else:
        break
print(sum(A))

### FIXED CODE ###

import bisect
def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
A = p[:X]+q[:Y]
B = []
A.sort(reverse=True)
for i in range(len(r)):
    n = r[i]
    if A[0] == 0:
      break
    if A[-1] < n:
        index = bisect_left_reverse(A,n)
        A.pop(-1)
        B.append(n)
    else:
        break
print(sum(A)+sum(B))
### BUGGY CODE ###

import math
def segmentTree(dat, f, sentinel):
        pad = 2 ** math.ceil(math.log(len(dat),2))
        dat = [0] * pad + dat + [sentinel] * (pad - len(dat))
        for i in range(pad - 1, 0, -1):
            dat[i] = f(dat[i * 2:i * 2 + 2])
        return dat

def get_lr(b,d):
    l = r = 0
    while r < len(b):
        while b[l] + d < b[r]:
            l += 1
        for r in range(r,len(b)):
            if b[l] + d < b[r]:
                r -= 1
                break
        r += 1
        yield l,r
        l += 1
    
import sys
f = sys.stdin

_, d = map(int, f.readline().split())

xyb = []
for line in f:
    xyb.append(tuple(map(int, line.split())))
from operator import itemgetter
xyb.sort(key=itemgetter(2))

x = [xybi[0] for xybi in xyb]
y = [xybi[1] for xybi in xyb]
b = [xybi[2] for xybi in xyb]

xmax = segmentTree(x,max,sentinel = 0)
xmin = segmentTree(x,min,sentinel = 2000000)
ymax = segmentTree(y,max,sentinel = 0)
ymin = segmentTree(y,min,sentinel = 2000000)


size = []
sa = size.append #万単位で呼び出す場合は若干早くなる
pad = len(xmax) // 2
for l,r in get_lr(b,d):
    # 参照するsegmentのindexを生成　※速度のためインライン展開
    l += pad 
    r += pad
    index = []
    ia = index.append
    while l < r:
        if r & 1:
            r -= 1
            ia(r)
        if l & 1:
            ia(l)
            l += 1
        l >>= 1
        r >>= 1

    sa((max(xmax[i] for i in index)
                 - min(xmin[i] for i in index))
                * (max(ymax[i] for i in index)
                   - min(ymin[i] for i in index)))
print(max(size))

### FIXED CODE ###

import math
def segmentTree(dat, f, sentinel):
        pad = 2 ** math.ceil(math.log(len(dat),2))
        dat = [0] * pad + dat + [sentinel] * (pad - len(dat))
        for i in range(pad - 1, 0, -1):
            dat[i] = f(dat[i * 2],dat[i * 2 + 1])
        return dat

def get_lr(b,d):
    l = r = 0
    while r < len(b):
        while b[l] + d < b[r]:
            l += 1
        for r in range(r,len(b)):
            if b[l] + d < b[r]:
                r -= 1
                break
        r += 1
        yield l,r
        l += 1
    
import sys
f = sys.stdin

_, d = map(int, f.readline().split())

xyb = []
for line in f:
    xyb.append(tuple(map(int, line.split())))
from operator import itemgetter
xyb.sort(key=itemgetter(2))

x = [xybi[0] for xybi in xyb]
y = [xybi[1] for xybi in xyb]
b = [xybi[2] for xybi in xyb]

xmax = segmentTree(x,max,sentinel = 0)
xmin = segmentTree(x,min,sentinel = 2000000)
ymax = segmentTree(y,max,sentinel = 0)
ymin = segmentTree(y,min,sentinel = 2000000)


pad = len(xmax) // 2
max_size = 0
def create_index(l,r):
    index = []
    ia = index.append
    while l < r:
        if r & 1:
            r -= 1
            ia(r)
        if l & 1:
            ia(l)
            l += 1
        l >>= 1
        r >>= 1
    return index

for l,r in get_lr(b,d):
    l += pad 
    r += pad
    index = create_index(l,r)

    now_xmax = max(xmax[i] for i in index)
    now_ymax = max(ymax[i] for i in index)
    if max_size < now_xmax * now_ymax:
        max_size = max(max_size,((now_xmax - min(xmin[i] for i in index)) * (now_ymax - min(ymin[i] for i in index))))
print(max_size)
### BUGGY CODE ###

N,M = map(int,input().split())
A = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    dp[i] = (dp[i-1] + dp[i-2])%(1000000007)
    if i in A:dp[i] = 0
    
print(dp[N])

### FIXED CODE ###

n,m=map(int,input().split())
a=set([int(input()) for i in range(m)])
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in a:dp[i]=0
print(dp[n])
### BUGGY CODE ###


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

loop = []
trace = [0] * (N+1)

ai = 1
for i in range(N+1):
    if ai in trace:
        ind = trace.index(ai)
        loop = trace[ind:i]
        trace = trace[:ind]
        break

    trace[i] = ai # ??
    ai = A_list[ai-1]

if len(trace) > K:
    print(trace[K])
else:
    ind = K - len(trace)
    ind = ind % len(loop)
    print(loop[ind])


### FIXED CODE ###


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

loop = []
trace = [0] * (N+1)
visited = set()

ai = 1
for i in range(N+1):
    if ai in visited:
        ind = trace.index(ai)
        loop = trace[ind:i]
        trace = trace[:ind]
        break
    visited.add(ai)
    
    trace[i] = ai # ??
    ai = A_list[ai-1]


if len(trace) > K:
    print(trace[K])
else:
    ind = K - len(trace)
    ind = ind % len(loop)
    print(loop[ind])
### BUGGY CODE ###

N_K=list(map(int,input().split()))
N=N_K[0]
K=N_K[1]
cost=list(map(int,input().split()))
#cost=[int(input()) for i in range(N)]

answers={0:0,1:abs(cost[1]-cost[0])}
if K==1:
	S=0
	for i in range(N-1):
		S += abs(cost[i]-cost[i+1])
	print (S)
else:
	for i in range(2,N):
		comp=[]
		if i<K:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,i+1)]
			answers[i]=min(comp)
		else:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,K+1)]
			answers[i]=min(comp)			
	print(answers[N-1])

### FIXED CODE ###

N_K=list(map(int,input().split()))
N=N_K[0]
K=N_K[1]
cost=list(map(int,input().split()))
answers=[0,abs(cost[1]-cost[0])]
if K==1:
	S=0
	for i in range(N-1):
		S += abs(cost[i]-cost[i+1])
	print (S)
else:
	for i in range(2,N):
		comp=[]
		if i<K:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,i+1)]
			answers.append(min(comp))
		else:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,K+1)]
			answers.append(min(comp))			
	print(answers[-1])
### BUGGY CODE ###

n = int(input())
s = []
for i in range(n):
    s.append(input())

ans = []
for i in range(n):
    ans.append(sorted(s[i]))

x = 0
for i in range(n):
    for j in range(i+1, n):
        if ans[i] == ans[j]:
            x = x + 1

print(x)

### FIXED CODE ###

from collections import Counter

n = int(input())
s = []
for i in range(n):
    s.append(''.join(sorted(input())))
    
v = list(Counter(s).values())
ans = []
for i in range(len(v)):
    if v[i] >= 2:
        ans.append((v[i] * (v[i]-1))/2)

print(int(sum(ans)))
### BUGGY CODE ###

x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  for i in range(k):
    xi -= d
    if xi <= 0:
      if (i+k) % 2 != 0:
        m = min(abs(xi),abs(xi+2*d),abs(xi-2*d))
      else:
        m = min(abs(xi+d),abs(xi-d))
      break
print(m)

### FIXED CODE ###

from math import ceil 
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  n = ceil(xi / d)
  if (n+k) % 2 == 0:
    m = abs(xi-d*n)
  else:
    m = abs(xi-d*(n-1))
print(m)
### BUGGY CODE ###

import math
denom = int(1e9+7)

def combi(n,r):
    return (int(math.factorial(n)) // int(math.factorial(r)) // int(math.factorial(n - r))) % denom


N, K = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort(reverse = True)

max_tot = 0
for i in range(N-K+1):
    max_tot += (A[i] * combi(N-i-1, K-1)) % denom
min_tot = 0
for i in range(N-K+1):
    min_tot += (A[N-i-1] * combi(N-i-1, K-1)) % denom
    
print((max_tot - min_tot)%denom)

### FIXED CODE ###

import math
denom = int(1e9+7)

def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


def combi2(n,k,p,f,pow_fun):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=fact_mod[n]
  b=fact_mod[k]
  c=fact_mod[n-k]
  return (a*pow_fun[b]*pow_fun[c])%p


N, K = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort(reverse = True)

fact_mod = [1]
current = 1
for i in range(1,N+1):
    current = (current * i) % denom
    fact_mod.append(current)

pow_fun = {}
for i in fact_mod:
    pow_fun[i]=power_func(i,denom-2,denom)

max_tot = 0
min_tot = 0
for i in range(N-K+1):
    max_tot += (A[i] * combi2(N-i-1, K-1, denom, fact_mod,pow_fun)) % denom
    min_tot += (A[N-i-1] * combi2(N-i-1, K-1, denom, fact_mod,pow_fun)) % denom
    
print((max_tot - min_tot)%denom)
### BUGGY CODE ###

[N,L] = [int(x) for x in input().split()]
A = {}
B = [0]*N
ANS = {}
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    B[i] = x
    if x in A : A[x] += [i]
    else : A[x] = [i]
for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            if j + k not in ANS :
                ANS[j+k] = i
                count += 1
    if count > N + 200 : break
for i in range(L-1,N-1) : print(ANS[i], end=" ")
print(ANS[N-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
bit = [0]*60
ans = 0
mod = 10**9+7
for i in a:
    cnt = 1
    while i:
        bit[-cnt] += i%2
        i //= 2
        cnt += 1
for i in range(60):
    ans += ((n-bit[-1-i])*bit[-1-i]) % mod * pow(2,i,mod)
    ans %= mod
print(ans%mod)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
bit = [0]*60
ans = 0
mod = 10**9+7
for i in a:
    cnt = 1
    while i:
        bit[-cnt] += i%2
        i //= 2
        cnt += 1
for i in range(60):
    ans += (n-bit[-1-i])*bit[-1-i] * (2**i) % mod
    ans %= mod
print(ans)
### BUGGY 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):
            tmp = math.gcd(i,j)
            ans += math.gcd(tmp,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):
        tmp = math.gcd(i,j)
        for k in range(1,n+1):
            ans += math.gcd(tmp,k)
print(ans)
### BUGGY CODE ###

import collections

n = int(input())
v = list(map(str, input().split()))

f = collections.Counter([v[i] for i in range(n) if i % 2 == 0])
s = collections.Counter([v[i] for i in range(n) if i % 2 == 1])

ans = []

for i in f.keys():
    for j in s.keys():
        if i == j:
            continue
        else:
            ans.append(f[i] + s[j])

if ans:
    print(n - max(ans))
else:
    print(n // 2)


### FIXED CODE ###

from collections import Counter

n = int(input())
v = list(map(str, input().split()))

f = Counter(v[::2]).most_common(2)
s = Counter(v[1::2]).most_common(2)

if f[0][0] != s[0][0]:
    print(n - f[0][1] - s[0][1])
else:
    if len(f) == 1 or len(s) == 1:
        print(n // 2)
    else:
        print(n - max(f[0][1] + s[1][1], f[1][1] + s[0][1]))
### BUGGY CODE ###

from fractions import gcd
from functools import reduce

N = int(input())
*A, = map(int, input().split())
mod = 10**9 + 7

lcm = reduce(lambda a,b: a*b//gcd(a,b), A)
print(sum(map(lambda x: lcm//x, A))%mod)

### FIXED CODE ###

from functools import reduce

def gcd(x, y):
    if (y==0):return x
    else:return gcd(y, x%y)

N = int(input())
*A, = map(int, input().split())
mod = 10**9 + 7
lcm = reduce(lambda a,b: a*b//gcd(a,b), A)

print(sum(map(lambda x: lcm//x, A))%mod)
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N,M = list(map(int,input().split()))
Network = UnionFind(N)
Friend = [0] * N
BlockInNetwork = [0] * N

for i in range(M):
    a, b = list(map(int,input().split()))
    Network.union(a-1, b-1)

out = 0
for L in Network.all_group_members().values():
    out = max(out,len(L))
print(out)

### FIXED CODE ###

N,M = list(map(int,input().split()))
from collections import deque

G = [[] for i in range(N)]
for i in range(M):
    A,B=list(map(int,input().split()))
    G[A-1].append(B-1)
    G[B-1].append(A-1)

Ls = []
dist = [0]*N
for i in range(N):
    if dist[i]==1:
        continue
    s = i
    que = deque([s])
    dist[s] = 1
    L = [s]
    while que:
        v = que.popleft()
        for w in G[v]:
            if dist[w]==1:
                continue
            dist[w] = 1
            que.append(w)
            L.append(w)
    Ls.append(L)
out = 0
for L in Ls:
    out=max(len(L),out)
print(out)
### BUGGY CODE ###

import bisect
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,M = map(int,readline().split())
A = np.array(readline().split(),np.int64)
C = np.cumsum(A)
ans = np.sum(C % M == 0)
for i in range(N-1):
  C -= A[i]
  X = bisect.bisect_left(C,M)
  C = C[X:]
  if X == N:break
  ans += np.sum(C % M == 0)
print(ans)

### FIXED CODE ###

from collections import defaultdict
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,M = map(int,readline().split())
A = np.array(readline().split(),np.int64)
A = np.insert(A,0,0)
C = np.cumsum(A)
C %= M
ans = 0
d = defaultdict(int)
for i in range(N+1):
  ans += d[C[i]]
  d[C[i]] += 1
print(ans)
### BUGGY CODE ###

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

for i in range(n):
  ans = 0
  acopy = a.copy()
  del acopy[i]
  m = [x for x in set(acopy) if acopy.count(x) > 1]
  for j in range(len(m)):
    k = acopy.count(m[j])
    ans += k*(k-1)//2
  print(ans)

### FIXED CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
v = c.values()
s = 0
for i in v:
    s += (i*(i-1))//2

for i in range(n):
    d = c[a[i]]
    x = (d*(d-1))//2 if d > 1 else 0
    y = ((d-1)*(d-2))//2 if d > 2 else 0
    print(s-x+y)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(n):
  ans *= a[i]
if ans <= 10**18:
  print(ans)
else:
  print(-1)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
if 0 in a:
  print(0)
  exit()
ans = 1
for i in range(n):
  ans *= a[i]
  if ans > 10**18:
    print(-1)
    exit()
print(ans)
### BUGGY CODE ###

n = int(input())
li = list(map(int,input().split()))
li.sort()
dp = [1]*n
done = [0]*n

for i in range(n):
    if done[i]==0:
        for j in range(i+1,n):
            if done[j]==0:
                if li[j]==li[i]:
                    done[i]=1
                    done[j]=1
                    dp[i]=0
                    dp[j]=0
                elif li[j]%li[i]==0:
                    done[j]=1
                    dp[j]=0

print(sum(dp))

### FIXED CODE ###

n  = int(input())
li = list(map(int,input().split()))
ok = set()
ng = set()
mul = set()

ans = 0

for i in li:
    if i not in ok:
        ok.add(i)
    else:
        ng.add(i)

for i in ok:
    for j in range(2,10**6):
        if i*j > 10**6:
            break
        else:
            mul.add(i*j)

for i in ok:
    if i not in mul:
        if i not in ng:
            ans+=1

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

def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			S=S.replace('10','',1)
			chk=1
			cnt+=1
		elif '01' in S:
			S=S.replace('01','',1)
			chk=1
			cnt+=1
	print(cnt*2)

resolve()

### FIXED CODE ###

def resolve():
	S=input()
	print(min(S.count('1'),S.count('0'))*2)
resolve()