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
				}
			}
		}
	}
}

C++: #include <iostream>
using namespace std;
int main(){
  int n,p;
  for(;;){
    cin >>n >> p;
    if(n == 0 && p == 0)break;
    int human[n];
    for(int i = 0;i < n;i++){
      human=0;
    }
    int stone = p;
    int turn = 0;
    for(;;){
      if(!stone){
        stone += human[turn];
        human[turn] = 0;

      } else if(stone > 0){
        stone--;
        human[turn]++;
        if(!stone && human[turn] == p){
          cout << turn << endl;
          break;
        }
      }

      turn++;
      if(turn >= n) turn = 0;
    }

  }
}

C++: #include<iostream>
#include<vector>
using namespace std;

int main(){
	int n,p;
	while(cin >> n >> p, n|p){
		vector<int> v(n,0);
		int cup=p;
		int num=0;
		while(1){
			if(cup!=0){
				v[num]++;
				cup--;
			}
			else if(v[num]!=0){
				cup=v[num];
				v[num]=0;
			}
			if(v[num]==p)
				break;
			num++;
			num%=n;
		}
		cout << num << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
typedef long double ld;
typedef complex<ld> Point;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const ld eps = 1e-9, pi = acos(-1.0);
const ld dtop = pi / 180.;
const ld ptod = 1. / dtop;


int main() {
  while (1) {
    int n, p; cin >> n >> p;
    if (!n)break;
    vector<int>stones(n, 0);
    int bowl(p);
    int nplayer = 0;
    while (1) {
      if (bowl) {
        bowl--;
        stones[nplayer]++;
        if (stones[nplayer] == p)break;
      }
      else {
        bowl += stones[nplayer];
        stones[nplayer] = 0;
      }
      nplayer = (nplayer + 1) %n;
    }
    cout << nplayer << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

#define NMAX 50

int main(){

	int n,q;
	int have[NMAX];
	int stone;
	int ans;
	bool f;

	while(1){

		cin>>n>>q;
		if(n==0&&q==0) break;

		stone=q;
		f=true;
		for(int i=0;i<n;i++) have[i]=0;
		while(f){
			for(int i=0;i<n;i++){
				if(stone!=0){
					stone--;
					have[i]++;
					if(have[i]==q){
						f=false;
						ans=i;
						break;
					}
				}
				else{
					stone+=have[i];
					have[i]=0;
				}
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}


int n, p;
int cen;
int a[100];

int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    while (cin >> n >> p) {
        if (n == 0) break;
        
        cen = p;
        memset(a, 0, sizeof(a));
        
        int ind;
        for (int i = 0; i < 1000100; ++i) {
            ind = i % n;
            
            
//            cout << i << " : " << cen << ", ";
//            for (int j = 0; j < n; ++j) cout << a[j] << ",";
//            cout << endl;
            
            if (cen > 0) {
                cen--; a[ind]++;
            }
            else {
                cen = a[ind]; a[ind] = 0;
            }
            
            if (cen == 0 && a[ind] == p) {
                break;
            }
        }
        
        cout << ind << endl;
    }
    
    
    return 0;
}

C++: #include <iostream>

#define N 55

using namespace std;

int main(void)
{

	int n,p;

	int m[N];

	int s;

	int i1;

	while(1){

		cin >> n >> p;
		if (n==0 && p==0) break;

		for(i1=0;i1<N;i1++){
			m[i1]=0;
		}

		i1=0;
		s=p;
		
		while(1){
			if(s>0){
				m[i1]++;
				s--;

				if (s==0 && m[i1]==p) break;
			}
			else{
				s+=m[i1];
				m[i1]=0;
			}

			if (i1==n-1){
				i1=0;
			}
			else i1++;
		}

		cout << i1 << endl;

	}


	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    int n,s;
    while(cin >> n >> s,n+s){
        int temp = s;
        vi v(n,0); int count = 0; bool check = true;
        while(true){
            if(s != 0){s-=1;v[count]++; if(v[count] == temp){cout << count << endl; break;}
            }else if(s == 0){
                s+=v[count]; v[count] = 0;
            }
            if(count == n-1)
                count =0;
            else
                count++;
            
        }
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,p,temp,a[60],i;
	while(cin>>n>>p,n||p){
		for(int j=0;j<n;j++)
			a[j]=0;
		temp=p;
		i=0;
		for(;;){
			if(temp>0){
				temp--;
				a[i++]++;
			}
			else if(temp==0){
				if(a[n-1]==p){
					cout<<n-1<<endl;
					break;
				}
				else
				if(a[i-1]==p){
					cout<<i-1<<endl;
					break;
				}
				else{
					temp=a[i];
					a[i++]=0;
				}
			}
			if(i>n-1)
				i=0;
		}
	}
	return 0;
}

C++: #include <iostream>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

int main(){
  while(1){
    int N;
    cin >> N;
    if(N==0) break;
    int x,y,map[22][22]={};
    rep(i,N){
      cin >> x >> y;
      map[y][x] = 1;
    }
    int Rx = 10,Ry = 10,tr = 0;
    int M;
    cin >> M;
    rep(i,M){
      string v;
      int d;
      cin >> v >> d;
      if(v == "N"){
	rep(j,d){ 
	  Ry++;
	  tr += map[Ry][Rx];
	}
      }
      else if(v == "E"){
	rep(j,d){ 
	  Rx++;
	  tr += map[Ry][Rx];
	}
      }
      else if(v == "S"){
	rep(j,d){ 
	  Ry--;
	  tr += map[Ry][Rx];
	}
      }
      else if(v == "W"){
	rep(j,d){ 
	  Rx--;
	  tr += map[Ry][Rx];
	}
      }
    }
    if(tr == N) cout << "Yes\n";
    else cout << "No\n";
  }
  return 0;
}