<doocs>0481.Magical String_1.py
def magicalString( n: int) -> int:
    s = list('1221121')
    i = 5
    while len(s) < n:
        if s[i] == '1':
            s.append('2' if s[-1] == '1' else '1')
        else:
            s.extend(list('22' if s[-1] == '1' else '11'))
        i += 1
    return s[:n].count('1')
def sample_funcname ( var_0 : int ) -> int :
    var_4 = list ( '1221121' )
    var_6 = 5
    while len ( var_4 ) < var_0 :
        if var_4 [ var_6 ] == '1' :
            var_4.append ( '2' if var_4 [ - 1 ] == '1' else '1' )
        else :
            var_4.extend ( list ( '22' if var_4 [ - 1 ] == '1' else '11' ) )
        var_6 += 1
    return var_4 [ : var_0 ].count ( '1' )
