#P10839. 【MX-J2-T0】Turtle and Equations

【MX-J2-T0】Turtle and Equations

Background

Original problem link: https://oier.team/problems/J2A.

Problem Description

You are given four positive integers a,b,c,da, b, c, d.

Now you have an expression (a  b)  c(a\ \Box\ b)\ \Box\ c. You need to determine whether it is possible to fill each of the two boxes with one of the three operators +,,×+, -, \times (operators may be reused) so that the value of the expression equals dd.

Input Format

The first line contains four positive integers a,b,c,da, b, c, d.

Output Format

If it is possible to make the result equal to dd, output Yes; otherwise output No.

1 1 1 3
Yes
5 2 9 27
Yes
1 1 4 514
No

Hint

Sample Explanation #1

Because (1+1)+1=3(1 + 1) + 1 = 3, you can put ++ in the first box and ++ in the second box.

Sample Explanation #2

Because (52)×9=27(5 - 2) \times 9 = 27, you can put - in the first box and ×\times in the second box.

Sample Explanation #3

No matter which operators you choose, you cannot make the result of the expression equal to 514514.

Constraints

For all testdata, 1a,b,c101 \le a, b, c \le 10 and 1d10001 \le d \le 1000.

Translated by ChatGPT 5