import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int[] a = new int[1000]; a[0] = sc.nextInt() % 10; a[1] = sc.nextInt() % 10; a[2] = sc.nextInt() % 10; long k = sc.nextLong() - 1; sc.close(); Map map = new HashMap<>(); int s = 0; int d = 0; map.put(a[0] * 100 + a[1] * 10 + a[2], 2); for (int i = 3; i < a.length; i++) { a[i] = a[i - 3] + a[i - 2] + a[i - 1]; a[i] %= 10; if (i == k) { System.out.println(a[i]); return; } int v = a[i - 2] * 100 + a[i - 1] * 10 + a[i]; if (map.containsKey(v)) { s = map.get(v); d = i - s; break; } map.put(v, i); } int x = (int) ((k - s) % d); System.out.println(a[s + x]); } }