## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Intersection and Union Codeforces Solution

F. Intersection and Union
time limit per test
5 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You are given $n$ segments on the coordinate axis. The $i$-th segment is $\left[{l}_{i},{r}_{i}\right]$. Let's denote the set of all integer points belonging to the $i$-th segment as ${S}_{i}$.

Let $A\cup B$ be the union of two sets $A$ and $B$$A\cap B$ be the intersection of two sets $A$ and $B$, and $A\oplus B$ be the symmetric difference of $A$ and $B$ (a set which contains all elements of $A$ and all elements of $B$, except for the ones that belong to both sets).

Let $\left[{op}_{1},{op}_{2},\dots ,{op}_{n-1}\right]$ be an array where each element is either $\cup$$\oplus$, or $\cap$. Over all ${3}^{n-1}$ ways to choose this array, calculate the sum of the following values:

In this expression, $|S|$ denotes the size of the set $S$.

Input

The first line contains one integer $n$ ($2\le n\le 3\cdot {10}^{5}$).

Solution Click Below:-  👉
👇👇👇👇👇

Then, $n$ lines follow. The $i$-th of them contains two integers ${l}_{i}$ and ${r}_{i}$ ($0\le {l}_{i}\le {r}_{i}\le 3\cdot {10}^{5}$).

Output

Print one integer — the sum of  over all possible ways to choose $\left[{op}_{1},{op}_{2},\dots ,{op}_{n-1}\right]$. Since the answer can be huge, print it modulo $998244353$.