peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N, K = map(int, input().split())
D = list(map(str, input().split()))

T = True
while T:
  x = str(N)
  p = 0
  for i in range(len(x)):
    if x[i] in D:
      p = 1
  
  if p == 0:
    T = False
  else:
    N += 1

print(N)
# Judge status: Wrong Answer
def main():
    N = int(input())
    i = 0
    while 4*i <= N:
        j = 0
        while (4*i + 7*j) <=N:
            print(4*i + 7*j)
            if (4*i+7*j == N):
                print('Yes')
                return
            j = j+1
        i = i+1
    print('No')
    return
main()
# Judge status: Accepted
n = int(input())
ds = {}

for i in range(n):
    s = input()
    if s in ds:
        ds[s] += 1
    else:
        ds[s] = 0

d_sorted = sorted(ds.items(), key=lambda x: x[0])
f_sorted = sorted(d_sorted, key=lambda x: x[1], reverse=True)

i = f_sorted[0][1]

for s in f_sorted:
    if s[1] == i:
        print(s[0])
    else:
        break
# Judge status: Accepted
a, b = map(int, input().split() )

if a % 3 != 0 and b % 3 != 0 and (a+b) % 3 != 0:
  print('Impossible')
else:
  print('Possible')
# Judge status: Accepted
x = int(input())
for i in range(1, 10 ** 5):
    if x <= (i * (i + 1)) // 2:
        print(i)
        break
# Judge status: Accepted
L, R, d = map(int, input().split())
ans = 0
for i in range(L, R+1):
    if i%d == 0:
        ans += 1
print(ans)
# Judge status: Accepted
x = input()
y = x[0] + 't' + x[1] + 't' + x[2] + 't' + x[3]
for i in range(8):
  for j in range(3):
    if ((i>>j) & 1) == 1:
      z = list(y)
      z[5-2*j] = '+'
      y = ''.join(z)
    else:
      z = list(y)
      z[5-2*j] = '-'
      y = ''.join(z)
      
  if eval(y) == 7:
    print(y+ '=7')
    break
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

res = 0
idx = 1
for v in a:
    if v == idx:
        idx += 1
    else:
        res += 1

if idx == 1:
    print(-1)
else:
    print(res)
# Judge status: Wrong Answer
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))
    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])
s = input()
n = len(s)
print(dfs(0, s[0]))
# Judge status: Accepted
import math

def check(A, x, k):
    cut_count = 0
    for number in A:
        cut_count += (math.ceil(number / x)) -1
    return cut_count <= k

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

l = 0
r = 10 ** 9
 
while r - l > 1:
    x = (r + l) // 2
  
    if check(a, x, k):
        r = x
    else:
        l = x   
print(r)
# Judge status: Accepted
from bisect import bisect_left
n = int(input())
a = [int(input()) for i in range(n)]
dp = [-float("inf")] * (n + 1)
for i in a:
    dp[bisect_left(dp, i) - 1] = i
print(dp[::-1].index(-float("inf")))
# Judge status: Accepted
from sys import stdin
from bisect import bisect

N = int(stdin.readline().rstrip())
A = []
for i in range(N):
    A.append(int(input()))

dp = []
for a in A[::-1]:
    i = bisect(dp, a)
    if i < len(dp):
        dp[i] = a
    else:
        dp.append(a)
print(len(dp))
# Judge status: Accepted
K,A,B=map(int,input().split())
if A+2>=B:
    print(K+1)
elif K<=A:
    print(K+1)
else:
    K-=A-1
    k=K//2
    print(B*k-A*(k-1)+K%2)
# Judge status: Accepted
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
cnt = 0
for v in collections.Counter([ri() for _ in range(n)]).values():
    if v&1:
        cnt += 1
print(cnt)
# Judge status: Accepted
K = int(input())
S = str(input())
if len(S)<=K:
    print(S)
elif len(S)>K:
    print(S[0:K]+"...")
# Judge status: Accepted
K = int(input())

if K % 7 == 0:
    K //= 7

L = 9 * K

ans = -1

r = 10

for i in range(L):
    if r % L == 1:
        ans = i + 1
        break
    else:
        r = 10 * (r % L)

print(ans)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())
t = 0
if a == b == c:
  print(-1)

else:
  while (a % 2 + b % 2 + c % 2) == 0:
    a, b, c = (b + c) / 2, (a + c) / 2, (a + b) / 2
    t += 1

  print(t)
# Judge status: Accepted
S,T=input().split()
A,B=map(int,input().split())
U=input()

if S==U:
    A-=1
else:
    B-=1

print(str(A)+" "+str(B))
# Judge status: Accepted
s = input()
if (s[-1]=='s'):
    print(s+'es')
else:
    print(s+'s')
# Judge status: Wrong Answer
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
d=0
for i in range(1,a):
  if b<=(i//10+(i-(i//10)*10))<=c:
    d=d+i
print(d)
# Judge status: Accepted
N=int(input())
a=[0]+list(map(int,input().split()))
b=[0]*(N+1)

for i in range(N,0,-1):
    cnt=0
    j=2
    while i*j<=N:
        cnt+=b[i*j]
        j+=1
    
    if (cnt+1)%2==a[i]:
        b[i]=1
    else:
        b[i]=0

M=0
s=''

for i in range(1,N+1):
    if b[i]==1:
        s+=str(i)+' '
        M+=1

print(M)
if M>0:
    print(s[:-1])
# Judge status: Wrong Answer
N = int(input())

if N % 2  == 0:
    print("0.5000000000")
else:
    tmp = int(N+1/2) +1
    print(tmp/N)
# Judge status: Accepted
n = input()

a, b, c, d = n.split(" ")
a = int(a)
b = int(b)
c = int(c)
d = int(d)

ac = a*c
ad = a*d
bc = b*c
bd = b*d

print(max([ac, ad, bc, bd]))
# Judge status: Accepted
A, B, C, K = map(int, input().split())

if A >= K:
    print(K)
elif A + B >= K:
    print(A)
else:
    D = K-A-B
    print(A-D)
# Judge status: Accepted
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

s = 0
num = 0
if x>sum(a):
  print(len(a)-1)
else:
  for i in range(len(a)):
      if x >= a[i]:
          x -= a[i]
          num += 1
      else:
          break

  print(num)
# Judge status: Accepted
N,H = map(int,input().split())
kill = []
throw = []
ans = 0
for i in range(N):
    a,b = map(int,input().split())
    kill.append(a)
    throw.append(b)
throw.sort()
throw.reverse()
const = max(kill)
for j in throw:
    if j <= const:
        break
    else:
        H -= j
        ans += 1
        if H <= 0:
            break
if H > 0:
    time = H//const
    if H % const == 0:
        ans += time
    else:
        ans += time+1
print(ans)
# Judge status: Accepted
N=int(input())
a=0
b=0
c=0
d=0
for _ in range(N):
    S=input()
    if S=='AC':
        a+=1
    elif S=='WA':
        b+=1
    elif S=='TLE':
        c+=1
    else:
        d+=1
print('AC x '+str(a))
print('WA x '+str(b))
print('TLE x '+str(c))
print('RE x '+str(d))
# Judge status: Accepted
A1, A2, A3 = map(int, input().split())

R = 'win'
if A1 + A2 + A3 >= 22:
    R = 'bust'

print(R)
# Judge status: Wrong Answer
n = input()
m = n.split()
a = [input() for l in range(0,1)]
b = a[0].split()
c = sorted(b, reverse=True)
p = 0
for i in range(0,int(m[1])):
    p = p + int(c[i])
print(p)
# Judge status: Accepted
a,b= map(int, input().split())

if a<=b:
    for i in range(b):
        print(a,end="")
else:
    for j in range(a):
        print(b,end="")
# Judge status: Accepted
n = int(input())
s = []
for i in range(n):
    s.append(input())
print(len(set(s)))
# Judge status: Accepted
w = list(input())

all = sorted([x for x in set(w) if w.count(x) > 0])
beautiful = sorted([x for x in set(w) if w.count(x) % 2 == 0])

if all == beautiful:
	print("Yes")
else :
	print("No")
# Judge status: Accepted
X=int(input())
cnt=0
a=100
while a<X:
    cnt+=1
    a=int(1.01*a)
print(cnt)
# Judge status: Accepted
n, m = map(int, input().split())
L=list(map(int, input().split()))
A=[]
for i in range(n):
	A.append(-L[i])

import heapq
heapq.heapify(A)

for i in range(m):
	a= -heapq.heappop(A)
	heapq.heappush(A, -(a//2))

print(-sum(A))
# Judge status: Accepted
s = input()
a = int(s[:2])
b = int(s[2:])

if (1 <= a <= 12) and (1 <= b <= 12):
  print("AMBIGUOUS")
elif (1 <= a <= 12):
  print("MMYY")
elif (1 <= b <= 12):
    print("YYMM")
else:
  print("NA")
# Judge status: Wrong Answer
n = int(input())
x = list(map(int,input().split()))

phy = []
tmp = 0
max = 0
count = 0

for i in range(101):
    phy.append(i*i)

for j in range(1,x[n-1]):
    for k in range(n):
        tmp += phy[abs((j-x[k]))]
    if(max > tmp or count == 0):
        max = tmp
    count += 1
    tmp = 0

print(max)
# Judge status: Accepted
from fractions import gcd
n=int(input())
*a,=map(int,input().split())
a.sort()
g=gcd(a[0],a[1])
for i in range(2,n):
	g=gcd(g,a[i])
print(g)
# Judge status: Accepted
n,k = map(int, input().split())
h = [[] for i in range(n)]
for i in range(n):
    h[i] = int(input())
h.sort()

diff = [[] for i in range(n-1)]
for i in range(n-1):
    diff[i] = h[i+1]-h[i]

t = [[] for i in range(n-1)]
t[0] = diff[0]
for i in range(1,n-1):
    t[i] = t[i-1]+diff[i]
t = [0] + t

# print(h)
# print(diff)
# print(t)

ans = float("inf")
for i in range(n-k+1):
    a = t[i+k-1]-t[i]
    ans = min(ans, a)

print(ans)
# Judge status: Accepted
s={chr(ord("a")+i): list(input()) for i in range(3)}
turn=s["a"].pop(0)
while s[turn]:
    turn=s[turn].pop(0)
print(turn.upper())
# Judge status: Accepted
S = list(input())
n = len(S)
ACGT = ["A","C","G","T"]
ans = 0
for i in range(n):
    if S[i] in ACGT:
        if i == n-1:
            ans = max(ans,1)
        else:
            streak = 1
            for j in range(i+1,n):
                if S[j] in ACGT:
                    streak += 1
                else:
                    break
            ans = max(ans,streak)

print(ans)
# Judge status: Wrong Answer
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a, b,c = map(int, input().split())

    print( min (a//b ,c))
# Judge status: Wrong Answer
#!/usr/bin/env python3
from itertools import*
n = int(input())
l = list(accumulate(map(int, input().translate(str.maketrans("#.","10")))))
q = l[-1]
m = INF = float("inf")
for i in range(n):
    m = min(m, l[i] + n - i - (q - l[i]) - 1)
print(m)
# Judge status: Accepted
n,m = map(int,input().split())
a = list(map(int,input().split()))
print('-1' if sum(a)>n else n-sum(a))
# Judge status: Accepted
num=int(input())


def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

ans=num2alpha(num).lower()

print(ans)
# Judge status: Accepted
def main():
    N = int(input())
    A = list()

    for i in range(N):
        a, b = map(int, input().split())
        A.append([a, b])

    A.reverse()
    ans = 0
    offset = 0

    for pair in A:
        a, b = pair

        if (a + offset) % b == 0:
            n = 0
        else:
            n = b - ((a + offset) % b)

        ans += n
        offset += n
        
    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
import re
a,b=input().split()
s=input()
pat ="^\d{"+a+"}-\d{"+b+"}$"
match = re.search(pat,s)
if match:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
s = input()
ans = 'x' * len(s)
print(ans)
# Judge status: Wrong Answer
X, K, D  = map(int, input().split())
shou = X//D
amari = X%D 

if D * K <= X:
    print(abs(X) - D*K)
elif K - shou % 2 == 0:
    print(amari)
else:
    print(abs(amari - D))
# Judge status: Wrong Answer
n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l.pop()
a = 0
ans = 0
for r in l:
  if abs((m / 2) - r) < a:
    a = abs((m / 2) - r)
    ans = r
print(m, ans)
# Judge status: Wrong Answer
N = int(input())
H = list(map(int,input().split()))
check = 0

for i in range(0,N-1):
  if(H[i+1] < H[i]):
    H[i+1] = H[i]
  elif(H[i]-H[i+1] >= 2):
    check = 1
    
if(check == 1):
	print("No")
else:
	print("Yes")
# Judge status: Accepted
import sys
h,w=map(int,input().split())
n=h*w
if h==1 or w==1:
  print(1)
  sys.exit()
if n%2==0:
  print(n//2)
else:
  print(n//2+1)
# Judge status: Accepted
N = int(input())
S = [input() for i in range(N)]

alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans = []
for i in alphabet:
    tmp = 1000
    for j in range(N):
        count = S[j].count(i)
        if count < tmp:
            tmp = count
    for j in range(tmp):
        ans.append(i)
    
for i in range(len(ans)):
    print(ans[i],end="")
# Judge status: Accepted
#!/usr/bin/env python3

print(input().count("1"))
# Judge status: Accepted
N=int(input())
A = []
for i in range(N):
  Ai=int(input())
  A.append(Ai)
on = 1 #現実世界での番号
for i in range(N):
  on = A[on-1] #次のボタンを知るために、配列を参照する
  if on == 2:
    print(i+1)
    break
if on != 2:
  print(-1)
# Judge status: Wrong Answer
D=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(D):
  s.append(input().split())
  print(i*2)
# Judge status: Accepted
A, B = map(int, input().split())
K = abs(A+B)//2
print(K if abs(A-K) == abs(B-K) else 'IMPOSSIBLE')
# Judge status: Wrong Answer
s=input()
ryoko={'S':False,'N':False,'W':False,'E':False}
for c in s:
    ryoko[c]=True
if (ryoko['S'] and ryoko['N']) or (ryoko['W'] and ryoko['E']):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import sys

n = int(sys.stdin.readline().rstrip())

def base_convert(n, b):
    res = ''
    while n:
        r = abs(n % b)
        res = str(r) + res
        n = (n - r) // b

    return int(res) if res else 0

def main():
    return base_convert(n, 3)

if __name__ == '__main__':
    ans = main()
    print(ans)
# Judge status: Accepted
n,k=map(int,input().split())
a=[1]*n
for i in range(k):
    d=int(input())
    x=list(map(int,input().split()))
    for j in x:
        a[j-1]=0
print(sum(a))
# Judge status: Accepted
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
dmax = max(d)
dmin = min(d[1:])
cnt = [0] * n
for i, dd in enumerate(d):
    cnt[dd] += 1

if d[0] != 0 or dmin == 0:
    print(0)
    exit()
ans = 1
before = cnt[0]
for i in range(1,dmax+1):
    ans *= pow(before, cnt[i],MOD)
    before = cnt[i]
ans %= MOD
print(ans)
# Judge status: Wrong Answer
ans=""
for i in list(input()):
    if ans and i=="B":ans=ans[:-1]
    else:ans=ans+i
print(ans)
# Judge status: Accepted
N, K = map(int,input().split())
H = sorted(list(map(int,input().split())))
    
if K >= N:
    print(0)
else:
    print(sum(H[:(N-K)]))
# Judge status: Accepted
K = eval(input())
A, B = [eval(v) for v in input().strip().split(" ")]

i = 1
while K * i <= B:
    if K * i >= A:
        print("OK")
        exit(0)
    i += 1

print("NG")
# Judge status: Wrong Answer
dd = {}
n, m = map(int, input().split())
for _ in range(m):
    a, b = map(int, input().split())
    dd[a] = dd.get(a,0) + 1
    dd[b] = dd.get(b,0) + 1
for i in sorted(dd.keys()):
    print(dd[i])
# Judge status: Accepted
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    _ = rl()
    S = input()
    MOD = 10 ** 9 + 7
    
    counter = defaultdict(int)
    for si in S:
        counter[si] += 1
    
    ans = 1
    s = set(S)
    for si in s:
        ans = ans * (counter[si] + 1) % MOD
    ans -= 1
    print(ans)


if __name__ == '__main__':
    solve()
# Judge status: Wrong Answer
s = input()

import re
output ="NO"
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
if s == "":
    output = "YES"
print(output)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
mx = max(A)
A = [a for a in A if a < mx]

A.sort(key=lambda a: abs(mx / 2 - a))
print(mx, A[0])
# Judge status: Accepted
A, B, C = map(int, input().split())
if A <= C <= B or A >= C >= B:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
l,r = map(int,input().split())
a = l%2019
b = r-l
if a+b >= 2019:
    print(0)
else:
    c = []
    for i in range(l,r+1):
        c.append(i%2019)
    c = sorted(c)
    print(c[0]*c[1])
# Judge status: Wrong Answer
n,k=map(int,input().split())
h=[int(input())for _ in range(n)]
h.sort()
ls=[]

for i in range(n-1):
  ls+=str(abs(h[i]-h[i+1]))
  
ls.sort()
ans=0
for i in range(k-1):
  ans+=int(ls[i])
  
print(ans)
# Judge status: Wrong Answer
A, B, C = map(int, input().split())
print("Yes" if A+B>C else "No")
# Judge status: Accepted
A, B, K = map(int, input().split())

AK = A-K

if AK < 0:
    BK = AK+B
    if BK < 0:
        print(0, 0)
    else:
        print(0, BK)
else:
    print(AK, B)
# Judge status: Accepted
n = int(input())
a = []
for i in range(5):
    a.append(int(input()))
x = min(a)
ans = (n-1)//x + 5
print(ans)
# Judge status: Accepted
import itertools as itr

N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i],y[i] = map(int,input().split())

L = list(range(N))
P = list(itr.permutations(L,N))

D = 0
for i in P:
    for j in range(N-1):
        D += ((x[i[j]] - x[i[j+1]])**2 + (y[i[j]] - y[i[j+1]])**2)**0.5

print(D / len(P))
# Judge status: Wrong Answer
N=int(input())
L=[[0,0,0]]
for i in range(N):
  L.append(list(map(int,input().split())))

s=0
for i in range(1,N+1):
  if abs(L[i][1]-L[i-1][1])+abs(L[i][2]-L[i-1][2]) > L[i][0]-L[i-1][0]:
    s=1
    break

print("Yes" if s==0 else "No")
# Judge status: Accepted
x, a, b = map(int, input().split())
if abs(x - a) < abs(x - b):
    print('A')
else:
    print('B')
# Judge status: Accepted
n = int(input())

li = [input() for _ in range(n)]

check = ['AC', 'WA', 'TLE', 'RE']
ans = [0] * 4

for i in li:
    for j in range(4):
        if i == check[j]:
            ans[j] += 1
            
for i in range(4):
    print(check[i] + ' x ' + str(ans[i]))
# Judge status: Accepted
S = input()
L = len(S)
res = ""
for l in range(L):
  res = res + "x"
print(res)
# Judge status: Wrong Answer
s=input()
s=s.split()
for i in range(len(s)):
    if(s[i]=='?'):
        s[i]='D'
#PD?D??P
for i in range(len(s)):
    print(s[i])
# Judge status: Wrong Answer
l,r=map(int,input().split())

cnt=[]


for i in range(l,r+1):
  if i%2019!=0:
    for j in range(l,r+1):
      if j%2019>=0:
        a=(l*(l+1)%2019)
        cnt.append(a)
        break
      else:
        a=(j*(j-1)%2019)
        cnt.appnd(a)
        break
print(min(cnt))
# Judge status: Accepted
import math

N, D = list(map(int, input().split()))
ans = 0
for _ in range(N):
	x, y = list(map(int, input().split()))
	d = math.sqrt(x ** 2 + y ** 2)
	if D >= d:
		ans += 1
print(ans)
# Judge status: Wrong Answer
i=int(input())
if(i==7 or i==5 or i==3):
    print("YES")
else:
    print("No")
# Judge status: Wrong Answer
N = int(input())
answer = 0
for x in range(1, 100000):
  if x ** 2 <= N:
    answer = x
  else:
    break
print(answer)
# Judge status: Wrong Answer
n = int(input())
a = [int(input()) for i in range(n)]

t = 1
while a.count(-1) <= n:
    t = a[t-1]
    a[t-1] = -1
    
#    print(t)
#    print(a)
    if t == -1:
        break
    elif t == 2:
        break

if a.count(-1) >= n:
    print(-1)
else:
    print(a.count(-1))
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
print('YNEOS'[a-b!=c-b::2])
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

if N == 0 and A[0] != 1:
  print(-1)
elif N != 0 and A[0] != 0:
  print(-1)
else:
  ans = 1
  nodes = 1
  preF = 0
  sucF = sum(A)
  
  for d in range(1, N+1):
    fol = A[d]
    nodes = min((nodes-preF)*2, sucF)
    
    if nodes < fol:
      print(-1)
      exit()
    
    ans += nodes
    preF = fol
    sucF -= fol
  print(ans)
# Judge status: Accepted
n,k=map(int,input().split())
if n%k==0:
    ans=0
else:
    ans=1
print(ans)
# Judge status: Accepted
import sys
N = int(input())
A = list(map(int,input().split()))
res = dict()
for key in A:
  if key not in res:
    res[key] = 0
  res[key] += 1
  if res[key] >= 2:
    print('NO')
    sys.exit(0)
print('YES')
# Judge status: Accepted
N=int(input())

print(0 if N%1000==0 else 1000-N%1000)
# Judge status: Accepted
S = input()
K = int(input())
last = "1"
ind = 100
for i,s in enumerate(S):
    if s != "1":
        last = s
        ind = i
        break
if K-1 < ind:
    print("1")
else:
    print(last)
# Judge status: Accepted
S = [*input()]
T = [*input()]

if S == T:
    print("Yes")
    exit()
for i in range(len(S) - 1):
    s = [S[-1], *S[:-1]]
    if s == T:
        print("Yes")
        exit()
    S = s[:]    
print("No")
# Judge status: Wrong Answer
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    total_length = sum(a_list)

    accum_length = 0
    for a in a_list:
        accum_length += a
        if 2 * accum_length >= total_length:
            ans = 2 * accum_length - total_length
            break

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
import sys

S = input()
T = input()

d_T = {}
d_S = {}

for i in range(len(S)):
    if T[i] in d_T and d_T[T[i]]!=S[i]:
        print("No")
        sys.exit()
    d_T[T[i]] = S[i]

for i in range(len(T)):
    if S[i] in d_S and d_S[S[i]]!=T[i]:
        print("No")
        sys.exit()
    d_S[S[i]] = T[i]


print("Yes")
# Judge status: Wrong Answer
n, m = map(int, input().split())

print((n-2)*(m-2))
# Judge status: Wrong Answer
# 柱の高さ（aメートル,bメートル,cメートル）を整数で入力
a,b,c = map(int,input().split())
# b-aとc-bが同じなら美しい（Yes）、そうでなければNo
if  b - a == c - b:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())

buttons = [0] * 10**5

for i in range(n):
    buttons[i] = int(input())

next = 1
i = 0
while next != 2:
    i += 1
    next = buttons[next-1]
    if next == 2:
        print(i)
        exit()
    if i >= 10**5:
        print(-1)
        break
# Judge status: Accepted
N = input()
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n=int(input())
m=int(n)
cnt=int(0)
while m>9:
    m/=10
    cnt+=1
ans=m-1+cnt*9
Ans=int(0)
while n>0:
    Ans+=n%10
    n/=10
print(int(max(Ans,ans)))
# Judge status: Accepted
N = int(input())

s = 0
for i in range(1, N + 1):
    s += i
    if s >= N:
        tmp = i
        break

n = s - N

for i in range(1, n):
    print(i)

for i in range(n + 1, tmp + 1):
    print(i)
# Judge status: Accepted
N=int(input())
S=input()
use=[0 if S[i]=="." else 1 for i in range(N)]
now=[0 for i in range(N)]
count=sum(use)
lst=set()
lst.add(count)


for i in range(N-1,-1,-1):
    now[i]=1
    if use[i]:
        use[i]=0
        count-=1
    else:
        use[i]=1
        count+=1
    lst.add(count)
print(min(lst))
# Judge status: Accepted
N, M = map(int, input().split())

if N == 1 and M == 1:
    print(1)
elif M == 1:
    print(N-2)
elif N == 1:
    print(M-2)
else:
    print((N-2)*(M-2))
# Judge status: Wrong Answer
from sys import exit
X, Y = map(int,input().split())
if X % Y == 0 or Y % X == 0: pass
else:
  for i in range(10 ** 18 + 1):
    if i % X == 0 and i % Y != 0:
      print(i)
      exit()
print(-1)
# Judge status: Accepted
import math
def prime(g):
    l = []
    p = 2
    while p * p <= g:
        if g % p != 0:
            p += 1
            continue
        while g % p == 0:
            g //= p
        l.append(p)
        p += 1
    if g != 1:
        l.append(g)
    return len(l)

a, b = map(int, input().split())
g = math.gcd(a, b)
print(prime(g) + 1)
# Judge status: Accepted
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
minv = min(A) + min(B)
for i in range(m):
	x, y, c = map(int, input().split())
	x -= 1
	y -= 1
	minv = min(minv, A[x] + B[y] - c)
print(minv)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
ans=[]
b=a.copy()
del b[0]
a1=0
for i in b:
    a1=a1^i
ans.append(a1)
for i in b:
    ansi=a1^i
    ans.append(ansi)

for i in range(n):
    print(ans[i],end=' ')
# Judge status: Wrong Answer
s=input()
s=list(s)
print("X"*len(s))
# Judge status: Accepted
a,b,c,X,Y=map(int,input().split())

s=min(X,Y)
t=max(X,Y)

ans1=2*c*s+a*(X-s)+b*(Y-s)
ans2=a*X+b*Y
ans3=2*c*t

print(min(ans1,ans2,ans3))
# Judge status: Accepted
n = int(input())
a_list = list(map(int, input().split()))
ans = 0
wait_for = 1
for a in a_list:
    if a == wait_for:
        wait_for += 1
    else:
        ans += 1
if wait_for == 1:
    print(-1)
else:
    print(ans)
# Judge status: Wrong Answer
l, r = list(map(int,input().split()))

mins = 10**9
for i in range(l, r):
  mins = min( (i * (i+1))%2019, mins)
  if mins == 0:
    break
    
print(mins)