# Task
 You are given two string `a` an `s`. Starting with an empty string we can do the following two operations:
```
append the given string a to the end of the current string.
erase one symbol of the current string.```
Your task is to find the least number of operations needed to construct the given string s. Assume that all the letters from `s` appear in `a` at least once.

# Example

 For `a = "aba", s = "abbaab"`, the result should be `6`.
 
 Coinstruction:
 
 `"" -> "aba" -> "ab" -> "ababa" -> "abba" -> "abbaaba" -> "abbaab".`
 
 So, the result is 6.

 For `a = "aba", s = "a"`, the result should be `3`.
 
 Coinstruction:
 
 `"" -> "aba" -> "ab" -> "a".`
 
 So, the result is 3.

 For `a = "aba", s = "abaa"`, the result should be `4`.
 
 Coinstruction:
 
 `"" -> "aba" -> "abaaba" -> "abaab" -> "abaa".`
 
 So, the result is 4.

# Input/Output


 - `[input]` string `a`

  string to be appended. Contains only lowercase English letters. 
  
  1 <= a.length <= 20


 - `[input]` string `s`

  desired string containing only lowercase English letters.
  
  1 <= s.length < 1000


 - `[output]` an integer

  minimum number of operations

Difficulty: introductory

Starter code:

def string_constructing(a, s):
	

Solutions:
def string_constructing(a, s):
    if len(s) == 0:
        return 0
    i = -1
    for j, c in enumerate(s):
        i = a.find(c, i+1)
        if i < 0 or i == len(a) - 1:
            break
    return len(a) - j + (i < 0) + string_constructing(a, s[j + (i >= 0):])

def string_constructing(pattern,target):
    pattern = list(pattern)
    target = list(target) + [None]
    buffer = [None]
    pos= 0
    count= 0
    while (True):
        
        if(target[pos]==buffer[pos]):
            if(target[pos]==None):
                return count
            pos +=1
        else:
            if(buffer[pos]==None):
                buffer[-1:-1]=pattern
                count+=1
            else:
                del buffer[pos]
                count+=1
            
    return count
        
    
    


import re

def string_constructing(a, s):
    n = len(re.findall('?'.join(list(a))+'?', s)) - 1          # "-1" because one empty string is always found at the end
    return n + len(a)*n - len(s)

def string_constructing(a, s):
    i = 0
    for c in s:
        while a[i % len(a)] != c:
            i += 1
        i += 1
    return (i + len(a) - 1) // len(a) * (len(a) + 1) - len(s)

def string_constructing(a, s):
    i, r = 0, 1
    for x in s:
        y = a[i % len(a)]
        while x != y:
            r += 1
            i += 1
            y = a[i % len(a)]
        i += 1
    return r + i // len(a) + -i % len(a) - (i % len(a) == 0)


def string_constructing(a, s):
    current = ""
    step = 0
    while current != s:
        for i in range(len(current)):
            if i >= len(s):
                return step + len(current) - len(s)
            if current[i] != s[i]:
                current = current[i+1:]
                s = s[i:]
                break
        else:
            current += a
        step += 1
                
    return step

def string_constructing(a, s):
    T = a
    c, al = 1, 0
    while T != s:
        if al < len(T) and al < len(s) and T[al] == s[al]:
            al += 1
        elif al == len(T):
            T += a
            c += 1
        elif len(s) < len(T) or T[al] != s[al]:
            T = T[:al] + T[al + 1:]
            al = max(al - 1, 0)
            c += 1
    return c

def common_len(s1,s2):
    n, m = len(s1), len(s2)
    i=0
    for c1 in s1:
        if i>=len(s2):
            break
        elif c1==s2[i]:
            i+=1
    return i

def string_constructing(a, s):
    r=[]
    c=0
    p=0
    while(p<len(s)):
        l=common_len(a,s[p:p+len(a)])
        c+=1+len(a)-l
        p+=l    
    return c

def string_constructing(a,b):
    s, c = [], 0
    while ''.join(s) != b:
        s.extend(list(a))
        c += 1 ; i = 0
        while i < len(s) and i < len(b):
            if s[i] == b[i] : i += 1
            else : c += 1 ; s.pop(i)
        if ''.join(s).startswith(b) : c += len(s[len(b):]) ; break
    return c

def string_constructing(a, s):
    if not s:
        return 0
    if set(s)-set(a):
        return False

    n = 1
    i = 0
    for c in s:
        while True:
            if i==len(a):
                i = 0
                n += 1
            if a[i]!=c:
                n += 1
                i+=1
            else:
                i+=1
                break
            
            
    return n+len(a)-i