a,b,x,n = map(int, input().split()) tak = [0,0]#kuro, shiro aok = [0,0] takst = 0 aokst = 0 for i in range(1,n+1): x = ((a*x+b)%6)+1 if i%2 == 0: aokst += x if aokst %2 == 1: aok[0] += 1 else: aok[1] += 1 else: takst += x if takst % 2 == 1: tak[0] += 1 else: tak[1] += 1 print(min(tak), min(aok))