Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if p+n<1:break
    man = [i for i in [0]*n]
    ball,a = p,0
    while p not in man:
        if ball >0:ball,man[a%n] =ball-1, man[a%n]+1
        elif ball == 0:ball,man[a%n] = man[a%n],ball
        a+=1
    print(man.index(max(man)))        

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if p+n<1:break
    man = [i for i in [0]*n]
    ball,a = p,0
    while p not in man:
        if ball >0:ball,man[a%n] =ball-1, man[a%n]+1
        elif ball == 0:ball,man[a%n] = man[a%n],ball
        a+=1
    print(man.index(max(man)))        

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if p+n<1:break
    man = [i for i in [0]*n]
    ball,a = p,0
    while p not in man:
        if ball >0:ball,man[a%n] =ball-1, man[a%n]+1
        elif ball == 0:ball,man[a%n] = man[a%n],ball
        a+=1
    print(man.index(max(man)))        

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man = [i for i in [0]*n]
    ball,a = p,0
    while p not in man:
        if ball >0:ball,man[a%n] =ball-1, man[a%n]+1
        elif ball == 0:ball,man[a%n] = man[a%n],ball
        a+=1
    print(man.index(max(man)))        

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man = [i for i in [0]*n]
    ball,a = p,0
    while p not in man:
        if ball == 0:ball,man[a%n] = man[a%n],ball
        if ball >0:
            ball,man[a%n] =ball-1, man[a%n]+1
        a+=1
    print(man.index(max(man)))        

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man = [i for i in [0]*n]
    ball,a = p,0
    while p not in man:
        if ball >0:ball,man[a%n] =ball-1, man[a%n]+1
        elif ball == 0:ball,man[a%n] = man[a%n],ball
        a+=1
    print(man.index(max(man)))        

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while p not in man:
        if ball >0:ball,man[a%n] =ball-1, man[a%n]+1
        elif ball == 0:ball,man[a%n] = man[a%n],ball
        a+=1
    print(man.index(max(man)))            

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Runtime Error):
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        if ball >0:ball,man[a%n] =ball-1, man[a%n]+1
        elif ball == 0:ball,man[a%n] = man[a%n],ball
        a+=1
        if p in man:break
    print(man.index(max(man)))        )            

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        if ball >0:ball,man[a%n] =ball-1, man[a%n]+1
        elif ball == 0:ball,man[a%n] = man[a%n],ball
        a+=1
        if p in man:break
    print(man.index(max(man)))                 

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:ball,man[a] =ball-1, man[a]+1
        elif ball == 0:ball,man[a] = man[a],ball
        a+=1
        if p in man:break
    print(man.index(max(man)))
              

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        a+=1
        if p in man:break
    print(man.index(max(man)))        

Fixed submission:
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(a)