Harryxun/stf_run huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

n, m, q = map(int, readline().split())
abcd = [list(map(int, readline().split())) for _ in range(q)]
ans = 0
for bit in product([1, 0], repeat=q):
    cnt = 0
    aaa = []
    aaaa = set()
    for i, (a, b, c, d) in enumerate(abcd):
        if bit[i] == 1:
            aaa.append([a, b, c])
            cnt += d
    if ans < cnt:
        for a, b, c in aaa:
            for aa, bb, cc in aaa[]:
                if aa == a and b < bb:
                    aaaa.add([b, bb, cc - c])
                elif aa == a and b > bb:
                    aaaa.add([bb, b, c - cc])
                if b == bb and aa > a:
                    aaaa.add([a, aa, cc - c])
                elif b == bb and aa < a:
                    aaaa.add([aa, a, c - cc])
        aaa += list(aaaa)
        flag = True
        for i, (a, b, c, d) in enumerate(abcd):
            if bit[i] == 1:
                for aa, bb, cc in aaa:
                    if (aa <= a < b <= bb and c > cc) or (a <= aa < bb <= b and c < cc):
                        if aa == a and bb == b and c == cc:
                            continue
                        else:
                            flag = False
                            break
                if not flag:
                    cnt = 0
                    break
        if ans < cnt:
            ans = cnt
print(ans)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import combinations_with_replacement

n, m, q = map(int, readline().split())
abcd = [list(map(int, readline().split())) for _ in range(q)]
ans = 0
for seq in combinations_with_replacement(range(m), n):
    cnt = 0
    for a, b, c, d in abcd:
        if seq[b - 1] - seq[a - 1] == c:
            cnt += d
    ans = max(ans, cnt)
print(ans)
i = int(iput())

if i/3600 != 0:
    h = i/3600
    a = a - 3600 * h
if i/60 != 0:
    m = i/3600
    a = a - 60 * m

print(h,":",m,":",a)


### FIXED CODE ###

i = int(input())

h = 0
m = 0

if i/3600 >= 1:
    h = int(i/3600)
    i = i - 3600 * h
if i/60 >= 1:
    m = int(i/60)
    i = i - 60 * m
    
s = str(h) + ":" + str(m) + ":" + str(i)

print(s)
n=int(input())
chara=input()
nc=len(chara)

if n=>nc:
  print(chara)
else:	
  print(chara[1:n])
  
  

### FIXED CODE ###

n=int(input())
chara=input()
nc=len(chara)

if n>=nc:
  print(chara)
else:	
  print(chara[0:n]+"...")
N = int(input("N = "))
a = []
ball = []
while N != len(a):
    a.append(int(input("a_i = ")))
    ball.append(0)
i = N
ballcount = 0
check = 2
out = 0
while i != 0 and out != N + 1:
    while check * i <= N: 
        ballcount += ball[check * i - 1]
        check += 1
    if ballcount % 2 != a[i - 1]:
        ball[i - 1] = 1
    check = 2
    i -= 1
    ballcount = 0
    out += 1
if out == N + 1:
    i = out
    print(-1)
M = 0
while i < N:
    if ball[i] == 1:
        M += 1
    i += 1
print(M)
i = 0
while i < N:
    if ball[i] == 1:
        print(i + 1,end=" ")
    i += 1

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
ball = [0 for c in range(N)]
i = N
ballcount = 0
check = 2
out = 0
while i != 0 and out != N + 1:
    while check * i <= N: 
        ballcount += ball[check * i - 1]
        check += 1
    if ballcount % 2 != a[i - 1]:
        ball[i - 1] = 1
    check = 2
    i -= 1
    ballcount = 0
    out += 1
if out == N + 1:
    i = out
    print(-1)
M = 0
while i < N:
    if ball[i] == 1:
        M += 1
    i += 1
print(M)
i = 0
while i < N:
    if ball[i] == 1:
        print(i + 1)
    i += 1
n,m=map(int,input().split())
ans=[0]*m
for i in range(n):
  x=[int(a),for a in input().split()]
  for j in range(1,x[0]+1):
    ans[x[j]-1]+=1
  
print(ans.count(n)) 
    


### FIXED CODE ###

a,b=map(int,input().split())
if b%a==0:
  print(a+b)
else:
  print(b-a)
import copy
import sys
input = sys.stdin.readline

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = 2 ** (N-1).bit_length()
        self.func = copy.deepcopy(func)
        self.I = copy.deepcopy(I)
        self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)]

    def assign(self, k, x):
        self.seg[k + self.sz] = copy.deepcopy(x)

    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])

    def update(self, k, x):
        k += self.sz
        self.seg[k] = copy.deepcopy(x)
        while k > 1:
            k //= 2
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = copy.deepcopy(self.I)
        R = copy.deepcopy(self.I)
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a //= 2
            b //= 2
        return self.func(L, R)

from math import gcd

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

def f(x,y):
    if x * y == 0:
        return x + y
    else:
        return gcd(x,y)

seg = SegmentTree(N + 1, f, 0)
for i in range(N):
    seg.assign(i , A[i])
seg.build()

ans = 1
for i in range(N):
    ans = max(ans , gcd(seg.query(0 , i) , seg.query(i + 1 , N)))
print(ans)



### FIXED CODE ###

from fractions import gcd
import copy

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = 2 ** (N-1).bit_length()
        self.func = copy.deepcopy(func)
        self.I = copy.deepcopy(I)
        self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)]

    def assign(self, k, x):
        self.seg[k + self.sz] = copy.deepcopy(x)

    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])

    def update(self, k, x):
        k += self.sz
        self.seg[k] = copy.deepcopy(x)
        while k > 1:
            k //= 2
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = copy.deepcopy(self.I)
        R = copy.deepcopy(self.I)
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a //= 2
            b //= 2
        return self.func(L, R)

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

def f(x,y):
    if x * y == 0:
        return x + y
    else:
        return gcd(x,y)

seg = SegmentTree(N + 1, f, 0)
for i in range(N):
    seg.assign(i , A[i])
seg.build()

ans = 1
for i in range(N):
    ans = max(ans , f(seg.query(0 , i) , seg.query(i + 1 , N)))
print(ans)
#!/usr/bin/env python3
import math
# n進数の各位の和
def base_10_n(x,n):
    a = int(math.log(x,n))
    ans = 0
    for i in range(a+1,0,-1):
        ans += x // n**i
        x %= n**i
    ans += x
    return ans

def main():
    N = int(input())
    ans = N
    for j in range(1,N//18 + 1):
        a = base_10_n(N-18*j,6)
        b = base_10_n(18*j,9)
        # print(18*j,a,b)
        ans = min(ans, a+b)
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import math
# n進数の各位の和


def base_10_n(x, n):
    if x == 0:
        return 0
    tmpx = x
    a = int(math.log(x, n))
    ans = 0
    for i in range(a, -1, -1):
        ans += tmpx // n**i
        tmpx %= n**i
    ans += tmpx
    return ans


def s(n, r):
    if n == 0:
        return 0
    return n % r + s(n // r, r)


def main():
    N = int(input())
    ans = 10**12
    for j in range(N+1):
        # c = base_10_n(N-j, 6)
        # d = base_10_n(j, 9)
        c = s(j,6)
        d = s(N-j,9)
        ans = min(ans, c+d)
    print(ans)


if __name__ == "__main__":
    main()
N,K = map(int,input().split())
A = list(map(int,input().split()))

l = []
kari = 1


for i in range(N*2):
    l.append(A[kari-1])
    kari = A[kari-1]
    
    zyuuhuku = set(l)
    if len(zyuuhuku) != len(l):
        tometatokoro = A[kari-1]
        break
    


    
    

#繰り返しでもどったところの列番号
aaaa = l.index(tometatokoro)

#繰り返すループの長さ
kurikaesi = len(l)-aaaa

#ループ繰り返す余り
ans = K % kurikaesi


ans = ans + aaaa

#print(l)
#print(ans)
print(l[ans])









### FIXED CODE ###

S = input()
T = input()

TT = T[:-1]



if S == TT:
    print("Yes")
else:
    print("No")
N=int(input())
A=list(map(int,input().split()))

flag=0
count=0
ans=[]
for a in A:
  if a%2==0:
    count=a/2
    ans.append(count)
  else:
    flag=1
if flag==0:
  print(int(min(ans)))
else:
  print(0)                                 

### FIXED CODE ###

print(input().count("1"))
while 1:
   H, W = map(raw_input().split())
  
   if H == 0 and W == 0:
      break
   for i in range(0, H-1):
      print '#'*W
   print '\n'

### FIXED CODE ###

while 1:
   H, W = map(int, raw_input().split())

   if H == 0 and W == 0: 
      break
   for i in range(H):
      print "#"*W
   print ""
r,g,b,n=map(int,input().split())
ans=0
for i in range(n+1):
    for j in range(n+1-i):   
        if (n-r*i-g*j-b*(n-i-j)==0:
                ans+=1
print(ans)
                


### FIXED CODE ###

r,g,b,n=map(int,input().split())
ans=0
for i in range(3001):
    for j in range(3001):   
        if (n-r*i-g*j)>=0 and (n-r*i-g*j)%b==0:
                ans+=1
print(ans)
import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())

def find_negative_loop(n,w,es):
  dist=[float("inf")]*n
  #この始点はどこでもよい
  dist[1]=0
  
  for i in range(n):
    for j in range(w):
      e=es[j]
      if dist[e[1]]>dist[e[0]]+e[2]:
        dist[e[1]]=dist[e[0]]+e[2]
        if i==n-1:
          return True
  return False

def shortest_path(s,n,w,es):
  #s→iの最短距離
  #s:始点, n:頂点数, w:辺の数, es[i]:[辺の始点,辺の終点,辺のコスト]
  dist=[float("inf")]*n
  #d[i]: s→iの最短距離
  dist[s]=0

  while True:
    update=False
    for p,q,r in es:
      # e: 辺iについて [from,to,cost]
      if dist[p]!=float("inf") and dist[q]>dist[p]+r:
        dist[q]=dist[p]+r
        update=True
    if not update:
      break
      
  return dist

graph=[[] for _ in range(N+1)]
elist=[]
for _ in range(M):
  a,b,c=map(int,input().split())
  graph[a].append(b)
  elist.append((a,b,-c))
  
#remove unnecessary vertex and edge
visited=[None]*(N+1)
def check_reachable(u):
  if u==N:
    reachable[u]=True
    return True
  
  visited[u]=True
  cnt=0
  for v in graph[u]:
    if not visited[v]:
      ret=check_reachable(v)
      if ret:
        cnt+=1
        
  if cnt>0:
    reachable[u]=True
    return True
  else:
    return False

reachable=[False*(N+1)]
for i in range(1,N+1):
  if not reachable[i]:
    visited=[False]*(N+1)
    check_reachable(i)
#print(reachable)
  
elist2=[]
for a,b,nc in elist:
  if reachable[b]:
    elist2.append((a,b,nc))
  
M2=len(elist2)
res1=find_negative_loop(N+1,M2,elist2)

if res1:
  print("inf")
else:
  res2=shortest_path(1,N+1,M2,elist2)
  print(-res2[N])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())

def find_negative_loop(n,w,es):
  dist=[float("inf")]*n
  #この始点はどこでもよい
  dist[1]=0
  
  for i in range(n):
    for j in range(w):
      e=es[j]
      if dist[e[1]]>dist[e[0]]+e[2]:
        dist[e[1]]=dist[e[0]]+e[2]
        if i==n-1:
          return True
  return False

def shortest_path(s,n,w,es):
  #s→iの最短距離
  #s:始点, n:頂点数, w:辺の数, es[i]:[辺の始点,辺の終点,辺のコスト]
  dist=[float("inf")]*n
  #d[i]: s→iの最短距離
  dist[s]=0

  while True:
    update=False
    for p,q,r in es:
      # e: 辺iについて [from,to,cost]
      if dist[p]!=float("inf") and dist[q]>dist[p]+r:
        dist[q]=dist[p]+r
        update=True
    if not update:
      break
      
  return dist

graph=[[] for _ in range(N+1)]
elist=[]
for _ in range(M):
  a,b,c=map(int,input().split())
  graph[a].append(b)
  elist.append((a,b,-c))
  
#remove unnecessary vertex and edge
visited=[None]*(N+1)
def check_reachable(s,u):
  if u==N:
    reachable_list[s]=True
    return True
  
  visited[u]=True
  for v in graph[u]:
    if not visited[v]:
      check_reachable(s,v)    
  return False

reachable_list=[False]*(N+1)
for i in range(1,N+1):
  visited=[False]*(N+1)
  check_reachable(i,i)
#print(reachable_list)
  
elist2=[]
for a,b,nc in elist:
  if reachable_list[b]:
    elist2.append((a,b,nc))
  
M2=len(elist2)
res1=find_negative_loop(N+1,M2,elist2)

if res1:
  print("inf")
else:
  res2=shortest_path(1,N+1,M2,elist2)
  print(-res2[N])
N = int(input())
b = [int(_) for _ in input().split()]


def delitable(numbers):
    return [v for i, v in enumerate(numbers) if v == i + 1]


b_searched = set()
b_unsearched = []


b_searched.add(tuple(b))
delit = delitable(b)

if delit == []:
    print("-1")
for delit_num in delit:
    b_unsearched.append([b[:delit_num - 1] + b[delit_num:], [delit_num]])


while b_unsearched:
    b, log = b_unsearched.pop()

    b_tuple = tuple(b)
    b_searched.add(b_tuple)
    delit = delitable(b)
    if max(b) > N - len(log):
        continue

    if not delit:
        if not b:
            log.reverse()
            print("\n".join(map(str, log)))
            break
        else:
            continue
    for delit_num in delit:
        b_temp = b[:delit_num - 1] + b[delit_num:]
        if not tuple(b_temp) in b_searched:
            b_unsearched.append([b_temp, log + [delit_num]])
else:
    print("-1")

### FIXED CODE ###

N = int(input())
b = [int(_) for _ in input().split()]


def delitable(numbers):
    return [v for i, v in enumerate(numbers) if v == i + 1]


log = []
while b:
    delit = delitable(b)
    if not delit:
        print(-1)
        break
    del b[delit[-1] - 1]
    log.append(delit[-1])
else:
    log.reverse()
    print("\n".join(map(str, log)))
N = int(input())
S_list = []
for N in range(N):
  S_list.append(input())

sorted(S_list)
name_list = []
vote_list = []
i, j = 0
while i < len(S_list):
  name = S_list[i]
  while j < len(S_list) and S_list[j] == name:
    j += 1
  name_list.append(name)
  vote_list.append(j - i)
  i = j
max_vote = max(vote_list)
for i in range(name_list):
  if vote_list[i] == max_vote:
    print (name_list[i])

### FIXED CODE ###

N = int(input())
S = {}
name_list = []
for i in range(N):
  name = input()
  if name not in S:
    S[name] = 1
    name_list.append(name)
  else:
    S[name] += 1
name_list = sorted(name_list)
max_vote_name = []
max_vote = -float('inf')
for name in name_list:
  if S[name] > max_vote:
    max_vote = S[name]
    max_vote_list = [name]
  elif S[name] == max_vote:
    max_vote_list.append(name)
for name in max_vote_list:
  print (name)
n, a, b = input().split(' '); n, a, b = int(n), int(a), int(b)

if a*n <= b:
  return a*n
else:
  return b

### FIXED CODE ###

n, a, b = input().split(' '); n, a, b = int(n), int(a), int(b)
 
if a*n <= b:
  print(a*n)
else:
  print(b)
n=int(input())
ans=0
counter=0
for i in range(1,n):
  if a[i]>a[i-1]:
    counter=0
  else:
    counter+=1
    ans=max(ans,counter)
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
counter=0
for i in range(1,n):
  if a[i]>a[i-1]:
    counter=0
  else:
    counter+=1
    ans=max(ans,counter)
print(ans)
N = int(input())


def dev(x):
    global cnt
    if x % 2 == 0:
        cnt += 1
        dev(x / 2)
    return cnt


min_cnt = 0
for i in range(2, N + 1, 2):
    cnt = 0
    result = dev(i)
    if min_cnt < result:
        min_i = i
        min_cnt = result
print(min_i)



### FIXED CODE ###

m = int(input())
a = 1
for c in range(7):
  if (2 ** c) > m:
    break
  a = (2 ** c)
 
print(a)
a = int(input())
b = int(input())

if(a >= 13):
    print(b,'\n')
elif(a >= 6 and a <= 12):
    print(b // 2,'\n')
else:
    print('0\n')
    

### FIXED CODE ###

a,b = map(int,input().split())

if(a >= 13):
    print(b,'\n')
elif(a >= 6 and a <= 12):
    print(b // 2,'\n')
else:
    print('0\n')
import math
a,b=map(int,input().split())
n=math.floor(math.log2(b))+1
ans=[0]*n
form="0"+str(n)+"b"
sa=format(a,form)
sb=format(b,form)
for i in range(n):
    if i==n-1:
        if (b-a+1)%2==0:
            ans[i]=((b-a+1)//2)%2
        else:
            if sa[i]=="1":
                ans[i]=((b-a+1)//2+1)%2
            else:
                ans[i]=((b-a+1)//2)%2
        break
    if sa[i]=="1" and sb[i]=="0":
        s_compa=sa[:i]+"1"*(n-i)
        cmpa=int(s_compa,2)
        ans[i]=(cmpa-a+1)%2
    elif sa[i]=="0" and sb[i]=="1":
        s_compb=sb[:i]+"1"+"0"*(n-i)
        cmpb=int(s_compb,2)
        ans[i]=(b-cmpb+1)%2
    elif sa[i]=="1" and sb[i]=="1":
        s_compa=sa[:i]+"1"*(n-i)
        cmpa=int(s_compa,2)
        s_compb=sb[:i]+"1"+"0"*(n-i)
        cmpb=int(s_compb,2)
        if cmpa>a:#cmpb<b
            ans[i]=((b-cmpb+1)+(cmpa-a+1))%2
        else:
            ans[i]=(b-a+1)%2
cnt=0
for i in range(n):
    cnt+=(ans[i]*2**(n-i-1))
print(cnt)


### FIXED CODE ###

import math
import sys
a,b=map(int,input().split())
if b==0:
    print(0)
    sys.exit()
n=math.floor(math.log2(b))+1
ans=[0]*n
form="0"+str(n)+"b"
sa=format(a,form)
sb=format(b,form)
for i in range(n):
    if i==n-1:
        if (b-a+1)%2==0:
            ans[i]=((b-a+1)//2)%2
        else:
            if sa[i]=="1":
                ans[i]=((b-a+1)//2+1)%2
            else:
                ans[i]=((b-a+1)//2)%2
        break
    if sa[i]=="1" and sb[i]=="0":
        s_compa=sa[:i]+"1"*(n-i)
        cmpa=int(s_compa,2)
        ans[i]=(cmpa-a+1)%2
    elif sa[i]=="0" and sb[i]=="1":
        s_compb=sb[:i]+"1"+"0"*(n-i)
        cmpb=int(s_compb,2)
        ans[i]=(b-cmpb+1)%2
    elif sa[i]=="1" and sb[i]=="1":
        s_compa=sa[:i]+"1"*(n-i)
        cmpa=int(s_compa,2)
        s_compb=sb[:i]+"1"+"0"*(n-i)
        cmpb=int(s_compb,2)
        if cmpa>a:#cmpb<b
            ans[i]=((b-cmpb+1)+(cmpa-a+1))%2
        else:
            ans[i]=(b-a+1)%2
cnt=0
for i in range(n):
    cnt+=(ans[i]*2**(n-i-1))
print(cnt)
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
  ans += min(a[i]+a[i+1],b[i])
  A[i+1] -= max(0,min(A[i+1],B[i]-A[i]))
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
  ans += min(A[i]+A[i+1],B[i])
  A[i+1] -= max(0,min(A[i+1],B[i]-A[i]))
print(ans)
n,k=raw_input().split()
u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split()))
n=list(n)
for i,d in enumerate(n):
 if d not in u:
  n[i:]=[next(e for e in u if e>d)]+[u[0]]*(len(n)-i-1)
  for j in range(i-1,-1,-1):
   if n[j+1]!=':':break
   n[j:j+2]=[next(e for e in u if e>n[j+1]),u[0]]
  else:n=[u[1 if'1'>u[0]else 0]]+[u[0]]*len(n)
print"".join(n)

### FIXED CODE ###

n,k=raw_input().split();u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split()));z=u[0];n=list(n)
for i,d in enumerate(n):
 if d in u:continue
 n[i:]=[next(e for e in u if e>d)]+[z]*(len(n)-i-1)
 for j in range(i-1,-1,-1):
  if n[j+1]<':':break
  n[j:j+2]=[next(e for e in u if e>n[j]),z]
 else:
  if n[0]>'9':n=[u[1 if'1'>z else 0]]+[z]*len(n)
print"".join(n)
cost_a,cost_b,cost_ab,num_a,num_b = map(int,input().split())
if num_a > num_b:
  num_ab = num_b * 2
  need_a = num_a - (num_ab // 2)
  if need_a < 0:
    need_a = -need_a
  cost1 = need_a * cost_a + num_ab * cost_ab
  
  num_ab = num_a * 2
  cost3 = num_ab * cost_ab
  
elif num_a < num_b:
  num_ab = num_a * 2
  need_b = num_b - (num_ab // 2)
  if need_b < 0:
    need_b = -need_b
  cost1 = need_b * cost_b + num_ab * cost_ab

  num_ab = num_b * 2
  cost3 = num_ab * cost_ab
else:
  num_ab = num_b * 2  
  cost1 = num_ab * cost_ab

cost2 = cost_a * num_a + cost_b * num_b
ans = min(cost1,cost2,cost3)
print(ans)



### FIXED CODE ###

cost_a,cost_b,cost_ab,num_a,num_b = map(int,input().split())
if num_a > num_b:
  num_ab = num_b * 2
  need_a = num_a - (num_ab // 2)
  cost1 = need_a * cost_a + num_ab * cost_ab
  
  num_ab = num_a * 2
  cost3 = num_ab * cost_ab
  cost1 = min(cost1,cost3)
elif num_a < num_b:
  num_ab = num_a * 2
  need_b = num_b - (num_ab // 2)
  cost1 = need_b * cost_b + num_ab * cost_ab

  num_ab = num_b * 2
  cost3 = num_ab * cost_ab
  cost1 = min(cost1,cost3)
else:
  num_ab = num_b * 2  
  cost1 = num_ab * cost_ab

cost2 = cost_a * num_a + cost_b * num_b
ans = min(cost1,cost2)
print(ans)
import sys
while True:
    x = sys.stdin.readline().strip()
    if x == "0 0":
        break
    a = list(map(int, x))
    sharp = "#" * a[1]
    for i in range(a[0]):
        print(sharp)

### FIXED CODE ###

while True:
    a = list(map(int, input().split()))
    if a[0] == a[1] == 0:
        break
    sharp = "#" * a[1]
    for i in range(a[0]):
        print(sharp)
    print()
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [i for i in range(-1000,1000) if i == X or i not in P]

if len(P) == 0:
    print(X)
    sys.exit()

idx = NL.index(X)
if abs(NL[idx + 1]) - X >= abs(NL[idx - 1]) - X ):
    print(NL[idx - 1])
else:
    print(NL[idx + 1])


### FIXED CODE ###

import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [ i for i in range(0, 102) if i == X or i not in P ]

if len(P) == 0 or X not in P:
    print(X)
    sys.exit()

idx = NL.index(X)
if NL[idx + 1] - X >= X - NL[idx-1]:
    print(NL[idx-1])
else:
    print(NL[idx+1])
from scipy.special import comb

N = int(input())
S = [input() for _ in range(N)]

li = []
for s in S:
    st = "".join(sorted(list(s)))
    li.append(st)

d = {}
for i in sorted(li):
    if i in d:
        d[i] = d[i] + 1
    else:
        d[i] = 1


ans = 0
for k, v in d.items():
    ans += comb(v, 2, exact=True)

print(ans)


### FIXED CODE ###

N = int(input())
S = [input() for _ in range(N)]

t = {}
ans = 0
for s in S:
    st = "".join(sorted(list(s)))
    if st in t.keys():
        t[st] += 1
        ans += t[st]
    else:
        t[st] = 0

print(ans)
i = int(input())
a = i % 10
if a in [2,4,5,7,9]:
  return 'hon'
if a in [0,1,6,8]:
  return 'pon'
if a in [3]:
  return 'bon'


### FIXED CODE ###

i = int(input())
a = i % 10
if a in [2,4,5,7,9]:
  print('hon')
if a in [0,1,6,8]:
  print('pon')
if a in [3]:
  print('bon')
l = [int(i) for i in input().split()]
print((l[3] + 0.5) // l[0] * l[1])

### FIXED CODE ###

l = [int(i) for i in input().split()]
print(int((l[2] + 0.5) // l[0] * l[1]))
s = input()
print(s.replace("2017,"2018"))

### FIXED CODE ###

s = input()
print(s.replace("2017","2018"))
s = input()
t = input()
s_list = list(s)
t_list = list(t)
compare = []
score = []

if s == t:
    print(0)
else:
    for i in range(len(s) - len(t) + 1):
        compare.append(s[i : i + len(t)])
    
    for v in compare:
        count = 0
        for v1, v2 in zip(list(v), t_list):
            #print(v1, v2)
            if v1 == v2:
                count += 1
        score.append(count)

print(len(t) - max(score))


### FIXED CODE ###

s = input()
t = input()
s_list = list(s)
t_list = list(t)
compare = []
score = []

if s == t:
    print(0)
else:
    for i in range(len(s) - len(t) + 1):
        compare.append(s[i : i + len(t)])
    
    for v in compare:
        count = 0
        for v1, v2 in zip(list(v), t_list):
            #print(v1, v2)
            if v1 == v2:
                count += 1
        score.append(count)
    print(len(t) - max(score))