Buggy python submission (verdict: Runtime Error):
from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

s = raw_input()
t = raw_input()

p = []
for i in range(26):
	p.append([])

for i in range(len(s)):
	p[ord(s[i]) - 97].append(i)

mn = 10**5 + 1
ans = 0
for i in range(len(t)):
	if p[ord(t[i]) - 97] == []:
		print -1
		break
	else:
		print p[ord(t[i]) - 97],mn
		if p[ord(t[i]) - 97][-1] <= mn:
			mn = p[ord(t[i]) - 97][0]
			ans += len(s)
			print ans
		else:
			mn = p[ord(t[i]) - 97][0]
# print p
print ans - len(s) + (p[ord(t[i]) - 97][-1] + 1) 

Fixed submission:
from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

alphabet = [chr(x) for x in range(ord('a'), ord('z')+1)]
alnum = lambda x: ord(x) - ord('a')


def next(i, n):
	return (i+1) % n
def prev(i, n):
	return (i-1+n) % n

def next_arr(ch, a):
	n = len(a)
	i = a.find(ch)
	if i == -1:
		return [-1] * n
	ret = [-1] * n
	while ret[prev(i,n)] == -1:
		if a[i] == ch:
			ret[prev(i,n)] = i
		else:
			ret[prev(i,n)] = ret[i]
		i = prev(i,n)
	return ret

a = raw_input()
b = raw_input()
n = len(a)

next_ = [next_arr(alphabet[i], a) for i in range(26)]
ptr = -1
ans = 0
for ch in b:
	old_ptr = ptr
	ptr = next_[alnum(ch)][ptr]
	if ptr == -1:
		print -1
		exit()
	if ptr <= old_ptr:
		ans += n
print ans+ptr+1

Buggy python submission (verdict: Runtime Error):
from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

s = raw_input()
t = raw_input()

p = []
for i in range(26):
	p.append([])

for i in range(len(s)):
	p[ord(s[i]) - 97].append(i)

mn = 10**5 + 1
ans = 0
for i in range(len(t)):
	if p[ord(t[i]) - 97] == []:
		print -1
		break
	else:
		if p[ord(t[i]) - 97][-1] <= mn:
			mn = p[ord(t[i]) - 97][0]
			ans += len(s)
# print p
print ans - len(s) + (p[ord(t[i]) - 97][-1] + 1) 

Fixed submission:
from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

alphabet = [chr(x) for x in range(ord('a'), ord('z')+1)]
alnum = lambda x: ord(x) - ord('a')


def next(i, n):
	return (i+1) % n
def prev(i, n):
	return (i-1+n) % n

def next_arr(ch, a):
	n = len(a)
	i = a.find(ch)
	if i == -1:
		return [-1] * n
	ret = [-1] * n
	while ret[prev(i,n)] == -1:
		if a[i] == ch:
			ret[prev(i,n)] = i
		else:
			ret[prev(i,n)] = ret[i]
		i = prev(i,n)
	return ret

a = raw_input()
b = raw_input()
n = len(a)

next_ = [next_arr(alphabet[i], a) for i in range(26)]
ptr = -1
ans = 0
for ch in b:
	old_ptr = ptr
	ptr = next_[alnum(ch)][ptr]
	if ptr == -1:
		print -1
		exit()
	if ptr <= old_ptr:
		ans += n
print ans+ptr+1

Buggy python submission (verdict: Runtime Error):
from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

s = raw_input()
t = raw_input()

p = []
for i in range(26):
	p.append([])

for i in range(len(s)):
	p[ord(s[i]) - 97].append(i)

mn = 10**5 + 1
ans = 0
for i in range(len(t)):
	if p[ord(t[i]) - 97] == []:
		print -1
		break
	else:
		if p[ord(t[i]) - 97][-1] <= mn:
			mn = p[ord(t[i]) - 97][0]
			ans += len(s)
# print p
print ans - len(s) + (p[ord(t[i]) - 97][-1] + 1) 

Fixed submission:
from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

alphabet = [chr(x) for x in range(ord('a'), ord('z')+1)]
alnum = lambda x: ord(x) - ord('a')


def next(i, n):
	return (i+1) % n
def prev(i, n):
	return (i-1+n) % n

def next_arr(ch, a):
	n = len(a)
	i = a.find(ch)
	if i == -1:
		return [-1] * n
	ret = [-1] * n
	while ret[prev(i,n)] == -1:
		if a[i] == ch:
			ret[prev(i,n)] = i
		else:
			ret[prev(i,n)] = ret[i]
		i = prev(i,n)
	return ret

a = raw_input()
b = raw_input()
n = len(a)

next_ = [next_arr(alphabet[i], a) for i in range(26)]
ptr = -1
ans = 0
for ch in b:
	old_ptr = ptr
	ptr = next_[alnum(ch)][ptr]
	if ptr == -1:
		print -1
		exit()
	if ptr <= old_ptr:
		ans += n
print ans+ptr+1