/*
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 DEFAULT_VALUE -1
long long merge_sort(int* a, int* b, int* c, int left, int right) {
if (left >= right) return 0;
// WRITE YOUR CODE HERE
}
// DO NOT MODIFY THE CODE BELOW
int main(void)
{
int n;
scanf("%d", &n);
int* a = (int*)malloc(sizeof(int) * n);
int* b = (int*)malloc(sizeof(int) * n);
int* c = (int*)malloc(sizeof(int) * n);
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
scanf("%d", &b[i]);
scanf("%d", &c[i]);
}
long long result = merge_sort(a, b, c, 0, n - 1);
printf("%lld\n", result);
return 0;
}
---------------------------------------End of Code---------------------------------------
## Value Computation
In this problem, you are tasked with calculating a weighted sum of inversions using a Merge Sort based approach.
You are given a sequence of n tuples $(a_i, b_i, c_i)$, for $i = 1, 2, \dots, n$.
A pair of indices $(i, j)$ is considered an inversion if: $i < j$ and $a_i > a_j$
For every such pair, a value is produced equal to the product of $b_i$ and $c_j$ (i.e., $b_i \times c_j$).
Your goal is to compute the total sum of these values across all valid pairs $(i, j)$.
### Input
The first line contains an integer $n\,(1 \leq n \leq 300,000)$, the number of tuples.
The following $n$ lines each contain three integers $a_i, b_i, c_i (0 < a_i \leq 10^5, 0 < b_i, c_i \leq 10^3).$
### Output
Print a single integer representing the total computed value.
Note: Given the constraints, the final answer may exceed the range of a 32-bit integer. Ensure you use a 64-bit integer type.
### Example
**Input**
```
5
3 3 3
4 4 4
1 1 1
2 2 2
5 5 5
```
**Output**
```
21
```
**Explanation**
The tuples are indexed from 1 to 5:
$(3, 3, 3)$
$(4, 4, 4)$
$(1, 1, 1)$
$(2, 2, 2)$
$(5, 5, 5)$
Valid pairs $(i, j)$ where $i < j$ and $a_i > a_j$:
$(1, 3): a_1 > a_3 \implies 3 \times 1 = 3$
$(1, 4): a_1 > a_4 \implies 3 \times 2 = 6$
$(2, 3): a_2 > a_3 \implies 4 \times 1 = 4$
$(2, 4): a_2 > a_4 \implies 4 \times 2 = 8$
Total Value: $3 + 6 + 4 + 8 = 21$.