#K51777. Counting Valid Sequences with a Unique 'ab' Substring

    ID: 29163 Type: Default 1000ms 256MiB

Counting Valid Sequences with a Unique 'ab' Substring

Counting Valid Sequences with a Unique 'ab' Substring

In this problem, you are given a positive integer ( N ) which represents the maximum length of sequences. For each sequence length ( L ) where ( 2 \leq L \leq N ), a valid sequence is defined as a string composed only of the characters 'a' and 'b' that contains exactly one occurrence of the substring ( \texttt{ab} ). Your task is to calculate the total number of valid sequences across all lengths from 2 to ( N ). It can be shown that the answer is given by the formula ( 2^{N-1} - 1 ). For example, when ( N = 2 ), the only valid sequence is "ab" (count = 1); when ( N = 3 ), there are 3 valid sequences in total. Ensure your solution reads from standard input and writes to standard output.

inputFormat

The input consists of a single integer ( N ) (with ( N \geq 2 )) provided via standard input.

outputFormat

Output a single integer which is the total number of valid sequences (as computed by ( 2^{N-1} - 1 )) for sequence lengths ranging from 2 to ( N ). The result must be printed to standard output.## sample

2
1