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:
S = input()
T = input()

answer = float('inf')
for s in range(len(S)):
    if len(S) - s < len(T):
        break
    count = 0
    for t in range(len(T)):

        if S[s+t] != T[t]:
            count += 1
            
    answer = min(answer, count)

print(answer)

Submission status: Accepted

Solution code:
S=input()
T=input()
ls=len(S)
lt=len(T)

ans=float('inf')
for i in range(0,ls-lt+1):
    ans=min(ans, sum([l!=m for l,m in zip(S[i:i+lt], T)]))
print(ans)

Submission status: Accepted

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

coincidence = 0
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
    coincidence = max(coincidence, count)

print(len(t) - coincidence)

Submission status: Accepted

Solution code:
import numpy as np

s = np.array([ord(x) for x in input()])
t = np.array([ord(x) for x in input()])

tlen = len(t)
res = tlen
for i in range(len(s)-tlen+1):
    tmp = s[i:i+tlen] - t
    c = tlen - list(tmp).count(0)
    res = min(res, c)
    if res == 0:
        break
print(res)

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = input()
    cnt = 0
    tmp = 0
    for i in range(len(S)-len(T)+1):
        for j in range(len(T)):
            if S[i+j] == T[j]:
                tmp += 1
        cnt = max(cnt,tmp)
        tmp = 0

    return(len(T)-cnt)


print(main())

Submission status: Accepted

Solution code:
S = input()
T = input()
len_T = len(T)
d = len(S)-len_T
result = 10000
for i in range(d+1):
    if i == d:
        x = S[i:]
    else:
        x = S[i:-d+i]
    sum = 0
    for i in range(len_T):
        if T[i] == x[i]:
            sum += 1
    sum = len_T - sum
    if result > sum:
        result = sum
print(result)

Submission status: Accepted

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

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

    ans = min(ans,count)

print(ans)

Submission status: Accepted

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

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

print(len(t) - cor)

Submission status: Accepted

Solution code:
def abc177_b():
    """
    シンプルに全探索でよい、ということだそうだよ。
    探索はsのほうに対して、インデックスをずらしながら何文字が一致するかを。
    """
    s = input()
    t = input()

    # 最大値はt文字分すべて置き換えが必要な場合
    ans = len(t)

    for i in range(len(s) - len(t) + 1):
        cnt = 0
        # s[i]からスタートして、tと何文字一致しない場所を数える(書き換えが必要な場所)
        for _s, _t in zip(s[i:], t):
            if _s != _t:
                cnt += 1

        ans = min(ans, cnt)

    print(ans)
   
if __name__ == '__main__':
    abc177_b()

Submission status: Accepted

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

tmp = []

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

ans = 0
ansl = []

for i in range(len(tmp)):
    for j in range(t):
        if tmp[i][j] != T[j]:
            ans += 1
    ansl.append(ans)
    ans = 0

print(min(ansl))

Submission status: Accepted

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

m=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
  m=max(m,c)

print(len(t)-m)

Submission status: Accepted

Solution code:

s = str(input().strip())
t = str(input().strip())
cnt_min = 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
    cnt = len(t) - cnt
    cnt_min = min(cnt, cnt_min)

print(cnt_min)

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = input()
    min = len(T)
    for i in range(len(S) - len(T) + 1):
        temp = 0
        for j in range(len(T)):
            if S[i + j] != T[j]:
                temp += 1
        if temp < min:
            min = temp
    print(min)
main()

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

Solution code:
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:
a=input()
b=input()

ans=10**10

for i in range(len(a)-len(b)+1):
  cnt=0
  for j in range(len(b)):
    if a[i+j]!=b[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):
    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()

min=len(t)
m=len(s)-len(t)
if m == 0:
    m = 1
for n in range(m):
    x=0
    for i in range(len(t)):
        if t[i] != s[n+i]:
            x=x+1

    if x<min:
        min = x
print(min)

Submission status: Accepted

Solution code:
s=input()
t=input()
ans=10000
for i in range(len(s)-len(t)+1):
    a=s[i:i+len(t)]
    cnt=0
    for j in range(len(a)):
        if a[j]!=t[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):
  tmp = 0
  for j in range(len(t)):
    if t[j] != s[i+j]:
      tmp += 1
  ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
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 main():
    s = s_input()
    t = s_input()
    l_s = len(s)
    l_t = len(t)
    ans = INF
    for i in range(l_s-l_t+1):
        trial = 0
        r = s[i:]
        for k in range(l_t):
            if t[k] != r[k]:
                trial += 1
        ans = min(ans,trial)
    print(ans)



if __name__=="__main__":
    main()

Submission status: Accepted

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


ma=0
for i in range(len(s)):
  cnt=0
  now=s[i:i+len(t)]
  if len(now)!=len(t):
    break


  
  for j in range(len(now)):
    if now[j]==t[j]:
      cnt+=1
  ma=max(cnt,ma)

print(len(t)-ma)

Submission status: Accepted

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

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

Submission status: Accepted

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

s_len =len(s)
t_len =len(t)
count = 0
ans = []



for i in range(s_len - t_len + 1):
    for j in range(t_len):
        if s[i:t_len + i][j] != t[j]:
            count += 1
    ans.append(count)
    count = 0

min_ans = min(ans)
print(min_ans)

Submission status: Accepted

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

answer = float('inf')
for s in range(len(S)):
    if len(S) - s < len(T):
        break
    count = 0
    for i in range(len(T)):

        if S[s+i] != T[i]:
            count += 1

    answer = min(answer, count)

print(answer)

Submission status: Accepted

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

ans = float('inf')
for i in range(len(S)):
    string = S[i:i + len(T)]
    if len(string) < len(T):
        continue

    score = len([1 for ch_s, ch_t in zip(string, T) if ch_s != ch_t])
    ans = min(ans, score)
print(ans)

Submission status: Accepted

Solution code:
import re
S=input()
T=input()
ans=10**1000

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

Submission status: Accepted

Solution code:
n_gram = lambda t, n: [t[i:i+n] for i in range(len(t) - n + 1)]

S = input()
T = input()

t_len = len(T)
count = t_len

s_list = n_gram(S, t_len)

for s in s_list:
    c = 0
    for i in range(len(s)):
        if s[i] != T[i]:
            c += 1
    count = min(count, c)

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
T=input()
NS=len(S)
NT=len(T)
MAX=0
for i in range(NS-NT+1):
    COUNT=0
    for j in range(NT):
        if S[i+j]==T[j]:
            COUNT+=1
    if COUNT>MAX:
        MAX=COUNT
print(NT-MAX)

Submission status: Accepted

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

answer = 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
  answer = min(answer, diff)

print(answer)

Submission status: Accepted

Solution code:
s = input()
t = input()
sl = len(s)
tl = len(t)

cnt = 0
ans = 0

for i in range(sl-tl+1):
    for j in range(tl):
        if t[j] == s[i+j]:
            cnt += 1
    
    ans = max(cnt, ans)
    cnt = 0

print(tl - ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
t = input()
ans = 10**10
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:
s=input()
t=input()
n=len(s)
nn=len(t)
k=nn-n
ans=0
for i in range(n-nn+1):
    tmp=0
    for j in range(nn):
        if t[j]==s[i+j]:
            tmp+=1
    if tmp>ans:
        ans=tmp
print(nn-ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
ans = float('inf')
for i2 in range(len(S)):
    if i2 + len(T) > len(S):
        break
    ans = min(ans, sum(S[i1] != T[i1 - i2] for i1 in range(i2, i2 + len(T))))
print(ans)

Submission status: Accepted

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

def checkCommonLength(a: str, b: str) -> int:
    l = len(a)
    count = 0
    for i in range(l):
        if a[i] == b[i]:
            count += 1
    return count

max_val = 0
for i in range(s):
    if i + t <= s:
        testStr = S[i : i + t]
        #print(testStr)
        max_val = max(max_val, checkCommonLength(S[i : i + t], T))

print(t - max_val)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Substring

s = input()
t = input()

def diff(s, t):
    return sum(1 for i, c in enumerate(s) if c != t[i])

m = min(diff(s[i:i + len(t)], t) for i in range(len(s) - len(t) + 1))
print(m)

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
mm = 0
min = len(t)
for i in range(len(s)-len(t)+1):
    sp = s[i:len(t)+i]
    for k in range(len(t)):
        if sp[k] != t[k]:
            mm += 1
    if min > mm:
        min = mm
    mm = 0
print(min)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(0,len(s)-len(t)+1):
    count = 0;
    substr = s[i:len(t)+i];
    # print(substr);
    for j in range(0,len(t)):
        if substr[j] == t[j]:
            count += 1;
        # print(count);
        if ans > len(t)-count:
            ans = len(t) - count;

print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
slen = len(s)
tlen = len(t)
ans = 10**20
temp = 0

for start in range(0,slen-tlen+1):
    temp = 0
    for i in range(0,tlen):
        if t[i] != s[start+i]:
            temp += 1
    ans = min(ans,temp)
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()
    T = input().strip()

    cnt = float("inf")
    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

        cnt = min(cnt, tmp)

    print(cnt)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
T = input()
lenS = len(S)
lenT = len(T)
minlength = 1000
for l_S in range(lenS - lenT + 1):
    cnt = 0
    for w in range(lenT):
        if S[l_S+w] != T[w]:
            cnt += 1
    minlength = min(minlength, cnt)
print(minlength)

Submission status: Accepted

Solution code:
from collections import deque
import sys, copy, itertools,heapq
#input = sys.stdin.readline
 
S = input()
T = input()
s = len(S)
t = len(T)
A=[0]*(len(S))
 
ans = t
for i in range(len(S)-len(T)+1):
  for j in range(len(T)):
    if S[i+j] != T[j]:
      A[i] += 1
  ans = min(ans, A[i])
 
#print(s)
#print(t)
#print(ANS)
print(ans)

Submission status: Accepted

Solution code:
import sys


def check(S, T):
    count = 0
    for s, t in zip(S, T):
        if s != t:
            count += 1
    return count


def main():
    S = input()
    T = input()
    dif = len(S) - len(T)
    ans = 10000
    for i in range(dif+1):
        compare = S[i: i+len(T)]
        count = check(compare, T)
        if count < ans:
            ans = count

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
t=input()
ans=float('inf')
for i in range(len(s)-len(t)+1):
  tmp=0
  for j in range(len(t)):
    if t[j]==s[i+j]:
      pass
    else:
      tmp+=1
  ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

s = input()
t = input()

m = 0
for i in range(len(s)):
    tmp = 0
    for j in range(len(t)):
        if(j + i >= len(s)):
            tmp = 0
            break
        if(s[j + i] == t[j]):
            tmp += 1
    m = max(m, tmp)
print(len(t) - m)

Submission status: Accepted

Solution code:


S = input()
T = input()

if len(T) > len(S) or len(S) == 0:
    print(0)

answer = float("inf")
for i in range(len(S) - len(T) + 1):

    sub = S[i: i + len(T)]

    unique = 0
    for s,o in zip(sub, T):
        if s != o:
            unique += 1
    
    answer = min(answer, unique)

print(answer)

Submission status: Accepted

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

N, M = len(S), len(T)
ans = float("inf")
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:
print((lambda S,T:len(T)-max(sum(s==t for s,t in zip(S[i:i+len(T)],T)) for i in range(len(S)-len(T)+1)))(input(),input()))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
s = input()
t = input()
start, end = 0, len(t)
def f(s, t, start, end):
    min_changes = len(t)
    count = 0
    for i in range(len(t)):
        if s[start:end][i] != t[i]: count += 1
    if start + len(t) == len(s): return min(count, min_changes)
    else: return min(count, f(s, t, start+1, end+1))

print(f(s, t, start, end))

Submission status: Accepted

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

ans = 10**18
for l in range(len(S) - len(T) + 1):
    cnt = 0
    for s, t in zip(S[l:], T):
        if s != t:
            cnt += 1
    ans = min(ans, cnt)

print(ans)

Submission status: Accepted

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

z = len(S)-len(T)

res = []
cnt = 0
if z == 0:
  for a,b in zip(S,T):
    if a != b:
      cnt += 1
  print(cnt)
  exit();
else:
  for i in range(z):
    s = S[i:i+len(T)]
    cnt = 0
    for j,k in zip(s,T):
      if j != k:
        cnt += 1
    res.append(cnt)
  print(min(res))

Submission status: Accepted

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

Slen = len(S)
Tlen = len(T)
diff = Slen - Tlen

ans = [0] * (diff+1)
for i in range(diff+1):
	S_i = i
	for j in range(Tlen):
		if S[S_i] != T[j]:
			ans[i] = ans[i] + 1
		S_i += 1
min_ans = min(ans)
print(min_ans)

Submission status: Accepted

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

answer = len(T)
for i in range(len(S) - len(T) + 1):
	check = 0
	for j in range(len(T)):
		if T[j] != S[j + i]:
			check += 1
	if check < answer:
		answer = check

print(answer)

Submission status: Accepted

Solution code:
s,(*t,_)=open(0)
print(min(sum(x!=y for x,y in zip(s[i:],t))for i in range(len(s)-len(t))))

Submission status: Accepted

Solution code:
S = input()
T = input()
ma = 0
for i in range(len(S)-len(T)+1):
    Ssub = S[i:i+len(T)]
    match = 0
    for j in range(len(T)):
        if Ssub[j] == T[j]:
            match += 1
    if ma < match:
        ma = match
print(len(T)-ma)

Submission status: Accepted

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

def main():
    input = sys.stdin.readline
    s = input().rstrip()
    t = input().rstrip()
    
    ans = float("INF")
    for start in range(len(s) - len(t) + 1):
        cnt = 0
        for char in range(len(t)):
            if s[start + char] != t[char]:
                cnt += 1
        ans = min(ans, cnt)
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
S = input()
T = input()
if T in S:
  print(0)
  sys.exit(0)

maxSameCharCount = 0
for i in range(len(S)-len(T)+1):
  sameCharCount = 0
  for j in range(len(T)):
    if S[i+j]==T[j]:
      sameCharCount += 1
  if maxSameCharCount < sameCharCount:
    maxSameCharCount = sameCharCount
print(len(T)-maxSameCharCount)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    s = ins()
    t = ins()
    ans = len(s)
    for i in range(len(s)):
        if i + len(t) > len(s):
            break
        count = 0
        for j in range(len(t)):
            if t[j] != s[i + j]:
                count += 1
        ans = min(ans, count)

    return ans


print(solve())

Submission status: Accepted

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

m=len(s)
n=len(t)

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

print(ans)

Submission status: Accepted

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

m,n=len(s),len(t)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#_______________________________________________________________#
def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x-1)
def lower_bound(li, num): 
	answer = -1
	start = 0
	end = len(li)-1

	while(start <= end):
		middle = (end+start)//2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer #index where x is not less than num
def upper_bound(li, num): 
	answer = -1
	start = 0
	end = len(li)-1

	while(start <= end):
		middle = (end+start)//2

		if li[middle] <= num:
			answer = middle
			start = middle + 1
		
		else:
			end = middle - 1
	return answer #index where x is not greater than num

def abs(x):
	return x if x >=0 else -x
def binary_search(li, val, lb, ub): 
	ans = 0
	while(lb <= ub):
		mid = (lb+ub)//2
		#print(mid, li[mid])
		if li[mid] > val:
			ub = mid-1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
def kadane(x): #maximum sum contiguous subarray
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = mpos(sum_so_far,current_sum)
	return sum_so_far
def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

#_______________________________________________________________#
'''
      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
   ▄███████▀▀▀▀▀▀███████▄
░▐████▀▒▒Aestroix▒▒▀██████
░███▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀████
░▐██▒▒▒▒▒KARMANYA▒▒▒▒▒▒████▌         ________________
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌  ? ?   |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒|
░░█▒▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▒▐███▌   ?    |___CM ONE DAY___|
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▒▐███▌     ? ? |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒|
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌    ? ?    
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌      ? 
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█     ? ? 
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀       ? 
░░░░▄█████████ ████=========█▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
░░░░░████████████████
'''
from math import *
#for _ in range(int(input())):
for _ in range(1):
	#n = int(input())
	#p,f = map(int,input().split())
	#d,t,s = map(int,input().split())
	#ws,wa = map(int,input().split())
	#b = list(input())
	#x = int(input())
	#n = len(b)
	#s2 = input()
	#r, g, b, w = map(int,input().split())
	#a = list(map(int,input().split()))
	#b = list(map(int,input().split()))
	#s1 = list(st)
	s = input()
	t = input()
	n = len(s)
	m = len(t)
	cnt = 10000
	for i in range(n-m+1):
		st = s[i:i+m]
		if st == t:
			cnt = 0
			break
		else:
			temp = 0
			for j in range(m):
				if st[j] != t[j]:
					temp += 1
			cnt = min(cnt,temp)
	print(cnt)

Submission status: Accepted

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

scores = {0}

for i in range(len(T)):
  for j in range(i, len(S) - len(T) + i + 1):
    if T[i] == S[j]:
      score = 1
      for k in range(1, len(T) - i):
        if T[i + k] == S[j + k]:
          score += 1
      scores.add(score)
      
print(len(T) - max(scores))

Submission status: Accepted

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

Submission status: Accepted

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

ans = float('inf')
for i in range(len(S)-len(T)+1):
    diff_count = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            diff_count += 1

    ans = min(ans, diff_count)

print(ans)

Submission status: Accepted

Solution code:
a=str(input())
b=str(input())
ans=0
c=[]
l=0
for x in range(len(a)-len(b)+1):
    ans=0
    for i in range(len(b)):
       if a[i+l]!=b[i]:
           ans+=1
    l+=1
    c.append(ans)
print(min(c))

Submission status: Accepted

Solution code:

import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


def readList():
    return list(map(int, input().strip().split()))


def solve(s, t):
    M, N = len(s), len(t)
    ans = N

    for i in range(M-N+1):
        curr = N

        for j in range(N):
            if s[i+j] == t[j]:
                curr -= 1

        ans = min(ans, curr)

    return ans


s = read()
t = read()

print(solve(s, t))

Submission status: Accepted

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

Submission status: Accepted

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

m = 0
for i in range(len(s) - len(t) + 1):
    b = s[i : i + len(t)]
    cnt = 0
    for j, v in enumerate(b):
        if v == t[j]:
            cnt += 1
    m = max(m, cnt)
print(len(t) - m)

Submission status: Accepted

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

m = 0
for i in range(0, len(s) - len(t) + 1):
    b = s[i : i + len(t)]
    cnt = 0
    for j, v in enumerate(b):
        if v == t[j]:
            cnt += 1
    m = max(m, cnt)
print(len(t) - m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
t = input()
maxi = 0 
for i in range(len(s)):
    maxG = 0
    if len(s[i:len(t)+i]) >= len(t):
        for l, j in zip(s[i:len(t)+i], t):
            if l == j:
                maxG += 1
        maxi = max(maxi, maxG)
print(len(t)-maxi)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
ans = len(t)
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 < ans:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
res=len(t)
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
    res=min(tmp,res)
print(res)

Submission status: Accepted

Solution code:

def process():
    s = input()
    t = input()
    ls, lt = len(s), len(t)
    minchanges = float("inf")

    for i in range(ls-lt+1):
        changes = 0
        for j in range(lt):
            changes += 0 if s[i+j] == t[j] else 1
            if changes > minchanges:
                break
        if changes == 0:
            return 0
        #print(i, changes)
        minchanges = min(minchanges, changes)
    return minchanges


print(process())

Submission status: Accepted

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


def solve(S: str, T: str):
    length = len(T)
    s_list =[]
    counter = length
    ans = 0

    for i in range(len(S)-length+1):
        s = S[i:i+length]
        for i in range(length):
            #print(s[i], T[i])
            if s[i] != T[i]:
                ans+=1

        counter = min(ans, counter)

        ans = 0

    return print(counter)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
T = input()
 
N = len(S)
M = len(T)
ans = 1001

# Sから順にM文字切り出し、切り出した文字列とTのハミング距離における最小値を求める
for i in range(N+1-M):
  dis = 0
  for j in range(M):
    if S[i+j] != T[j]:
      dis += 1
  ans = min(ans, dis)
  
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
 
N = len(S)
M = len(T)
l = []
# Sから順にM文字切り出し、切り出した文字列とTのハミング距離における最小値を求める
for i in range(N+1-M):
  dis = M
  for j in range(M):
    if S[i:i+M][j] == T[j]:
      dis -= 1
  l.append(dis)
  
print(min(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
T = input()
ans = 1001
for i in range(len(S) - len(T) + 1):
  a = 0
  for s in range(len(T)):
    if T[s] != S[i+s]:
      a += 1
  if a < ans:
    ans = a
print(ans)

Submission status: Accepted

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

ans = 1000
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 = list(input())
T = list(input())
cmin = 1000

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

print(cmin)

Submission status: Accepted

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

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

total = 100000000
for i in range(lens-lent+1):
    count = 0
    for j in range(lent):
        if s[i+j]!=t[j]:
            count+=1
    total = min(total,count)

if total == 100000000:
    print(lent)
else:
    print(total)

Submission status: Accepted

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