import java.util.*; public class Test11 { final long a,b,m; long x; Test11(long a,long b,long x){ this.a=a; this.b=b; this.m=(long)Integer.MAX_VALUE+Integer.MAX_VALUE+2; this.x=x%m; } int roll(){ x=(a*x+b)%m; int tmp=(int)(x%6)+1; return tmp; } public static void main(String[] args){ Scanner sc=new Scanner(System.in); String[] line; line=sc.nextLine().split(" "); Test11 dice; { long a=Long.parseLong(line[0]); long b=Long.parseLong(line[1]); long x=Long.parseLong(line[2]); dice=new Test11(a,b,x); } int n=Integer.parseInt(line[3]); int[] stayed=new int[2],black=new int[2],white=new int[2]; for(int i=0;i<2;i++) stayed[i]=black[i]=white[i]=0; for(int i=0;i