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

#!/usr/bin/env python3
import math

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]

    dv = []
    for _ in range(60):
        l = [0] * N
        dv.append(l)
    
    for n in range(N):
        dv[0][n] = A[n] - 1
    
    for k in range(1, 60):
        for n in range(N):
            dv[k][n] = dv[k - 1][dv[k - 1][n]]
    
    a = []
    for i in range(60):
        if K>>i & 1:
            a.append(i)

    now = 0
    for i in reversed(a):
        now = dv[i][now]
    print(now + 1)





    pass

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]

    count = 0
    now = 1
    visited = [-1] * N
    visited[now - 1] = 0 # 町1 は0かいでいける
    while count < K:
        now = A[now - 1]
        count += 1
        if visited[now - 1] == -1:
            visited[now - 1] = count
        else:
            loop = count - visited[now - 1]
            rest = (K - visited[now - 1]) % loop
            #print("resr", rest)
            if rest == 0:
                break
            for i in range(len(visited)):
                if visited[i] == visited[now - 1] + rest:
                    now = i + 1
                    count = K # break
                    break
    #print(visited[0])
    print(now)




    pass

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

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    ans = '0'
    for i in range(N):
        if S[i]=='1':
            l = []
            for j in range(i+1,N):
                if S[j]=='0':
                    l.append(A[j])
            cand = []
            for a in l:
                cand.append(a)
                for b in l:
                    cand.append(a^b)
            cand = list(set(cand))
            cand.sort()
            s = A[i]
            for a in cand:
                if s^a<s:
                    s ^= a
            for a in cand:
                if s^a<s:
                    s ^= a
            if s != 0:
                ans = '1'
                
    print(ans)

T = int(input())
for t in range(T):
    solve()

### FIXED CODE ###

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    ans = '0'
    for i in range(N):
        if S[i]=='1':
            l = []
            for j in range(i+1,N):
                if S[j]=='0':
                    l.append(A[j])
            for k in range(len(l)):
                l.sort()
                for j in range(len(l)-1):
                    if l[j+1]^l[j] < l[j+1]:
                        l[j+1],l[j] = l[j],l[j+1]^l[j]
                
            s = A[i]
            for j in range(len(l)-1,-1,-1):
                if s^l[j] < s:
                    s ^= l[j]
            if s != 0:
                ans = '1'
    print(ans)
def main():
    T = int(input())
    for t in range(T):
        solve()

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

n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0:
        maxv = max(n)
        winner = n.index(maxv)
    else:
        if n[a] > maxv:
            maxv, winner = n[a], a
        elif n[a] == maxv:
            winner = n.index(maxv)
    print(winner, maxv)

### FIXED CODE ###

n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0 and a == winner:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)
### BUGGY CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, m = li()
s = list(li())
t = list(li())

MOD = 10**9 + 7

dp = [[0]*(m+1) for _ in range(n+1)]
# for i in range(n+1):
#     dp[i][0] = 1
#
# for j in range(m+1):
#     dp[0][j] = 1

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % MOD
        else:
            dp[i + 1][j + 1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD

print((dp[n][m] + 1) % MOD)


### FIXED CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, m = li()
s = list(li())
t = list(li())

MOD = 10**9 + 7

dp = [[0]*(m+1) for _ in range(n+1)]
# for i in range(n+1):
#     dp[i][0] = 1
#
# for j in range(m+1):
#     dp[0][j] = 1

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % MOD
        else:
            dp[i + 1][j + 1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD

print((dp[n][m] + 1) % MOD)
### BUGGY CODE ###

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

ans = 1

for i in range(n):
    ans = ans * A[i]

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

### FIXED CODE ###

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

ans = 1
A.sort(reverse = True)
flag = True

if 0 in A:
    ans = 0
    flag = False

if flag:
    for i in range(n):
        ans = ans * A[i]
        if ans > 10 ** 18:
            ans = -1
            break

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

#!/usr/bin/env python3
import sys
import heapq


def solve(N: int, A: "List[int]", B: "List[int]"):
    diff = [(p[0] - p[1], i) for i, p in enumerate(zip(A, B))]
    heapq.heapify(diff)
    # print(diff)
    count = 0
    while True:
        d, i = heapq.heappop(diff)

        if d == 0:
            break

        x = B[(i+1)%N] + B[i-1]
        d += x
        B[i] -= x

        if d > 0:
            print(-1)
            return

        heapq.heappush(diff, (d, i))
        count += 1
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import heapq


def solve(N: int, A: "List[int]", B: "List[int]"):
    diff = [(p[0] - p[1], i) for i, p in enumerate(zip(A, B))]
    heapq.heapify(diff)
    # print(diff)
    count = 0
    while True:
        d, i = heapq.heappop(diff)

        if d == 0:
            break

        x = B[(i+1)%N] + B[i-1]
        n = -d // x
        if n <= 0:
            print(-1)
            return
        d += n * x
        B[i] -= n * x


        heapq.heappush(diff, (d, i))
        count += n
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B)

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

import sys
input = sys.stdin.readline
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [0] + p
c = list(map(int, input().split()))
c = [0] + c
score = [[0] * (n + 1) for _ in range(n + 1)]
# score[i][j]: iからstartしてj回移動した時のスコア
l_cycle = [0] * (n + 1)
for i in range(1, n + 1):
    start = i
    move_cnt = 0
    nxt = i
    while move_cnt < n:
        nxt = p[nxt]
        score[i][move_cnt + 1] += score[i][move_cnt] + c[nxt]
        move_cnt += 1
        if nxt == start:
            l_cycle[start] = move_cnt
            break
# for i in range(1, n + 1):
#     print(score[i])
# print('l_cycle', l_cycle)
ans = -float('inf')
for s in range(1, n + 1):
    if k <= l_cycle[s]:
        # サイクルを回らないので
        temp = max(score[s][1:k + 1])
        ans = max(ans, temp)
        continue
    # 以降は一周以上出来る時

    # 一周以下でやめる場合を探索
    temp = max(score[s][1:l_cycle[s] + 1])
    ans = max(ans, temp)
    # if score[s][l_cycle[s]] <= 0:
    #     # 周回する意味がない
    #     continue
    sk = k // l_cycle[s]  # 何周出来るか
    remk = k % l_cycle[s]
    temp = sk * score[s][l_cycle[s]]  # 周回によるスコア
    if remk != 0:
        temp += max(score[s][1:remk + 1])
    ans = max(ans, temp)

print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(n):
    p[i] -= 1
ans = -float('inf')
for st in range(n):
    x = st
    score = []
    tot = 0
    while True:
        x = p[x]
        score.append(c[x])
        tot += c[x]
        if x == st:
            break
    l = len(score)
    now = 0
    t = 0
    for i in range(l):
        t += score[i]
        if i + 1 > k:
            break
        now = t
        if tot > 0:
            cycle_num = (k - (i + 1)) // l
            now += tot * cycle_num
        ans = max(ans, now)
print(ans)
### BUGGY CODE ###

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

for i in range(1,n+1):
    number = 0
    ans.append(a.count(i))

for j in ans:
    print(j)


### FIXED CODE ###

from collections import deque

n = int(input())
a = list(map(int,input().split()))
ans = [0] * n

for i in a:
    ans[i-1] += 1

for j in ans:
    print(j)
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
ans = []
for i in range(q):
    l, r = map(int, input().split())
    ans.append(s[l - 1: r].replace("AC", "*").count("*"))
print(*ans, sep="\n")


### FIXED CODE ###

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

from collections import Counter
N = int(input())
S_lis = []
for n in range(N):
    S = input()
    S_lis.append(S)

ans_lis = []
for key, value in Counter(S_lis).items():
    if value == max(Counter(S_lis).values()):
        ans_lis.append(key)
for item in sorted(ans_lis):
    print(item)


### FIXED CODE ###

N = int(input())

S_dic = {}
maximum = 0
for n in range(N):
    S = input()
    if S not in S_dic:
        S_dic[S] = 1
    else:
        S_dic[S] += 1
    if maximum < S_dic[S]:
        maximum = S_dic[S]


for key, value in sorted(S_dic.items(), key=lambda x: x[0]):
    if value == maximum:
        print(key)
### BUGGY CODE ###

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

import itertools
a = []
for i in range(q):
    a.append(input().split())

suma = sum([int(aa[3]) for aa in a])

ans = 0
l = [i for i in range(m)]
for v in itertools.combinations_with_replacement(l, n):
    ans_ = 0
    for j in range(q):
        if v[int(a[j][1])-1] - v[int(a[j][0])-1] == int(a[j][2]):
            ans_ += int(a[j][3])
    if ans_ > ans:
        ans = ans_
        if ans == suma:
            break
print(ans)

### FIXED CODE ###

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

import itertools
a = []
for i in range(q):
    a.append(input().split())

suma = sum([int(aa[3]) for aa in a])

ans = 0
l = [i for i in range(m)]
for v in itertools.combinations_with_replacement(l, n-1):
    ans_ = 0
    v = [0]+list(v)
    for j in range(q):
        if v[int(a[j][1])-1] - v[int(a[j][0])-1] == int(a[j][2]):
            ans_ += int(a[j][3])
    if ans_ > ans:
        ans = ans_
        if ans == suma:
            break
print(ans)
### BUGGY CODE ###

import sys
from itertools import combinations
def input(): return sys.stdin.readline().strip()
inf = sys.maxsize

h, w, k = map(int,input().split())
s = [[int(i) for i in input()] for _ in range(h)]

ans = inf
for i in range(h): #縦方向の割り方を全探索 O(512)
    arr = list(combinations(range(h - 1), i))
    for ii in range(len(arr)):
        hdiv = [1 if j in arr[ii] else 0 for j in range(h - 1)]
        hdiv.append(1)
        tmpans = i
        partsum = [0 for _ in range(i + 1)]
        j = 0
        while j < w: #O(2 * 10 ** 3)
            tmp = 0
            idx = 0
            flag = True
            for kk in range(h): #O(10)
                tmp += s[kk][j]
                if hdiv[kk]:
                    partsum[idx] += tmp
                    if partsum[idx] > k:
                        tmpans += 1
                        partsum = [0 for _ in range(i + 1)]
                        flag = False
                        break
                    tmp = 0
                    idx += 1
            if flag:
                j += 1
        ans = min(ans, tmpans)
print(ans)


### FIXED CODE ###

import sys
inf = sys.maxsize

if __name__ == '__main__':
    h, w, k = map(int, sys.stdin.readline().strip().split())
    s = [[int(i) for i in sys.stdin.readline().strip()] for _ in range(h)]
    
    ans = inf
    for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(512)
        hdiv = [1 if i & 2 ** j else 0 for j in range(h - 1)]
        hdiv.append(1)
        sh = sum(hdiv)
        tmpans = sh - 1
        partsum = [0 for _ in range(sh)]
        partsum_p = [0 for _ in range(sh)]
        j = 0
        for j in range(w): #O(10 ** 3)
            tmp = 0
            idx = 0
            flag = False
            for kk in range(h): #O(10)
                tmp += s[kk][j]
                if hdiv[kk]:
                    partsum_p[idx] = partsum[idx]
                    partsum[idx] += tmp
                    if partsum[idx] > k and not flag:
                        tmpans += 1
                        flag = True
                    tmp = 0
                    idx += 1
            if flag:
                partsum = [partsum[l] - partsum_p[l] for l in range(sh)]
                partsum_p = [0 for _ in range(sh)]
                for kk in range(sh):
                    if partsum[kk] > k:
                        tmpans = inf
                        break
        ans = min(ans, tmpans)
    print(ans)
### BUGGY CODE ###

import bisect
n = int(input())
m = list(map(int,input().split()))
num=1
for i in range(n):
  if num in m:
    t = m.index(num)
    del m[:t]
    num+=1
if num == 1:
  print(-1)
else:
  print(n-num+1)

### FIXED CODE ###

n = int(input())
m = list(map(int,input().split()))
num=1
for i in range(n):
  if m[i] == num:
    num+=1
    
if num == 1:
  print(-1)
else:
  print(n-num+1)
### BUGGY CODE ###

import sys
import heapq
n, k = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
f_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort(reverse=True)
f_ls.sort()
res = [- a * f for a, f in zip(a_ls, f_ls)]
heapq.heapify(res)
cnt = 0
flg = False
while True:
    for i in range(n):
        if a_ls[i] == 0:
            continue
        if a_ls[i] * f_ls[i] == - res[0]:
            cnt += 1
            a_ls[i] -= 1
            heapq.heappop(res)
            heapq.heappush(res, - a_ls[i] * f_ls[i])
        if cnt == k:
            flg = True
            break
    if not any(a_ls):
        flg = True
    if flg:
        break
print(- res[0])

### FIXED CODE ###

import sys
import numpy as np
n, k = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
f_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort(reverse=True)
f_ls.sort()
a_sum = sum(a_ls)
a_ls = np.array(a_ls)
f_ls = np.array(f_ls)
minimum = 0
maximum = (a_ls * f_ls).sum()
def check(x):
    """
    :param x:
    :return: x以下で可能か
    """
    return a_sum - np.minimum(a_ls, x // f_ls).sum() <= k
while True:
    center = (maximum + minimum) // 2
    if check(center):
        if maximum == center:
            res = center
            break
        maximum = center
    else:
        if minimum == center:
            if check(maximum):
                res = maximum
                break
            else:
                res = minimum
        minimum = center
print(res)
### BUGGY CODE ###

N, T = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]

DP = [[[0] * 2 for _ in range(T)] for _ in range(N)]

a, b = AB[0]
if a < T:
  DP[0][a][0] = b
DP[0][0][1] = b

for i in range(1, N):
  a, b = AB[i]
  if a < T:
    DP[i][a][0] = b
  DP[i][0][1] = b
  for j in range(T):
    DP[i][j][0] = max(DP[i][j][0], DP[i - 1][j][0])
    DP[i][j][1] = max(DP[i][j][1], DP[i - 1][j][1])
    if j + a < T: 
      DP[i][j + a][0] = max(DP[i][j + a][0], DP[i - 1][j][0] + b)
      DP[i][j + a][1] = max(DP[i][j + a][1], DP[i - 1][j][1] + b)
    DP[i][j][1] = max(DP[i][j][1], DP[i - 1][j][1])
    DP[i][j][1] = max(DP[i][j][1], DP[i - 1][j][0] + b)

ans = 0
for i in range(T):
  ans = max(ans, DP[-1][i][0])
  ans = max(ans, DP[-1][i][1])

print(ans)

### FIXED CODE ###

N, T = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]


AB.sort(reverse = True)
DP = [[0] * T for _ in range(N)]
DP[0][0] = AB[0][1]
for i in range(1, N):
  a, b = AB[i]
  DP[i][0] = max(DP[i - 1][0], b)
  for j in range(T):
    DP[i][j] = max(DP[i][j], DP[i - 1][j])
    if j + a < T:
      DP[i][j + a] = DP[i - 1][j] + b

print(max(DP[-1]))
### BUGGY CODE ###

m,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
a=0
flag=False
for d,c in z:
    if flag:
        m=[b]
    else:
        m=[]
        flag=True
    while c//2:
        cd=c//2
        a+=cd
        if c%2:
            m+=d,
        d*=2
        if d>9:
            a+=cd
            d=sum(map(int,str(d)))
        c=cd
    for t in m[::-1]:
        d+=t
        a+=1
        if d>9:
            d=sum(map(int,str(d)))
            a+=1
    b=d
print(a)

### FIXED CODE ###

m,*t=map(int,open(0).read().split())
a=b=0
for d,c in zip(*[iter(t)]*2):
    m=[b]
    while c//2:
        cd=c//2
        a+=cd
        if c%2:
            m+=d,
        d*=2
        if d>9:
            a+=cd
            d=d//10+d%10
        c=cd
    for t in m[::-1]:
        d+=t
        a+=1
        if d>9:
            d=d//10+d%10
            a+=1
    b=d
print(a-1)
### BUGGY CODE ###


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

A=list(map(int,input().split()))
B=[]
for i in range(2):
    for j in range(N):
        B.append(A[j])
b=len(B)
count=0
for i in range(b):
    for j in range(b-i):
        if B[i]>B[i+j]:
            count+=1
#print(count)

a=len(A)
counter=0
for i in range(a):
    for j in range(a-i):
        if B[i]>B[i+j]:
            counter+=1
#print(count)
#print(counter)
#print(count-2*counter)

ans=(counter*K+((count-2*counter)*(K-1)*K)//2)%(1000000007)

print(ans)


### FIXED CODE ###


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

A=list(map(int,input().split()))
B=[]
for i in range(2):
    for j in range(N):
        B.append(A[j])
b=len(B)


a=len(A)
counter=0
for i in range(a):
    for j in range(a-i):
        if B[i]>B[i+j]:
            counter+=1


count=0
for i in range(b//2):
    for j in range(b//2):
        if B[i]>B[b//2+j]:
            count+=1
#print(count)
#print(count)
#print(counter)
#print(count-2*counter)

#print(counter)
#print(count)
#ans=(counter*K+((count-2*counter)*(K-1)*K)//2)%(1000000007)
answer=(counter*K+(count*(K-1)*K)//2)%(1000000007)
#print(ans)
print(answer)
### BUGGY CODE ###

n= int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

lal = sorted(al,reverse = True)
lbl = sorted(bl,reverse = True)
lcl = sorted(cl,reverse = True)



d =[0]*n

for i in range(n):
    x = lbl[i]
    for j in range(n):
        y = lal[j]
        if x > y:
            d[i] = (n-j)
            break
        
res =0
for i in range(n):
    x = lcl[i]
    for j in range(n):
        y = lbl[j]
        if x >y:            
            res += sum(d[j:])
            break

print(res)

### FIXED CODE ###

n= int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

lal = sorted(al)
lbl = sorted(bl)
lcl = sorted(cl)


from bisect import bisect_left, bisect_right
 

res = 0

for i in range(n):
    bx = lbl[i]
    ax = bisect_left(lal,bx)
    cx = n - bisect_right(lcl,bx)
    
    res += ax*cx

print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
l = ["".join(sorted([c for c in input()])) for i in range(N)]
l.sort()


def fac(n):
    """階乗"""
    res = 0
    for i in range(1, n+1):
        res += i
    return res

hash_t = {}
for i in range(N-1):
    if l[i] == l[i+1]:
        if l[i] in hash_t.keys():
            hash_t[l[i]] += 1
        else:
            hash_t[l[i]] = 1

cnt = 0
for x in hash_t.values():
    cnt += fac(x)
print(cnt)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
l = ["".join(sorted([c for c in input()])) for i in range(N)]
l.sort()


def fac(n):
    """階乗"""
    res = 0
    for i in range(1, n+1):
        res += i
    return res


hash_l = []
for i in range(N-1):
    if l[i] == l[i+1]:
        if i == 0:
            hash_l.append(0)
        if l[i-1] == l[i]:
            hash_l[-1] += 1
        else:
            hash_l.append(1)

cnt = 0
for x in hash_l:
    cnt += fac(x)
print(cnt)
### BUGGY CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(m):
  v = max(a)//2
  a[a.index(max(a))] = v
print(sum(a))

### FIXED CODE ###

import heapq
n,m = map(int,input().split())
a = list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)
for i in range(m):
  maxv = heapq.heappop(a)*(-1)
  heapq.heappush(a,(maxv//2)*(-1))
print(sum(a)*(-1))
### BUGGY CODE ###

n = int(input())
P = list(map(float, input().split()))

DP = [[0]*(n+1) for _ in range(n+1)]
DP[0][0] = 1

for i in range(n):
  for j in range(n+1):
    if j==0:
      DP[0][i+1] = DP[0][i] * (1-P[i])
    else:
      DP[j][i+1] = DP[j][i] * (1-P[i]) + DP[j-1][i] * P[i]

ans = 0
for k in range(n//2+1, n+1):
  ans += DP[k][n]

print(ans)

### FIXED CODE ###

n = int(input())
P = list(map(float, input().split()))

DP = [[0]*(n+1) for _ in range(n+1)]
DP[0][0] = 1

for i in range(n):
  for j in range(n+1):
    if j==0:
      DP[0][i+1] = DP[0][i] * (1-P[i])
    else:
      DP[j][i+1] = DP[j][i] * (1-P[i]) + DP[j-1][i] * P[i]

ans = 0
for k in range(n//2+1, n+1):
  ans += DP[k][n]

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

from collections import deque
import sys
input=sys.stdin.readline
s=input().rstrip()
d=deque([])
for i in range(len(s)):
    d.append(int(s[i]))
d.append(2)
ans=0
while 0 in d and 1 in d:
    if d[0]+d[1]==1:
        d.popleft()
        d.popleft()
        ans+=2
    else:
        d.rotate(-1)
 
print(ans)

### FIXED CODE ###

s=input()
print(2*min(s.count("0"), s.count("1")))
### BUGGY CODE ###

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

ans = 1
for i in range(N):
    ans *= A[i]

if ans > 1e18:
    ans = -1

print(ans)

### 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 > 1e18:
        ans = -1
        break
print(ans)