Counting Triples

**For original problem statement, pls refer to the source image down below **

Once upon a time, in a land where numbers roamed free, there existed a magical array that could contain as many integers as it desired. The array was curious and ever-changing, for it was governed by a series of mystical commands known as queries.

Our story begins with the array starting off completely empty, a blank slate awaiting adventure. The queries came in two forms:

  • The "+x" spell: When cast, this spell would summon the integerx and place it into the array. The array, being very welcoming, allowed multiple instances of the same integer to coexist harmoniously.
  • The "-x" spell: This spell had the power to banish all instances of the integer x from the array, sending them away to realms unknown.

After each spell was cast, the array would ponder upon the number of magical triples (x, y, z) within itself. These triples had to meet a special condition: the difference between and had to be the same as the difference between and . This special difference was known as "diff."

The array, being wise and meticulous, would count these triples after each query and keep track of the counts.

In our tale, it is important to note that:

  • The integers mentioned in the queries ranged from -109 to 109
  • Each "-x" query was always valid, meaning the integer it referred to was indeed present in the array.
  • The number of triples for each query was guaranteed to fit into a 32-bit integer.

Thus, the array embarked on its journey, processing each query and recounting its magical triples, sharing the results as it went along.

Constraints: N/A

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: