Problem:


Score : 200 points

Problem Statement

Given are two strings S and T.

Let us change some of the characters in S so that T will be a substring of S.

At least how many characters do we need to change?

Here, a substring is a consecutive subsequence. For example, xxx is a substring of yxxxy, but not a substring of xxyxx.

Constraints

The lengths of S and T are each at least 1 and at most 1000.

The length of T is at most that of S.

S and T consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the minimum number of characters in S that need to be changed.

Sample Input 1

cabacc
abc

Sample Output 1

1

For example, changing the fourth character a in S to c will match the second through fourth characters in S to T.

Since S itself does not have T as its substring, this number of changes - one - is the minimum needed.

Sample Input 2

codeforces
atcoder

Sample Output 2

6



Sample input:
cabacc
abc


Sample output:
1

Submission status: Accepted

Solution code:
import difflib
import math

S = input()
T = input()

same = 0
for i in range(len(S) - len(T)+1):
    tmp_same = 0
    for j in range(len(T)):
        if S[i+j] == T[j] :
            tmp_same += 1
    if tmp_same > same:
        same = tmp_same


print(len(T) - same)

Submission status: Accepted

Solution code:
S=input()
T=input()
lenS=len(S)
lenT=len(T)
lendiff=lenS-lenT
ans=lenT
for i in range(lendiff+1):
    cost=lenT
    for j in range(lenT):
        if T[j]==S[i+j]:
            cost-=1
    ans=min(ans,cost)
print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
n = len(t)
sl = len(s)
mmax= 0
for i in range(sl):
    cnt=0
    for y in range(n):
        #print(s[i+y],t[y])
        if i+y>=sl:
            cnt=0
            break
        if s[i+y]==t[y]:
            cnt+=1
    mmax = max(mmax,cnt)
print(n-mmax)

Submission status: Accepted

Solution code:
def matchCount(str1, str2):
  r = len(str1)
  for idx in range(0, len(str1)):
    if str1[idx] == str2[idx]:
      r -= 1
  return r

s=input()
t=input()
slength = len(s)
tlength = len(t)
r = slength

for idx in range(0, slength - tlength + 1):
  ss = s[idx:idx + tlength]
  rr = matchCount(ss,t)
  if rr < r:
    r = rr
print(r)

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())

ans = []


for i in range(len(S)-len(T)+1):
    diff = 0
    for j in range(len(T)):
        if S[i:i+len(T)][j] == T[j]:
            pass
        else:
            diff += 1
    ans.append(diff)
    

print(min(ans))

Submission status: Accepted

Solution code:
S = input()
T = input()

cand = []
for start in range(len(S) - len(T) + 1):
    cnt = sum([not T[i] == S[start:start+len(T)][i] for i in range(len(T))])
    cand.append(cnt)

print(min(cand))

Submission status: Accepted

Solution code:
S = input()
T = input()
c = 0
l = []
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if (T[j] != S[i+j]):
            c += 1       
    l.append(c)
    c = 0
#print(l)
print(min(l))

Submission status: Accepted

Solution code:
S,T=open(0).read().split()
n=len(T)
def diff(a,b):
    d=0
    for i in range(n):
        if a[i]!=b[i]:
            d+=1
    return d
dmin=1000
for i in range(len(S)-n+1):
    dmin=min(dmin,diff(S[i:],T))
print(dmin)

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()
t = input()

ans = 10**5

len_s = len(s)
len_t = len(t)

S = []

for i in range(len_s):
    S.append(s[i])

for i in range(len_s - len_t+1):
    tmp = 0
    ss = S[i:i+len_t]
    for j in range(len_t):
        if t[j] != ss[j]:
            tmp += 1
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
ans=0
for i in range(ls-lt+1):
  k=0
  for j in range(lt):
    if s[i+j]==t[j]:k+=1
  ans=max(ans,k)
print(lt-ans)

Submission status: Accepted

Solution code:
import sys
s=input()
t=input()
n=10**5
k=0
h=[]
for i in range(len(s)-len(t)+1):
    h=s[i:i+len(t)]
    l=0
    for j in range(len(t)):
        if h[j]!=t[j]:
            l+=1
    n=min(n,l)
print(n)

Submission status: Accepted

Solution code:
S= input()
T= input()
s=len(S)
t=len(T)
a=0
for i in range(s-t+1):
    cnt=0
    for j in range(t):
        if S[i+j]==T[j]:
            cnt=cnt+1
    if cnt>a:
        a=cnt
print(t-a)

Submission status: Accepted

Solution code:
s=input()
t=input()
n=len(s)
m=len(t)
r=m
for i in range(n-m+1):
    c=0
    for j in range(m):
        if s[i+j]!=t[j]:
            c+=1
    r=min(r,c)
print(r)

Submission status: Accepted

Solution code:
S = str(input())
T = str(input())
count = 0
max_count = 0

for i in range(len(S)-len(T)+1):
    nowS = S[i:i+len(T)]
    for j in range(len(T)):
        if nowS[j] == T[j]:
            count += 1
    max_count = max(max_count, count)
    count = 0
print(len(T) - max_count)

Submission status: Accepted

Solution code:
import sys
s = input()
t = input()
ans = 0
for i in range(len(s)- len(t) + 1):
    cnt = 0
    for j in range(len(t)):
        if t[j] == s[i+j]:
            cnt += 1
    ans = max(ans,cnt)
print(len(t)-ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
s=list(s)
t=list(t)
d=[]
c=0
if len(s)==len(t):
    for j in range(len(t)):
        if s[j]!=t[j]:
            c+=1
    d.append(c)
else:
    for i in range(len(s)-len(t)):
        c=0
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                c+=1
        d.append(c)
print(min(d))

Submission status: Accepted

Solution code:
s = input()
t = input()
u = t
ans =0
count=0
maxans=0
if len(s) == len(t):
    for j in range(len(t)):
        if s[j] == t[j]:
            count+=1
    maxans = count
else:
    for i in range(len(s)-len(t)):
        count =0
        for j in range(len(t)):
            if s[j+i] == t[j]:
                count+=1
        maxans = max(maxans, count)

print(len(t)-maxans)

Submission status: Accepted

Solution code:
s = input()
t = input()
n = len(s) - len(t) + 1
ans = len(t)
for i in range(n):
    temp = 0
    for j in range(len(t)):
        if t[j] != s[j+i]:
            temp += 1
    ans = min(temp,ans)
print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
ans=1000000000
for i in range(len(s)-len(t)+1):
    cnt=0
    for j in range(len(t)):
        if t[j]!=s[i+j]:
            cnt+=1
    if cnt<ans:
        ans=cnt
print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()

s = ''.join(s)
t = ''.join(t)


count = 0
maxcount = 0
slen = len(s)
tlen = len(t)
j = 0

while j <= slen-tlen:
    k = j
    for i in range(tlen):
        if t[i] == s[k]:
            count += 1
        k+= 1
    j += 1
    if count > maxcount :
        maxcount = count
    count = 0
print(len(t)-maxcount)

Submission status: Accepted

Solution code:
s = input()
t = input()

maxi = 0

for i in range(0, len(s)-len(t)+1):
    temp = 0
    for j in range(len(t)):
        if s[i+j] == t[j]:
            temp += 1
    maxi = max(temp, maxi)

print(len(t) - maxi)

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = input()
    answer = solve(S, T)
    print(answer)


def solve(S, T):
    min_diff_cnt = len(T)
    for i in range(len(S) - len(T) + 1):
        s = S[i:i+len(T)]
        diff = [(x, y) for x, y in zip(list(s), list(T)) if x != y]
        diff_cnt = len(diff)
        if diff_cnt < min_diff_cnt:
            min_diff_cnt = diff_cnt

    return min_diff_cnt

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
T = input()
ans = len(T)

for i in range(len(S)-len(T)+1):
  s = S[i:i+len(T)]
  tmp = 0
  for j in range(len(T)):
    if s[j] != T[j]:
      tmp += 1
  ans = min(ans, tmp)
  
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()

chageCountMin = len(T)

for i,_ in enumerate(S[:len(S) if len(T) == 1 else -len(T) + 1:]):
	changeCount = 0
	for j,_ in enumerate(T):
		if S[i + j] != T[j]:
			changeCount+=1
	chageCountMin = min(chageCountMin,changeCount)
print(chageCountMin)


#D,T,S = map(int,input().split())
#print('Yes' if D <= T * S else 'No')
#N = int(input())
#A = list(map(int,input().split()))
#Q = int(input())
#B = [0] * Q
#C = [0] * Q

#ans = []

#Adic = {}
#sum = 0
#for n in range(N):
#	sum += A[n]
#	if not A[n] in Adic:
#		Adic[A[n]] = 1
#	else:
#		Adic[A[n]] +=1

#for i in range(Q):
#	B,C = map(int,input().split())
#	if B in Adic:
#		sum = sum - B * Adic[B] + C * Adic[B]
		
#		if C in Adic :
#			Adic[C] += Adic[B]
#		else:
#			Adic[C] = Adic[B]
#		Adic.pop(B)

#	ans.append(sum)

#for a in ans:
#	print(a)



#N = int(input())
#ans = []
#while(N != 0):
#	N -=1
#	ans.append(N % 26)
#	N = N // 26
#ans_str = ''
#for i in range(len(ans)):
#	ans_str+=chr(97 + ans[len(ans) - i - 1])
#print(ans_str)

#N,K = map(int,input().split())
#p = list(map(int,input().split()))
#p.sort()

#print(sum(p[:K]))




#a = input()

#print('a' if a.islower() else 'A')


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

##Adic = {}

##for i in range(N):
##	Adic[A[i]] = i + 1

#Asorted = sorted(A)
#divlist = []
#dup = [x for x in set(Asorted) if Asorted.count(x) > 1]
#Asorterd = set(Asorted)

#count = 0
#for i in range(len(Asorted)):
#	divflag = False
#	#for j in range(i):
#	for div in divlist:
#		#if Asorted[i] % Asorted[i - j - 1] == 0:
#		if Asorted[i] % div == 0:
#			divflag = True
#			break
#	if divflag == False:
#		divlist.append(Asorted[i])

#print(len(set(divlist)-set(dup)))

#X,N = map(int,input().split())
#if N == 0:
#	print(X)
#	exit()

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

#P.sort()
#for i in range(N):
#	if P[i] > X:
#		print(X)
#		break
#	elif P[i] == X:
#		#下に
#		under = X
#		underflag = False
#		upper = X
#		upperflag = False
#		for j in range(i):
#			if P[i - j - 1] != X - j - 1:
#				under = X - j - 1
#				underflag = True
#				break
#		if underflag == False:
#			under = P[0] - 1

#		for j in range(N - i - 1):
#			if P[i + j + 1] != X + j + 1:
#				upper = X + j + 1
#				upperflag = True
#				break
#		if upperflag == False:
#			upper = P[N - 1] + 1
#		print(under if abs(X - under) <= abs(X - upper) else upper)
#		break



#X,Y = map(int,input().split())
#flag = False

#for i in range(X + 1):
#	if 2 * (i) + 4 * (X - i) == Y:
#		flag = True

#print('Yes' if flag else 'No')




#x = list(map(int, input().split()))

#for i in range(1,6):
#	if x[i - 1] == 0:
#		print(i)
#		break

#def prime_factorize(n):
#    a = []
#    while n % 2 == 0:
#        a.append(2)
#        n //= 2
#    f = 3
#    while f * f <= n:
#        if n % f == 0:
#            a.append(f)
#            n //= f
#        else:
#            f += 2
#    if n != 1:
#        a.append(n)
#    return a

#import collections

#N = int(input())
#A = collections.Counter(prime_factorize(N))

#ans = 0
#for a in A.values():
#	b = 1
#	c = 1
#	while True:
#		if b > a:
#			break
#		c+=1
#		b = b + c
#	ans+=c-1
#print(ans)




#import math

#A,B = input().split()



#C = int(int(A) * float(B) * 100)


#print(C // 100)

#N = int(input())
#As = list(map(int,input().split()))

#sum = 1

#if any(b == 0 for b in As):
#	sum = 0
#else:
#	for a in As:
#		sum*=a
#		if sum > 1000000000000000000:
#			sum = -1
#			break
#print(sum)


#A,B=map(int,input().split())

Submission status: Accepted

Solution code:
s = input()
t = input()
minDiff = 1001

for i in range(len(s) - len(t) + 1):
    cnt = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            cnt += 1
    if cnt < minDiff:
        minDiff = cnt
print(minDiff)

Submission status: Accepted

Solution code:
S = input()
T = input()

ans = 0
ans2 = 10000

for i in range(len(S)-len(T)+1):
    tmp = S[i:i+len(T)]
    ans = 0
    for j in range(len(T)):
        if tmp[j] != T[j]:
            ans += 1
    ans2 = min(ans,ans2)
            
print(ans2)

Submission status: Accepted

Solution code:
S = str(input())
T = str(input())

max_equal_count = 0

for i in range(len(S) - len(T) + 1):
    equal_count = 0
    
    for j in range(len(T)):
        if S[i + j] == T[j]:
            equal_count = equal_count + 1

    if max_equal_count < equal_count:
        max_equal_count = equal_count

print(len(T) - max_equal_count)

Submission status: Accepted

Solution code:
s = input()
t = input()
best = len(t)
for i in range(len(s) - len(t) + 1):
    sub = s[i:i+len(t)]
    score = sum(x!=y for x,y in zip(sub,t))
    if score < best: best = score
print(best)

Submission status: Accepted

Solution code:
s = input()
t = input()

ans = float("inf")

for i in range(len(s) - len(t) + 1):
    num = 0
    for j in range(len(t)):
        if s[i + j] == t[j]:
            continue
        else:
            num += 1

    ans = min(ans, num)

print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
n = len(s)
m = len(t)

ans = 10000

for i in range(n-m+1):
    rem = 0
    for j in range(m):
        if(s[i+j] != t[j]):
            rem += 1
    ans = min(rem, ans)
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
ev = []
for i in range(len(S) - len(T) + 1):
  commit = 0
  for j in range(len(T)):
    if S[i + j] == T[j]:
      commit += 1
  ev.append(commit)

ev.sort(reverse=True)
print(len(T) - ev[0])

Submission status: Accepted

Solution code:
# def partial_match_table(word):
#     table = [0] * (len(word) + 1)
#     table[0] = -1
#     i, j = 0, 1

#     while j < len(word):
#         matched = word[i] == word[j]

#         if not matched and i > 0:
#             i = table[i]
#         else:
#             if matched:
#                 i += 1
#             j += 1
#             table[j] = i

#     return table


# def kmp_search(text, word):
#     table = partial_match_table(word)
#     i, p = 0, 0

#     while i < len(text) and p < len(word):
#         if text[i] == word[p]:
#             i += 1
#             p += 1
#         elif p == 0:
#             i += 1
#         else:
#             p = table[p]

#     return (-1, i - p)[p == len(word)]


def match(s, t):
    ret = 0
    assert len(s) == len(t), (s, t)
    for i in range(len(s)):
        if s[i] == t[i]:
            ret += 1
    return ret


def main():
    s = input()
    t = input()
    ret = 1001

    for i in range(len(s)-len(t)+1):
        _ret = len(t) - match(s[i:i + len(t)], t)

        if ret > _ret:
            ret = _ret

    print(ret)


    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
t = input()

slist = list(s)
tlist = list(t)
ans = 0
for i in range(len(slist)-len(tlist)+1):
    
    num = 0
    for k in range(len(tlist)):
        if slist[i+k] == tlist[k]:
            num += 1
    if num >= ans:
        ans = num
print(len(tlist)-ans)

Submission status: Accepted

Solution code:
import sys 
def minimumChar(S1, S2): 
    n, m = len(S1), len(S2) 
    ans = sys.maxsize 
    for i in range(m - n + 1): 
        minRemovedChar = 0
        for j in range(n): 
            if (S1[j] != S2[i + j]): 
                minRemovedChar += 1
        ans = min(minRemovedChar, ans) 
    return ans 

s = input()
t = input()
print(minimumChar(t,s))

Submission status: Accepted

Solution code:
s = input()
t = input()
l = []
for i in range(len(s)-len(t)+1):
    s2 = s[i:]
    cnt = 0
    for j in range(len(t)):
        if s2[j] == t[j]:
            cnt += 1
    l.append(cnt)
print(len(t)-max(l))

Submission status: Accepted

Solution code:
S = input()
T = input()
list_a = []
if len(S) - len(T) ==0:
    cnt = 0
    for j in range(len(T)):
        if T[j] != S[j]:
            cnt += 1
    list_a.append(cnt)
else:
    for i in range(len(S) - len(T)):
        cnt = 0
        for j in range(len(T)):
            if T[j] != S[i + j]:
                cnt += 1
        list_a.append(cnt)
print(min(list_a))

Submission status: Accepted

Solution code:
S = input()
T = input()

N = len(T)

if (T in S):
    print(0)
    exit(0)

min_change = N
for i in range(len(S) - N+1):
    S_part = S[i:i + N]

    change = N
    for j in range(N):
        if (S_part[j] == T[j]):
            change = change - 1

    if (change < min_change):
        min_change = change

print(min_change)

Submission status: Accepted

Solution code:
import sys
S=sys.stdin.readline().strip()
T=sys.stdin.readline().strip()

ans=float("inf")
for i in range(len(S)-len(T)+1):
    temp_ans=0
    for s,t in zip(S[i:],T):
        if s!=t:
            temp_ans+=1
    ans=min(ans,temp_ans)
print ans

Submission status: Accepted

Solution code:
S = input()
T = input()
m = len(T)
for i in range(len(S)-len(T)+1):
    s = S[i:len(T)+i]
    d = 0
    for j in range(len(T)):
        if s[j] != T[j]:
            d += 1
    m = min(m, d)
print(m)

Submission status: Accepted

Solution code:
S = input().rstrip()
T = input().rstrip()
count = 0
lens = len(S)
lent = len(T)
for i in range(lens-lent+1):
    tempcount=0
    for j in range(lent):
        if S[i+j]==T[j]:
            tempcount += 1
    #print(tempcount)
    count = max(count,tempcount)

print(lent-count)

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())
ans=len(t)
for i in range(len(s)-len(t)+1):
  x=0
  for j in range(len(t)):
    if s[i+j]!=t[j]:
      x+=1
  if ans>x:
    ans=x
print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
l = len(t)
ans = 0
a = 0
list1 = [0]
for i in range(len(s) - l + 1):
  ss = list(s[i:i+l])
  for j in range(l):
    if ss[j] ==t[j]:
      ans += 1
      list1.append(ans)
    else:
      pass
  ans = 0
m =  max(list1)
print(l-m)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def cout_dif(a, b):
    sum = 0
    for i in range(len(a)):
        if a[i] != b[i]:
            sum += 1
    return sum
    
def main():
    s = input()
    t = input()
    min = 10**5
    for i in range(len(s)-len(t)+1):
        sum = cout_dif(t, s[i:i+len(t)])
        if sum < min:
            min = sum
    print(min)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
t = input()
n = int(len(s)) - int(len(t)) + 1
kari = []

for i in range(n):
    kari.append(s[i:i+int(len(t))])

ans = []
n_2 = int(len(t))
for j in kari:
    t_2 = 0
    for k in range(n_2):
        if j[k] == t[k]:
            t_2 += 1
    ans.append(n_2-t_2)

print(min(ans))

Submission status: Accepted

Solution code:
s = input()
t = input()

slen = len(s)
tlen = len(t)
arr = []
upto = slen - tlen + 1 

for i in range(upto):
    c = (s[i:i+tlen])
    d = 0
    for j in range(tlen):
        if t[j] != c[j]:
            d += 1
    arr.append(d)
    
print(min(arr))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

s = input().strip()
t = input().strip()

sn = np.array([ord(a) for a in s])
tn = np.array([ord(a) for a in t])
mi = 1000
if t in s:
    print(0)

else:
    l = len(tn)
    for i in range(len(sn)-l+1):
        tt = sn[i:i+l] -tn
        mi = min(len(np.nonzero(tt)[0]), mi)
    print(mi)

Submission status: Accepted

Solution code:
S = input()
T = input()
cnt = len(S)-len(T)+1
res = []
for i in range(cnt):
    res2 = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            res2 += 1
    res.append(res2)
print(min(res))

Submission status: Accepted

Solution code:
S = input()
T = input()
ans = len(T)
for i in range(0, len(S)-len(T)+1):
    cnt = len(T)
    for j in range(len(T)):
        if S[i+j] == T[j]:
            cnt -= 1
    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
def main():
  S = list(input())
  T = list(input())
  
  l_S = len(S)
  l_T = len(T)
  
  best = l_S
  
  for i in range(l_S - l_T + 1):
    X = S[i : i + l_T]
    count = l_T
    for j, y in enumerate(X):
      if T[j] == y:
        count -= 1
    if best > count:
      best = count
    
  print(best)
    
main()

Submission status: Accepted

Solution code:
s = input()
t = input()

x = 0
y = 0

answer = 0

for i in range(0,len(s) - len(t) + 1):
    count = 0
    for j in range(0, len(t)):
        if s[i+j] == t[j]:
            count += 1
    answer = max(count, answer)

print(len(t) - answer)

Submission status: Accepted

Solution code:
s = input()
t = input()
ans = 0
for i in range(len(s)-len(t)+1):
    count = 0
    for j in range(len(t)):
        if t[j] == s[j+i]:
            count += 1
    ans = max(ans, count)
print(len(t) - ans)

Submission status: Accepted

Solution code:
s = input().strip()
t = input().strip()

if t in s:
    print(0)
else:
    ans = 10001
    for i in range(len(s) - len(t) + 1):
        count = 0
        cnt = i
        for j in range(len(t)):
            if s[cnt] != t[j]:
                count += 1
            cnt += 1
        ans = min(count, ans)
    print(ans)

Submission status: Accepted

Solution code:
s,t = raw_input(),raw_input()
m = len(t)

def f(s,t):
	if len(s) < len(t):
		return +float('inf')
	c = 0
	for u,v in zip(s,t):
		if u != v:
			c+=1
	return c
for i in range(len(s)):
	m = min(m,f(s[i:i+len(t)],t))
print m

Submission status: Accepted

Solution code:
s = input()
t = input()
ratio = []
cnt = 0
if len(s) == len(t):
    for i in range(len(t)):
        if s[i] == t[i]:
            cnt += 1
    ratio.append(cnt)
else:
    for k in range(len(s) - len(t)):
        for i in range(len(t)):
            if s[i + k] == t[i]:
                cnt += 1
        ratio.append(cnt)
        cnt = 0
res = len(t) - max(ratio)
print(res)

Submission status: Accepted

Solution code:
S=input()
T=input()
a=int(len(S))
b=int(len(T))
count=0
c=0
if a==b:
    for j in range(b):
        if S[j]==T[j]:
            count+=1
    c=count
else:
    for i in range(a-b):
        for j in range(b):
            if S[i+j]==T[j]:
                count+=1
        if c<count:
            c=count
        count=0
print(b-c)

Submission status: Accepted

Solution code:
S=input()
T=input()
SL=len(S)
TL=len(T)

def match(x,y):
  c=0
  for i in range(TL):
    if x[i]==y[i]:
      c+=1
  return c

max_match=0
for j in range(SL-TL+1):
  m=match(S[j:],T)
  max_match=max(max_match,m)

print("{}".format(TL-max_match))

Submission status: Accepted

Solution code:
S = input()
T = input()

N = len(T)
count = 0
count_list = []
index_list = []

if len(S)-len(T) != 0:
    for i in range(len(S)-N+1):
        index_list.append(S[0+i:N+i])

    for i in range(len(index_list)):
        count = 0
        for j in range(N):
            if index_list[i][j] == T[j]:
                count +=1
        count_list.append(count)
                
    print(N - max(count_list))
else:
    for i in range(N):
        if S[i] == T[i]:
            count += 1
    print(N - count)

Submission status: Accepted

Solution code:
def check(a,b):
    cnt=0
    for x in range(len(a)):
        if a[x]!=b[x]:
            cnt+=1
    return cnt        
s=input()
t=input()
k=len(t)
ans=k
for x in range(len(s)-len(t)+1):
    ans=min(ans,check(s[x:x+k],t))
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


S = input()
T = input()


def n_rewrite(S, T):
    assert len(S) == len(T), (S, T)
    ret = 0
    for s, t in zip(S, T):
        if s != t:
            ret += 1
    return ret


ans = 10**9
for i in range(len(S) - len(T) + 1):
    ans = min(ans, n_rewrite(T, S[i:i + len(T)]))

print(ans)

Submission status: Accepted

Solution code:
s=input()
l=input()
a=len(l)
big=0
for i in range(len(s)-a+1):
    cnt=0

    for j in range(i,i+a):
        if s[j]==l[j-i]:
            cnt+=1
    if cnt>big:
        big=cnt
print(a-big)

Submission status: Accepted

Solution code:
def main():
    s = input()
    t = input()
    ans = 0
    substr = ''
    len_s = len(s)
    len_t = len(t)
    if t in s:
        print(0)
    else:
        for i in range(len_s - len_t + 1):
            substr = s[i: i + len_t]
            tmp = 0
            for sn, tn in zip(substr, t):
                if sn == tn:
                    tmp += 1
            ans = max(ans, tmp)
            if ans == len_t - 1:
                break
        print(len(t) - ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
T = input()
s = len(S)
t = len(T)
L = [""]*(s-t+2)
match = [0]*(s-t+1)


for p in range(s-t+1):
    for q in range(t):
        L[p] += S[p+q]

for r in range(s-t+1):
    for s in range(t):
        if L[r][s] == T[s]:
            match[r] += 1

print(t-max(match))

Submission status: Accepted

Solution code:
# = int(input())
# = str(input())
# = map(int, input().split())
S = list(input())
T = list(input())
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
lt = len(T)
ls = len(S)
count = []
for i in range(ls-lt+1):
    counter = 0
    for j in range(lt):
        if S[j] != T[j]:
            counter += 1
    count.append(counter)
    del S[0]

print(min(count))

Submission status: Accepted

Solution code:
s=input()
t=input()
ans=1500
for i in range(len(s)-len(t)+1):
	ssub=s[i:i+len(t)]
	cnt=0
	for j in range(len(t)):
		if(ssub[j]==t[j]):
			continue
		else:
			cnt+=1
	if(ans>cnt):
		ans=cnt
print(ans)

Submission status: Accepted

Solution code:
S=input()
T=input()
LS=len(S)
LT=len(T)
ans=0

for i in range(LS-LT+1):
    cnt=0
    kari=S[i:i+LT]
    for j in range(LT):
        if kari[j]==T[j]:
            cnt+=1
    #print(kari,cnt,ans)
    ans=max(cnt,ans)        

print(LT-ans)

Submission status: Accepted

Solution code:
import math
min = math.inf
S = input()
T = input()

len_t = len(T)
for s in range(0,len(S)-len_t+1):
    sub = S[s: s+len_t]
    diff = 0
    for i in range(len_t):
        if sub[i] != T[i]:
            diff += 1
            if diff > min:
                break
    else:
        if diff < min:
            min = diff
print(min)

Submission status: Accepted

Solution code:
S = input()
T = input()

result = len(T)
for i in range(len(S)-len(T)+1):
    n = 0
    for j in range(len(T)):
        if S[j+i] != T[j]:
            n += 1
    result = min(result, n)

print(result)

Submission status: Accepted

Solution code:
s = input()
t = input()
ans = 0
max = 0

if t in s:
  print(ans)
else:
  for i in range(len(s) - len(t) + 1):
    for j in range(len(t)):
      if t[j] == s[j + i]:
        ans += 1
    if max < ans:
        max = ans
    ans = 0
  print(len(t) - max)

Submission status: Accepted

Solution code:
#abc177_B_1
list_1 = list(str(input()))
list_2 = list(str(input()))

int_agg_count_max_diff = 10000
for i in range(len(list_1) - len(list_2) + 1):
  list_1_tmp = list_1[i:i+len(list_2)]
  
  int_count_max_diff = 0
  for j in range(len(list_2)):
    if list_1_tmp[j] != list_2[j]:
      int_count_max_diff = int_count_max_diff + 1
  if int_agg_count_max_diff > int_count_max_diff:
    int_agg_count_max_diff = int_count_max_diff
print(int_agg_count_max_diff)

Submission status: Accepted

Solution code:
s=input()
t=input()
n=len(s)
k=len(t)
l=[]
for i in range(n-k+1):
    count=0
    for j in range(k):
        if(s[i+j]!=t[j]):
            count+=1
    l.append(count)
print(min(l))

Submission status: Accepted

Solution code:
S = str(input())
T = str(input())

s_len = len(S)
t_len = len(T)

Ss = list(S)
Ts = list(T)

answer = 9999

for si in range(s_len):
    candidate = 0
    if si + t_len > s_len:
        continue

    for ti in range(t_len):
        if Ss[si + ti] != Ts[ti]:
            candidate += 1

    if candidate < answer:
        answer = candidate

print(answer)

Submission status: Accepted

Solution code:
S = input()
T = input()
ss = len(S)
tt = len(T)
a = tt
for r in range(ss - tt + 1):
    n = 0
    for x in range(tt):
        z = S[r:r+tt]
        if z[x] != T[x]:
            n += 1
    a = min(a, n)
print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 29 20:26:17 2020

@author: wiste
"""

S = list(input())
T = list(input())


cm = 0
for i in range(len(S) - len(T) + 1):
    c =0
    for j in range(len(T)):
        if S[i+j] == T[j]:
            c += 1
    cm = max(cm, c)

ans = len(T) - cm


print(ans)

Submission status: Accepted

Solution code:
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
    S = s_input()
    T = s_input()

    min = 100000
    for i in range(0,len(S)-len(T)+1):
        count = 0
        for j in range(0,len(T)):
            if(S[i+j] != T[j]):
                count=count+1
        if(count<=min):
            min = count


    print(min)

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
T = input()

ans = float("Inf")

len_s = len(S)
len_t = len(T)
for i in range(len_s-len_t+1):
    _ans = 0
    for j in range(len_t):
        if S[i+j] != T[j]:
            _ans += 1
    ans = min(ans, _ans)

print(ans)

Submission status: Accepted

Solution code:

def char_match(s,t,m):
    match = 0
    for i in range(m):
        if s[i] == t[i]:
            match += 1
    return match
def substring(S,T):
    m = len(T)
    char_mismatch = m
    for i in range(0,(len(S)-m) +1):
        char_mismatch = min(char_mismatch, m - char_match(S[i:i+m],T, m))
    return char_mismatch

def start():
    S = input()
    T = input()
    print(substring(S,T))
start()