package main import ( "bufio" "fmt" "os" ) var reader = bufio.NewReader(os.Stdin) var writer = bufio.NewWriter(os.Stdout) func toDigits(x, base int) []int { if x == 0 { return []int{0} } ans := make([]int, 0) for x != 0 { ans = append(ans, x%base) x = x / base } return ans } func main() { defer writer.Flush() var p, q, r, k int fmt.Fscan(reader, &p, &q, &r, &k) a := make([]int, 1000000) a[1] = p % 10 a[2] = q % 10 a[3] = r % 10 used := make([]int, 1009) used[(a[1] + a[2] + a[3]%10)] = 3 m2 := 0 for i := 4; i <= k; i++ { a[i] = (a[i-1] + a[i-2] + a[i-3]) % 10 nex := (a[i]*100 + a[i-1]*10 + a[i-2]*1) % 10 if used[nex] != 0 { m2 = i - used[nex] break } used[nex] = i } if m2 == 0 { fmt.Fprintf(writer, "%v", a[k]) return } n2 := k % m2 a = make([]int, 1000000) for i := 1; i <= n2; i++ { if i == 1 { a[i] = p % 10 continue } if i == 2 { a[i] = q % 10 continue } if i == 3 { a[i] = r % 10 continue } a[i] = (a[i-1] + a[i-2] + a[i-3]) % 10 } fmt.Fprintf(writer, "%v", a[n2]) }