Modified Fibonacci
Easy Accuracy: 19.7% Submissions: 306 Points: 2

Given 4 integers A, B, C and N, find the value of F(N) such that
F(1) = A + B
F(2) = B + C
F(N) = F(N-1) - F(N-2),  for N > 2.

Example 1:

Input: N = 2, A = 2, B = 3, C = 4
Output: 7
Explaination: F(2) = B+C = 3+4 = 7

Example 2:

Input: N = 3, A = 2, B = 3, C = 4
Output: 2
Explaination: F(3) = F(2)- F(1) = 7-5 = 2

You do not need to read input or print anything. Your task is to complete the function modifiedFib() which takes the values N, A, B and C as input parameters and returns F(N). Since F(N) modulo (109+7).

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ N ≤ 1012
1 ≤ A, B, C ≤ 109

We are replacing the old Disqus forum with the new Discussions section given below.