Problem:
Score : 100 points

Problem Statement

CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard.

He intended to write CODEFESTIVAL2016 on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length.

So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to CODEFESTIVAL2016.

Find the minimum number of iterations for the rewrite operation.

Constraints

S is 16 characters long.

S consists of uppercase and lowercase alphabet letters and numerals.

Input

Inputs are provided from Standard Input in the following form.

S

Output

Output an integer representing the minimum number of iterations needed for the rewrite operation.

Sample Input 1

C0DEFESTIVAL2O16

Sample Output 1

2

The second character 0 must be changed to O and the 14th character O changed to 0.

Sample Input 2

FESTIVAL2016CODE

Sample Output 2

16

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <cstring>
#include <stdio.h>
#define MAXN (1000000)

class TrieNode {
public:
    bool exist;
    int  son_count;
    TrieNode* nodes[26]={0};
    TrieNode():son_count(0),exist(false){}
    TrieNode * & getNode(const char & chr)
    {
        return nodes[chr-'a'];
    }
}nodes[MAXN];

int nodes_cnt = 0;

class Trie {
public:
    Trie() {
        root = new TrieNode();
    }

    void insert(const char *  word) {
        TrieNode * now = root;
        while(*word)
        {
            now->son_count++;
            if(!now->getNode(*word))
                now = now->getNode(*word) = &nodes[nodes_cnt++];
            else
                now = now->getNode(*word);
            word++;
        }
        now->son_count ++;
        now->exist = true;
    }

    int get_rank(const char * word, const char * char_rank) {
        int rank = 1;
        TrieNode * now = root, *last = NULL, *tmp;
        while(*word)
        {
            for(int i = 0; char_rank[i] != *word; i++)
            {
                tmp = now->getNode(char_rank[i]);
                if(tmp)
                    rank+= tmp->son_count;
            }
            last = now;
            now = now->getNode(*word);
            word++;
            if(*word && last->exist)
                rank++;
        }
        return rank;
    }
private:
    TrieNode* root;
};
#define MAX_CHAR_LEN (5000000)
#define MAX_STR_CNT  (800000+5)

char char_buffer[MAX_CHAR_LEN];
char * str_table[MAX_STR_CNT];

int main()
{
    int N,Q,k;
    char char_rank[32], * ptr = char_buffer;
    Trie trie;
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        str_table[i] = ptr;
        scanf("%s",ptr);
        trie.insert(ptr);
        ptr += strlen(ptr) + 1;
    }
    scanf("%d",&Q);
    for(int i = 0; i < Q; i++)
    {
        scanf("%d%s", &k, char_rank);
        int rank = trie.get_rank(str_table[k-1], char_rank);
        printf("%d\n", rank);
    }
    //printf("%d")
    return 0;
}