<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

123. The sum

time limit per test: 0.25 sec.
memory limit per test: 4096 KB


The Fibonacci sequence of numbers is known: F1 = 1; F2 = 1; Fn+1 = Fn + Fn-1, for n>1. You have to find S - the sum of the first K Fibonacci numbers.


Input

First line contains natural number K (0<K<41).


Output

First line should contain number S.


Sample Input

5
Sample Output

12
Author	: Paul "Stingray" Komkoff, Victor G. Samoilov
Resource	: 5th Southern Subregional Contest. Saratov 2002
Date	: 2002-10-10

<|response|>
1. Abridged Problem Statement  
Given an integer K (1 ≤ K ≤ 40), compute the sum S = F₁ + F₂ + … + F_K of the first K Fibonacci numbers, where  
  • F₁ = 1  
  • F₂ = 1  
  • Fₙ = Fₙ₋₁ + Fₙ₋₂ for n > 2  
Output the value of S.

2. Key Observations  
- The Fibonacci numbers grow quickly but with K ≤ 40, all intermediate values and the sum fit comfortably in a 64-bit integer.  
- A direct O(K) loop that builds each Fibonacci number and accumulates a running total is more than fast enough for K up to 40.  
- There is a well-known closed-form identity:  
    S = F₁ + F₂ + … + F_K = F_{K+2} − 1  
  With that, you can compute F_{K+2} in O(K) and then subtract 1.  

3. Full Solution Approach  
Method A (Iterative Summation):  
  1. Read integer K.  
  2. Handle the smallest cases directly:  
     – If K = 1, then S = 1.  
     – If K = 2, then S = 1 + 1 = 2.  
  3. Otherwise, initialize two variables a = F₁ = 1, b = F₂ = 1, and a running sum S = a + b.  
  4. For i from 3 to K:  
       • Compute the next Fibonacci number c = a + b.  
       • Add c to S.  
       • Shift the window: a ← b, b ← c.  
  5. After the loop, S holds F₁ + F₂ + … + F_K. Print S.

Method B (Using the Summation Identity):  
  1. Read K.  
  2. Compute F_{K+2} by the same O(K) loop (start with a=1, b=1 and iterate K+2−2 times).  
  3. Output F_{K+2} − 1.

Because K is at most 40, both methods run in a few dozen operations. Method A is slightly more direct if you want the sum “on the fly.”

4. C++ Implementation with Detailed Comments  
```cpp
#include <iostream>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int K;
    cin >> K;  // Number of Fibonacci terms to sum

    // Handle trivial cases
    if (K == 1) {
        cout << 1 << "\n";
        return 0;
    }
    if (K == 2) {
        cout << 2 << "\n";  // 1 + 1
        return 0;
    }

    long long a = 1;     // F1
    long long b = 1;     // F2
    long long sum = a + b;  // start sum = F1 + F2

    // Build F3..FK, add each term to sum
    for (int i = 3; i <= K; ++i) {
        long long c = a + b;  // next Fibonacci number
        sum += c;             // accumulate
        a = b;                // shift window
        b = c;
    }

    cout << sum << "\n";
    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
import sys

def main():
    data = sys.stdin.read().strip().split()
    if not data:
        return
    k = int(data[0])

    # Handle small k directly
    if k == 1:
        print(1)
        return
    if k == 2:
        print(2)  # 1 + 1
        return

    # Initialize first two Fibonacci numbers
    a, b = 1, 1
    total = a + b  # sum of F1 and F2

    # Generate F3..Fk and accumulate their sum
    for _ in range(3, k + 1):
        c = a + b     # next Fibonacci number
        total += c    # add to running total
        a, b = b, c   # shift for next iteration

    print(total)

if __name__ == "__main__":
    main()
```