logo AlgoBeat OnlineJudge
登录 注册

#215988. [TOPC 2023] Gadget Construction

内存限制:512 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Grigory is a talented engineer who has a love in developing drones and, of course, geometry. As a skilled problem solver, he is able to come up with solutions in difficult situations, but today, he encountered a problem that his abilities alone are not enough to solve. Therefore, as his best sidekick, your task is to assist him.

There are cogs on the Cartesian plane. The -th cog is located at the coordinates and has a character that describes its color – “b” means it is a black cog, while “w” means it is a white cog. In addition, no three cogs lie on the same line.

Grigory wants to build a gadget using some cogs. To do this, he first chooses a subset that consists of 4 or more of the cogs. Then, a loop of chains is placed around the cogs. The loop is chosen such that:

  • Every cog in either touches the loop or lies in its interior.
  • The total length of chains is minimal.

For example, the image below shows the chains that would be placed for a chosen set of cogs.

:::align{center} :::

Finally, consider the cogs in that touch the loop. These are the most important cogs, so they cannot be interfering with each other. Therefore, any two adjacent cogs on the loop must have different colors, otherwise the resulting gadget won’t be working properly. If a cog in does not touch the loop, then it may have an arbitrary color.

How many different sets can Grigory choose to build a properly working gadget? Since the answer can be very large, find the value modulo .

输入格式

The first line contains an integer . Then lines follow. The -th line contains two integers and a character denoting the coordinates and color of the -th cog.

输出格式

Print the number of sets that satisfy the conditions modulo .

样例

样例输入 1

4
0 0 w
1 0 b
1 1 w
0 1 b

样例输出 1

1

样例输入 2

6
0 0 w
0 4 b
1 2 w
3 2 b
4 0 b
4 4 w

样例输出 2

9

样例输入 3

4
0 0 b
1 0 w
1 1 w
0 1 b

样例输出 3

0

数据范围与提示

  • for
  • for
  • for
  • No three cogs lie on the same line.