Under construction

Still being built. Things may change

House Deconstruction

Time limit1sMemory limit2048 MB

Summary
Given people and houses on a circle, find the minimum total walking distance after destroying some houses, and count the sets of destroyed houses that reach it.
Level

Hard9 of 10

Topics
Combinatorics, Greedy, Math
Solved
No attempts yet

Problem

In the land of Circleland, there is a circle with equally spaced points around its circumference. The distance between any two adjacent points is 11.

Each point holds a person, an empty house, or nothing. Each person wants to walk to a different house, and each house can contain at most one person. People can only walk along the circumference of the circle and cannot cut across.

There are more houses than people, so you want to destroy some of the houses. Suppose you destroy a set of houses SS. Let f(S)f(S) be the minimum total walking distance needed to move each person to a different house that was not destroyed.

Compute the minimum value of f(S)f(S). Then compute how many sets SS achieve this minimum. Since that count can be large, output it modulo 998 244 353998\,244\,353.

Input

The first line contains three integers xx, nn, and mm (1≤n<m≤2⋅105,n+m≤x≤1091 \leq n < m \leq 2 \cdot 10^5, n+m \leq x \leq 10^9), where xx is the number of points around the circle, nn is the number of people, and mm is the number of houses. The points are labeled 11 to xx, and point xx is adjacent to point 11.

The next n+mn+m lines each contain an integer pp (1≤p≤x1 \le p \le x) and a character tt (t∈{t \in \{P,H}\}). Here pp is the position of a person or house, and tt is the type of the point: P for person, H for house. All positions are distinct and given in increasing order.

Output

Output two lines. The first line contains the minimum possible value of f(S)f(S). The second line contains the number of sets SS that achieve this minimum, modulo 998 244 353998\,244\,353.

Hint

In the first sample, the minimum total walking distance is 22. Destroying the houses at positions 22 and 55, 44 and 55, or 55 and 66 achieves it.

In the second sample, destroying the houses at positions 66 and 3141592631415926 gives a minimum total walking distance of 44. The minimum can be reached in more than one way, but the set of destroyed houses is the same, so it is counted once.

Examples2

  1. Example 1

    Input
    6 2 4
    1 P
    2 H
    3 P
    4 H
    5 H
    6 H
    
    Expected output
    2
    3
    
  2. Example 2

    Input
    1000000000 2 4
    1 P
    6 H
    31415926 H
    999999998 H
    999999999 H
    1000000000 P
    
    Expected output
    4
    1