Narrower Passageway
시간 제한1초메모리 제한2048 MB
각 열이 1/2 확률로 안개에 덮이고, 안개가 없는 최대 연속 구간마다 정의된 강도의 합의 기댓값을 998244353으로 나눈 나머지를 구한다.
문제
You are a strategist of The ICPC Kingdom. You received an intel that there will be monster attacks on a narrow passageway near the kingdom. The narrow passageway can be represented as a grid with rows (numbered from to ) and columns (numbered from to ). Denote as the cell in row and column . A soldier with a power of is assigned to protect every single day.
It is known that the passageway is very foggy. Within a day, each column in the passageway has a chance of being covered in fog. If a column is covered in fog, the two soldiers assigned to that column are not deployed that day. Otherwise, the assigned soldiers will be deployed.
Define a connected area () as a maximal set of consecutive columns from to (inclusive) such that each column in the set is not covered in fog. The following illustration is an example of connected areas. The grayed cells are cells covered in fog. There are connected areas: , , , and .

The strength of a connected area can be calculated as follows. Let and be the maximum power of the soldiers in the first and second rows of the connected area, respectively. Formally, for . If , then the strength is . Otherwise, the strength is .
The total strength of the deployment is the sum of the strengths for all connected areas. Determine the expected total strength of the deployment on any single day.
입력
The first line consists of an integer ().
Each of the next two lines consists of integers ().
출력
Let . It can be shown that the expected total strength can be expressed as an irreducible fraction such that and are integers and . Output an integer in a single line such that and .