a,b,x,N = map(int,input().split(' ')) c = [0,0] d = [0,0] for i in range(N): x = (a*x+b)%6+1 if i%2==0: c[x%2] += 1 else: d[x%2] += 1 print(min(c),min(d))