Counting Values by Double Hashing

/*
Time limit: 1000ms
Memory limit: 256mb

---------------------Copy the following code, complete it and submit---------------------
I, <Your Full Name>, am submitting the assignment for
an individual project.
I declare that the assignment here submitted is original except for
source material explicitly acknowledged, the piece of work, or a part
of the piece of work has not been submitted for more than one purpose
(i.e. to satisfy the requirements in two different courses) without
declaration. I also acknowledge that I am aware of University policy
and regulations on honesty in academic work, and of the disciplinary
guidelines and procedures applicable to breaches of such policy and
regulations, as contained in the University website
http://www.cuhk.edu.hk/policy/academichonesty/.
It is also understood that assignments without a properly signed
declaration by the student concerned will not be graded by the
teacher(s).
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define INF -1

const int hashTableSize = 2000003;
struct hashNode {
    int key;
    int value;
};

typedef struct hashNode* HashTable;

int h1(int key)
{
    // WRITE YOUR CODE HERE

}

int h2(int key)
{
    // WRITE YOUR CODE HERE

}

void Insert(HashTable T, int key, int value) {
    // WRITE YOUR CODE HERE

}

int Get(HashTable T, int key) {
    // WRITE YOUR CODE HERE

}

long long Solve(int n, int K1, int K2, int* a) {
    // WRITE YOUR CODE HERE

}

int main() 
{
    int n, K1, K2;
    scanf("%d%d%d", &n, &K1, &K2);
    int* a = (int*)malloc(n * sizeof(int));
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    printf("%lld\n", Solve(n, K1, K2, a));
    return 0;
}

---------------------------------------End of Code---------------------------------------

## Counting Values by Double Hashing

In this problem, you must process a sequence of integers to identify "valuable intervals." You are required to implement a Hash Table using Open Addressing and Double Hashing for collision resolution.

Given a sequence of $n$ positive integers $a_1, a_2, \dots, a_n$ and two constants $K_1$ and $K_2$, an interval $[l, r]$ (where $1 \le l \le r \le n$) is considered valuable if it satisfies one of the following conditions based on its length $L = r - l + 1$:

 - $(-1)^L \cdot \sum_{i=l}^r a_i = K_1$

 - $(-1)^L \cdot \sum_{i=l}^r a_i = K_2$

Each valuable interval $[l, r]$ contributes a "value" equal to its length, $(r - l + 1)$. Your task is to calculate and output the sum of the values of all such valuable intervals in the sequence.

### Input
The first line contains three integers: 

 - $n$: the number of elements in the sequence ($1 \leq n \leq 300,000$). 

 - $K_1$: a positive parameter ($0 < K_1 < n \cdot 100$).
 
 - $K_2$: a negative parameter ($-n \cdot 100 < K_2 < 0$).

The next $n$ lines each contain a single integer $a_i$ ($0 < a_i < 101$).

### Output
A single integer representing the total sum of the lengths of all valuable intervals.

### Example
**Input**

```
7 6 -3
3
4
1
1
2
2
4

```

**Output**

```
7
```

**Explanation**

We are looking for intervals where the sum and length $L$ satisfy the conditions. 

Given $K_1 = 6$ and $K_2 = -3$:

If $L$ is even, we need $\sum a_i = K_1 = 6$.

If $L$ is odd, we need $-\sum a_i = K_2 \Rightarrow \sum a_i = -K_2 = 3$.

In the example sequence [3, 4, 1, 1, 2, 2, 4]:

Interval $[1, 1]$ (value 3): Length $L=1$ (odd), Sum $= 3$. This satisfies the $K_2$ condition. Value = 1.

Interval $[3, 6]$ (values 1, 1, 2, 2): Length $L=4$ (even), Sum $= 6$. This satisfies the $K_1$ condition. Value = 4.

Interval $[6, 7]$ (values 2, 4): Length $L=2$ (even), Sum $= 6$. This satisfies the $K_1$ condition. Value = 2.

Total Value $= 1 + 4 + 2 = 7$.
Submit