from multiprocessing.spawn import old_main_modules a,b,x0,n = map(int,input().split()) li = [-1]*7 li[x0%6] = 0 now = x0%6 prd = -1 loop = [x0%6] for i in range(7): now = (a*now+b)%6 if li[now] == -1: li[now] = i+1 loop.append(i+1) else: prd = i+1-li[now] srt = li[now] #print(now,i+1) break li = loop #print(li) if prd % 2 == 1: li2 = li[srt:srt+prd]+li[srt:srt+prd] else: #print(srt,srt+prd,"srtprd") li2 = li[srt:srt+prd] tk = [0]*2 ao = [0]*2 for i in range(len(li2)): if (i+srt) % 2 == 0: tk[li2[i]%2] += 1 else: ao[li2[i]%2] += 1 lcnt = (n-srt)//len(li2) for i in range(2): tk[i] *= lcnt ao[i] *= lcnt for i in range(srt): if i % 2 == 0: tk[li[i]%2] += 1 else: ao[li[i]%2] += 1 #print(li,li2,prd,srt) #exit() for i in range(srt+prd*lcnt,n): #print(i) if i % 2 == 0: tk[li2[(i-(srt+prd*lcnt))]%2] += 1 else: ao[li2[(i-(srt+prd*lcnt))]%2] += 1 print(min(tk),min(ao))