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

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
point_start_with = [0 for i in range(n)]
roop_count = [1 for i in range(n)]
for i in range(n):
    now = (i + 1)
    now_score = 0
    while p[now - 1] != (i + 1):
        now = p[now - 1]
        now_score += c[now - 1]
        roop_count[i] += 1
    point_start_with[i] = now_score
# 多分0でいい
ans = -(10**9 * 5000)
for i in range(n):
    # iからスタートする場合
    score = 0
    remain_move = 0
    cand_score = 0
    if point_start_with[i] + c[i] > 0 and k > roop_count[i]:
        # 一周以上する可能性がある場合
        # n週して、残りの動ける回数
        # print("Yes")
        round_count = (k // roop_count[i]) - 1
        remain_move = k - round_count * roop_count[i]
        cand_score = round_count * ( point_start_with[i] + c[i] )
    else:
        remain_move = k
        score = -(10**9 * 5000)
        cand_score = 0
    now = i
    for j in range(remain_move):
        now = p[now] - 1
        cand_score += c[now]
        score = max(score, cand_score)
    # print("start : {}  score : {}".format(i,score))
    ans = max(score, ans)
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
point_start_with = [0 for i in range(n)]
roop_count = [1 for i in range(n)]
for i in range(n):
    now = (i + 1)
    now_score = 0
    while p[now - 1] != (i + 1):
        now = p[now - 1]
        now_score += c[now - 1]
        roop_count[i] += 1
    point_start_with[i] = now_score
# 多分0でいい
ans = -(10**9 * 5000)
for i in range(n):
    # iからスタートする場合
    score = 0
    remain_move = 0
    cand_score = 0
    if point_start_with[i] + c[i] > 0 and k > roop_count[i]:
        # 一周以上する可能性がある場合
        # n週して、残りの動ける回数
        # print("Yes")
        round_count = (k // roop_count[i]) - 1
        remain_move = k - round_count * roop_count[i]
        cand_score = round_count * ( point_start_with[i] + c[i] )
    else:
        remain_move = min(k,roop_count[i])
        score = -(10**9 * 5000)
        cand_score = 0
    now = i
    for j in range(remain_move):
        now = p[now] - 1
        cand_score += c[now]
        score = max(score, cand_score)
    # print("start : {}  score : {}".format(i,score))
    ans = max(score, ans)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
#Query = []
#for _ in range(m):
#    b,c = map(int,input().split())
#    Query.append([c,b])
#Query.sort(reverse=True)
Query = [list(map(int,input().split())) for _ in range(m)]
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)
ans = 0
for b,c in Query:
    #b,c = Query[i][1],Query[i][0]
    #b,c = Query[i][0],Query[i][1]
    if A[0] >= c:
        break
    else:
        #A.sort()
        index = bisect.bisect_left(A,c)
        ans += sum(A[index:])
        if b <= index:
            #for i in range(b):
            #    A[i] = c
            A = A[b:index] + [c for i in range(b)]
        else:
            #for i in range(index):
            #    A[i] = c
            A = [ c for i in range(index)]
    #print(A)
print(ans + sum(A))

### FIXED CODE ###

import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
index = 0
for b,c in Query:
    if index >= n:
        break
    #print("----")
    cnt = 0
    Flag = True
    while Flag:
        #print(A,b,c,index)
        if A[index] < c:
            A[index] = c
            cnt += 1
            index += 1
            if (cnt >= b) or (index >= n):
                Flag = False
        else:
            Flag = False
    '''
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        if index > len(A):
            ans += c * len(A)
            break
        else:
            ans += c * index
            A = A[index:]
    print(A)
    '''
print(sum(A))
### BUGGY CODE ###

N,Y=map(int,input().split())
#N=a+b+c
#Y=10000*a+5000*b+1000*c
ans=[]
maxA=Y//10000
maxB=Y//5000
maxC=Y//1000
for a in range(maxA+1):
  for b in range(maxB+1):
    for c in range(maxC+1):
      if N==a+b+c:
        if Y==10000*a+5000*b+1000*c:
          ans.append(str(a)+" "+str(b)+" "+str(c))
if len(ans)!=0:
  print(ans[0])
else:
  print(str(-1)+" "+str(-1)+" "+str(-1))

### FIXED CODE ###

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

maxA=Y//10000
ans=[]

for a in range(maxA+1):
  for b in range(N+1-a):
      if Y==10000*a+5000*b+1000*(N-a-b):
        ans.append(str(a)+" "+str(b)+" "+str(N-a-b))
    
if len(ans)!=0:
  print(ans[0])
else:
  print(str(-1)+" "+str(-1)+" "+str(-1))
### BUGGY CODE ###

N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = float("INF")
b = a
for k in range(N):
    c = [float("INF")]*N
    ans_inst = 0
    for i in range(N):
        c[i] = min(b[i],a[i-k])
        ans_inst += c[i]
    ans = min(ans, ans_inst+k*x)
    b = c
print(ans)


### FIXED CODE ###

N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = float("INF")
b = [[float("INF")]*N for _ in range(N)]
b[0] = a
for k in range(N):
    for i in range(N):
        b[k][i] = min(b[k-1][i],a[i-k])
    ans = min(ans, sum(b[k])+k*x)

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

import sys
readline = sys.stdin.readline

S = readline().rstrip()
T = readline().rstrip()

# dp[i][j] = Sのi文字目まで、Tのj文字目までの最長

dp = [[0] * (len(T) + 1) for i in range(len(S) + 1)]

for i in range(len(S)):
  for j in range(len(T)):
    if S[i] == T[j]:
      dp[i + 1][j + 1] = dp[i][j] + 1
    else:
      dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

#for d in dp:
#  print(d)
# 復元
ans = ""
y = len(T)
x = len(S)
while x > 0 and y > 0:
#  print("x",x,"y",y,"ans",ans)
  if dp[x][y] == dp[x - 1][y - 1] + 1:
    ans += S[x - 1]
    x -= 1
    y -= 1
  else:
    x -= 1

print(ans[::-1])

### FIXED CODE ###

import sys
readline = sys.stdin.readline

S = readline().rstrip()
T = readline().rstrip()

# dp[i][j] = Sをi文字目、Tをj文字目まで進めたときの最長
# S[i] == S[j]のとき
# dp[i][j] = dp[i - 1][j - 1] + 1
# S[i] != S[j]のとき
# dp[i][j] = max(dp[i - 1][j],dp[i][j - 1])

# その際、自分がどこから来たか？を記録する
# dp[i - 1][j] > dp[i][j - 1]であれば
# route[i][j] = (i,j)を記録

dp = [[0] * (len(T) + 1) for i in range(len(S) + 1)]
route = [[(0,0)] * (len(T) + 1) for i in range(len(S) + 1)]

for i in range(len(S)):
  for j in range(len(T)):
    if S[i] == T[j]:
      dp[i + 1][j + 1] = dp[i][j] + 1
      route[i + 1][j + 1] = (i,j)
    else:
      if dp[i][j + 1] > dp[i + 1][j]:
        dp[i + 1][j + 1] = dp[i][j + 1]
        route[i + 1][j + 1] = (i,j + 1)
      else:
        dp[i + 1][j + 1] = dp[i + 1][j]
        route[i + 1][j + 1] = (i + 1,j)

# routeのとびさきの文字を追加していく
x,y = len(S),len(T)
ans = ""
while x != 0 and y != 0:
  if S[x - 1] == T[y - 1]:
    ans += S[x - 1]
  x,y = route[x][y]

print(ans[::-1])
### BUGGY CODE ###

s = input()
n = len(s)
d = {}
d[s] = 1
for i in range(n-1):
	for j in range(i+2, n+1):
		_s = ''
		if i > 0:
			_s += s[:i]
		tmp = s[i:j]
		_s += tmp[::-1]
		_s += s[j:]
		#print(i, j, tmp, _s)
		if _s in d:
			continue
		d[_s] = 1
print(len(d.items()))


### FIXED CODE ###

s = input()
n = len(s)
ans = n * (n - 1) / 2 + 1
c_list = [0 for _ in range(26)]
for c in s:
	c_list[ord(c) - ord('a')] += 1

delta = 0
for i in c_list:
	if i > 0:
		delta += i * (i - 1) / 2
print(int(ans - delta))
### BUGGY CODE ###

n = int(input())
lista = [int(x) for x in input().split()]

total = 0
for i in range(n-1):
    for j in range(i+1, n):
        total += lista[i] * lista[j]
    total %= (10 ** 9 + 7)
print(total)


### FIXED CODE ###

d = 10 ** 9 + 7
n = int(input())
lista = [int(x) for x in input().split()]
for k in lista:
    k %= d

totalJ = sum(lista)

total = 0
for i in range(n-1):
    totalJ -= lista[i]
    total += totalJ * lista[i]
total %= d
print(total)
### BUGGY CODE ###

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

from collections import defaultdict
dic = defaultdict(int)
for _ in range(q):
   p,x = map(int,input().split())
   dic[p-1] += x

ans = [0 for i in range(n)]
ans[0] = dic[0]

used = [0 for i in range(n)]
used[0] = 1
quu = [0]
while quu:
   k = quu.pop(0)
   for l in m[k]:
      if used[l] == 0:
         used[l] = 1
         quu.append(l)
         ans[l] = ans[k] + dic[l]

for i in ans:
   print(i)

### FIXED CODE ###

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

from collections import defaultdict
dic = defaultdict(int)
for _ in range(q):
   p,x = map(int,input().split())
   dic[p-1] += x

ans = [0 for i in range(n)]
ans[0] = dic[0]

used = [0 for i in range(n)]
used[0] = 1
quu = [0]
while quu:
   k = quu.pop()
   for l in m[k]:
      if used[l] == 0:
         used[l] = 1
         quu.append(l)
         ans[l] = ans[k] + dic[l]

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

# -*- coding:utf-8 -*-
"""
問題
https://atcoder.jp/contests/dp/tasks/dp_d

解説
https://qiita.com/drken/items/dc53c683d6de8aeacf5a#d-%E5%95%8F%E9%A1%8C---knapsack-1
"""

def solve():
    N, LIMIT = list(map(int, input().split()))
    W, V = [None], [None]
    for i in range(N):
        w, v = list(map(int, input().split()))
        W.append(w)
        V.append(v)
    
    # dp[i][w] := i個目までの品物を選んだ時の、重さがwのときの価値の最大値
    dp = [[w for w in range(LIMIT+1)] for i in range(N+1)]
    for w in range(LIMIT+1):
        dp[0][w] = 0
    
    #O(N*LIMIT) = O(10**7)
    for i in range(1, N+1):
        for w in range(LIMIT+1):
            if w-W[i] >= 0:
                dp[i][w] = max(dp[i-1][w], dp[i-1][w-W[i]] + V[i])
            else:
                dp[i][w] = dp[i-1][w]

    ans = 0
    for w in range(LIMIT+1):
        ans = max(ans, dp[N][w])

    print(ans)


if __name__ == "__main__":
    solve()


### FIXED CODE ###

# -*- coding:utf-8 -*-
"""
問題
https://atcoder.jp/contests/dp/tasks/dp_d

解説
https://qiita.com/drken/items/dc53c683d6de8aeacf5a#d-%E5%95%8F%E9%A1%8C---knapsack-1
"""

def solve():
    """
    Python: TLE (´･_･`)
    """
    N, LIMIT = list(map(int, input().split()))
    W, V = [None], [None]
    for i in range(N):
        w, v = list(map(int, input().split()))
        W.append(w)
        V.append(v)
    
    # dp[i][w] := i個目までの品物を選んだ時の、重さがwのときの価値の最大値
    dp = [[w for w in range(LIMIT+1)] for i in range(N+1)]
    for w in range(LIMIT+1):
        dp[0][w] = 0
    
    #O(N*LIMIT) = O(10**7)
    for i in range(1, N+1):
        for w in range(LIMIT+1):
            if w-W[i] >= 0:
                dp[i][w] = max(dp[i-1][w], dp[i-1][w-W[i]] + V[i])
            else:
                dp[i][w] = dp[i-1][w]

    ans = 0
    for w in range(LIMIT+1):
        ans = max(ans, dp[N][w])

    print(ans)


if __name__ == "__main__":
    solve()
### BUGGY CODE ###

N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
for m in range(M):
    A[A.index(max(A))] = A[A.index(max(A))] // 2
print(sum(A))

### FIXED CODE ###

N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
import heapq
heapA = []
for a in A:
    heapq.heappush(heapA,-a)
for m in range(M):
    tmp = -heapq.heappop(heapA)
    tmp = tmp//2
    tmp = -1 * tmp
    heapq.heappush(heapA,tmp)
print(-sum(heapA))
### BUGGY CODE ###

import itertools
n,y = map(int,input().split())
z = y//1000

list = list(range(n+1))
for a,b,c in itertools.product(list,list,list):
    v = 10*a + 5*b + c
    w = a + b + c
    if v == z and w == n:
        break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))


### FIXED CODE ###

import itertools
n,y = map(int,input().split())
z = y//1000

list = list(range(n+1))
for a,b in itertools.product(list,list):
    c = n - a - b
    if c>=0:
        v = 10*a + 5*b + c
        w = a + b + c
        if v == z and w == n:
            break
else:
    a = -1
    b = -1
    c = -1

print(str(a),str(b),str(c))
### BUGGY CODE ###

MOD = 10 ** 9 + 7
K = int(input())
M = len(input())
N = M + K

pow25 = [1] * (N + 1)
fac = [1] * (N + 1)
inv = [1] * (N + 1)
for x in range(1, N + 1):
    fac[x] = fac[x - 1] * x % MOD
    pow25[x] = pow25[x - 1] * 25 % MOD
inv[N] = pow(fac[N], MOD-2, MOD)
for x in range(N - 1, -1, -1):
    inv[x] = inv[x + 1] * (x + 1) % MOD

def binom(n, k):
    return fac[n] * inv[n - k] % MOD * inv[k] % MOD

ans = 0
for k in range(M, N + 1):
    ans += binom(N, k) * pow25[N - k] % MOD
    ans %= MOD
print(ans)

### FIXED CODE ###

MOD = 10 ** 9 + 7
K = int(input())
M = len(input())
N = M + K

pow25 = [1] * (N + 1)
fac = [1] * (N + 1)
inv = [1] * (N + 1)
for x in range(1, N + 1):
    fac[x] = fac[x - 1] * x % MOD
    pow25[x] = pow25[x - 1] * 25 % MOD
inv[N] = pow(fac[N], MOD-2, MOD)
for x in range(N - 1, -1, -1):
    inv[x] = inv[x + 1] * (x + 1) % MOD

def binom(n, k):
    return fac[n] * inv[n - k] % MOD * inv[k] % MOD

ans = 0
for k in range(M, N + 1):
    ans += binom(N, k) * pow25[N - k] % MOD
    ans %= MOD
print(ans)
### BUGGY CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


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

# 足場iに到るコスト
dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
    for j in range(1, k + 1):
        if i < j:
            continue
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

print(dp[-1])


### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


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

INF = 10 ** 9
dp = [INF] * n
dp[0] = 0
for i in range(n - 1):
    for j in range(1, k + 1):
        if j >= n - i:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(H[i + j] - H[i]))
print(dp[-1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
seq = [int(x) for x in input().split()]
visited = [False for _ in xrange(n)]
ans = 0
p = set()
for i, val in enumerate(seq):
    if val > n:
        continue

    for j in xrange(min(n,i+val-2), n):
        if abs(j-i) == val + seq[j]:
            if not visited[i]:
                visited[i] = True
            if not visited[j]:
                visited[j] = True
            if (i,j) not in p:
                ans += 1
                p.add((i,j))
    for j in xrange(0, max(i-val, 0)):
        if abs(i - j) == val + seq[j]:
            if not visited[i]:
                visited[i] = True
            if not visited[j]:
                visited[j] = True
            if (j,i) not in p:
                ans += 1
                p.add((j,i))
print(ans)



### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
seq = [(int(x),i) for i, x in enumerate(input().split())]
seq1 =(i-x for x,i in seq)
seq2 =(i+x for x,i in seq)

d1 = dict()
d2 = dict()
s1 = set()
s2 = set()
for val in seq1:
    try:
        d1[val] += 1
    except:
        d1[val] = 1
for val in seq2:
    try:
        d2[val] += 1
    except:
        d2[val] = 1

ans = 0
for key in d1:
    try:
        ans += d1[key] * d2[key]
    except:
        pass

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

import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

a, b = map(int, input().split())
count = 1
for i in range(1,min(a,b)+1):
    if a % i == 0 and b % i == 0:
        if is_prime(i) == True:
            count += 1

print(count)


### FIXED CODE ###

# 再帰関数の最大回数を増やす
import sys
sys.setrecursionlimit(1000000)

import math

def gcd(i, j):
    """
    2値 i, j の最大公約数を求める。
    """

    if j == 0:
        return i
    else:
        return gcd(j, i % j)

def factorize(n):
    """
    素因数分解した個数を返す
    """
    count = 1
    rep = math.ceil(math.sqrt(n))
    for i in range(2, rep + 1):
        if n % i != 0:
            continue
        else:
            count += 1
            while n % i == 0:
                n /= i
        if n == 1:
            return count
    if n != 1:
        count += 1
    return count

def main():
    a, b = map(int, input().split())

    #最大公約数を求める
    x = gcd(a, b)

    #最大公約数を素因数分解する
    count = factorize(x)

    #結果を出力する
    print(count)

main()
### BUGGY CODE ###

# coding: utf-8

import sys
import math
import collections
import itertools
from functools import lru_cache
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")

H, W = LI()
S = RS(H)

@lru_cache(10**5)
def dfs(x, y):
    stack = [[x, y-1, 1], [x+1, y, 2], [x, y+1, 3], [x-1, y, 4]]
    ret = 1

    while stack:
        x, y, dist = stack.pop()

        if not(0 <= x < W) or not(0 <= y < H) or S[y][x] == "#":
            continue

        ret += 1

        if dist == 1:
            stack.append([x, y-1, 1])
        elif dist == 2:
            stack.append([x+1, y, 2])
        elif dist == 3:
            stack.append([x, y+1, 3])
        else:
            stack.append([x-1, y, 4])
    
    return ret


ans = 0
for x in range(W):
    for y in range(H):
        if S[y][x] == ".":
            ans = max(ans, dfs(x, y))

print(ans)


### FIXED CODE ###

# coding: utf-8

import sys
import math
import collections
import itertools
from functools import lru_cache
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")

H, W = LI()
S = RS(H)

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]

for i in range(H):
    lf = 0
    rf = 0
    for j in range(W):
        if S[i][j] == ".":
            lf += 1
            L[i][j] = lf
        else:
            lf = 0

        if S[i][W-1-j] == ".":
            rf += 1
            R[i][W-1-j] = rf
        else:
            rf = 0

for i in range(W):
    uf = 0
    df = 0
    for j in range(H):
        if S[j][i] == ".":
            df += 1
            D[j][i] = df
        else:
            df = 0

        if S[H-1-j][i] == ".":
            uf += 1
            U[H-1-j][i] = uf
        else:
            uf = 0

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, U[i][j]+D[i][j]+L[i][j]+R[i][j]-3)

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

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

N = int(input())
input_list = list(map(int, input().split()))
ans = 0
for i in range(N):
    for j in range(i):
        if input_list[i] > input_list[j]:
            break
    else:
        ans += 1
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
 
N = int(input())
P = list(map(int, input().split()))

ans = 0
min_val = P[0]
for i in range(N):
    if P[i] <= min(min_val, P[i]):
        ans += 1
        min_val = min(min_val, P[i])
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ba = [format(i,'b').zfill(60) for i in a]
mod = 10**9+7

#2^iをmodで割った余りを出しておく
twos = [1]
for i in range(1,60):
    twos.append((twos[i-1]*2)%mod)

#各baのbitごとに0の個数と1の個数を求める
c0 = [0]*60
c1 = [0]*60
for i in range(n):
    for j in range(60):
        if ba[i][j] == "0":
            c0[59-j] += 1
        else:
            c1[59-j] += 1

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[i]*c1[i])%mod)*twos[i])%mod

ans %= mod
print(ans)


### FIXED CODE ###

import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
mod = 10**9+7

twos = 1
ans = 0
for i in range(0,60):
    cou1 = np.count_nonzero((a >> i) & 1)
    ans += (cou1*(n-cou1)*twos)%mod
    twos = (twos*2)%mod

ans %= mod
print(ans)
### BUGGY CODE ###

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

ans = 0
for i in range(N-1):
  for j in range(i+1, N):
    tmp = A[i] * A[j]
    tmp %= (10**9)+7
    ans += tmp
    ans %= (10**9)+7
print(ans)

### FIXED CODE ###

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

left = A[0]
left %= (10**9)+7
right = sum(A) - A[0]
right %= (10**9)+7
ans = 0
for i in range(1, N):
  tmp = left * right
  tmp %= (10**9)+7
  ans += tmp
  ans %= (10**9)+7
  left = A[i]
  right -= A[i]
print(ans)
### BUGGY CODE ###

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

from itertools import accumulate


def solve():
    N, M = map(int, input().split())
    S = map(int, input().split())
    *T, = map(int, input().split())
    dp = [0]*(M+1)
    for s in S:
        *acc, = accumulate(map(lambda d,t: (d+1 if s.__eq__(t) else 0), dp, T))
        *dp, = map(int.__add__, dp, [0]+acc)
    res = (dp[-1]+1)%(10**9+7)
    return str(res)

if __name__ == '__main__':
    print(solve())


### FIXED CODE ###

# -*- coding: utf-8 -*-
def solve():
    N, M = map(int, input().split())
    S = map(int, input().split())
    *T, = map(int, input().split())
    dp = [1]*(M+1)
    for s in S:
        is_s = s.__eq__
        dp_ = dp[:]
        acc = 0
        for i, t in enumerate(T):
            if is_s(t):
                acc += dp_[i]
            dp[i+1] = dp_[i+1] + acc
    res = (dp[-1])%(10**9+7)
    return str(res)

if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

import numpy as np
N, K, Q=map(int, input().split())
A=[int(input()) for i in range(Q)]

point=[0]+[K for i in range(N)]
point=np.array(point)

for i in range(Q):
  point=point-1
  point[A[i]]+=1
  
for i in range(1, N+1):
  if point[i]>0:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

N, K, Q=map(int, input().split())
A=[int(input()) for i in range(Q)]
point=[K]*(N+1)

for i in range(Q):
  point[A[i]]+=1
  
for i in range(1, N+1):
  if point[i]>Q:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

K = int(input())
if K % 2 == 0:
    print(-1)
    exit()
i = 1
ans = 1
while True:
    if int("7" * i) % K == 0:
        print(ans)
        break
    i += 1
    ans += 1

### FIXED CODE ###

K = int(input())
n = 7 % K
for k in range(1, K + 1):
    if n == 0:
        print(k)
        exit()
    n = (n*10+7)%K
print(-1)
### BUGGY CODE ###

from functools import reduce

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

before = reduce(lambda x, acc: x * acc, ai[ 0 : k ], 1)

for i in range(n - k):
    after = before * ai[i + k] // ai[i]

    if before < after:
        print('Yes')

    else:
        print('No')

    before = after


### FIXED CODE ###

from math import log2

n, k = map(int, input().split())
ai   = list(map(lambda x: log2(int(x)), input().split()))

before = sum(ai[ 0 : k ])

for i in range(n - k):
    after = before + ai[i + k] - ai[i]

    if before < after:
        print('Yes')

    else:
        print('No')

    before = after
### BUGGY CODE ###

N = int(input())
S = list(input() for _ in range(N))

a = list(set(S))

b = []
n = 0
for i in range(len(a)):
  if n == S.count(a[i]):
    b.append(a[i])
  elif n < S.count(a[i]):
    b = [a[i]]
    n = S.count(a[i])

b.sort()
for j in b:
  print(j)

### FIXED CODE ###

N = int(input())
S = list(input() for _ in range(N))

import collections
a = collections.Counter(S).most_common()
ans = []
for i in range(len(a)):
  if i == 0:
    ans.append(a[i][0])
  elif a[i - 1][1] == a[i][1]:
    ans.append(a[i][0])
  else:
    break
ans.sort()

for j in ans:
  print(j)