import sys input=lambda:sys.stdin.readline().rstrip() ans,F,pt=0,[0,0],0 *F,N=map(int,input().split()) while max(F): if (F[0]%2)|(F[1]%2)==1 and (F[0]%2)*2+F[1]%2-N%3-1!=0: ans+=1<>=1 F[1]>>=1 print(ans)