#abc291d. D - Flip Cards

D - Flip Cards

Score : 400400 points

问题描述

设有 NN 张卡片,编号从 11NN,在一条线上排列。对于每个 i (1i<N)i\ (1\leq i < N),第 ii 张卡片和第 (i+1)(i+1) 张卡片相邻。第 ii 张卡片正面写有数字 AiA_i,背面写有数字 BiB_i。最初,所有卡片都是正面朝上。

考虑从这 NN 张卡片中选择零张或多张进行翻转。在 2N2^N 种选择卡片翻转的方式中,找出满足以下条件的翻牌方式的数量(模 998244353998244353):

  • 当所选卡片被翻转后,每对相邻卡片的正面朝上的整数都不相同。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

NN cards, numbered 11 through NN, are arranged in a line. For each i (1i<N)i\ (1\leq i < N), card ii and card (i+1)(i+1) are adjacent to each other. Card ii has AiA_i written on its front, and BiB_i written on its back. Initially, all cards are face up.

Consider flipping zero or more cards chosen from the NN cards. Among the 2N2^N ways to choose the cards to flip, find the number, modulo 998244353998244353, of such ways that:

  • when the chosen cards are flipped, for every pair of adjacent cards, the integers written on their face-up sides are different.

Constraints

  • 1N2×1051\leq N \leq 2\times 10^5
  • 1Ai,Bi1091\leq A_i,B_i \leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

Output

Print the answer as an integer.

Sample Input 1

3
1 2
4 2
3 4

Sample Output 1

4

Let SS be the set of card numbers to flip.

For example, when S={2,3}S=\{2,3\} is chosen, the integers written on their visible sides are 1,21,2, and 44, from card 11 to card 33, so it satisfies the condition.

On the other hand, when S={3}S=\{3\} is chosen, the integers written on their visible sides are 1,41,4, and 44, from card 11 to card 33, where the integers on card 22 and card 33 are the same, violating the condition.

Four SS satisfy the conditions: {},{1},{2}\{\},\{1\},\{2\}, and {2,3}\{2,3\}.

Sample Input 2

4
1 5
2 6
3 7
4 8

Sample Output 2

16

Sample Input 3

8
877914575 602436426
861648772 623690081
476190629 262703497
971407775 628894325
822804784 450968417
161735902 822804784
161735902 822804784
822804784 161735902

Sample Output 3

48

update @ 2024/3/10 12:08:51

}