Time

11:00:39
11 Feb 2012
ACM-ICPC Thailand Southern Region Programming Contest 2011
Left: 3 hours 0 minutes
End: 11.02.2012 15:00
Leader: Informatimukas
Five for week 22
Left: 10 hours 0 minutes
End: 11.02.2012 22:00
Leader: NuM
Version for print

Dragon

prb16

   Every S-leg have 1 head. Find the quantity of legs N in K-head dragon, if they have A head and B legs together.


Specifications

   Input

   4 numbers: S, K, A, B. Every numbers is <= 1000.

   Output

   The quantity of legs of dragon. If input data is contradiction, then output in file –1, if you have some ways of solution – find free from it.


Problem information

Time Limit: 1 seconds
Memory Limit: 64 MB
Balls for the passed test: 10
Complexity: 50% 148/297

Example

Example input

4 7 35 36

Example output

2


← Mouse and corns Problems Gardener-painter →