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

import re

s = input()
pattern = "(01)|(10)"
count = 0
while re.search(pattern,s):
    count += 2
    s = re.sub(pattern, "", s,1)

print(count)

### FIXED CODE ###

import re

s = input()
zero = re.findall("0", s)
one = re.findall("1", s)
print(2 * min(len(zero), len(one)))
### BUGGY CODE ###


n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]
enuq = list(enumerate(qs))
rails.sort(key=lambda x:x[1])
 
enuq.sort(key = lambda x:x[1][0])
ansli = [0 for i in range(q)]


for (i,(p,q)) in enuq:
    removelist=[]
    for (j,(l,r)) in enumerate(rails):
        if p<=l and r<=q:
            ansli[i]=ansli[i]+1
        elif l<p:
            removelist.append(j)
        if r>q:
            break
    for jj in sorted(removelist,reverse=True):
        rails.pop(jj)



for a in ansli:
    print(a)


### FIXED CODE ###

from collections import Counter
from itertools import product

n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]

xlist = [[0 for j in range(n)] for i in range(n)]
sumlist = [[0 for j in range(n+1)] for i in range(n)]
for (l,r),i in Counter(rails).items():
    xlist[l-1][r-1]=i


for (i,j) in product(range(n),range(n)):
    sumlist[i][j+1]=sum(xlist[i][0:j+1])


for (p,q) in qs:
    ans = 0
    for i in range(p-1,q):
        ans = ans+sumlist[i][q]-sumlist[i][p-1]
    print(ans)
### BUGGY CODE ###

n = int(input())
a = {}
count = 0
for _ in range(n):
    res = 5381
    s = input()
    for i in s:
        res = ((res << 5) + res)
    if res not in a:
        a[res] = []
        a[res].append(s)
        count += 1
    else:
        if s not in a[res]:
            a[res].append(s)
            count += 1
print(count)

### FIXED CODE ###

n = int(input())
str_list = []
count = 1
for _ in range(n):
    s = input()
    str_list.append(s)
str_list.sort()
for i in range(n-1):
    if str_list[i] != str_list[i+1]:
        count += 1
print(count)
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect


def solve():
    n, m, q = map(int, input().split())
    nl = [[] for j in range(n + 1)]
    for i in range(m):
        l, r = map(int, input().split())
        bisect.insort_left(nl[l], r)
    table = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            table[i][j] = len([1 for k in nl[i] if k <= j])

    for i in range(q):
        l, r = map(int, input().split())
        ans = 0
        for j in range(l, r + 1):
            ans += table[j][r] - table[j][l - 1]
        print(ans)


if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect
import array


def solve():
    n, m, q = map(int, input().split())
    nl = [[0 for i in range(n + 1)] for j in range(n + 1)]
    for e in [input().split() for _ in range(m)]:
        l, r = int(e[0]), int(e[1])
        nl[l][r] += 1
    table = [array.array("i", [0] * (n + 2)) for j in range(n + 2)]
    ran = array.array("i", range(n + 1))
    for i in ran:
        for j in ran:
            table[i][j + 1] = table[i][j] + nl[i][j]

    for i, e in enumerate([input().split() for _ in range(q)]):
        l, r = int(e[0]), int(e[1])
        ans = 0
        for j in range(l, r + 1):
            ans += table[j][r + 1] - table[j][l]
        print(ans)


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

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]

d = [1] + [1]*n
for i in range(1, n):
  if i in a:
    d[i] = 0
    d[i+1] = d[i-1]
  else:
    d[i+1] = d[i] + d[i-1]
    
print(d[n]%1000000007)

### FIXED CODE ###

n, m = map(int, input().split())
a = set()
for _ in range(m):
  a_ = int(input())
  a.add(a_)

dp = [0] * (n+1)
if 1 not in a:
  dp[1] = 1
if 2 not in a and n != 1:
  dp[2] = dp[1] + 1
for i in range(3, n+1):
  if i not in a:
    dp[i] = dp[i-1] + dp[i-2]

print(dp[n]%(10**9+7))
### BUGGY CODE ###

a,b,x = map(int,input().split())
l=[a]
for i in range(a, b):
    while a<b:
        a+=1
        l.append(a)
        
print([i % x for i in l].count(0))



### FIXED CODE ###

a,b,x = map(int,input().split())
print(b//x-(a-1)//x)
### BUGGY CODE ###

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
ans = 0
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
BC = sorted(BC, key=lambda x: x[1], reverse=True)
list = []
for bc in BC:
    for _ in range(bc[0]):
        list.append(bc[1])
        if len(list) == N:
            break
    else:
        continue
    break
#print(list)
ans = sum(A)
for i in range(min(N, len(list))):
    ans = max(ans, sum(A[:-(i + 1)]) + sum(list[:(i + 1)]))
print(ans)



### FIXED CODE ###

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
ans = 0
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
BC = sorted(BC, key=lambda x: x[1], reverse=True)
list = []
for bc in BC:
    for _ in range(bc[0]):
        list.append(bc[1])
        if len(list) == N:
            break
    else:
        continue
    break
#print(list)
#for i in range(1, N):
#    A[i] += A[i-1]
#for i in range(1, len(list)):
#    list[i] += list[i-1]
for i in range(min(N, len(list))):
    if A[i] >= list[i]:
        break
    A[i] = list[i]
print(sum(A))
### BUGGY CODE ###

from collections import deque
n=int(input())
*p,=map(int, input().split())

for i in range(n*n):p[i]-=1
seats=[
    [min(i,j,n-i-1,n-j-1) for i in range(n)] 
    for j in range(n)
    ]

exist=[[1]*n for _ in range(n)]
dxy=[(0,1),(1,0),(-1,0),(0,-1)]

ans=0
q=deque()
for pi in p:
    ans+=seats[pi//n][pi%n]
    exist[pi//n][pi%n]=0
    q.append((pi//n,pi%n))
    while q:
        i,j=q.popleft()
        for dx,dy in dxy:
            idx=i+dx;jdy=j+dy
            if 0<=idx<n and 0<=jdy<n:
                if seats[i][j]+exist[i][j]<seats[idx][jdy]:
                    seats[idx][jdy]=seats[i][j]+exist[i][j]
                    q.append((idx,jdy))


print(ans)

### FIXED CODE ###

from collections import deque
n=int(input())
*p,=map(int, input().split())

for i in range(n*n):p[i]-=1
seats=[min(i//n,i%n,n-(i//n)-1,n-(i%n)-1) for i in range(n*n)] 

exist=[1]*(n*n)
dxy=(n,-n,1,-1)

ans=0
q=deque()
for pi in p:
    ans+=seats[pi]
    exist[pi]=0
    q.append(pi)
    while q:
        i=q.popleft()
        for dx in dxy:
            idx=i+dx
            if 0<=idx<n*n :
                if seats[i]+exist[i]<seats[idx]:
                    seats[idx]=seats[i]+exist[i]
                    q.append(idx)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


n,q = map(int,input().split())
c = list(map(int,input().split()))
Q = []
for i in range(q):
    l,r = map(int,input().split())
    Q.append([l,r,i])

Q.sort(key=lambda x: x[1])

bit = BIT(n)
ind = [-1]*(n+1)

ans = [0]*q
now = 0
for l,r,num in Q:
    while now < r:
        x = c[now]
        if ind[x] == -1:
            ind[x] = now
            bit.add(now,1)
        else:
            bit.add(ind[x],-1)
            ind[x] = now
            bit.add(now,1)
        now += 1
    ans[num] = bit.sum(r)-bit.sum(l-1)
for i in ans:
    print(i)



### FIXED CODE ###

import sys
input = sys.stdin.readline

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


n,q = map(int,input().split())
c = list(map(int,input().split()))
Q = []
for i in range(q):
    l,r = map(int,input().split())
    Q.append([l,r,i])

Q.sort(key=lambda x: x[1])

bit = BIT(n)
ind = [-1]*(n+1)

ans = [0]*q
now = 0
for l,r,num in Q:
    while now < r:
        x = c[now]
        if ind[x] == -1:
            ind[x] = now
            bit.add(now,1)
        else:
            bit.add(ind[x],-1)
            ind[x] = now
            bit.add(now,1)
        now += 1
    ans[num] = bit.sum(r)-bit.sum(l-1)
for i in ans:
    print(i)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(k):
  b = [0]*n
  for i in range(n):
    l = max(0, i-a[i])
    r = min(n, i+a[i]+1)
    b[l] += 1
    if r < n:
      b[r] -= 1
  for i in range(1, n): 
    b[i]+=b[i-1]
  a = b
  if a.count(n) == n:
    break
print(" ".join(list(map(str, a))))
      
  


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(min(k, 41)):
  b = [0]*n
  for i in range(n):
    l = max(0, i-a[i])
    r = min(n, i+a[i]+1)
    b[l] += 1
    if r < n:
      b[r] -= 1
  for i in range(1, n): 
    b[i]+=b[i-1]
  a = b

print(" ".join(list(map(str, a))))
### BUGGY CODE ###

def main():
    x = input()
    tmp = x.replace("ST", "")
    for i in range(10**6):
        if x == tmp:
            break
        x = tmp
        tmp = tmp.replace("ST", "")
    print(len(x))

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    x = input()
    s, t = 0, 0
    for i in x:
        if i == "S":
            s += 1
        else:
            if s:
                s -= 1
            else:
                t += 1
    print(s + t)

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

N = int(input())
S = list(input())
m = N
for i in range(N):
    S1 = S[0:i]
    S2 = S[i+1:]
    n1 = list.count(S1, 'W')
    n2 = list.count(S2, 'E')
    m = min(m, n1+n2)

print(m)

### FIXED CODE ###

N = int(input())
S = list(input())
S1 = []
S2 = S[1:]
n1 = 0
n2 = list.count(S2, 'E')
m = n1 + n2
for i in range(N-1):
    elem1 = S[i]
    elem2 = S[i+1]
    if elem1 == 'W':
        n1 = n1+1
    if elem2 == 'E':
        n2 = n2-1
    m = min(m, n1 + n2)

print(m)
### BUGGY CODE ###

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

ans = 1
for i in range(1, N):
    if min(P[0:i]) >= P[i]:
        ans += 1
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 1
    m = P[0]
    for i in range(1, N):
        if P[i - 1] < m:
            m = P[i - 1]
        if m >= P[i]:
            ans += 1
    print(ans)

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

import itertools
n=int(input())
c=0
for i,j,k in itertools.product(range(1,n+1),range(1,n+1),range(1,n+1)):
    s=i*j+k
    if s==n:
        c+=1
print(c)                

### FIXED CODE ###

n=int(input())
c=0
for i in range(1,n):
    c+=(n-1)//i
print(c)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=set(a)
mx=0
for i in b:
  mx=max(mx,a.count(i-1)+a.count(i+1)+a.count(i))
print(mx)

### FIXED CODE ###

from collections import *
n=int(input())
a=list(map(int,input().split()))
b=set(a)
d=defaultdict(int)
mx=0
for i in a:
  d[i]+=1
for i in b:
  mx=max(mx,d[i-1]+d[i]+d[i+1])
print(mx)
### BUGGY CODE ###

li=list(map(int,input().split()))

ans=[]
for i in range(li[0],li[1]+1):
  for j in range(li[2],li[3]+1):
    a=i*j
    ans.append(a)
    
print(max(ans))

### FIXED CODE ###

li=list(map(int,input().split()))
ans=[]
a=li[0]*li[2]
b=li[0]*li[3]
c=li[1]*li[2]
d=li[1]*li[3]
ans.append(a)
ans.append(b)
ans.append(c)
ans.append(d)

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

N, M, Q = map(int, input().split())

range_array = [[0 for _ in range(N)] for _ in range(N)]
ans = [[0 for _ in range(N)] for _ in range(N)]

for _ in range(M):
    l, r = map(int, input().split())
    range_array[l - 1][r - 1] += 1

for i in range(N):
    sum = 0
    for j in range(N):
        sum += range_array[i][j]
        range_array[i][j] = sum

for i in range(N):
    for j in range(i, N):
        sum = 0
        for k in range(i, j + 1):
            sum += range_array[k][j]
        ans[i][j] = sum

for _ in range(Q):
    p, q = map(int, input().split())
    print(ans[p - 1][q - 1])


### FIXED CODE ###

N, M, Q = map(int, input().split())

range_array = [[0 for _ in range(N)] for _ in range(N)]
ans = [[0 for _ in range(N)] for _ in range(N)]

for _ in range(M):
    l, r = map(int, input().split())
    range_array[l - 1][r - 1] += 1

for i in range(N):
    sum = 0
    for j in range(N):
        sum += range_array[i][j]
        range_array[i][j] = sum
'''
for i in range(N):
    for j in range(i, N):
        sum = 0
        for k in range(i, j + 1):
            sum += range_array[k][j]
        ans[i][j] = sum
'''
for _ in range(Q):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    sum = 0
    for k in range(p, q + 1):
        sum += range_array[k][q]
    print(sum)
### BUGGY CODE ###

import sys
import heapq
import bisect
 
mod = 10**9+7
 
def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(list(sys.stdin.readline())[:-1])
 
def main():
    H,W = LI()
    A = [LI() for _ in range(H)]
    B = [LI() for _ in range(H)]
    D = [[abs(A[h][w]-B[h][w]) for w in range(W)] for h in range(H)]
    dp = [[[False for _ in range(6401)] for w in range(W)] for h in range(H)]

    dp[0][0][D[0][0]] = True

    for h in range(1,H):
        for i in range(6401):
            if dp[h-1][0][i]:
                dp[h][0][abs(i-D[h][0])] = True
                if i+D[h][0]<6401:
                    dp[h][0][i+D[h][0]] = True
    for w in range(1,W):
        for i in range(6401):
            if dp[0][w-1][i]:
                dp[0][w][abs(i-D[0][w])] = True
                if i+D[0][w]<6401:
                    dp[0][w][i+D[0][w]] = True

    for h in range(1,H):
        for w in range(1,W):
            for i in range(6401):
                if dp[h-1][w][i]:
                    dp[h][w][abs(i-D[h][w])] = True
                    if i+D[h][w]<6401:
                        dp[h][w][i+D[h][w]] = True
                if dp[h][w-1][i]:
                    dp[h][w][abs(i-D[h][w])] = True
                    if i+D[h][w]<6401:
                        dp[h][w][i+D[h][w]] = True

    ans = 6400
    for i in range(6401):
        if dp[H-1][W-1][i]:
            ans = min(ans,i)
    return(ans)
 
if __name__ == "__main__":
    print(main())


### FIXED CODE ###

import sys
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def main():
    H,W = LI()
    A = [LI() for _ in range(H)]
    B = [LI() for _ in range(H)]
    D = [[abs(A[h][w]-B[h][w]) for w in range(W)] for h in range(H)]
    dp=[[0]*W for _ in range(H)]
    dp[0][0]=1<<D[0][0]<<20000

    for h in range(H):
        for w in range(W):
            if(h>0):
                dp[h][w] |= dp[h-1][w]<<D[h][w]
                dp[h][w] |= dp[h-1][w]>>D[h][w]
            if(w>0):
                dp[h][w] |= dp[h][w-1]<<D[h][w]
                dp[h][w] |= dp[h][w-1]>>D[h][w]
    for i in range(81):
        bit = 1<<(20000+i)
        bit |= 1<<(20000-i)
        if dp[H-1][W-1]&bit:
            return(i)
 
if __name__ == "__main__":
    print(main())
### BUGGY CODE ###

N = int(input())
List = list(map(int,input().split()))
counter = 0
for i in range(N-1):
  for j in range(i+1,N):
    if List[i]+List[j] == j - i:
      counter += 1
print(counter)

### FIXED CODE ###

from collections import defaultdict
N = int(input())
List = list(map(int,input().split()))
dicL = defaultdict(int)
dicR = defaultdict(int)
for i in range(N):
  dicL[List[i]+i] += 1
  dicR[i - List[i]] += 1
counter = 0
for item in dicL:
  if item in dicR:
    counter += dicL[item]*dicR[item]
print(counter)
### BUGGY CODE ###

# 4 5 (4 cities and 5 steps)
# 3 2 4 1

# 1 => 3
# 2 => 2
# 3 => 4
# 4 => 1

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

paths = {}

for i in range(N):
    paths[i+1] = A_i[i]

# print('paths:', paths)

# 6 5 2 5 3 2

state = 1
steps = 0
flag = False
known_states = {}

while steps < K:
    known_states[state] = steps

    state = paths[state]
    steps += 1

    # print(f'steps: {steps}, state: {state}')

    # if state in known_states and not flag:
    #     loop_steps = (steps - known_states[state])
    #     steps = K -  (K % loop_steps) - 1
    #     flag = True
        # print('loop detected')


print(state)


### FIXED CODE ###

# 4 5 (4 cities and 5 steps)
# 3 2 4 1

# 1 => 3
# 2 => 2
# 3 => 4
# 4 => 1

# 1 (0)
# 1 => 3 (1)
# 3 => 4 (2)
# 4 => 1 (3)

# 2 を作る 5 と2 と 1 を使う
# 2  = (5 - 3) % 2 + 3 - 1

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

paths = {}

for i in range(N):
    paths[i+1] = A_i[i]

# print('paths:', paths)

# 6 5 2 5 3 2

# 1 => 6 (1)
# 6 => 2 (2)
# 2 => 5 (3)
# 5 => 3 (4)
# 3 => 2 (5)

# loop_steps = 5 - 2 - 1 = 2
# 5 + 2 * m + r = 727202214173249351
# steps + loop_steps * m + r = K
# r = (K - steps) % loop_steps

state = 1
steps = 0
flag = False
known_states = {}

while steps < K:
    known_states[state] = steps # state => 2, steps => 2

    state = paths[state] # state => 5
    steps += 1 # steps => 3

    # print(f'steps: {steps}, state: {state}')

    if state in known_states and not flag: # state => 2 steps => 5
        loop_steps = steps - known_states[state]
        K = (steps - loop_steps) + (K - (steps - loop_steps))  % loop_steps
        # print('loop_steps:', loop_steps)
        # print('steps - loop_steps:', steps - loop_steps)
        # print('K:', K)
        state = 1
        steps = 0
        # print('steps:', steps)
        flag = True
        # print('loop detected')



print(state)
### BUGGY CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for i in range(Q)]

    for i in range(Q):
        B, C = tuple(BC[i])
        for j in range(N):
            if A[j] == B:
                A[j] = C
        print(sum(A))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [list(map(int, input().split())) for i in range(Q)]

    g = {}
    ans = 0
    for a in A:
        ans += a
        if a not in g:
            g[a] = 1
        else:
            g[a] += 1

    for i in range(Q):
        B, C = tuple(BC[i])
        if B in g:
            t = g.pop(B)
            ans += t * (C - B)
            if C in g:
                g[C] += t
            else:
                g[C] = t
        print(ans)


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

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

mod = 10 ** 9 + 7
sum = 0

for i in range(n):
    for j in range(i + 1, n):
        sum += a[i] * a[j]

print(sum % mod)

### FIXED CODE ###

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

mod = 10 ** 9 + 7
s = sum(a)
sum = 0

for i in range(n):
    s -= a[i]
    sum += s * a[i] % mod

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

def mod_max(loop, mod):
    if mod == 0:
        return 0
    loop_len = len(loop)
    mm = min(loop)
    for start in range(loop_len):
        current_sum = 0
        for i in range(mod):
            current_sum += loop[(start + i) % loop_len]
            mm = max(current_sum, mm)
    return mm


def main():
    n, k = map(int, input().split())
    p = [int(i) - 1 for i in input().split()]
    c = [int(i) for i in input().split()]

    seen = set()
    loop_list = []
    for start in range(n):
        v = start
        loop = []
        while v not in seen:
            seen.add(v)
            loop.append(c[v])
            v = p[v]
        seen.add(v)
        if loop:
            loop_list.append(loop)

    ans = min(c)
    for loop in loop_list:
        loop_len = len(loop)
        loop_num = k // loop_len
        loop_mod = k % loop_len
        loop_sum = sum(loop)
        ans = max(mod_max(loop, min(loop_len, k)), ans)
        if loop_num > 0:
            ans = max(loop_sum * loop_num + mod_max(loop, loop_mod), ans)
            ans = max(loop_sum * (loop_num - 1) + mod_max(loop, loop_len), ans)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def mod_max(loop, mod):
    if mod == 0:
        return 0
    loop_len = len(loop)
    mm = min(loop)
    for start in range(loop_len):
        current_sum = 0
        for i in range(mod):
            current_sum += loop[(start + i) % loop_len]
            mm = max(current_sum, mm)
    return mm


def main():
    n, k = map(int, input().split())
    p = [int(i) - 1 for i in input().split()]
    c = [int(i) for i in input().split()]

    seen = set()
    loop_list = []
    for start in range(n):
        v = start
        loop = []
        while v not in seen:
            seen.add(v)
            loop.append(c[v])
            v = p[v]
        seen.add(v)
        if loop:
            loop_list.append(loop)

    ans = min(c)
    for loop in loop_list:
        loop_len = len(loop)
        loop_num = k // loop_len
        loop_mod = k % loop_len
        loop_sum = sum(loop)
        ans = max(mod_max(loop, min(loop_len, k)), ans)
        if loop_num > 0:
            ans = max(loop_sum * loop_num + mod_max(loop, loop_mod), ans)
            ans = max(loop_sum * (loop_num - 1) + mod_max(loop, loop_len), ans)
    print(ans)


if __name__ == '__main__':
    main()