package main import ( "bufio" "fmt" "os" "strconv" ) func min(x, y int) int { if x < y { return x } return y } func main() { var ( a uint32 b uint32 x uint32 ) a = uint32(readInt()) b = uint32(readInt()) x = uint32(readInt()) N := readInt() p0 := 0 p1 := 0 s0 := 0 s1 := 0 for i := 0; i < N; i++ { x = a*x + b p0 += int(x&1 + 1) s0 += p0 & 1 x = a*x + b p1 += int(x&1 + 1) s1 += p1 & 1 } fmt.Printf("%d %d \n", min(s0, N-s0), min(s1, N-s1)) } const ( ioBufferSize = 1 * 1024 * 1024 // 1 MB ) var stdinScanner = func() *bufio.Scanner { result := bufio.NewScanner(os.Stdin) result.Buffer(make([]byte, ioBufferSize), ioBufferSize) result.Split(bufio.ScanWords) return result }() func readString() string { stdinScanner.Scan() return stdinScanner.Text() } func readInt() int { result, err := strconv.Atoi(readString()) if err != nil { panic(err) } return result } func readInts(n int) []int { result := make([]int, n) for i := 0; i < n; i++ { result[i] = readInt() } return result }