private static int destroy(List<Integer> c, int x, int i) {
        int sum = 0;        
        int j = i;            
        while (!c.isEmpty()) {     
            x = c.get(j);
            for (; j >= 0 && c.get(j) == x; j--);
            
            int j1 = ++j;
            for (; j1 < c.size() && c.get(j1) == x; j1++);
            
            if (j1 - j > 2) {
                for (; j < c.size() && c.get(j) == x;) {
                    c.remove(j);
                    sum++;
                }
                
                if (j == c.size()) j--;
            }
            else {
                break;
            }
       }
        
        return sum;
    }