Left recursion#1703

Left recursion

1 second
64 megabytes
Very easy

In the theory of formal grammars and automata, context-free grammars (CFGs) play an important role. A CFG is defined as a quadruple consisting of a set of non-terminal symbols, a set of terminal symbols, a set of rules (productions), and a start symbol S \in N.

Each production p \in P has the form A \rightarrow \alpha, where is a non-terminal symbol (A \in N), and is a sequence of terminal and non-terminal symbols. The derivation process begins with a string containing only the start symbol . At each step, one of the non-terminal symbols in the current string is replaced by the right-hand side of a production where it appears on the left. If after such an operation the string contains only terminal symbols, the process terminates.

In many theoretical problems, it is useful to consider so-called normal forms of grammars. The process of transforming a grammar to normal form often starts with eliminating left recursion. In this problem, we consider only a special case called immediate left recursion. A rule A \rightarrow \alpha is said to have immediate left recursion if the first symbol of the sequence is .

A context-free grammar is given. Find the number of rules with immediate left recursion.

Input

The first line contains the number (1 \leq n \leq 1000) of rules in the grammar. Each of the next lines contains one rule. Non-terminal symbols are denoted by uppercase Latin letters, and terminal symbols by lowercase letters. The left side of a production is separated from the right side by the symbol ->. The right-hand side of a production is always non-empty and has a length not greater than symbols.

Output

Output the answer to the problem.

Examples

Example 1

Loading
Loading