JEDNAKOS - JEDNAKOST


While browsing a math book, Mirko found a strange equation of the form A=S.What makes the equation strange is that A and S are not the same,which makes the equation incorrect. Mirko realized that the left side of the equation should have addition operations between some pairs of digits in A. Write a program that inserts the smallest number of addition operations on the left side to make the equation correct. The numbers in the corrected equation may contain arbitrary amounts of eading zeros.

Input

The first line contains the equation in the form A=S.

A and S will both be positive integers without leading zeros. They will be different.

A will contain at most 1000 digit

S will be less than or equal to 5000

Note: The input data will guarantee that a solution, although not necessarily unique, will always exist.

Output

Output the number of addition operations needed

Example

Input:
143175=120

Output:
2
Input:
5025=30

Output:
1
Input:
999899=125

Output:
4


hide comments
kmkhan_014: 2018-05-11 22:19:09

Century!

abhishek_8: 2018-02-19 11:50:47

100100400300040103040=318
The answer should be 6 ( 100 + 1 + 004 + 0030 + 0040 + 103 + 040 = 318 )
Spojtoolkit gives 7 :/

mastik5h_1998: 2017-10-18 03:27:59

try to eliminate zeros at left side to achieve ac.

phanduy16: 2017-08-20 05:45:23

I passed all test cases by COCI, and got runtime error (SIGSEGV) here @@

Last edit: 2017-08-20 15:14:30
omartarek32: 2016-08-28 13:12:46

tle with java , I think this judge put one time for all languages . I'm sure from the solution , and this not the first problem that I have met this problem

gasser: 2016-04-22 13:38:41

if there is test case:
10000000000000000=1
the output is:
0 or 1???

naruto09: 2015-12-30 10:58:35

Last edit: 2015-12-30 12:06:35
topke: 2015-11-30 14:00:04

Care about ending zeros caused me a lot of WA. All in all not hard problem except that small corner case.

Sarthak Munshi: 2015-10-10 18:52:30

11th case = TLE !

rajbir: 2015-02-17 19:40:38

nice one


Added by:sieunhan
Date:2009-01-21
Time limit:0.145s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO
Resource:Croatia regional competition 2008