Problem:


FizzBuzz

「Fizz Buzz」と言われる数字を使ったゲームがあります。このゲームは複数のプレイヤーで数字を1 から順にひとつずつ数え上げていくもので、各プレイヤーは直前のプレイヤーが発言した次の数字をひとつだけ発言します。その時、3 で割り切れる場合は 「Fizz」, 5 で割り切れる場合は 「Buzz」、両者で割り切れる場合は「FizzBuzz」と数の代わりに発言しなければなりません。例えば、最初の 16 までの発言は以下のようになります。

    1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, ・・・

  太郎君は友達と「Fizz Buzz」をして遊ぶことにしました。太郎君たちはルールを次のように決めました。 

  

  「間違えた人は脱落する。その次の人は間違えた数の次の数から始める。つまり、1, 2, 3 と発言した場合、3 で間違えたので次は 4 から始めることになる。」

  

このルールに従ってゲームを行うのですが、ゲームに慣れていないため、間違えたことに気付かないことがあり、公平な判断ができません。そこであなたは太郎君たちがこのゲームを楽しめるように、決められた発言回数が終わった時点で残っていた人を出力するプログラムを作成することにしました。

  プレイヤー数、ゲーム中に発言された回数、それぞれの発言を入力とし、入力が終わった時点で残っているプレイヤーの番号を小さい順に出力するプログラムを作成してください。ただし、プレイヤーには 1 から番号が割り振られており、発言順番も 1 番目のプレイヤーから順に行い、一通り発言が終わると、再度 1 番目のプレイヤーから発言することとします。順番の回ってきたプレイヤーが既に脱落している場合は、その次のプレイヤーが発言します。また、このプログラムは、プレイヤーが一人になった時点で、その後の発言を無視しなければなりません。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。
各データセットは以下の形式で与えられます。

m n
s1
s2
:
sn

1 行目にプレイヤー数 m (2 ≤ m ≤ 1000) と発言回数 n (1 ≤ n ≤ 10000) が与えられます。

続く n 行に i 番目の発言 s1 が与えられます。 si は整数、Fizz、Buzz、または FizzBuzz を示す文字列（8文字以下）です。

n 行に i 番目の発言 s1 が与えられます。 si は数字、Fizz、Buzz、FizzBuzz、あるいは間違った発言を示すその他の文字列 (20 文字以下) です。

-->

データセットの数は 50 を超えません。

Output

入力データセットごとに、指定された発言回数まで入力されたときに残っているプレイヤーの番号を小さい順に出力します。

Sample Input

5 7
1
2
Fizz
4
Buzz
6
7
3 5
1
2
3
4
5
0 0

Output for the Sample Input

2 3 4 5
1



Sample input:
5 7
1
2
Fizz
4
Buzz
6
7
3 5
1
2
3
4
5
0 0


Sample output:
2 3 4 5
1

Submission status: Runtime Error

Solution code:
while(True):
    m,n = map(int,input().split())
    if not m: break
    a = list(range(1,m+1))
    b = [input() for _ in range(n)]
    t = [str(i+1) for i in range(n)]
    t[2::3]   = ["Fizz"]*len(t[2::3])
    t[4::5]   = ["Buzz"]*len(t[4::5])
    t[14::15] = ["FizzBuzz"]*len(t[14::15])
    i=0
    for j in range(n):
        if len(a) <2: break
        if b[j] != t[j]: del a[i]; continue
        i += 1
        i = i%len(a)
    print(" ".join(str(e) for e in a))

Submission status: Runtime Error

Solution code:
def fizz_buzz():
    c = 1
    while True:
        res = ''
        if c % 3 == 0:
            res = res + 'Fizz'
        if c % 5 == 0:
            res = res + 'Buzz'
        if res == '':
            yield str(c)
        else:
            yield res
        c += 1

while True:
    m,n = map(int,raw_input().split())
    if m == 0: break

    player = range(m)

    p = 0
    fb = fizz_buzz()
    for i in range(n):
        inp = raw_input()
        if len(player) > 1:
            if  inp <> fb.next():
                del player[p] 
            else:
                p = (p+1) % len(player)

    result = str(player[0]+1)
    for pi in player[1:]:
        result += ' ' + str(pi+1)

    print result

Submission status: Runtime Error

Solution code:

def fizz_buzz():
    c = 1
    while True:
        res = ''
        if c % 3 == 0:
            res = res + 'Fizz'
        if c % 5 == 0:
            res = res + 'Buzz'
        if res == '':
            yield str(c)
        else:
            yield res
        c += 1

while True:
    m,n = map(int,raw_input().split())
    if m == 0: break

    player = range(m)

    p = 0
    fb = fizz_buzz()
    for i in range(n):
        inp = raw_input()
        if len(player) > 1:
            if  inp != fb.next():
                del player[p] 
            else:
                p = (p+1) % len(player)

    result = str(player[0]+1)
    for pi in player[1:]:
        result += ' ' + str(pi+1)

    print result

Submission status: Runtime Error

Solution code:
def fizz_buzz():
    c = 1
    while True:
        res = ''
        if c % 3 == 0:
            res = res + 'Fizz'
        if c % 5 == 0:
            res = res + 'Buzz'
        if res == '':
            yield str(c)
        else:
            yield res
        c += 1

while True:
    m,n = map(int,input().split())
    if m == 0: break

    player = list(range(m))

    p = 0
    fb = fizz_buzz()
    for i in range(n):
        inp = input()
        if len(player) > 1:
            if  inp != next(fb):
                del player[p] 
            else:
                p = (p+1) % len(player)

    result = str(player[0]+1)
    for pi in player[1:]:
        result += ' ' + str(pi+1)

    print(result)

Submission status: Runtime Error

Solution code:
def fizz_buzz():
    c = 1
    while True:
        res = ''
        if c % 3 == 0:
            res = res + 'Fizz'
        if c % 5 == 0:
            res = res + 'Buzz'
        if res == '':
            yield str(c)
        else:
            yield res
        c += 1

while True:
    m,n = map(int,input().split())
    if m == 0: break

    player = list(range(m))

    p = 0
    fb = fizz_buzz()
    for i in range(n):
        inp = input()
        if len(player) > 1:
            if  inp != next(fb):
                del player[p] 
            else:
                p = (p+1) % len(player)

    result = str(player[0]+1)
    if len(player) > 1:
        for pi in player[1:]:
            result += ' ' + str(pi+1)

    print(result)

Submission status: Runtime Error

Solution code:
def fizz_buzz():
    c = 1
    while True:
        res = ''
        if c % 3 == 0:
            res = res + 'Fizz'
        if c % 5 == 0:
            res = res + 'Buzz'
        if res == '':
            yield str(c)
        else:
            yield res
        c += 1

while True:
    m,n = map(int,input().split())
    if m == 0: break

    player = list(range(m))

    p = 0
    fb = fizz_buzz()
    for i in range(n):
        inp = input()
        if len(player) > 1:
            if  inp != next(fb):
                del player[p] 
            else:
                p = (p+1) % len(player)

    print(result)

Submission status: Runtime Error

Solution code:
def fizzbuzz(i):
    if i % 15 == 0:
        return 'FizzBuzz'
    elif i % 5 == 0:
        return 'Buzz'
    elif i % 3 == 0:
        return 'Fizz'
    else:
        return str(i)

import sys
f = sys.stdin

while True:
    m, n = map(int, f.readline().split())
    if m == n == 0:
        break
    member = list(range(1, m + 1))
    s = [f.readline().strip() for _ in range(n)]
    offset = 0
    for i in range(n):
        if s[i] != fizzbuzz(i + 1):
            pos = (i - offset) % m
            member.remove(member[pos])
            offset = i - pos
            if len(member) == 1:
                break
        
    print(*member)

Submission status: Runtime Error

Solution code:
while(1):
    [m,n]=[int(x) for x in raw_input().split()]
    if m==0:
        break
    else:
        truenum=0
        player=[x for x in range(1,m+1)]
        for i in range(n):
            if len(player)>1:
                shout=raw_input()
                pnow=player.pop(0)
                truenum=truenum+1
                if truenum%15==0:
                    if shout=="FizzBuzz":
                        player.append(pnow)
                elif truenum%5==0:
                    if shout=="Buzz":
                        player.append(pnow)
                elif truenum%3==0:
                    if shout=="Fizz":
                        player.append(pnow)
                else:
                    if shout==str(truenum):
                        player.append(pnow)
        print " ".join([str(x) for x in sorted(player)])

Submission status: Runtime Error

Solution code:
while True:
    M, N = map(int, raw_input().split())
    if M == N == 0: break
    m = [i for i in range(1, M+1)]
    index = 0
    num = 1
    for i in range(N):
        line = raw_input()
        if num % 15 == 0:
            if line != 'FizzBuzz':
                del m[index]
        elif num % 3 == 0:
            if line != 'Fizz':
                del m[index]
        elif num % 5 == 0:
            if line != 'Buzz':
                del m[index]
        else:
            if not line.isdigit():
                del m[index]
            else:
                if int(line) != num:
                    del m[index]
        if len(m) == 1:
            break
        elif index+1 >= len(m):
            index = 0
        else:
            index += 1
        num += 1
    else:
        print ' '.join(map(str, m))

Submission status: Runtime Error

Solution code:
while True:
    M, N = map(int, raw_input().split())
    if M == N == 0: break
    m = [i for i in range(1, M+1)]
    index = 0
    num = 1
    for i in range(N):
        line = raw_input()
        if num % 15 == 0:
            if line != 'FizzBuzz':
                del m[index]
        elif num % 3 == 0:
            if line != 'Fizz':
                del m[index]
        elif num % 5 == 0:
            if line != 'Buzz':
                del m[index]
        else:
            if not line.isdigit():
                del m[index]
            else:
                if int(line) != num:
                    del m[index]
        if len(m) == 1:
            break
        elif index+1 >= len(m):
            index = 0
        else:
            index += 1
        num += 1
    print ' '.join(map(str, m))

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a,i,c=[i+1 for i in range(m)],1,0
    while i<=n:
        b,f=input(),0
        if i%15==0:
            if b!='FizzBuzz':
                del a[c]
                f=1
        elif i%5==0:
            if b!='Buzz':
                del a[c]
                f=1
        elif i%3==0:
            if b!='Fizz':
                del a[c]
                f=1
        else:
            if b!=str(i):
                del a[c]
                f=1
        if f:m-=1
        else:c=(c+1)%m

        i+=1
    print(*a)

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a,i,c=[i+1 for i in range(m)],1,0
    while i<=n:
        b,f=input(),0
        if m==1:continue
        if i%15==0:
            if b!='FizzBuzz':
                del a[c]
                f=1
        elif i%5==0:
            if b!='Buzz':
                del a[c]
                f=1
        elif i%3==0:
            if b!='Fizz':
                del a[c]
                f=1
        else:
            if b!=str(i):
                del a[c]
                f=1
        if f:m-=1
        else:c=(c+1)%m
        i+=1
    print(*a)

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a,i,c=[i+1 for i in range(m)],0,0
    while i<n:
        i+=1
        b,f=input(),0
        if m==1:continue
        if i%15==0:
            if b!='FizzBuzz':
                del a[c]
                f=1
        elif i%5==0:
            if b!='Buzz':
                del a[c]
                f=1
        elif i%3==0:
            if b!='Fizz':
                del a[c]
                f=1
        else:
            if b!=str(i):
                del a[c]
                f=1
        if f:m-=1
        else:c=(c+1)%m
    print(*a)

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a,i,c=[i+1 for i in range(m)],0,0
    while i<n:
        i+=1
        b,f=input(),0
        if len(a)==1:continue
        if i%15==0:
            if b!='FizzBuzz':
                del a[c]
                f=1
        elif i%5==0:
            if b!='Buzz':
                del a[c]
                f=1
        elif i%3==0:
            if b!='Fizz':
                del a[c]
                f=1
        else:
            if b!=str(i):
                del a[c]
                f=1
        if f:m-=1
        else:c=(c+1)%m
    print(*a)

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a,i,c=list(range(1,m+1)),0,0
    while i<n:
        i+=1
        b,f=input(),0
        if m<2:continue
        if i%15==0:
            if b!='FizzBuzz':
                del a[c]
                f=1
        elif i%5==0:
            if b!='Buzz':
                del a[c]
                f=1
        elif i%3==0:
            if b!='Fizz':
                del a[c]
                f=1
        elif b!=str(i):
            del a[c]
            f=1
        if f:
            m-=1
            c%m
        else:c=(c+1)%m
    print(*a)

Submission status: Runtime Error

Solution code:
while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    player = [i+1 for i in range(m)]
    j = 0
    for i in range(1, n+1):
        s = input()
        if i % 3 == 0 and i % 5 == 0 and s != 'FizzBuzz':
            del player[j]
        elif i % 3 == 0 and s != 'Fizz':
            del player[j]
        elif i % 5 == 0 and s != 'Buzz':
            del player[j]
        if len(player)-1 == j or len(player) == j:
            j = 0
        else:
            j += 1
    print(*player)

Submission status: Runtime Error

Solution code:
while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    player = [i+1 for i in range(m)]
    j = 0
    for i in range(1, n+1):
        s = input()
        if i % 3 == 0 and i % 5 == 0 and s != 'FizzBuzz':
            del player[j]
        elif i % 3 == 0 and s != 'Fizz':
            del player[j]
        elif i % 5 == 0 and s != 'Buzz':
            del player[j]
        if len(player) == 1:
            break
        if len(player)-1 == j or len(player) == j:
            j = 0
        else:
            j += 1
    print(*player)

Submission status: Runtime Error

Solution code:
hoge = [0] + ["FizzBuzz" if i % 3 == 0 and i % 5 == 0 else("Fizz" if i % 3 == 0 else("Buzz" if i % 5 == 0 else str(i))) for i in range(1, 10001)]

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = [str(i) for i in range(1, m+1)]
    a, b = divmod(n, m)
    man = a*man+man[:b]
    idx = 0
    for i in range(1, n+1):
        if hoge[i] == input():
            idx += 1
        else:
            v = man[idx]
            man = list(filter((v).__ne__, man))
    print(*sorted(list(set(man))))

Submission status: Runtime Error

Solution code:
hoge = []
for i in range(10001):
    if i % 3 == 0 and i % 5 == 0:
        hoge.append("FizzBuzz")
    elif i % 3 == 0:
        hoge.append("Fizz")
    elif i % 5 == 0:
        hoge.append("Buzz")
    else:
        hoge.append(str(i))

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = [str(i) for i in range(1, m+1)]
    a, b = divmod(n, m)
    man = a*man+man[:b]
    idx = 0
    for i in range(1, n+1):
        if hoge[i] == input():
            idx += 1
        else:
            v = man[idx]
            man = list(filter((v).__ne__, man))
    print(*sorted(list(set(man))))

Submission status: Runtime Error

Solution code:
hoge = ["FizzBuzz" if i % 3 == 0 and i % 5 == 0 else("Fizz" if i % 3 == 0 else("Buzz" if i % 5 == 0 else str(i))) for i in range(10001)]

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = [str(i) for i in range(1, m+1)]
    a, b = divmod(n, m)
    man = a*man+man[:b]
    idx = 0
    for i in range(1, n+1):
        if hoge[i] == input():
            idx += 1
        else:
            v = man[idx]
            man = list(filter((v).__ne__, man))
            if len(man) == 1:
                break
    print(*sorted(list(set(man))))

Submission status: Runtime Error

Solution code:
hoge = ["FizzBuzz" if i % 3 == 0 and i % 5 == 0 else("Fizz" if i % 3 == 0 else("Buzz" if i % 5 == 0 else str(i))) for i in range(10001)]

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = [str(i) for i in range(1, m+1)]
    a, b = divmod(n, m)
    man = a*man+man[:b]
    idx = 0
    for i in range(1, n+1):
        if hoge[i] == input():
            idx += 1
        else:
            v = man[idx]
            man = list(filter((v).__ne__, man))
            if len(man) == 1:
                break
    print(*sorted([int(v) for v in set(man)]))

Submission status: Runtime Error

Solution code:
hoge = ["FizzBuzz" if i % 3 == 0 and i % 5 == 0 else("Fizz" if i % 3 == 0 else("Buzz" if i % 5 == 0 else str(i))) for i in range(10001)]

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = [str(i) for i in range(1, m+1)]
    a, b = divmod(n, m)
    man = a*man+man[:b]
    idx = 0
    for i in range(1, n+1):
        if hoge[i] == input():
            idx += 1
        else:
            v = man[idx]
            man = list(filter((v).__ne__, man))
            if len(set(man)) == 1:
                break
    print(*sorted(list(set(man))))

Submission status: Runtime Error

Solution code:
hoge = ["FizzBuzz" if i % 3 == 0 and i % 5 == 0 else("Fizz" if i % 3 == 0 else("Buzz" if i % 5 == 0 else str(i))) for i in range(10001)]

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = [str(i) for i in range(1, m+1)]
    a, b = divmod(n, m)
    man = a*man+man[:b]
    idx, k = 0, 1
    while k < n+1:
        x = input()
        if hoge[i] == x:
            idx += 1
        else:
            v = man[idx]
            man = list(filter((v).__ne__, man))
            if len(set(man)) == 1:
                for i in range((n+1)-k):
                    input()
                break
        k += 1
    print(*sorted(list(set(man))))

Submission status: Runtime Error

Solution code:
hoge = ["FizzBuzz" if i % 3 == 0 and i % 5 == 0 else("Fizz" if i % 3 == 0 else("Buzz" if i % 5 == 0 else str(i))) for i in range(10001)]

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = [str(i) for i in range(1, m+1)]
    a, b = divmod(n, m)
    man = a*man+man[:b]
    idx, k = 0, 1
    while k < n+1:
        x = input()
        if hoge[k] == x:
            idx += 1
        else:
            v = man[idx]
            man = list(filter((v).__ne__, man))
            if len(set(man)) == 1:
                for i in range((n+1)-k):
                    input()
                break
        k += 1
    print(*sorted(list(set(man))))

Submission status: Runtime Error

Solution code:
hoge = ["FizzBuzz" if i % 3 == 0 and i % 5 == 0 else("Fizz" if i % 3 == 0 else("Buzz" if i % 5 == 0 else str(i))) for i in range(10001)]

while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    man = [str(i) for i in range(1, m+1)]
    a, b = divmod(n, m)
    man = a*man+man[:b]
    idx, k = 0, 1
    while k < n+1:
        x = input()
        if hoge[k] == x:
            idx += 1
        else:
            v = man[idx]
            man = list(filter((v).__ne__, man))
            if len(set(man)) == 1:
                for i in range(n-k):
                    input()
                break
        k += 1
    print(*sorted(list(set(man))))

Submission status: Runtime Error

Solution code:
while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    player = list(range(1, m+1))
    idx = 0
    for i in range(1, n+1):
        ans = "Fizz"*(i%3==0) + "Buzz"*(i%5==0) or str(i)
        if ans == input():
            idx += 1
        else:
            player.pop(idx)
            if len(player) == 1:
                break
        idx %= len(player)
    print(*player)

Submission status: Runtime Error

Solution code:
while True:
    m, n = map(int, input().split())
    if m == 0:
        break
    player = list(range(1, m+1))
    idx = 0
    for i in range(1, n+1):
        ans = "Fizz"*(i%3==0) + "Buzz"*(i%5==0) or str(i)
        if ans == input():
            idx += 1
        else:
            del player[idx]
            if len(player) == 1:
                break
        idx %= len(player)
    print(*player)

Submission status: Runtime Error

Solution code:
# Aizu Problem 0221: Fizz Buzz

import sys, math, os, struct

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def valid(k, a):
    if k % 3 == 0 and k % 5 == 0:
        return a == "FizzBuzz"
    elif k % 3 == 0:
        return a == "Fizz"
    elif k % 5 == 0:
        return a == "Buzz"
    else:
        return int(a) == k

    
def fizz_buzz(m, n, A):
    players = list(range(1, m + 1))
    p = 0
    k = 0
    while len(A) > 0:
        k += 1
        a = A.pop(0)
        if valid(k, a):
            p = (p + 1) % m
        else:
            players.pop(p)
            m -= 1
            if p == m:
                p = 0
    print(' '.join([str(p) for p in players]))
    
    
while True:
    m, n = [int(_) for _ in input().split()]
    if m == n == 0:
        break
    A = [input().strip() for _ in range(n)]
    fizz_buzz(m, n, A)

Submission status: Runtime Error

Solution code:
# Aizu Problem 0221: Fizz Buzz

import sys, math, os, struct

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def valid(k, a):
    if k % 3 == 0 and k % 5 == 0:
        return a == "FizzBuzz"
    elif k % 3 == 0:
        return a == "Fizz"
    elif k % 5 == 0:
        return a == "Buzz"
    else:
        return int(a) == k

    
def fizz_buzz(m, n, A):
    players = list(range(1, m + 1))
    p = 0
    k = 0
    while len(A) > 0:
        k += 1
        a = A.pop(0)
        if valid(k, a):
            p = (p + 1) % m
        else:
            if len(players) == 0:
                print()
                return
            players.pop(p)
            m -= 1
            if p == m:
                p = 0
    print(' '.join([str(p) for p in players]))
    
    
while True:
    m, n = [int(_) for _ in input().split()]
    if m == n == 0:
        break
    A = [input().strip() for _ in range(n)]
    fizz_buzz(m, n, A)

Submission status: Runtime Error

Solution code:
# Aizu Problem 0221: Fizz Buzz

import sys, math, os, struct

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def valid(k, a):
    if k % 3 == 0 and k % 5 == 0:
        return a == "FizzBuzz"
    elif k % 3 == 0:
        return a == "Fizz"
    elif k % 5 == 0:
        return a == "Buzz"
    else:
        return int(a) == k

    
def fizz_buzz(m, n, A):
    players = list(range(1, m + 1))
    p = 0
    k = 0
    while len(A) > 0:
        k += 1
        a = A.pop(0)
        if valid(k, a):
            p = (p + 1) % m
        else:
            if len(players) == 0:
                print()
                return
            players.pop(p)
            m -= 1
            if p == m:
                p = 0
    print(' '.join([str(p) for p in players]))
    
    
while True:
    m, n = [int(_) for _ in input().split()]
    if m == 0:
        break
    A = [input().strip() for _ in range(n)]
    fizz_buzz(m, n, A)

Submission status: Runtime Error

Solution code:
# Aizu Problem 0221: Fizz Buzz

import sys, math, os, struct

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def valid(k, a):
    if k % 3 == 0 and k % 5 == 0:
        return a == "FizzBuzz"
    elif k % 3 == 0:
        return a == "Fizz"
    elif k % 5 == 0:
        return a == "Buzz"
    else:
        return int(a) == k

    
def fizz_buzz(m, n, A):
    players = list(range(1, m + 1))
    p = 0
    k = 0
    while len(A) > 0:
        k += 1
        a = A.pop(0)
        if valid(k, a):
            p = (p + 1) % m
        else:
            if len(players) == 0:
                print()
                return
            players.pop(p)
            if len(players) == 1:
                break
            m -= 1
            if p == m:
                p = 0
    print(' '.join([str(p) for p in players]))
    
    
while True:
    m, n = [int(_) for _ in input().split()]
    if m == 0:
        break
    A = [input().strip() for _ in range(n)]
    fizz_buzz(m, n, A)

Submission status: Runtime Error

Solution code:
import sys

def main():
    for line in sys.stdin:
        m, n = map(int, line.split())
        if m == 0 and n == 0:
            break
        else:
            s = []
            for x in range(1, n + 1):
                s.append(input())

            a = []
            for x in range(int(s[0]), n + 1):
                if x % 3 == 0 and x % 5 != 0:
                    a.append("Fizz")
                elif x % 3 != 0 and x % 5 == 0:
                    a.append("Buzz")
                elif x % 3 == 0 and x % 5 == 0:
                    a.append("FizzBuzz")
                else:
                    a.append(str(x))

            print("s", s)
            print("a", a)

            m_list = [i for i in range(1, m + 1)]
            f = True
            for x in range(n):
                if s[x] != a[x]:
                    if m_list[x % 5] != 0:
                        m_list[x % 5] = 0
                    else:
                        for y in range(m - 1):
                            hoge = x % m + y
                            if hoge > m - 1:
                                hoge -= m
                            if m_list[hoge] != 0:
                                m_list[hoge] = 0
                                break
                            if y == m - 2:
                                f = False

            if f == True:
                for x in range(m):
                    if m_list[x] != 0:
                        print(m_list[x], end = " ")
                print()

            else:
                print(0)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

def main():
    for line in sys.stdin:
        m, n = map(int, line.split())
        if m == 0 and n == 0:
            break
        else:
            s = []
            for x in range(1, n + 1):
                s.append(input())

            a = []
            for x in range(int(s[0]), n + 1):
                if x % 3 == 0 and x % 5 != 0:
                    a.append("Fizz")
                elif x % 3 != 0 and x % 5 == 0:
                    a.append("Buzz")
                elif x % 3 == 0 and x % 5 == 0:
                    a.append("FizzBuzz")
                else:
                    a.append(str(x))

            print("s", s)
            print("a", a)

            m_list = [i for i in range(1, m + 1)]
            f = True
            for x in range(n):
                if s[x] != a[x]:
                    if m_list[x % 5] != 0:
                        m_list[x % 5] = 0
                    else:
                        for y in range(m - 1):
                            hoge = x % m + y
                            if hoge > m - 1:
                                hoge -= m
                            if m_list[hoge] != 0:
                                m_list[hoge] = 0
                                break
                            if y == m - 2:
                                f = False
                                break

            if f == True:
                for x in range(m):
                    if m_list[x] != 0:
                        print(m_list[x], end = " ")
                print()

            else:
                print(0)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

def main():
    for line in sys.stdin:
        m, n = map(int, line.split())
        if m == 0 and n == 0:
            break
        else:
            s = []
            for x in range(1, n + 1):
                s.append(input())

            a = []
            for x in range(int(s[0]), n + 1):
                if x % 3 == 0 and x % 5 != 0:
                    a.append("Fizz")
                elif x % 3 != 0 and x % 5 == 0:
                    a.append("Buzz")
                elif x % 3 == 0 and x % 5 == 0:
                    a.append("FizzBuzz")
                else:
                    a.append(str(x))

            m_list = [i for i in range(1, m + 1)]
            f = True
            for x in range(n):
                if s[x] != a[x]:
                    if m_list[x % m] != 0:
                        m_list[x % m] = 0
                    else:
                        for y in range(m - 1):
                            hoge = x % m + y
                            if hoge > m - 1:
                                hoge -= m
                            if m_list[hoge] != 0:
                                m_list[hoge] = 0
                                break
                            if y == m - 2:
                                f = False
                                break

            if f == True:
                for x in range(m):
                    if m_list[x] != 0:
                        print(m_list[x], end = " ")
                print()

            else:
                print(0)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0221

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def FizzBuzz(count=1):
    while True:
        if count % 15 == 0:
            ans = 'FizzBuzz'
        elif count % 5 == 0:
            ans = 'Buzz'
        elif count % 3 == 0:
            ans = 'Fizz'
        else:
            ans = str(count)
        yield ans
        count += 1


def main(args):
    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break
        players = deque(range(1, m+1))
        fb = FizzBuzz()
        for i in range(1, n+1):
            p = input().strip('\n')
            if p != fb.__next__():
                players.popleft()
            else:
                players.rotate(-1)
            if len(players) == 1:
                break

        result = list(players)
        result.sort()
        print(*result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0221

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def FizzBuzz(count=1):
    while True:
        if count % 15 == 0:
            ans = 'FizzBuzz'
        elif count % 5 == 0:
            ans = 'Buzz'
        elif count % 3 == 0:
            ans = 'Fizz'
        else:
            ans = str(count)
        yield ans
        count += 1


def main(args):
    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break
        players = deque(range(1, m+1))
        fb = FizzBuzz()
        for _ in range(n):
            p = input().strip('\n')
            # print('player {}: {}'.format(players[0], p))
            if p != fb.__next__():
                drop = players.popleft()
                # print('player {} dropped'.format(drop))
                if len(players) == 1:
                    break
            else:
                players.rotate(-1)

        result = list(players)
        result.sort()
        print(*result)


if __name__ == '__main__':
    main(sys.argv[1:])