1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define IDLE 0
#define OPEN_PARENT 1
#define IN_PARENT 2
int var[1000004];

int main()
{
	int n;
	scanf("%d", &n);
	char c;
	int OP = IDLE;
	int neg = 0;
	int v;
	long long res = 1;
	bool first = true;
	while (scanf("%c", &c))
	{
		bool _bn = false;
		if (c == '\n')
		{
			if (first)
			{
				first = false;
				continue;
			}
			break;
		}
		if (c == ' ' || c == '^' || c == 'v') continue;
		if (c == '(')
		{
			neg = 0;
			OP = OPEN_PARENT;
			continue;
		}
		if (c == ')')
		{
                        if(neg > 0){
			if (res == 0) res = 1;
			res = (res * neg)%1000000007;}
			OP = IDLE;
			continue;
		}
		if (OP == OPEN_PARENT)
		{
			//scanf("%c", &c);
			if (c == '~')
			{
				scanf("%c", &c);
				_bn = true;
			}
			scanf("%d", &v);
			if (_bn)
			{
				if (var[v] == 1) neg++;
				var[v] = -1;
			}
			else
			{
				if (var[v] == -1) neg++;
				var[v] = 1;
			}
			continue;
		}
	}
	printf("%lld", res);
	return 0;
}