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 sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *	
from heapq import *
from math import *
from itertools import permutations ,product
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
def inc(d,c):
	d[c]=d[c]+1 if c in d else 1
def bo(i):
	return ord(i)-ord('A')	
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0		
def gi():	
	return [xx for xx in input().split()]
def fi():
	return int(input())
def pro(a): 
	return reduce(lambda a,b:a*b,a)		
def swap(a,i,j): 
	a[i],a[j]=a[j],a[i]	
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())			
def gh():
	sys.stdout.flush()
def isvalid(i,j):
	return 0<=i<n and 0<=j<n	
def bo(i):
	return ord(i)-ord('a')	
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)


tt=1

while tt>0:
	tt-=1
	s=si()
	t=si()
	n=len(s)
	m=len(t)
	i=m-1
	mini=n	
	while i<n:
		c=0
		for j in range(0,m):
				if s[i-m+1+j]!=t[j]:
					c+=1
		mini=min(mini,c)
		i+=1		
	print(mini)

Submission status: Accepted

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

ret = len(T)


# burst force
for st in range(0, len(S)-len(T) + 1):

    diff = 0

    for idx in range(0, len(T)):
        if S[st + idx] != T[idx]:
            diff += 1

    ret = min(ret, diff)

print('{}'.format(ret))

Submission status: Accepted

Solution code:
import sys

def main():
    # input = sys.stdin.read()
    # data = list(map(int, input.split()))

    s = input()
    p = input()
    cnt = 0
    for i in range(len(s) - len(p)+1):
        mx = 0
        for j in range(len(p)):
            if s[i+j] == p[j]:
                mx += 1
            # print(i, mx)
        cnt = max(cnt, mx)

    # print(p,cnt)
    print(len(p)-cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# p = list(map(int, input().split()))
# a, b, c = map(int, input().split())
# n = int(input())
# s = input()
# print(i, end=" ")
s = input()
t = input()
ans = len(t)

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

    ans = min(ans, dif)
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
a = len(T)
for i in range(len(S)-len(T)+1):
    c = 0
    for j, t in enumerate(T):
        if S[i+j] != t:
            c += 1
    a = min(a, c)
print(a)

Submission status: Accepted

Solution code:
S= input()
T=input()
mi = 3000
for i in range(0,len(S)-len(T)+1):
    c = 0
    for j in range(0,len(T)):
        #print(S[i+j]+":"+T[j])
        
        if S[i+j] != T[j]:
            c += 1

        #print(c)
    if mi > c:
        mi = c
print(mi)

Submission status: Accepted

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

for i in range(len(s)):
    if i+len(t) > len(s):
        break
    u = s[i:i+len(t)]
    cnt = 0
    for j in range(len(t)):
        if t[j] != u[j]:
            cnt += 1
    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
n = len(s)
m = len(t)
ans = 2000
for i in range(n):
  if i+m > n:
    break
  u = s[i:i+m]
  cnt = 0
  for j in range(m):
    if t[j] != u[j]:
      cnt += 1
  ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

def Judge(S, T):
    ls = len(S)
    lt = len(T)
    m = 0
    for i in range(ls-lt+1):
        tmp = 0
        for j in range(lt):
            if S[i+j] == T[j]:
                tmp += 1
        if m < tmp:
            m = tmp
    return lt - m

S = input().strip()
T = input().strip()

print(Judge(S, T))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
s = len(S)
T = input()
t = len(T)

cnt = t
for i in range(s-t+1):
    dif = 0
    for j in range(t):
        if S[i+j] != T[j]:
            dif += 1
    if cnt > dif:
        cnt = dif
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def compare(t,s):
  diff=0
  assert len(t) == len(s)
  for i in range(len(s)):
    if s[i]!=t[i]:
      diff+=1
  return diff
 
t = input().strip()
s = input().strip()
smallchange = len(s)
assert len(t) >= len(s)
for i in range(len(t)-len(s)+1):
  x = compare(t[i:len(s)+i], s)
  if smallchange > x:
    smallchange = x
 
print(smallchange)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
max_=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
  max_ = max(max_, c)
print(len(t)-max_)

Submission status: Accepted

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

    len_s, len_t = len(s), len(t)
    num_iter = len_s - len_t + 1
    answer = len_t
    for i in range(num_iter):
        s_sub = s[i : i+len_t]
        count = 0
        for s_i, t_i in zip(s_sub, t):
            if s_i == t_i:
                count += 1
        answer = min(answer, len_t-count)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

s, t = len(S), len(T)
ans = s

for i in range(s-t+1):
    tmp = S[i:i+t]

    cnt = 0
    for i, j in zip(T, tmp):
        if i != j:
            cnt += 1

    ans = min(ans, cnt)

print(ans)

Submission status: Accepted

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

ans = int(10**10)
# 10**3文字以下なので、O(N**2)でも間に合う
for i in range(len(S) - len(T)+1):
    part = S[i:i+len(T)]
    #print(part, T)
    cnt = 0
    for j, c in enumerate(part):
        if T[j] != c:
            cnt += 1
    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

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

ans = 1000000
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 = min(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
def rewrite(s, t):
	
	min = len(t)

	for i in range(len(s) - len(t) + 1):
		count = 0
		for j in range(len(t)):
			if s[j + i] != t[j]:
				count  += 1
		
		if min > count:
			min = count

	return min


str_s = input()
str_t = input()
rewrite_word = rewrite(str_s, str_t)
print(rewrite_word)

Submission status: Accepted

Solution code:
from math import inf
class solution(object):
    def __init__(self, S: str, T:str) -> None:
        self.S = S
        self.T = T
    
    def solve(self)->int:
        ans = inf
        for i in range(0, len(self.S)-len(self.T)+1):
            temp = 0
            for j in range(0, len(self.T)):
                if(self.S[i+j]!=self.T[j]): temp+=1;
            ans = min(ans,temp)
        return ans

if __name__=='__main__':
    S = input()
    T = input()
    problem = solution(S,T)
    ans = problem.solve()
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
hoge=input()
huga=input()
ans=0
for i in range(len(hoge)+1-len(huga)):
  tmp_ans=0
  for j in range(len(huga)):
    if(hoge[i+j]==huga[j]):
      tmp_ans+=1
  ans=max(ans,tmp_ans)

print(len(huga)-ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
list = []

for i in range(len(s)-len(t)+1):
    n=0
    U = s[i:i + len(t)]
    for j in range(len(t)):
        if U[j] != t[j]:
            n+=1
    list.append(n)
print(min(list))

Submission status: Accepted

Solution code:
s=input()
t=input()
slen=len(s)
tlen=len(t)
min=tlen
def howdifferent(t1,t):
    count=0
    for i in range(len(t)):
        if t1[i]!=t[i]:
            count+=1
    return count
for i in range(slen-tlen+1):
    t1 = s[i:]
    if howdifferent(t1,t)<min:
        min = howdifferent(t1,t)
print(min)

Submission status: Accepted

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

tlen = len(t)
print(
  min(
    sum(1 for a, b in zip(s[i:i+tlen], t) if a != b)
    for i in range(0, len(s) - len(t) + 1)
  )
)

Submission status: Accepted

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

min_cnt = float("inf")
for i in range(len(S)-len(T)+1):
    cnt = 0
    dummy = S[i:i+len(T)]
    for j in range(len(dummy)):
        if dummy[j] != T[j]:
            cnt += 1
    if cnt < min_cnt:
        min_cnt = cnt
print(min_cnt)

Submission status: Accepted

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

lt = len(T)
ans = lt
for num in range(len(S) - lt + 1):
    s = S[num:num+lt]
    diff = 0
    for i in range(len(T)):
        if(T[i] != s[i]):
            diff += 1
    ans = min(ans, diff)

print(ans)

Submission status: Accepted

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

for i in range(len(s) - len(t) + 1):
    score = 0
    a = s[i : i + len(t) + 1]
    for j in range(len(t)):
        score += a[j] != t[j]
    ans = min(ans, score)

print(ans)

Submission status: Accepted

Solution code:

S = input()
T = input()

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

print(len(T) - count_max)

Submission status: Accepted

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

lens = len(s)
lent = len(t)

kotae = 1000
for i in range(lens-lent+1):
    temp = 0
    for j in range(lent):
        if(s[i+j] == t[j]):
            temp += 1
    kotae = min(kotae,lent-temp)

print(kotae)

Submission status: Accepted

Solution code:
a = input()
b = input()

arr = []
la = len(a)
lb = len(b)

for i in range(la-lb+1):
    c = a[i:i+lb] 
    cu = 0
    for j in range(lb):
        if c[j] != b[j]:
            cu += 1
    arr.append(cu)
    
print(min(arr))

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
n = len(s) - len(t) + 1

ans = len(t)
for i in range(n) :
  new_s = s[i:i+len(t)]
  k = 0
  for j in range(len(t)):
    if new_s[j] != t[j] :
      k += 1
  ans = min(ans,k)
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(len(S)-len(T)+1):
    tmp = 0
    pos = i
    for j in range(len(T)):
        if pos < len(S):
            if S[pos] == T[j]:
                tmp += 1
        pos += 1
    ans = max(tmp, ans)

print(len(T)-ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
ans = 10**10
for k in range(len(S)-len(T)+1):
    U = S[k:k+len(T)]
    temp = 0
    for l in range(len(T)):
        if U[l] != T[l]:
            temp += 1
    ans = min(temp,ans)
print(ans)

Submission status: Accepted

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

if T in S:
    print(0)
else:
    min = 1000
    for i in range(len(S)-len(T)+1):
        tmp = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                tmp += 1
        if tmp < min:
            min = tmp
    print(min)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(s, t):
    n = len(s)
    m = len(t)
    best = m
    for i in range(n-m+1):
        num = 0
        for j in range(m):
            if s[i+j] != t[j]:
                num += 1
        best = min(best, num)
    return best

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

Submission status: Accepted

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

res = len(t)

for i in range(len(s)-len(t)+1):
    tmp=len(t)
    for j in range(len(t)):
        if(s[i+j] == t[j]):
            tmp -= 1
    if res > tmp:
        res = tmp

print(res)

Submission status: Accepted

Solution code:

S = input()
T = input()

S_list = list(S)
T_list = list(T)
answer = 1000

for i in range(len(S_list)-len(T_list)+1):
    count = 0
    for j in range(len(T_list)):
        if(S_list[i+j] != T_list[j]):
            count +=1
    answer = min(count, answer)
print(answer)

Submission status: Accepted

Solution code:
from sys import stdin
inp = lambda : stdin.readline().strip()

s = inp()
t = inp()
ans = len(t)
for i in range(len(s)-len(t) + 1):
    curr = 0
    for i,j in zip(s[i:len(t)+i],t):
        if i == j:
            curr += 1
    ans = min(ans, len(t)- curr)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import math
inp = lambda : stdin.readline().strip()
 
s=inp()
t = inp()
ans = len(t)
for i in range(len(s)-len(t)+1):
    cur = len(t)
    for j in range(len(t)):
        if s[i+j] == t[j]:
            cur -= 1
    ans = min(ans, cur)
print(ans)

Submission status: Accepted

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

ans = len(S)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

s = input()
t = input()

ans = len(t)
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
    ans = min(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
def subst(S, T)-> int:
  lenT = len(T)
  result = lenT
  for i in range(lenT, len(S) + 1):
    tempS = S[i-lenT:i]
    tempResult = 0
    for j in range(lenT):
      if T[j] != tempS[j]:
        tempResult += 1
    if tempResult < result:
      result = tempResult
    
  return result

if __name__ == "__main__":
  S = input()
  T = input()
  print(subst(S, T))

Submission status: Accepted

Solution code:
def subst(S, T)-> int:
  lenT = len(T)
  result = lenT
  for i in range(len(S) - lenT + 1):
    # tempS = S[i-lenT:i]
    tempResult = 0
    for j in range(lenT):
      if T[j] != S[j + i]:
        tempResult += 1
    if tempResult < result:
      result = tempResult
    
  return result

if __name__ == "__main__":
  S = input()
  T = input()
  print(subst(S, T))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
T = input()
ct_f = len(T)
for i in range(len(S)-len(T)+1):
    ct = len(T)
    S_sub = S[i:i+len(T)]
    for j in range(len(T)):
        if S_sub[j] == T[j]:
            ct -= 1

    if ct_f > ct:
        ct_f = ct
        
print(ct_f)

Submission status: Accepted

Solution code:
S = input()
T = input()
lenS = len(S)
lenT = len(T)
lowest = lenT

for st in range(lenS-lenT+1):
    cnt = lenT
    for i in range(lenT):
        if S[st+i] == T[i]:
            cnt -= 1
    if cnt < lowest:
        lowest =cnt
print(lowest)

Submission status: Accepted

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

mc=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
    mc=max(c,mc)
print(len(t)-mc)

Submission status: Accepted

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

li = []
for i in range(len(s)-len(t)+1):
	count = 0
	for j in range(len(t)):
		if s[i+j] != t[j]:
			count += 1
	li.append(count)
print(min(li))

Submission status: Accepted

Solution code:
def check_same_sentence(big_str, small_str):
    num_b = len(big_str)
    num_s = len(small_str)
    ans = 0
    for i in range(num_b - num_s + 1):
        tmp = 0
        for j in range(num_s):
            if big_str[i+j] == small_str[j]:
                tmp += 1
        ans = max(ans, tmp)
    # 最大で何文字同じかを返す
    return ans

S = input()
T = input()

ans = check_same_sentence(S, T)
print(len(T)-ans)

Submission status: Accepted

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

ans=10**9
for i in range(len(s)-len(t)+1):
  ss=s[i:i+len(t)]
  t_ans=0
  for j in range(len(t)):
    if ss[j]!=t[j]:
      t_ans+=1
  ans=min(ans,t_ans)

print(ans)

Submission status: Accepted

Solution code:

s=input()
t=input()
ls=len(s)
lt=len(t)

min_change=lt
# print(min_change)

for i in range(0,ls-lt+1):
    if(True):
        d = 0
        for j in range(0,lt):
            if(s[i+j]!=t[j]):
                d+=1

        min_change=min(min_change,d)

print(min_change)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

st = []
for _ in range(2):
    st.append(input())
S=st[0]
T=st[1]

ans=len(T)

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

print(ans)

Submission status: Accepted

Solution code:
import sys; input = sys.stdin.readline
inf = int(1e10)
s = input().strip()
t = input().strip()
n, m = len(s), len(t)
minn = inf
for i in range(0, n-m+1):
	dis = 0
	for j in range(m):
		if s[i+j] != t[j]: dis += 1
	minn = min(minn, dis)
print(minn)

Submission status: Accepted

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

score = []
for i in range(len(S)-len(T)+1):
    U = S[i: i+len(T)]
    cnt = 0
    for j in range(len(T)):
        if U[j] != T[j]:
            cnt = cnt + 1
    score.append(cnt)
print(min(score))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

@mt
def slv(S, T):
    ans = INF
    for i in range(len(S)-len(T)+1):
        t = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                t += 1
        ans = min(ans, t)

    return ans


def main():
    S = read_str()
    T = read_str()
    print(slv(S, T))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
"""
https://atcoder.jp/contests/abc177/tasks/abc177_b
"""

def solve(s, t):
    def calc_diff_words(s0, s1):
        cnt = 0
        for w0, w1 in zip(s0, s1):
            if w0 != w1:
                cnt += 1
        return cnt

    def extract_sub(s, t, i):
        return s[i:i + len(t)]

    min = len(s)
    for i in range(len(s) - len(t) + 1):
        ss = extract_sub(s, t, i)
        dw = calc_diff_words(ss, t)
        if dw < min:
            min = dw

    return min

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

Submission status: Accepted

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

S_len = len(S)
T_len = len(T)

ans = T_len

for i in range(S_len - T_len + 1):

    diff = 0

    for j in range(T_len):

        if T[j] != S[i+j]:

            diff += 1

    ans = min(ans, diff)

print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
x = len(s)-len(t)
ans = 10**9
for i in range(x+1):
    cnt = 0
    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:
#B - Substring 
S = str(input())
T = str(input())
i = 0
j = 0

Slen = len(S)
Tlen = len(T)
change_min = Tlen

for i in range(Slen - Tlen + 1):
    diff = 0
    for j in range(Tlen):
        if T[j] != S[i + j]:
            diff += 1
    change_min = min(change_min,diff)

# 出力
print(change_min)

Submission status: Accepted

Solution code:
import numpy as np

s=np.array(list(input()))
t=np.array(list(input()))

ans = len(t)

for i in range(len(s)-len(t)+1):
    tmp = sum(s[i:i+len(t)] == t)
    if ans > len(t) - tmp:
        ans = len(t) - tmp

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ls = len(s)
lt = len(t)
res = float("inf")
cnt = 0
for i in range(ls - lt+1):
    cnt= 0
    for j in range(lt):
        if s[i + j] != t[j]:
            cnt += 1
    res = min(res,  cnt)
print(res)

Submission status: Accepted

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
mx = 0
for i in range(ls - lt + 1):
  S2 = S[i:i + lt]
  cnt = 0
  for j in range(lt):
    if S2[j] == T[j]:
      cnt += 1
  mx = max(mx, cnt)

print(lt - mx)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
t=input()
s1=len(s)
t1=len(t)
def p(val):
    print(val)


count = 0
for i in range(s1-t1+1):
    miss = 0
    for j in range(t1):
        if s[j+i] != t[j]:
            miss +=1
    if i == 0:
        count = miss
    else:
        if count>=miss:
            count = miss

p(count)

Submission status: Accepted

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

ls = len(s)
lt = len(t)

max_char = lt

for i in range(0, ls - lt+1):
    s2 = s[i:i + lt]
    # print(s2)
    count = 0
    for cs, ct in zip(s2, t):
        if cs != ct:
            count += 1
    max_char = min(count, max_char)
print(max_char)

Submission status: Accepted

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

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

print(len(T) - ans)

Submission status: Accepted

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

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

print(l)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def sdiff(s1, s2):
  score = 0
  for i in range(0, len(s2)):
    if s1[i] != s2[i]: score += 1
  return score

S = input()
T = input()
Ans = len(T)

for i in range(0, len(S) - len(T) + 1):
  Ans = min(sdiff(S[i:], T), Ans)

print(Ans)

Submission status: Accepted

Solution code:
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""


s = input()
t = input()
ans = len(t)

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 = min(ans, cnt)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S,T=input(),input()
S_l=len(S)
T_l=len(T)
score=[]

for i in range(S_l-T_l+1):
  score_1=0
  S0=S[i:i+T_l]
  for j in range(T_l):
    if T[j]==S0[j]:
      score_1=score_1+1
  score.append(T_l-score_1)

print(min(score))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def solve(S, T):
    ans = len(T)

    # Sのi文字目から、Tに一致するかどうかを調べる
    for i in range(len(S) - len(T) + 1):
        target = S[i:]
        diff = 0

        # target と t の diff を算出
        for j in range(len(T)):
            if target[j] != T[j]:
                diff += 1

        ans = min(ans, diff)

    return ans


def main():
    S = input()
    T = input()
    result = solve(S, T)
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input().rstrip()
t = input().rstrip()
count = 0
min_count = 10000
for i in range(len(s) - len(t) + 1):
    s_selected = s[i:i + len(t)]
    #print(s_selected)
    count = 0
    for j in range(len(t)):
        if t[j] != s_selected[j]:
            count += 1
    #print(count)
    if count < min_count:
        min_count = count
print(min_count)

Submission status: Accepted

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

ans = 1001
for i in range(len(s) - len(t) + 1):
    num = 0
    x = s[i : i + len(t)]

    for j in range(len(t)):
        if x[j] != t[j]:
            num += 1

    ans = min(ans, num)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

L = len(T)
ans = 0

for i in range(len(S)-L+1):
    cnt = 0
    for j in range(L):
        
        if S[i+j] == T[j]:
            cnt += 1
        ans = max(ans,cnt)
        
print(L-ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
c=0
for i in range(len(s)-len(t)+1):
    x=s[i:i+len(t)]
    tmp=0
    for j in range(len(t)):
        if x[j]==t[j]:
            tmp+=1
    if c<tmp:
        c=tmp
print(len(t)-c)

Submission status: Accepted

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

ans = len(T)

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

Submission status: Accepted

Solution code:
s = input()
t = input()
S,T = len(s),len(t)
ans = T
for i in range(S-T+1):
    tmp = [c1!=c2 for c1,c2 in zip(s[i:i+T],t)].count(True)
    ans = min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
ns = len(s)
nt = len(t)
ans = float("inf")

for i in range(ns-nt+1):
    res = 0
    
    for j in range(nt):
        if t[j] != s[i:i+nt][j]:
            res += 1
            
    ans = min(ans,res)
    
print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
T,S=len(t),len(s)

ans=T
for i in range(S-T+1):
    tmp=[c1!=c2 for c1,c2 in zip(s[i:i+T],t)].count(True)
    ans=min(ans,tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = len(T)

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

print(ans)