Longest common sub sequences with a condition


Consider a sequences if called good if it contains at least one pair one adjacent numbers which are equal.A good sub-sequence of a array is a sub sequence of that array which is good and has its length is highest.Now you are given two array $ S$ and $ T$ with integers,you need to find sub sequences with is common to both arrays and has maximum length and is a good sub sequence.

This is a pure dynamic programming problem,in which states are $ dp[i][j]$ is answer for $ S[1:i]$ and $ T[1:j]$ ($ A[1:i]$ means subarray of $ A$ from $ 1$ to $ i$ ). But i could not find transition between states,could anyone help me.