Find total number of triplet a,b,c

Given two array A and B. Both have size n. Each element of both array are from 1 to n and there are no duplicate element in any of the array. Means both array has same element but they are shuffle.
** for example: A={1 ,2 ,3 ,4 ,5 ,8 ,6 ,7} , B={ 5, 6 ,7 ,8 ,3 ,4 ,2 ,1 }**

What is the total number of unordered triplets (a, b, c) such that the relative ordering of (a, b, c) is the same in both the arrays.

one solution i thought is to find longest common subsequence and from that LCS find all possible a,b,c.
Is it my approach is right or not? if not than plz suggest optimized approach.