Harryxun/stf_run huggingface dataset:
N=int(input())
A=[int(x) for x in input().split()]
for i in range(N):
  A[i]=A[i]-1-i
b=A[N//2]
c=A[(N//2)+1]
ans1,ans2=0,0
for i in range(N):
  ans1+=abs(A[i]-b)
  ans2+=abs(A[i]-c)
print(min(ans1,ans2))

### FIXED CODE ###

N=int(input())
A=[int(x) for x in input().split()]
for i in range(N):
  A[i]=A[i]-1-i
A.sort()
if N==1:
  print(0)
else:
  b=A[N//2]
  c=A[(N//2)+1]
  ans1,ans2=0,0
  for i in range(N):
    ans1+=abs(A[i]-b)
    ans2+=abs(A[i]-c)
  print(min(ans1,ans2))
S = list(input())
T = list(input())
a = 0
for i in range(0,s):
    if S[i] != T[i]:
        a = 1
if a == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

S = list(input())
T = list(input())
a = 0
s = len(S)
for i in range(0,s):
    if S[i] != T[i]:
        a = 1
if a == 0:
    print('Yes')
else:
    print('No')
print(chr(ord(input()+1)))

### FIXED CODE ###

C=input()
print(chr(ord(C[0])+1))
a=sorted(map(int,input().split()))[::-1]
print("%d %d %d %d %d"%tuple(a))

### FIXED CODE ###

a=sorted(map(int,raw_input().split()))[::-1]
print("%d %d %d %d %d"%tuple(a))
s = input().split(" ")
N = int(s[0])
K = int(s[1])

h = []
for i in range(N) : 
    s = input()
    h.append(int(s))
    
h = sorted(h)
minDiff = h[len(h) - 1] - h[0]
for i in range(N) : 
    try : 
        diff = h[len(h) - K + i] - h[i]
        print(f"diff={h[len(h) - K + i]} - {h[i]} = {diff}")
        minDiff = min(minDiff , diff)
        
    except : 
        if i == 0 : minDiff = 0
        continue
print(minDiff)
    

### FIXED CODE ###

s = input().split(" ")
N = int(s[0])
K = int(s[1])

h = []
for i in range(N) : 
    s = input()
    h.append(int(s))
    
h = sorted(h)
minDiff = h[len(h) - 1] - h[0]
for i in range(N) : 
    try : 
        diff = h[i + K - 1] - h[i]
        minDiff = min(minDiff , diff)
        
    except : 
        if i == 0 : minDiff = 0
        continue
print(minDiff)
n, k = map(int, input().split())
list = list(input().split(' '))

new_list = sorted(list)

j = 0
i = 0

while i <= k-1:
  j += int(new_list[i])
  i += 1

print(j)

### FIXED CODE ###

alpha = input()

if alpha.isupper():
  print('A')
elif alpha.islower():
  print('a')
s = [input() for _ in range(int(input()))]
t = [input() for _ in range(int(input()))]
yMax = 0
c = count

for i in s:
    cnt = s.c(i) - t.c(i)
    if yMax < cnt:
        yMax = cnt
print(yMax)


### FIXED CODE ###

n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
yenMax = 0

for i in s:
    cnt = s.count(i) - t.count(i)
    if yenMax < cnt:
        yenMax = cnt
print(yenMax)
import heapq as hq

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

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  ans -= hp.heappop(h)
  
print(ans)
  

### FIXED CODE ###

import heapq as hp

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

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  if a<=m:
  	lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  if len(h)>0:
    ans -= hp.heappop(h)
print(ans)
N,K=map(int,input().split())
P=list(map(input().split()))

P.sort()
price=0
for i in range(K):
  price+=P[i]
  
print(price)

### FIXED CODE ###

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

P.sort()
price=0
for i in range(K):
  price+=P[i]
  
print(price)
A,B,C,X,Y = map(int,input().split())

#全部Cで買うとき
a = 2*C*min(X,Y) + 2*C*(max(X,Y)-min(X,Y))

#片方を全部Cで買うとき
if X > Y:
    b = 2*C*Y + (X-Y)*A
elif Y > X:
    b = 2*C*X + (Y-X)*A

#全部AとBで買うとき
c = A*X + B*Y

print(min(a,b,c))    

### FIXED CODE ###

A,B,C,X,Y = map(int,input().split())

#全部Cで買うとき
a = 2*C*min(X,Y) + 2*C*(max(X,Y)-min(X,Y))

#片方を全部Cで買うとき
if X > Y:
    b = 2*C*Y + (X-Y)*A
elif Y > X:
    b = 2*C*X + (Y-X)*B
else:
    b = a
    
#全部AとBで買うとき
c = A*X + B*Y

print(min(a,b,c))
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

N, A, B = map(int, read().split())

if A > B:
    A, B = B, A

dp1 = np.zeros((N, B), dtype=np.int64)  # その時点で確定している長さ集計
dp2 = np.zeros((N, B), dtype=np.int64)  # もし右に十分な 0 があったとしたときの、長さ集計
dp1_sum = np.zeros(N, dtype=np.int64)

ans = 0
for n in range(N):
    # そこで初めての 1 がたつ場合
    if n + 1 < B:
        if n >= A:
            dp1[n, n + 1] += 1
        else:
            dp1[n, 1] += 1
    # ひとつ手前から 1 を立てて遷移した場合
    dp1[n, 1:] += dp1[n - 1, :-1]
    dp1[n] %= MOD
    # 使えない個数の 0 をはさんで遷移した場合
    dp1[n, 1] += dp1_sum[n - A:n - 1].sum() % MOD
    # たくさんの個数の 0 をはさんで遷移した場合
    if n >= A + 1:
        dp1[n, A + 1:B] += dp2[n - A - 1, 0:B - (A + 1)]
    dp1[n] %= MOD
    # 右を 0 埋めして足せるなら答に足す
    dp1_sum[n] = dp1[n].sum() % MOD
    if (N - n - 1) < A:
        ans += dp1_sum[n]
        ans %= MOD
    else:
        # あと N - n - 1 のびても B にならないような範囲
        M = B - (N - n - 1)
        if M > 0:
            ans += dp1[n, :M].sum() % MOD
    dp2[n] += dp1[n]
    dp2[n, 1:] += dp2[n - 1, :-1]
    dp1[n] %= MOD
    dp2[n] %= MOD

x = pow(2, N, MOD) - ans
print(x % MOD)

### FIXED CODE ###

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

N, A, B = map(int, read().split())

def solve(N, A, B):
    if A > B:
        A, B = B, A
    if A == 1:
        return pow(2, N, MOD)
    dp1 = np.zeros((N, B), dtype=np.int64)  # その時点で確定している長さ集計
    dp2 = np.zeros((N, B), dtype=np.int64)  # もし右に十分な 0 があったとしたときの、長さ集計
    dp1_sum = np.zeros(N, dtype=np.int64)
    ans = 0
    for n in range(N):
        # そこで初めての 1 がたつ場合
        if n < A:
            dp1[n, 1] += 1
        else:
            if n + 1 < B:
                dp1[n, n + 1] += 1
        # ひとつ手前から 1 を立てて遷移した場合
        if n > 0:
            dp1[n, 1:] += dp1[n - 1, :-1]
        # 使えない個数の 0 をはさんで遷移した場合
        dp1[n, 1] += dp1_sum[max(0, n - A):n - 1].sum() % MOD
        # たくさんの個数の 0 をはさんで遷移した場合
        if n >= A + 1 < B:
            dp1[n, A + 1:B] += dp2[n - A - 1, 0:B - (A + 1)]
        dp1[n] %= MOD
        # 右を 0 埋めして足せるなら答に足す
        dp1_sum[n] = dp1[n].sum() % MOD
        if (N - n - 1) < A:
            ans += dp1_sum[n]
            ans %= MOD
        else:
            # あと N - n - 1 のびても B にならないような範囲
            M = B - (N - n - 1)
            if M > 0:
                ans += dp1[n, :M].sum() % MOD
        dp2[n] += dp1[n]
        dp2[n, 1:] += dp2[n - 1, :-1]
        dp1[n] %= MOD
        dp2[n] %= MOD
    x = pow(2, N, MOD) - ans
    return x % MOD

print(solve(N, A, B))
from collections import defaultdict

mod=1000000007
def mpow2(n):
    ret=1
    while n>0:
        ret*=2
        ret%=mod
        n-=1
    return ret

def gcd(a,b):
    if a<0:
        a*=-1
    if b<0:
        b*=-1
    if a<b:
        a,b=b,a
    if a%b:
        return gcd(b,a%b)
    return b

shift=2**64
d=defaultdict(int)
n=int(input())
l=[]
cnt0=0
for i in range(n):
    a,b=map(int,input().split())
    if a==b==0:
        cnt0+=1
        continue
    g=gcd(a,b)
    a//=g
    b//=g
    l.append((a,b))
    d[a*shift+b]+=1
res=1
for p in l:
    a=p[0]
    b=p[1]
    c=d[a*shift+b]+d[-a*shift-b]
    if c==0:
        continue
    d[a*shift+b]=0
    d[-a*shift-b]=0
    a=-p[1]
    b=p[0]
    cc=d[a*shift+b]+d[-a*shift-b]
    d[a*shift+b]=0
    d[-a*shift-b]=0
    if cc==0:
        res*=mpow2(c)
        res%=mod
    else:
        res*=mpow2(c)+mpow2(cc)-1
        res%=mod
print((res+cnt0+mod-1)%mod)


### FIXED CODE ###

from collections import defaultdict

mod=1000000007
def mpow2(n):
    ret=1
    while n>0:
        ret*=2
        ret%=mod
        n-=1
    return ret

def gcd(a,b):
    if a<0:
        a*=-1
    if b<0:
        b*=-1
    if a<b:
        a,b=b,a
    if a%b:
        return gcd(b,a%b)
    return b

shift=2**64
d=defaultdict(int)
n=int(input())
l=[]
cnt0=0
for i in range(n):
    a,b=map(int,input().split())
    if a==b==0:
        cnt0+=1
        continue
    elif a==0:
        b=1
    elif b==0:
        a=1
    else:
        g=gcd(a,b)
        a//=g
        b//=g
    l.append((a,b))
    d[a*shift+b]+=1
res=1
for p in l:
    a=p[0]
    b=p[1]
    c=d[a*shift+b]+d[-a*shift-b]
    if c==0:
        continue
    d[a*shift+b]=0
    d[-a*shift-b]=0
    a=-p[1]
    b=p[0]
    cc=d[a*shift+b]+d[-a*shift-b]
    d[a*shift+b]=0
    d[-a*shift-b]=0
    if cc==0:
        res*=mpow2(c)
        res%=mod
    else:
        res*=mpow2(c)+mpow2(cc)-1
        res%=mod
print((res+cnt0+mod-1)%mod)
n = int(input())
x = list(map(int, input().split()))
d = []
for x1, x2 in zip(x, x[1:]):
    d.append(x2 - x1)
mod = 10 ** 9 + 7
base = 1

P = 10**9 + 7
N = 10000
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

for i in range(1, n):
    base *= i
    base %= mod
ans = 0
b = base
for i, di in enumerate(d):
    ans += (base * di)  % mod
    ans %= mod
    base += b * inv_t[i+2]
    base % mod
print(ans)


### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
d = []
for x1, x2 in zip(x, x[1:]):
    d.append(x2 - x1)
mod = 10 ** 9 + 7
base = 1

P = 10**9 + 7
N = n+2
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

for i in range(1, n):
    base *= i
    base %= mod
ans = 0
b = base
for i, di in enumerate(d):
    ans += (base * di)  % mod
    ans %= mod
    base += b * inv_t[i+2]
    base % mod
print(ans)
a,b=int(input())
if a-1=>b:
  print(2*a-1)
elif a==b:
  print(2a)
else:
  print(2*b-1)

### FIXED CODE ###

a,b=map(int,input().split())
if a-1>=b:
  print(2*a-1)
elif a==b:
  print(2*a)
else:
  print(2*b-1)
N =int(input())
N,X,T=map(int,input().split())
if N%T ==0:
    print(NT//X)
else:
    print((N//X+1)*T)

### FIXED CODE ###

N,X,T=map(int,input().split())
if N%X ==0:
    print(N*T//X)
else:
    print(((N//X)+1)*T)
a,b=map(int,input().split())
cnt=0
for i in range(2):
if a>=b:
    cnt+=a
    a-=1
else:
    cnt+=b
    b-=1
return (cnt)

### FIXED CODE ###

a,b=map(int,input().split())
cnt=0
for i in range(2):
    if a>=b:
        cnt+=a
        a-=1
    else:
        cnt+=b
        b-=1
print(cnt)
print(-int(input()) + int(input()*2)

### FIXED CODE ###

print(-int(input()) + int(input())*2)
a,b=int(input().split())
ad = a+b
minus = a-b
cross = a*b
lis = [ad, minus, cross]
print(max(lis))

### FIXED CODE ###

a,b=input().split()
a = int(a)
b = int(b)
ad = a+b
minus = a-b
cross = a*b
lis = [ad, minus, cross]
print(max(lis))
a,b = map(int,input().split())
cnt = 0
for i in range(a,b+1):
    lst = list(i)
    if lst[0] == lst[-1] and lst[1] == lst[-2]:
        cnt += 1
print(cnt)

### FIXED CODE ###

a,b = map(int,input().split())
cnt = 0
for i in range(a,b+1):
    lst = list(str(i))
    if lst[0] == lst[-1] and lst[1] == lst[-2]:
        cnt += 1
print(cnt)
n = int(input())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

print(sum([abs(x-y) for x, y in zip(xs, ys)]))
print(math.sqrt(sum([(x-y)**2 for x, y in zip(xs, ys)])))
print((sum([(x-y)**3 for x, y in zip(xs, ys)]))**(1/3))
print(max([abs(x-y) for x, y in zip(xs, ys)]))

### FIXED CODE ###

import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

print(sum(map(lambda v: math.fabs(v[0] - v[1]), zip(x, y))))
print(sum(map(lambda v: math.fabs((v[0] - v[1]) ** 2), zip(x, y))) ** (1/2))
print(sum(map(lambda v: math.fabs((v[0] - v[1]) ** 3), zip(x, y))) ** (1/3))
print(max(map(lambda v: math.fabs(v[0] - v[1]), zip(x, y))))
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

count = 0

for i in range(N):
    count += B[i]

for i in range(0, N - 1):
    count += C[i]

if N > 2:
    count -= C[A[N - 1] - 1]

print(count)

### FIXED CODE ###

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

count = 0

for i in range(N):
    count += B[i]

    if  i >= 1 and A[i] == A[i - 1] + 1:
        count += C[A[i - 1] - 1]

print(count)
S = str(Input())
if S.count('AB') is 0 and S.count('BA') is 0:
    print('No')
else:
    print('Yes')

### FIXED CODE ###

S = str(input())
if S.count('AB') is 0 and S.count('BA') is 0:
    print('No')
else:
    print('Yes')
from collections import defaultdict

n,q=[int(x) for x in input().split()]
ab=[[int(x) for x in input().split()] for _ in range(n-1)]
px=[[int(x) for x in input().split()] for _ in range(q)]

s=[0,]*n

def calc(dd,i,num):
  global s
  if dd[i]==[]:
    s[i-1]+=num
    return(True)
  else:
    s[i-1]+=num
    for item in dd[i]:
      calc(dd,item,num)
    return(True)


dd=defaultdict(list)
for key in range(1,n):
  dd[ab[key-1][0]].append(ab[key-1][1])

for item in px:
  calc(dd,item[0],item[1])

print(*s)

### FIXED CODE ###


n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
 
neigh = {}
 
scores = [0] * n
 
for i in range(q) :
    scores[px[i][0] - 1] += px[i][1]
#print(*scores) 
for i in range(n - 1) :
    neigh.setdefault(ab[i][0], []).append(ab[i][1])
#print(neigh)

sortKey = sorted(neigh.keys())
 
for k in sortKey :
    for e in neigh[k]:
        scores[e-1]+=scores[k-1]
 
print(*scores)
#/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

def input():
    return stdin.readline()

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

adj = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = (a - 1, b - 1)
    adj[a].append(b)
    adj[b].append(a)
    
values = [0 for _ in range(N)]
    
for _ in range(Q):
    p, x = map(int, input().split())
    values[p - 1] += x

def dfs(node, parent):
    for child in adj[node]:
        if child == parent: continue
        values[child] += values[node]
        dfs(child, node)

dfs(0, -1)

print(" ".join(map(str, values)))
    

### FIXED CODE ###

#/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

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

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

adj = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = (a - 1, b - 1)
    adj[a].append(b)
    adj[b].append(a)
    
values = [0 for _ in range(N)]
    
for _ in range(Q):
    p, x = map(int, input().split())
    values[p - 1] += x

def dfs(node, parent):
    for child in adj[node]:
        if child == parent: continue
        values[child] += values[node]
        dfs(child, node)

dfs(0, -1)

print(" ".join(map(str, values)))
N, M = map(int, input().split(' '))

def fib(n):
    a, b = 0, 1
    for i in range(0, n):
        a, b = b, a + b
    return a

a_p = int(input())
sum = fib(a_p)
for i in range(M-1):
    a = int(input())
    diff = a - a_p
    if diff == 1:
        print('0')
        exit()
    sum *= fib(diff-1)
    sum %= 1000000007
    a_p = a

if (N - a_p == 1):
    print('0')
    exit()

sum *= fib(N - a_p)
sum %= 1000000007
print(sum)


### FIXED CODE ###

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

MOD = 1000000007

def fib(n):
    a, b = 0, 1
    for i in range(0, n):
        a, b = b, a + b
    return a

broken_step = []
p_a = -1
for i in range(M):
    a = int(input())
    if (a - p_a == 1):
        print("0")
        exit()
    else:
        p_a = a
    broken_step.append(a-1)

count_0 = 0
count_1 = 1
next_broken = 0
pre_is_broken = False
for i in range(N):
    if (next_broken >= len(broken_step) or i != broken_step[next_broken]):
        if (pre_is_broken):
            count_0 = 0
            pre_is_broken = False
        else:
            count_0, count_1 = count_1, count_0 + count_1
            count_0 %= MOD
            count_1 %= MOD
    else:
        next_broken+=1
        count_0 = 0
        pre_is_broken = True

print(count_1)
a,b = map(int,input().split())

if a == b:
    print(a)
    exit()
ansl = []
if a % 2 == 1:
    ansl.append(a)
    a += 1
if b % 2 == 0:
    ansl.append(b)
    b -= 1

k = b - a
k = k // 2

if k % 2 == 1:
    ansl.append(1)

if len(ansl) == 1:
    print(ansl[0])
elif len(ansl) == 2:
    print(ansl[0] ^ ansl[1])
else:
    print(ansl[0] ^ ansl[1] ^ ansl[2])

### FIXED CODE ###

a,b = map(int,input().split())

a1 = 0
b1 = 0
l = []
if a % 2 != 0:
   a1 = 1
if b % 2 == 0:
   b1 = 1
if a1 == 1:
   l.append(a)
one = b - a + 1 - a1 -b1
if one // 2 % 2 == 0:
   l.append(0)
if one // 2 % 2 == 1:
   l.append(1)
if b1 == 1:
   l.append(b)

if len(l) == 1:
   print(l[0])
if len(l) == 2:
   print(l[0]^l[1])
if len(l) == 3:
   print(l[0]^l[1]^l[2])
from math import gcd
[a,b,c,d]=[int(x) for x in input().split()]
k=(c*d)//gcd(c,d)
count=(b-a+1)-((b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//k-(a-1)//k))
print(count)
    

### FIXED CODE ###

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
[a,b,c,d]=[int(x) for x in input().split()]
k=(c*d)//gcd(c,d)
count=(b-a+1)-((b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//k-(a-1)//k))
print(count)
import bisect
N = int(input())
list = list(map(int,input().split()))
list = sorted(list)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        x = list[i]+list[j]
        ind = bisect.bisect_left(list,x)
        ans+=(ind-j-1)
print(ans)
    
    

### FIXED CODE ###

import bisect
N = int(input())
list = list(map(int,input().split()))
list = sorted(list)
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        x = list[i]+list[j]
        ind = bisect.bisect_left(list,x)
        ans+=(ind-j-1)
print(ans)
N,M= map(int, raw_input().split())
A=list(map(int, raw_input().split()))
A.sort()
A.reverse()
K=sum(A)
for i in range(0,N):
    if  A[i]>K/(4*M):
        continue
    else:
        answer=i+1
        break
if answer>=M:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

N,M=map(int, input().split())
A=list(map(int, input().split()))
A.sort()
A.reverse()
K=sum(A)
answer=0
breakflag=0
for i in range(0,N):
  if  A[i]*M*4>=K:
    if i==N-1:
      breakflag=1
    continue
  else:
    answer=i
    break
if breakflag==1:
  answer=N
if answer>=M:
    print("Yes")
else:
    print("No")
n = int(input())
P = [int(i) for i in input().split()]
cnt = 0
for i in range(n):
  if i+1==P[i]:
    a = P[i]
    P[i] = P[i+1]
    P[i+1] = a
    cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
P = [int(i) for i in input().split()]
cnt = 0
for i in range(n):
  if i == n-1 and P[i]==i+1:
    cnt += 1
    break
  if i+1==P[i]:
    a = P[i]
    P[i] = P[i+1]
    P[i+1] = a
    cnt += 1
print(cnt)
def operate( cmd, text, cur ):
    lentxt = len(text)
    if cmd == "forward char":
        if cur < lentxt: cur += 1
    elif cmd == "backward char":
        if cur > 0: cur -= 1
    elif cmd == "forward word":
        while cur < lentxt and text[cur] == ' ': cur += 1
        while cur < lentxt and text[cur] != ' ': cur += 1
    elif cmd == "backward word":
        while cur > 0 and text[cur - 1] == ' ': cur -= 1
        while cur > 0 and text[cur - 1] != ' ': cur -= 1
    elif cmd == "delete char":
        text = text[:cur] + text[cur + 1:]
    elif cmd == "delete word":
        d = 0
        while cur + d < lentxt and text[cur + d] == ' ': d += 1
        if cur + d == lentxt: break
        while cur + d < lentxt and text[cur + d] != ' ': d += 1
        text = text[:cur] + text[cur + d:]
    else:
        ins = cmd[8:-1]
        text = text[:cur] + ins + text[cur:]
        cur += len(ins)
    return cur, text

if __name__ == "__main__":
    a = int(raw_input())
    for i in range(a):
        text = raw_input()
        cnt = int(raw_input())
        cursor = 0
        for j in range(cnt):
            command = raw_input()
            cursor, text = operate( command, text, cursor )
        print (text[:cursor] + '^' + text[cursor:])

### FIXED CODE ###

def operate( cmd, text, cur ):
    lentxt = len(text)
    if cmd == "forward char":
        if cur < lentxt: cur += 1
    elif cmd == "backward char":
        if cur > 0: cur -= 1
    elif cmd == "forward word":
        while cur < lentxt and text[cur] == ' ': cur += 1
        while cur < lentxt and text[cur] != ' ': cur += 1
    elif cmd == "backward word":
        while cur > 0 and text[cur - 1] == ' ': cur -= 1
        while cur > 0 and text[cur - 1] != ' ': cur -= 1
    elif cmd == "delete char":
        text = text[:cur] + text[cur + 1:]
    elif cmd == "delete word":
        d = 0
        while cur + d < lentxt and text[cur + d] == ' ': d += 1
        if cur + d != lentxt:
            while cur + d < lentxt and text[cur + d] != ' ': d += 1
            text = text[:cur] + text[cur + d:]
    else:
        ins = cmd[8:-1]
        text = text[:cur] + ins + text[cur:]
        cur += len(ins)
    return cur, text

if __name__ == "__main__":
    a = int(raw_input())
    for i in range(a):
        text = raw_input()
        cnt = int(raw_input())
        cursor = 0
        for j in range(cnt):
            command = raw_input()
            cursor, text = operate( command, text, cursor )
        print (text[:cursor] + '^' + text[cursor:])
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N , M)
X = [""] * L
for i in range(N):
    idx = i * (L // N)
    X[idx] = S[i]
for i in range(M):
    idx = i * (L // M)
    if X[idx] != "" and X[idx] != T[i]:
        print(-1)
        exit()
print(L)


### FIXED CODE ###

import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N , M)
x = {}
for i in range(N):
    idx = i * (L // N)
    x[idx] = S[i]
for i in range(M):
    idx = i * (L // M)
    if idx in x and x[idx] != T[i]:
        print(-1)
        exit()
print(L)
a,b,t=map(int,input().split())
print((t+0.5)//a＊b)

### FIXED CODE ###

a, b, t = map(int, input().split())

ans = int(((t+0.5)//a)*b)
print(ans)
from typing import List
N, M = map(int, input().split())
graph:List[List[int]] = [[] for _ in range(N)]
for _ in range(N):
    a,b = map(lambda x : int(x) -1 , input().split())
    graph[a].append(b)
    graph[b].append(a)
prev = [-1]*N
prev[0] = 0
import queue
qu = queue.Queue()
qu.put(0)
while not qu.empty():
    top = qu.get()
    for nxt in graph[top]:
        if prev[nxt] == -1:
            prev[nxt] = top
            qu.put(nxt)
if all(x != -1 for x in prev[1:]):
    print("Yes")
    print("\n".join(map(lambda x : str(x+1), prev[1:])))
else :
    print("No")

### FIXED CODE ###

from typing import List
N, M = map(int, input().split())
graph:List[List[int]] = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(lambda x : int(x) -1 , input().split())
    graph[a].append(b)
    graph[b].append(a)
prev = [-1]*N
prev[0] = 0
import queue
qu = queue.Queue()
qu.put(0)
while not qu.empty():
    top = qu.get()
    for nxt in graph[top]:
        if prev[nxt] == -1:
            prev[nxt] = top
            qu.put(nxt)
if all(x != -1 for x in prev[1:]):
    print("Yes")
    print("\n".join(map(lambda x : str(x+1), prev[1:])))
else :
    print("No")
n,x = map(int,input().split())
a = list(input().split())
ans = 0

if int(a[0]) > x:
    ans += a[0]-x
    a[0] = x
for i in range(n-1):
    c = int(a[i+1]) + int(a[i])
    if c > x:
        ans += c-x
        a[i+1] = int(a[i+1])-(c-x)
print(ans)

### FIXED CODE ###

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

if int(a[0]) > x:
    ans += int(a[0])-x
    a[0] = x
for i in range(n-1):
    c = int(a[i+1]) + int(a[i])
    if c > x:
        ans += c-x
        a[i+1] = int(a[i+1])-(c-x)
print(ans)