Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		p, _ := strconv.Atoi(chunks[1])
		cnts := make([]int, n, n)
		for i := 0; true; i++ {
			j := i % n
			if p == 0 {
				p, cnts[j] = cnts[j], 0
			} else {
				cnts[j]++
				p--
			}

			if p == 0 {
				noneCnt := 0
				winner := 0
				for j, c := range cnts {
					if c == 0 {
						noneCnt++
					} else {
						winner = j
					}
				}
				if noneCnt == n-1 {
					fmt.Println(winner)
					break
				}
			}
		}
	}
}

Python: 
while True:
    n, p = [ int(i) for i in input().split() ]

    if n == p == 0:
        break

    # print("start: ", n, p)

    leaders = [0] * n
    result = 0
    index = 0
    stone_num = p

    while True:

        if stone_num > 0:
            leaders[index] += 1
            stone_num -= 1

            # ??¨??¨????????£??????????????????
            if leaders[index] == p:
                result = index
                break
                
        elif leaders[index] > 0:
            stone_num = leaders[index]
            leaders[index] = 0

        index = (index + 1) % n


    print(result)

Python: while 1:
    n,p=map(int,input().split())
    if n==p==0:break
    p2=p
    stone=[0]*n
    pos=0
    while 1:
        if p==0:
            p+=stone[pos]
            stone[pos]=0
        else:
            p-=1
            stone[pos]+=1
        if stone[pos]==p2:break
        pos=[pos+1,0][pos+1==n]
    print(pos)

Python: 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)))

Python: while 1:
    n,p=map(int,input().split())
    if n+p==0:
        break
    x=[0]*n
    i=0
    while 1:
        if p==0:
            p+=x[i]
            x[i]=0
        else:
            x[i]+=1
            p-=1
        if x[i]==n:
            print (i)
            break
        i+=1
        if i==n:
            i=0

Python: # encoding: utf-8

def runStep(candidates,n,p):
    mayor = 0
    decidedFlg = False
    if p > n:
        for i in range(0,n):
            candidates[i] += 1
        p -= n
    else:
        for i in range(0,n):
            if p == 0:
                result,mayor = checkEmpty(candidates,n)
                if result:
                    result = mayor
                    decidedFlg = True
                    break
                else:
                    p = candidates[i]
                    candidates[i] = 0
            else:
                candidates[i] += 1
                p -= 1
    return candidates,p,mayor,decidedFlg

def checkEmpty(candidates,n):
    result = True
    count = 0
    mayor = 0
    for i in range(0,n):
        if candidates[i] != 0:
            count += 1
            mayor = i
            if count > 1:
                result = False
                break
    return result,mayor

while True:
    data = input().split()
    n, p = int(data[0]),int(data[1])
    if n == 0 and p == 0: break
    candidates = [0] * n
    while True:
        candidates,p,mayor,decidedFlg = runStep(candidates,n,p)
        if decidedFlg:
            print(mayor)
            break

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

    holding = [0]*n
    ctr = 0
    wan = p
    for _ in range(1000000):
        if wan>=n:
            dist = wan//n
            wan -= dist*n
            for i in range(n):
                holding[i] += dist

        if wan != 0:
            holding[ctr] += 1
            wan -= 1
            if wan == 0 and holding[ctr] == p:
                print(ctr)
                break
        else:
            wan = holding[ctr]
            holding[ctr] = 0
        ctr += 1
        if ctr >= n: ctr -= n

Python: 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)))

Python: def c(lst,idx):
    for i in range(len(lst)):
        if lst[i] > 0 and i != idx:
            return False
    return True
            
while 1:
    N, P = list(map(int,input().split()))
    if not N:break
    h = [0] * N

    while 1:
        flg = False
        for i in range(N):
            if P > 0:
                h[i] += 1
                P -= 1
                if P == 0 and c(h,i):
                    print(i)
                    flg = True
                    break
            elif h[i] > 0:
                P = h[i]
                h[i] = 0


        if flg:break

Python: import numpy as np

while True:
    try:
        l = list(map(int, input().split()))
        S = l[0]
        p = np.zeros(S)
        M = l[1]
        i = 0
        N = M

        while True:
            if p[i] == M:
                print(i)
                break

            if N == 0:
                N = p[i]
                p[i] = 0
                i += 1
                i %= S

            else:
                N -= 1
                p[i] += 1
                i += 1
                i %= S

    except:
        break

Python: from sys import stdin, stdout, stderr

while 1:
    n, p = map(int, stdin.readline().split())

    if n + p == 0:
        break

    a = [0] * n
    wan = p

    for i in range(10**6):
        if wan > 0:
            a[i % n] += 1
            wan -= 1
        else:
            wan += a[i % n]
            a[i % n] = 0

        if a[i % n] == p:
            print(i % n)
            break

Python: ans = []
while True:
    N, P = map(int, input().split())
    box, lists = P, [0 for i in range(N)]
    
    if not N and not P:
        break
    
    roop = True
    while roop:
        for i in range(N):
            if lists[i] == P:
                ans.append(i)
                roop = False
                break
                
            if box:
                lists[i] += 1
                box -= 1
            else:
                box = lists[i]
                lists[i] = 0
                
[print(i) for i in ans]

Python: import numpy as np

while True:
    try:
        l = list(map(int, input().split()))
        S = l[0]
        p = np.zeros(S)
        M = l[1]
        i = 0
        N = M

        while True:
            if N == M and i != 0:
                ans = i % S - 1
                if ans < 0:
                    ans = S + ans
                print(ans)
                break

            if N == 0:
                N = p[i % S]
                p[i % S] = 0
                i += 1

            else:
                N -= 1
                p[i % S] += 1
                i += 1

    except:
        break;