#1228
Unrated
SLON
시간 제한
1s
메모리 제한
64MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

1 second, 64 MB, 120 points A student called Slon is very mischievous in school. He is always bored in class and he is always making a mess. The teacher wanted to calm him down and “tame” him, so he has given him a difficult mathematical problem. The teacher gives Slon an arithmetic expression A, the integer P and M. Slon has to answer the following question: “What is the minimal non-negative value of variable x in expression A so that the remainder of dividing A with M is equal to P?”. The solution will always exist. Additionally, it will hold that, if we apply the laws of distribution on expression A, variable x will not multiply variable x (formally, the expression is a polynomial of the first degree in variable x). Examples of valid expressions A: 5 + x ∗(3 + 2), x + 3 ∗x + 4 ∗(5 + 3 ∗(2 + x −2 ∗x)). Examples of invalid expressions A: 5 ∗(3 + x ∗(3 + x)), x ∗(x + x ∗(1 + x)).

입력

The first line of input contains the expression A (1 ⩽|A| ⩽100 000). The second line of input contains two integers P (0 ⩽P ⩽M −1) i M (1 ⩽M ⩽1 000 000). The arithmetic expression A will only consists of characters +, -, *, (, ), x and digits from 0 to 9. The brackets will always be paired, the operators +, - and * will always be applied to exactly two values (there will not be an expression (-5) or (4+-5)) and all multiplications will be explicit (there will not be an expression 4(5) or 2(x)).

출력

The first and only line of output must contain the minimal non-negative value of variable x.

예제 입력 1

5+3+x
9 10

예제 출력 1

1

예제 입력 2

20+3+x
0 5

예제 출력 2

2

예제 입력 3

3*(x+(x+4)*5)
1 7

예제 출력 3

1
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.