a[9]={2,3,4,0,2,2,3,3},j;main(i){for(;read(0,&i,1)?++a[i&15]:a[j]%5?++j:a[--i]%5-2;);printf("%d %d",i,j);}