import java.util.Stack;
class Solution {
public int solution(int[][] board, int[] moves) {
int answer = 0;
Stack<Integer> stack = new Stack<>();
for (int i : moves) {
for (int[] ints : board) {
if (ints[i - 1] != 0) {
if (!stack.isEmpty() && stack.peek() == ints[i - 1]) {
stack.pop();
answer++;
} else {
stack.add(ints[i - 1]);
}
ints[i-1] = 0;
break;
}
}
}
return answer * 2;
}
}