/*
Online Java - IDE, Code Editor, Compiler

Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
*/

//VERSION 2a

public class Main
{
    //used for stop clock
    static long startTime;
    static long endTime;
    static boolean running;
    static long elapsed;
    
    static int lengthFirstNumber; //number digits wide. This will get shorter during recursion.
    static int lengthSecondNumber; //number digits wide. This will get shorter during recursion.
    
    //these will work in conjunction with substring of the number to obtain last digit 
    static String lastDigitFirstNumber;  
    static String lastDigitSecondNumber;
    
    //this is used in area of code that deals with reducing substring
    //of number until last digit of remaining portion is not a nine.
    //it deals with situations where there are two or more consecutive 9s
    static int counter;
    
     //reason for new code v2, dealing with consecutiveNines
    static boolean consecutiveNines;
    
    //I have now removed this, main reason for creation of v2 
    static int temp;
    
    //extremely difficult to provide meaningful name
    //if there is NO frontal number (i.e) total less than 10, expect 0 in firstDigitTotalDigits
    //if total is between 10 -  18(9+9),   expect  firstDigitTotalDigits=1
    //crucial part of adding two digits together
    //In practice this is also the carry forward
    static int firstDigitTotalDigits;
    
    //9 + 3 = 12     firstDigitTotalDigits=1   lastDigitTotalDigits = 2
    static int lastDigitTotalDigits;
    
    static int total; //stores total of two digits
    
    //used to output the running grandtotal
    //similar to expectation of manually completing addition
    static String grandTotal=""; 
    
    //all below variables are closely linked
    //in addition, if a number is wider with extra digits, those additional
    //MSD need to drop straight down into grandtotal under right conditions
    static String remainingPortion;
    
    //if a number is more than 1 digit wider than other number, 
    //the LSD of this portion has to be excluded. (since in real life addition, this is subject to 
    //change if a number is carried forward).
    //if for instance, this is 9, then 9+1 =0, and carry 1.
    //in practice this could go on if all the digits in remainingPortionInteger is 9!
    //so would need to catch this ArrayIndexOutOfBoundsException should
    //String exceed limit of the long
    static int remainingPortionInteger;
    
    //This is conversion of remainingPortionInteger into String 
    static String remainingPortionString;
    
    //exactly this, least MSD of remaining portion of String number1
    static int lastDigitNumberOneRemainingPortion;
    
    //exactly this, least MSD of remaining portion of String number2
    static int lastDigitNumberTwoRemainingPortion;

     //these come into play in the first catch statement...
     //it does not know which caused the exception.
     //so the variable names need to be generalised to ensure user friendly name
     //to support calculations...
     static String number;
     static int lastDigitRemainingPortion;
     static int lengthNumber;
     static String lastDigitNumber;
    
    
    public static void start() 
    {
        Main.startTime = System.nanoTime();
        Main.running = true;
    }

    public static void stop() 
    {
        Main.endTime = System.nanoTime();
        Main.running = false;
    }

    public static long getElapsedTime() 
    {
        if (running) {
            elapsed = System.nanoTime() - startTime;
        } 
        else 
        {
            elapsed = endTime - startTime;
        }
        return elapsed;
    }

    public static double getElapsedTimeInSeconds() 
    {
        return getElapsedTime() / 1_000_000_000.0;
    }
    
    public static void main(String[] args) 
    {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        System.out.println("Addition program, ensure String has maximum characters: " + "2,147,483,648");
        
        //it now functions formatted as below (without whitespace)
        //ALTHOUGH NO VALIDATION HAS BEEN PROVIDED, 
        //DO NOT INCLUDE WHITESPACES IN STRING WHATSOEVER
        //THIS REPLICATES THE CHALLENGE.
        //EXPECT ERRORS IF ATTEMPTED
        //THERE ARE LOTS TEST CASES, SINCE IT WAS REALISED THAT WHEN FIXING CODE,
        //CASES FAILED AND THEN PASSED, AND VICE VERSA
        //ALSO CAN CHANGE VARIABLE number2 to number1 and vice versa.
        
        //***PASS****  - 100*** via final test
        //String number2="99";
        //String number1= "1";
        
        //***PASS**1764*** via final test 0,2,3,4,5,27
        //String number2="993";
        //String number1="771";
        
        //to see reachability of final test 1
        //***PASS**1764*** via final test 0,1,3,5,27
        //String number2="243";
        //String number1="541";
        
        //PASS*****160****** - via final test 
        //String number2 = "136";
        //String number1 =  "24";
        
        //PASS******846370032454542****** via final test 
        //String number2 = "846369999999999";
        //String number1 =        "32454543";
        
        //PASS****82160**** via final test 
        //String number2 = "81636";   
        //String number1 =   "524";
        
        //PASS******* - 400219  via final test 
        //String number2 = "399627";   
        //String number1 =    "592";
        
        //pass********* - 400019 via final test 
        //String number2 = "399947";   
        //String number1 =     "72";
        
        //PASS***4962****** getting via final test 
        //String number2 =   "3970";   
        //String number1 =    "992";
        
        //PASS******  562  via final test 
        //String number1 =   "370";   
        //String number2 =   "192";
        
        //PASS**** - 1000  via final test 
        //String number2 =   "999";   
        //String number1 =     "1";
        
        //PASS*****  1998 via final test 
        //String number1 =   "999";   
        //String number2 =   "999";
        
        //PASS ******* 1098 via final test 
        //String number1 =   "999";   
        //String number2 =    "99";
        
        //***PASS***108 via final test 
        //String number1 =   "99";   
        //String number2 =   " 9";
    
         //***PASS**** 1400019  via final test
         //String number2 = "1399947";   
         //String number1 =      "72";
         
        //***PASS****5210*** via final test 
        //String number2 = "4666";
        //String number1 =  "544";
        
        //***PASS***711**** via final test 
        //String number2 =  "652";
        //String number1 =   "59";
        
        //PASS****1390219 ***** via final test 
        //String number2 = "1389627";   
        //String number1 =     "592";        

        //PASS***********22023**** via final test 
        //String number1 = "21999";   
        //String number2 =     "24";
        
        //PASS****2*******  via final test 
        //String number1 = "1";   
        //String number2 = "1";
        
        //PASS***10********  via final test 
        //String number1 = "1";   
        //String number2 = "9";
        
        //PASS***95759******** via final test 
        //String number1 = "95427";   
        //String number2 =   "332";
        
        //PASS*****9719******   via final test
        //String number1 = "9647";   
        //String number2 =   "72";
        
        //PASS****100119*******   via  final test 
        //String number1 = "99647";   
        //String number2 =   "472";
        
        //   **PASS** 10009 via  final test 
        //String number1 ="9947"; 
        //String number2 = " 62";
        
        //***FAIL ****
        //PASS via  final test 
        //PASS  22023
        //String number1 = "21999";   
        //String number2 =     "24";
        
        //PASS 108 via  final test 
        //String number1 = "99";   
        //String number2 =  "9";
        
        //PASS getting 1000  via final test 3,4,8,10,11,13,15,18,19,22,23,26,27
        //String number1 = "999";
        //String number2 = "1";
        
        //PASS via final test 3,7,8,10,11,12,27
        //String number1 = "888";
        //String number2 = "1";
        
        //PASS  via final test 3,4,27
        //String number1 = "99999999999999999999999999999999999999999999999999999999";
        //String number2 = "32423543534543532423432423432494355443534532235324324333";
        
        //shortened the numbers same outcome 
       //FAIL NumberFormatException  remainingPortionFirstNumber=Long.valueOf(number1);  (v3,v3a)
       //PASS via final test 0,3,4,2,7,8,9,11,19   (v3c)
       //PASS via final test (not known) - (v2a)
        //String number1 = "99999999999999999999999999999999999";
        //String number2 = "32423543534543532";
        
        //shortened the numbers same outcome 
        //PASS via final test 0,3,4,2,7,8,9,11,19   (v3c)
        //Pass via final test unknown  (v2a)
        //String number1 = "321326263232722172323121232212212212";
        //String number2 = "32423543534543531";
        
        //shortened the numbers, any longer than this and program will render 
        //FAIL NumberFormatException  remainingPortionFirstNumber=Long.valueOf(number1);
        //***PASS*** 1845561698584545666  via final test 0,1,2,3,4,5,6 (v3,v3a)
        //***PASS*** 1845561698584545666  via final test 0,1,3,4,5,6,7,19 (v3c)
        //String number1 = "921326263239897898";
        //String number2 = "924235435344647768";
        
        
        //**************INTRODUCING FEW EXTRA TEST CASES
        
        //***PASS   1000000  via final test  3,4,6,7,8,10,11,13,15,17,18,19,22,23,26,27
        //String number1 = "999999";
        //String number2 = "1";
        
        //****PASS  10001424201998***  via final test 3,4,5,6,7,8,10,11,13,15,17,18,19,22,23,26,27
        //String number1 = "9999990767676";
        //String number2 = "1433434322";
        
        //****PASS  giving 9999990767677***  NOW FIXED via final test 3,5,6,7,8,10,11,12,27
        //similar issues below previously
        //String number1 = "9999990767676";
        //String number2 = "1";
        
        //****PASS  giving 7899990767677***  NOW FIXED via final test 3,5,6,7,8,10,11,12,27
        //String number1 = "7899990767676";
        //String number2 = "1";
        //hence issue with transition from non-9s to 9s
        //so I am getting the code to print GrandTotal
        //at all the final test locations in which
        //it modifies the grandTotal
        //it is bizarre that it has not shown system.out.println() other
        //than grandTotal=7
        
        //PASS  ***78990767677****   via final test 3,5,6,7,8,10,,11,12,27
        //String number1 = "78990767676";
        //String number2 = "1";
        
        //****PASS  giving 97653***  via final test 3,5,6,7,8,10,11,27
        //String number1 = "97652";
        //String number2 = "1";
        
        //Test case exclusive to v2a (between 3500-4000 digits wide)
        //*** PASS (4607 digits wide) *** via final test (unknown)  (v2a)
        //String number1="09504409235942143699028682862323093753872682264060897242515240887016138615587582390386132124170486983911177811528516575254977835519496528009088679104241186353315196036435399088976464708709624071104608498925970921819996781310073741100049405498641416090113095607640038766539961379304021884278664482684127102262882292313939076004106472132345567627682529295934331982242224153356209185730864215015448590614213192124535512664954506543764037507997366870220040613468937008873524440981074353404294107731024443496261674797951898312944982738811199468845329708906668199155612114124858156671938400576566135236748418529538314140079742176784327919225170726668431714118635047794712561288232589606958724834824089864907318983672716789991747382627124082738001996558139535030458862530304186942049575078313797682860897604194442312532292573017679369492869574687637455853884563105792684723331333442109122396094236321132688651435218501686757512916363045163414919124156431525790047845395664825204414951310615051882003465872899439651885065174381395676813100157353934108212248866753460045204230543003769589060067917607254786864551711592724984753083770576956614109629554406642645857136524736162808296568720629872703534749968891938990984004270735064807463898597313119178179936350486633456650992741178823096977277482953134042869404043612138666600927676934956300466806196421946062786128158242873208625810667111300974373774274447752494643011404508833516962652135016652030655835239359009118242575692048347441907733999566865828636236621419740924673661859912239186093041201229503765633029863529781093266159841588200370714905747625656830945316950933481104863650114691822653520059889899195542986475982555069593154249341162757950930340024969473024048782356544401389170948224868931768393329994919614677731149348536198497311845864112401605575686018057156102493303091934634327292134522486929737319576879168089473622786709874258890943622395489281284262053021973086978752043089916073132349153494997642642784584054066462895779226748579511243098645770439401875618341679974985087752931243561875447087057595125406383182328803466444344067433956340614854594110426488358348516214399583927060360811437929901502881846178885842519319937532975739356784345079183111735718972172682834873541166169232571525211292625064243843029997484959855595486649784064767884119597868602862541605400579198838412195359664210148765180814495240141591875732654728303895457849222510319087051801587530737758189941771319588182781666119448988625800932125023519611213593110566729718864593897453671478696841239236986734414000727015564798594337772530321750321555121106420999789635230849896366017354809620884224821325245674227938832462419558203502137609248583981172859566194809498871300699618788925401080138519647286533825160316277436897886833866867917049059412197473716181404186563365383248809332326452830141268575973419205087282995394751420485951704213387135272462779864106046312762439414456272727989999802160062602126997585884616308169743314082504235589789256182818210598161025740215168550207916961836388100868074570792001675624364414785307903237363387159690397470248498519853663478913204681926416183073187901414996378397381695734556974045576854674432535907985565916095051887291975900855395549889365194197821007858004080157679300842483715386048920935444585474991466765536630288056983639880762279841541770311953384727910352186832707918671805147431930922766333079436040610165140144665272877115102524179834732715825230455541136130852207954849855007656080468692102521319150567994130538130629649452929012962901651692607032062343464617359694027939376171619300447602593420015981391518401195285749652050949073761769001187070167456821819650091176774746916425025578751415359071364508534303994608386508230170160280435029585198462869340771988456045465641381229234920812283703338311532194298800264743030002915292089113715822255391145384929606865948201713733164766244355794034232437196212449812266722608197497806360273688142979470277051322615595828949518275435861633055818679782715704732421172906347765645596737827677339827242278299567102147887611540911926595989086261029867890042036715002559672949277183934922194453939932052171321467571465824547117228312689926570220070521063075596531886473826133003949302363455496718308717295510639514552618375679895250660279708951197061601721709372519139689906644918889107486844465863321104372006801167797097479751854657600452480187500869795748906781650285979756939137962046863704959755190118269071548062734821737611883107487555026681891213654427240615394918115025564416759458692506182209660811518819115282205967929090096420543329651140261005444750873982118122708743";
        //String number2="97727783089184504140820968625846445998070649528234744407065890135226289696603858956594794133844215324521933153372500843413956400351140362079160933532943323043790513853560410786226123059517837072739381216163813697071314732056127900672685203295071602494482819959426781977099994146656126647971178341601779992471885080629402351802749258725055328106344446473595422333307262678811590961672950522361709093033371065217091908341204124039938444875203945357710932601283849243214268956225726770590822991758510047216671414147943531360138538239236183677282184256799671253570512331438927909485240453077257563691888820539024239936638108873830482153659863563530041445125351605178407037754517537307784561582121130786493880208174427303176471048755342695764898402621472235515660066877719041130477414261775484957023086004489743520871318175203356644360618835773230997184416198899610779937858568584808112950955065622039307585967550362989976931347431744506409063392084575224239330019570685732887687060507043082809613948022777311260114111420322870273292625114632824971163091800919431233886293137716210157817471724206537810587268407611383424463646220627271186786136317527039508714784739323819310857155456472096694030200601202639912778518070892325758986801285822880957301854503581528904172726148819681617746045086657977607040621385008430635667058990501031339870762940925507603659324666989034925531622751880516680978404816227955980439892119838509893723911175062013516945539059410585748707618600597696062687071582576113861567643081435516437449173549828596819513020366498148663066444469729532573239066401499277925723421426397451044936831138865422139318863984375292813193538707345381039374345094953396096725091430744241462925437921324663679927281419826565158405436737905517911239288722813894854141638614900637191919073316335094511593583753977519844627724213571965102976172408391227468264412380317456520912281227187720554010417356035748200885287765478428279759420492298382498663560145402709893363911816874778030674007799319159493631185053315558335941013972001329703568959465830303531890862554751593646978915582735501240571880896440318431563196974581885250128794592570579808050652261233068604739523223117697833740291336521177032600402528532434214629858127695184673092675689985524361665117099204107831201656857904497884619032633416949723137756528515974643226651181420309387437384892937227258794605380584380518341924180028488448308857331405942067202255622784856361294307857056276111751301347674899741220307863453068749100125979693199048164082999300141642262544177402378006707874108414173717457695851483690091280832022890104843072490186665486408342771118596342191196790193625836843516402967771376842318488479915200045514032231467994122956329019942751015953039768386638192163954912891081277614611089784095745595057851215139309080778058925193398652484315881807248812743309228484847561927634822354076745083873140158948375196369950588054376513699686220564667462931822092352557678472927584814195768984039994931517951087530087076654171439272006912070342854513680389765752589463302842211130475661703508936200518914858263671663689809292531735909050396411746756802319057682528670786811187470731609265919985149591285520191879122104325779026546284498218800718791376330500890992492379737197198983145822399580975496301847778373058551192378592585994283826309904260878010331801433296811859083179498043627517448713395099911848769229518203062145595047249678467417166075538789693533141292321984640685415135957482012830497013128433222844995593586317268422621858731170233074940479982006549080248852640906185540562386914527043432630355100077605547098536211155804992462320364914735338852895219628967103510792295357939454172294595615610948231957362647103343245739265151117091490014021532907351540483255184241219980848115895150902100057897440416367539211479474377705884743472326699922106360807031196951974123417258186130219511526098350674007464216009400617385407331569163021134024894076126024371418875005815089235150208211802403629404458138582191253425560868053455557773166959525137974475349508831219927571581723126378058037710342006665199108326143547542317045735114343134649649537230714567009150453396925690937140014673025633760014580289621490422480762993322988967743033021015247742671338818800307237739758020671579762154409697762765882452491720761978512181051856483896426086280330699653650072506874892469915200094366637773933262526746349693089154368140352954655831836429382818090291092169938967354051098772730955826429199077180538098199128983779285914451363407020865479984910619034949944650764584313617420563543246474142211317757823549819425484461470309041996398343";
        
        //Test case exclusive to v3d (5000 digits wide)
        //***FAILS*** - immediate stackOverflow (v3d)
        //***FAILS*** - immediate stackOverflow (v2a)
        //String number1="66974341891780712946298511271969263897010912395403025403368259563704748364443121677661462107862978619367706212020622000333451155391081888171044812458774180119971436985109358962799598967755201127166729993418162886868074403045028211792993728700164421376382902364846267839233580973582295979062386817930235910804467368179712673210099396939432027926677757703845108441534913726984985659056325756265910784339478151911400559283628002792088352117389623821439910614091363370204701364266167537364013318102104880247238257828107374943922108800896526938601188660824099230006724725614436622365176741736032112551862076963545113663545907985684968201344921370760479162092242595890062909108602182929345703879639186615020565248997056752225207485547171571413776967146837469665927471817321938453729973493911430730790147178784691915815144247862258701253353093807142325254254175056829259717054799407830048194815466732592790860918888511536700705173731961647393040390457846753680243677882083636516669770180831752377123426916542176051970937139260682101462158182190825357612155801401168386651349999463761354997220203276531145835877157619181766845516977287276714965827890271759989391126384216956783961870108600447080886282655687462987724040927352651767207209749959388386973300467469371734632228893009679102147119990265797349210637919615614690424181658081479747361470938032087616142881450613356137279002450763459537384090479408054160635880187283078954539063614671383006350988375154126656264641495630763423670319723143853264620446771366962947268930650248788917700105210425753340789449502966726004308403272830802154962852132878181907946277136042026927752497266652068021575294326313235532245314338482565886159197716667527137475533645999183219883053455585072534315689428649661843420234871904836555504973780458908771126296600696878559906242646968005559284097761437203958410446807744963388034730140092356451201252740845232681485490883138453907061621561744376584024938075321851778159472556920241514445939053187908551112334699306003373877291346132692729177634279230737225898113117937452280261845368620264338461374262135058007949599786504129490183853447708577232586935231642768352288978270222193128742745253142112777172779349530204264484134662349057466811765636372630090943204974646114896162596835715182496135507515004215448407633067694696724899410091971369397653376087706208532367314644570493327239738523564349308340443483300529738848531332136286601164046013868904320460518548138847685782842340252982224733477356573981546756686547844603596866834163287379860403543510892790572940030250928223050624633124559416467144822784102307302749990319226565410398829852691756294825525584775601692534441327362980997354495030010840034428368827062435641984797628605756006908575050952266664366993100542745383325737348840497233238114304175925600505138063121839943635713465258984648787708801320982832716406320320802034823587612046330285437508633018142142162036612860012454935894365240889888221813775967575760700548163936456639273464727711410498990610828267647783085300112182322222959265005292830358153510158028468672867335417561922355921715856521679161976359030119379485892851874529281925964834864387574367862485794554037592313256966664123793518961660103590267772113515971804582577159359489846261369264705009622211595706656686233362137694293117879017310845523066225769599290733415602296796022239839467450185762760670547537192890673652512317812712033386732814946435482437263616021610887716342713984887943644941280636329267647542295938168712468540465680193874241371172096455208123697447144069474556779602067483160945617179190592787807073224879022603068904656871009656699644726699813707225962367579254140386993871982690207107124785561698572464069461840244559674791667466996458198897051373623944149291739951871746498872472983294277492178751828181757311233518492204769079517815253038528771775809998139666921305804710931751784813818057701362662782551895080896560693991329448936078466684957398453582396209118267109713095566882933856949678540445053246044534498530121401685422142004750746516052211129249383140608084295979408176764351546961785145998771362961461200876555731216064387040191284287225980046909490938090028582181433805858752906162474982458026892778057050118576502557236862352478857247378045006060699810666755473606375209654112355471866112372984857795671015355316688209420359229197432339505723323976053972164076190761527218799174633718593820065470971236471918555516020750762109170120956628155390410647533942845796010592998249937172598216015629845173257314940610701298147417480681432623158332828741527808745650161215421292578210623526645347739175652494384310656047294409617174301818924750005890493119894711934391050410726310934434398841044901292379418903012119623476600408872219943774754457703016577793888781042401061238725472093859329597473764890774959016389538346540867241788890971725324490546281703639221979908917534715880692282810306630551005002451809075900199378774512466129995338268503456059573443083590813972379488007451565024452880064356572202995265";
        //String number2="66974341891780712946298511271969263897010912395403025403368259563704748364443121677661462107862978619367706212020622000333451155391081888171044812458774180119971436985109358962799598967755201127166729993418162886868074403045028211792993728700164421376382902364846267839233580973582295979062386817930235910804467368179712673210099396939432027926677757703845108441534913726984985659056325756265910784339478151911400559283628002792088352117389623821439910614091363370204701364266167537364013318102104880247238257828107374943922108800896526938601188660824099230006724725614436622365176741736032112551862076963545113663545907985684968201344921370760479162092242595890062909108602182929345703879639186615020565248997056752225207485547171571413776967146837469665927471817321938453729973493911430730790147178784691915815144247862258701253353093807142325254254175056829259717054799407830048194815466732592790860918888511536700705173731961647393040390457846753680243677882083636516669770180831752377123426916542176051970937139260682101462158182190825357612155801401168386651349999463761354997220203276531145835877157619181766845516977287276714965827890271759989391126384216956783961870108600447080886282655687462987724040927352651767207209749959388386973300467469371734632228893009679102147119990265797349210637919615614690424181658081479747361470938032087616142881450613356137279002450763459537384090479408054160635880187283078954539063614671383006350988375154126656264641495630763423670319723143853264620446771366962947268930650248788917700105210425753340789449502966726004308403272830802154962852132878181907946277136042026927752497266652068021575294326313235532245314338482565886159197716667527137475533645999183219883053455585072534315689428649661843420234871904836555504973780458908771126296600696878559906242646968005559284097761437203958410446807744963388034730140092356451201252740845232681485490883138453907061621561744376584024938075321851778159472556920241514445939053187908551112334699306003373877291346132692729177634279230737225898113117937452280261845368620264338461374262135058007949599786504129490183853447708577232586935231642768352288978270222193128742745253142112777172779349530204264484134662349057466811765636372630090943204974646114896162596835715182496135507515004215448407633067694696724899410091971369397653376087706208532367314644570493327239738523564349308340443483300529738848531332136286601164046013868904320460518548138847685782842340252982224733477356573981546756686547844603596866834163287379860403543510892790572940030250928223050624633124559416467144822784102307302749990319226565410398829852691756294825525584775601692534441327362980997354495030010840034428368827062435641984797628605756006908575050952266664366993100542745383325737348840497233238114304175925600505138063121839943635713465258984648787708801320982832716406320320802034823587612046330285437508633018142142162036612860012454935894365240889888221813775967575760700548163936456639273464727711410498990610828267647783085300112182322222959265005292830358153510158028468672867335417561922355921715856521679161976359030119379485892851874529281925964834864387574367862485794554037592313256966664123793518961660103590267772113515971804582577159359489846261369264705009622211595706656686233362137694293117879017310845523066225769599290733415602296796022239839467450185762760670547537192890673652512317812712033386732814946435482437263616021610887716342713984887943644941280636329267647542295938168712468540465680193874241371172096455208123697447144069474556779602067483160945617179190592787807073224879022603068904656871009656699644726699813707225962367579254140386993871982690207107124785561698572464069461840244559674791667466996458198897051373623944149291739951871746498872472983294277492178751828181757311233518492204769079517815253038528771775809998139666921305804710931751784813818057701362662782551895080896560693991329448936078466684957398453582396209118267109713095566882933856949678540445053246044534498530121401685422142004750746516052211129249383140608084295979408176764351546961785145998771362961461200876555731216064387040191284287225980046909490938090028582181433805858752906162474982458026892778057050118576502557236862352478857247378045006060699810666755473606375209654112355471866112372984857795671015355316688209420359229197432339505723323976053972164076190761527218799174633718593820065470971236471918555516020750762109170120956628155390410647533942845796010592998249937172598216015629845173257314940610701298147417480681432623158332828741527808745650161215421292578210623526645347739175652494384310656047294409617174301818924750005890493119894711934391050410726310934434398841044901292379418903012119623476600408872219943774754457703016577793888781042401061238725472093859329597473764890774959016389538346540867241788890971725324490546281703639221979908917534715880692282810306630551005002451809075900199378774512466129995338268503456059573443083590813972379488007451565024452880064356572202995265";
        
        //Test case exclusive to v3d (4000 digits wide)
        //***FAILS*** - immediate stackOverflow (v3d)
        //***FAILS*** - immediate stackOverflow (v2a)
        //String number1="2121500366998957872281636482415337004357962190551663580288881712235949026839978922376942491056137171829589666056275599179429301313876342113325201417328321552084782273015368436618049733480527613057506438340238272981756459560148465082892465030950077189715421505524804741271259399221996636331113907600007096644859448989792766569779500577363983006577292227648538665788773211908408284217358129270113100968299480519050343557788041852776046323154113426519612152761129849739472247695985548105513527268492452700163937606690294026660088174892789114403361605880972741801406844722422620355121513484941826866919945321398069719944782982482758369959851076545396635427630033901201895443123836562418673239117453115335867798469575897677083811229044279811003485725583854825481948972758964729456228245618065677218084435637665337823993984809396308934713927372657954454161420738701627499726460951039835917519384331920308500278958394439620306849973797394362954497498877132992417830379404881977640351211143621216322338116752854805076108764669648857425566201787033783011615501307079618393245589528051078382915684354846632026782010307151743006473466213576059388890761491201887136532534253826608873537325039768187768355521611461719552759945955519320074837439712022454702389467720771699380292867131921758109896165916586968508043779957472316581233789601360723450724608699674937211240693066871446608185070125650660338951996381141885415511732368774958420171548123359327363332901944537059151788969091229931795008338765265227769253193435536645587531406170147023987527093529309453285433854753831186675215418061774302246168148716583753981482168809929255913463461028797966336588843025068134689524256072542723482167418692758241576896130565182749287456256460377068376566221044145375249018736274234325740664448191142852437056165105657375901317407850015025003000535484747184244396510759460003215304797441636460068005968038556518938693846942023226067306616746169048074277624362143037107904485300423775995746176767577269294888917259932241189207083424736459111437036571463518276660623849885095329950408757214655748437348140624980465291266803498399524709263774323320301439210816011754429947436395045132753027901701191625416941231730837839785619666171619262556877653536501491412828602588062881811822476678997044071833709424830330509110534578843789696498402973541126448340087711774946023792839064789023856261297356237531869734695611095632946072111502257307770191308953568250942948439774755729947173878930969880508993207512844957711129821551255608336395101619449626129841001706125602302218819134969372181226729612402930983242193262641122310772641225151734443999877302345593699111274890902340334270255816704118674391194610497354752246146733948459034220696204702880806224994853481298343024373911699282314534403513142093323029354339107575971217414596739539191948319947308096503625490022538538925327695273070258675283561787630388220694424183156329675745457898204812622913472324727015988464171750240332783240146927470911638774544088189400785522800776668081222811276594572566359550295329747558521066108079267441845733572833877451644845115461199086931338052667338694753607282866198030659374710844517161576983139917209936793919203042937779787711399987325458583653281021912508145564071503274009617297903375871105081159924981760414372834151243573971144600356005435455616662389391249102576124548985570025030880520277726071011838852788074742081419800783088023230271522092740341863015837398319591870783687153380886658070106322697076025886485268171402407291515106007586505480182196446598908845066970229495258962008033139701179948583761327585317854326366795559722150960088881285442556726075830640210176863616827659769655633119408180907145351909085687126334256921805485331409323280899917994145239328799346032505381327507179592850244147357871189548588323770502410844869198826632037544351541737933605526012580539337286470347862956926990532551082425718156660159772191562152202189563670416557394008111299883242009644281804374671473367745403663730785866804031320023839";
        //String number2="3415516772429160197945690621367136886262122718443450243813213365623478510518467704848999458602072715203562840732657164359980894376721457100455063844371608322091938877074279545391380390069940475299462353760298245639804647649003487029060359820696158138964794294958960302471367562825530255627508584355756169175725664352700724529032121515498679985817385668820584967717447746344111559682797463887533040102599913979711744915523690533959682841577912041518407773366004590602453087175708950123528635135888558820052491563461554342871447966077623728385574639424861626900998937561363246084073126311453016484812120324427096463651039841355429191548048266613352146006920475742123527840301474772287357412765912925756568761878167371767528411599666805932674128824151329925906268034443112738559121727669489193059441751400938720471725235613931509989388722384781347667241624539264116276045719312788259871413183480768375306441949836027511728597891448004123431884534636140383435628272799361928228166674902387665839866489244130028961521897992114814400013858596380659927012475716463712597816975878199230803381547549500739212212614366366080578700659334626708038107466171277282951961024424320681613871058323059607814194940391647517047427825933635021634858436665063048360783213340029006265304288313168945600098168909498893578815401840707135093646101832260301561187792403470609598580700288727746083807223937465742939201694747070465126192567519610160060873938606752473499393257217479216748256497597375272775988684858741670914158388409114369571584180512012647255827811156575097884279651057821241795733146450733053129819704365788846752304123434901340990798977002871417518281884815978022008145276830556175419744456136529954201080731926253129562900239110599662914999418917244746017988748370347640815484370430916389410522915419847084920561499198887998133554464594442381432701846331758937332656114201188646174789782366884994080886691405624536506973164897076151080709376886252884336652617513424991521635696467380939110501858575851427138598112457340013069804784505858766132123633557108765755746202305444735511983628069123984363654175723684004458778504893195751797261882156239069236690123120313227880758476178600920101117076930865056211443338693875716903886428721671769089153691326994357943825401745479998964918932291095390663378242602038806324122327672627836225631782306324015634765176175149596985144507368354931885983827057876703169069167745166969994481679509399151098121264552257697797546821769467935322024808027436866033708971826532036870993255211488647189731325217600601402916352133217306178255397272226150899726394432860915848212760118642803447580161975851065115658547380937911797975507811833664802410867840125650499267718337854847577105500912341447442882474346019460076624390413991431081553631467817622445786793234777427617261394055769595584886531504606065166344652222548043417159910634203658188353964855570185000046211943553491953480344633816817670398912343448883602429741498486756572090848551886504979738899496465732858989302810935218119304943101463232199623302443401616244424612917940640533767791821292811517210326948909841819598678862601967813741449718038574302537597785864413450354856607738018284652595225777213099727276369941242738886474960514857719546087305112483102317157746698615400675094932892492838755436533793882445651164879980307070500118982534670487074255266364804746810589220092868655035507498762869162180288018320536917577071478720053556913144435534009136095008691008631651032285272916732619433958937013577117246705778847893222347632157479348021574771940353796140770143669720150911594489618891604635604689428661699274342074427285015750344495824991362497572939136516385969195332157658356149168644432985573402262839495408446980317489549978544637165751736508311325924097314938110406784769873937106626024382797658579898556010623074754956935867752800947721040749730392653446682005914213718362471248972962529799061777593491273274568571861747271466218849926955583741778342972505559301067527255575430509289112911521573935159";
        
        //Test case exclusive to v3d (3500 digits wide)
        //***FAILS*** - immediate stackOverflow (v3d)
        //***PASSES*** -  via final test  (unknown), commented out (v2a)
        //String number1="57763872417420202965899931516761756833070170973297395844480779182502133061277497070143240254099368832095104780095811844292275441661896098958976807941359575147253017528268506010390649921517710060321746488483160324362891695932492111489479295817959330563539801886495246271933501078961094152460401690897029591542972777566348819011520392051346420231727645812744865355076390172692018416923070908645537412667840319864298964509556159471047358958551218344459408716207332651305768167669466603040631588097402908802409315561812141533282185225742037780752202649393598498331147626736608759676912734528059178746689234710126833085168579110495284928333965280451159640380872315034609008398082924379820302701530648878232207140187353272620900729973950410274593830464775825317159001240992856006361169604257423847208914307357615868946936418389078265672243252509262720151986544278229596637399975973245487360074315193403562848714881348086536269649836300393893230690295956760962342724798829427819189836000171530851034866048257952800521594181395413222357054563615254285841673887516326610920949614208292807751029111584781545664508774107986347843136215373147198697849771797002525021825168452347255821475765441424316095488961900723906729597318335567400223370768705900105008277861810522497694172281057699388561057069229547227390712282473048227178684791094670467546641632804738539911399526264987294696583327266049653688395419885460694839123484284418814279844682118592525983769584173692722920273179115148770031258167759516575508883189607563550511883765903368685343834270827253205232077209254178109263490245874734072867324408446923395019252030948957930237410208254149633356937036921293681093389489652752527731876410717895324519977501137194344249402531187690279361329503937650983898971350355891095944329208918990279731621763212208414684005986851575721136580936905708335350629058386683960896680163738467540943163185083755728139180873805198637918613925668569233137621360958540641031854119801443455551808461024363333677136675291312097298229270799513051196577805522784973941875748170408488611961010026017627007923972720028614057381036825012462236157440876737350979677592365579126595015933110838289208306142383736474506373018451466326244876188597338588528593789834478337633786698991269518084048295780022729753767830006879354437201176820672538048850131126049674311543104491867945742181864052907139079219349473608941383544941952758507172653173658325243727928324219929816145985562008622911046666471686928396703611984448874104703471925886270740604738134720011908272303248787128169568349318656877628687880933303480468450886050747454238298229838320486230579211965140683573463131705221087871940906532875627196894837316238018285532357044397064076603065466843222841087069028508882732559549558000048593324164742340375241385479317529394475983304581073257722148019621927227543149595984524505443181487716756248004916737888187066901946902042163745889993012351030299456738623636537436608607090732416974005831721916202368191201623028253307316839911368829598841320051909669444692632835747252352087503091259818808652203114925937104902371929076606907444768459127552338699602405858091177196235155688356448812227269384457053000250895059237710435878367502836339977211824266360450168593387314055440207602088823975854448571226118216780809410923304425233815137394386228675755031468523849338122435498235916198775832793875344276459475350468697895939512919797275477956114603384356350883374933166120076186735931121751025941815365810193676881789099218463198886465920174";
        //String number2="60509686308953792251283294402106345574380997155404037478903173007462653808873637310887153528240501887551967396855100974795237527487141127974591470834067386630539221676329696051691252697469169614937604011991568794880948396544689648530943624358519322047288520354459258861876675370181920563876593406934818689972403863245333995482297681481113422528398601283925940405148509272245409440288097000580501886263323697925504389209238139540158587780449473487158635553575576460833005433199111917611606333872165168978598337781974588236555484564971465569449946670622654406974986479176659330165102061004539259790461757651344534067706127600363599256950521595938374938461485697014293379658446531592762478409645398611027231404567343229217222127877133114284271461037422607179370689296555698525564935132981689201041360668551460021806690723243305359249867412214060726022618040229459770071144908906568143870423451621542611654199814029822263145165256229239182491295299767376106684101171919809103063259878093656628097650035541622446881526545683873165790691268035218643321562751611952777299543801013362126835703700789965069548928054113732384250634760011209662497735606413555949370752019336896226352652609668174144653642404845844291740214649872006443809251568659988631814863404101016421776331083376941490121418660215099939192604188919076979265275043706277982797394243268560166608528830500612179258069801583526318199211793643347520482543152941469174768832871351463570849665048860100369489159552553697505865748825656639827368046711894967754196617911223608371745857918829463520813735183330624383696963341053677624312189737406390333338687216496057731627390509161814586054080004999315098397560543516258784027086195964672977011640210619066208734436426969797076438613185145113928996733699786622020790628332866643708261099874346918539955159841644032660357650434165054244924989654239235542126971599007377326615743944436490075120225850429145013479426020787271361500117850869016020462758574103748069559023294190840433129300734852890452489916631384280283936785077871245487350529365527296093952993028271337674867026000887532537111002000910884046280605948568415523542741666033936812591329063808025191197747743257370483898631755114654607364558852062936901161732714972396592121908157813577399447829669855880693167382518262840932439250687336414093805932657226488685620162239056828285806311662884297186974399283699635294129459631568418961810897192777252334573049944176354783906317130394344857172973444490898827316412279463285367127262256445622633984129155072595570848537841561758379204141345542442501479711644419220008206221015869514262213422681498404768960484423219948713714501530372231581492619445694604221716813967674642089414386918752027813817284932585041627639439668154724868887844635339794475374629654044367738625997515289871404920357707572582449335295058240597791758967413012673554421884326554760593083977726622013441451072753415477010070260008247034708233105485272874857595787082257129267907397820261199521950293703105957968996078101813243448005372392165044855225972133241785368477676929064342925363516708872007749722526437612048620572420822970182161842334146337789209582679067421488933993889204730286666112923344367012251894195872489871929815361427219234979686623582898984784983302654108324388983817848418425193315404469954170961144423171145881409232470354978003669858735317902355924377473617858655859085532752483752269924003815213003569782966932575976610001821690904366458405743444309196740086142355708090977965011345560370056479821979";
        
        //PASSES  (3466 characters) (v3d)
        //***FAILS*** - immediate stackOverflow unsure since shorter than above!(v3d)
        //String number1="5776387241742020296589993151676175683307017097329739584448077918250213306127749707014324025409936883209510478009581184429227544166189609895897680794135957514725301752826850601039064992151771006032174648848316032436289169593249211148947929581795933056353980188649524627193350107896109415246040169089702959154297277756634881901152039205134642023172764581274486535507639017269201841692307090864553741266784031986429896450955615947104735895855121834445940871620733265130576816766946660304063158809740290880240931556181214153328218522574203778075220264939359849833114762673660875967691273452805917874668923471012683308516857911049528492833396528045115964038087231503460900839808292437982030270153064887823220714018735327262090072997395041027459383046477582531715900124099285600636116960425742384720891430735761586894693641838907826567224325250926272015198654427822959663739997597324548736007431519340356284871488134808653626964983630039389323069029595676096234272479882942781918983600017153085103486604825795280052159418139541322235705456361525428584167388751632661092094961420829280775102911158478154566450877410798634784313621537314719869784977179700252502182516845234725582147576544142431609548896190072390672959731833556740022337076870590010500827786181052249769417228105769938856105706922954722739071228247304822717868479109467046754664163280473853991139952626498729469658332726604965368839541988546069483912348428441881427984468211859252598376958417369272292027317911514877003125816775951657550888318960756355051188376590336868534383427082725320523207720925417810926349024587473407286732440844692339501925203094895793023741020825414963335693703692129368109338948965275252773187641071789532451997750113719434424940253118769027936132950393765098389897135035589109594432920891899027973162176321220841468400598685157572113658093690570833535062905838668396089668016373846754094316318508375572813918087380519863791861392566856923313762136095854064103185411980144345555180846102436333367713667529131209729822927079951305119657780552278497394187574817040848861196101002601762700792397272002861405738103682501246223615744087673735097967759236557912659501593311083828920830614238373647450637301845146632624487618859733858852859378983447833763378669899126951808404829578002272975376783000687935443720117682067253804885013112604967431154310449186794574218186405290713907921934947360894138354494195275850717265317365832524372792832421992981614598556200862291104666647168692839670361198444887410470347192588627074060473813472001190827230324878712816956834931865687762868788093330348046845088605074745423829822983832048623057921196514068357346313170522108787194090653287562719689483731623801828553235704439706407660306546684322284108706902850888273255954955800004859332416474234037524138547931752939447598330458107325772214801962192722754314959598452450544318148771675624800491673788818706690194690204216374588999301235103029945673862363653743660860709073241697400583172191620236819120162302825330731683991136882959884132005190966944469263283574725235208750309125981880865220311492593710490237192907660690744476845912755233869960240585809117719623515568835644881222726938445705300025089505923771043587836750283633997721182426636045016859338731405544020760208882397585444857122611821678080941092330442523381513739438622867575503146852384933812243549823591619877583279387534427645947535046869789593951291979727547795611460338435635088337493316612007618673593112175102594181536581019";
        //String number2="6050968630895379225128329440210634557438099715540403747890317300746265380887363731088715352824050188755196739685510097479523752748714112797459147083406738663053922167632969605169125269746916961493760401199156879488094839654468964853094362435851932204728852035445925886187667537018192056387659340693481868997240386324533399548229768148111342252839860128392594040514850927224540944028809700058050188626332369792550438920923813954015858778044947348715863555357557646083300543319911191761160633387216516897859833778197458823655548456497146556944994667062265440697498647917665933016510206100453925979046175765134453406770612760036359925695052159593837493846148569701429337965844653159276247840964539861102723140456734322921722212787713311428427146103742260717937068929655569852556493513298168920104136066855146002180669072324330535924986741221406072602261804022945977007114490890656814387042345162154261165419981402982226314516525622923918249129529976737610668410117191980910306325987809365662809765003554162244688152654568387316579069126803521864332156275161195277729954380101336212683570370078996506954892805411373238425063476001120966249773560641355594937075201933689622635265260966817414465364240484584429174021464987200644380925156865998863181486340410101642177633108337694149012141866021509993919260418891907697926527504370627798279739424326856016660852883050061217925806980158352631819921179364334752048254315294146917476883287135146357084966504886010036948915955255369750586574882565663982736804671189496775419661791122360837174585791882946352081373518333062438369696334105367762431218973740639033333868721649605773162739050916181458605408000499931509839756054351625878402708619596467297701164021061906620873443642696979707643861318514511392899673369978662202079062833286664370826109987434691853995515984164403266035765043416505424492498965423923554212697159900737732661574394443649007512022585042914501347942602078727136150011785086901602046275857410374806955902329419084043312930073485289045248991663138428028393678507787124548735052936552729609395299302827133767486702600088753253711100200091088404628060594856841552354274166603393681259132906380802519119774774325737048389863175511465460736455885206293690116173271497239659212190815781357739944782966985588069316738251826284093243925068733641409380593265722648868562016223905682828580631166288429718697439928369963529412945963156841896181089719277725233457304994417635478390631713039434485717297344449089882731641227946328536712726225644562263398412915507259557084853784156175837920414134554244250147971164441922000820622101586951426221342268149840476896048442321994871371450153037223158149261944569460422171681396767464208941438691875202781381728493258504162763943966815472486888784463533979447537462965404436773862599751528987140492035770757258244933529505824059779175896741301267355442188432655476059308397772662201344145107275341547701007026000824703470823310548527287485759578708225712926790739782026119952195029370310595796899607810181324344800537239216504485522597213324178536847767692906434292536351670887200774972252643761204862057242082297018216184233414633778920958267906742148893399388920473028666611292334436701225189419587248987192981536142721923497968662358289898478498330265410832438898381784841842519331540446995417096114442317114588140923247035497800366985873531790235592437747361785865585908553275248375226992400381521300356978296693257597661000182169090436645840574344430919674008614235570";
        
        //Test case exclusive to v3d (3000 digits wide)
        //PASS - turned off all screen outputs (v3d)
        //***PASSES*** -  via final test  (unknown), commented out (v2a)
        //String number1 = "555418988416629253420718496854693264446474315507822060564627820358402026037619780575719162769259233240677357230285005574138788049820951536266943641343868373054036422306040612520405178100180293101998852886175892595497014909238920567104007718236270873344927275067759361986159805092101349760180463561804291165677915570777010626278787600378321378528047863827661820193955762460980802839063358710941685295302615716858918474136247281407287902016435261032949712160632909405566717210543005928647366009685704248278514232489765740842990292328100313874234122350835427637430570622752281657588314883417933780097848579181168582541706830021455847487835866156184681077571144849322487612026435858373496520076262818794628906205136750568571231972727888696631517785393735220736899567696283261966821668758337251128415123175574822732701514218363578125114334610277400914683579917932926355947086615477669433272783159334591442120394876307977131708213500428710414254996105111008334105824641062126913743510029384032576024311535794162494454365573081048783349376009605991745760367857223801163391884749828111118568782126637654265393555367637453157902650200901485099564543885819595829443417667457266939276277542402272872787758465939757592666549608042845808267552227165769896438612600524989518089308306901630302969581715978295414389377950694590497520013571493468663115508104375951193039502068203311605630573624649547711033264419670249864359411748936248287060181569152779817317083323683347772054014181664534121665664284049704124025589636942060083254891220283948871204245947340029983736760279945585276084618422954611563618966204146231384884166616470176301523477159011045211234647169631835618060644746452880717528936963350841013172204549326187682185633834405693947974284268377142737918235037347187031628788509972430926364446070331053179589876387479745809048456686428402150358329392645949354998895711510215383600507233642800387618664165402394173141617754309370825658824690920012557689369158089755389892989060020902128085844240284431912772652499318834073283889577791317785763868993714436215719671312776891246815229708778186136125640034995358027281475984261427286561684463667353282809628692514817508740664706989481492450494095219534414355149362123381260357058994601712437069183054903151982922039123229845992802458511251246175064376257810830220967512798974674114150391028958423016789737231824391305199716541594292475603550248435334846584807683005537502969888511034884560894449184484384662679574368704998482999646717457123180680676271918406563566183815385124938987162039289790234249860579530475233249201555890111600802357765945476399459875412226244008482291879648261073520331418780025823322313400354096680831133586920411305127357706154314807056522304267060033761635805851616087521596024455119928634495176868882939659321878601090783146626173890080797308176965614442514230933843947966834728017013072090440872156926708232367126650828171096694215817337609751687964584640980343703643858781412493074886419371908976020284644880192576646947745990402";
        //String number2 = "756541625661614044115454171719166500882450810184545431163638632431188800305523852577696972185206860082332659373323544231768753086901937545839874964392551608328911367467724031781071714939915243895631026414474123860908079432963469686612343353299274073505574026486262928001346865957839108753979515824625094526513421684676718860425880212727636689456465957249035129663980423286072565471949888364373216379646410386642142871506714085403264778960096932009245145862760321892446484514613246510444370837070901673756455684783828619422395123205355035965589598004918493114330475698767060185225490734181883323802548020374480176871569382691903295475123930542732273364749053450141776414160074462826977673380396362682578483705391707192054637328836338069616068819040078722876217092595444062950680108366975901657688319068513219990744558109302252536784959170745382338177835335507642363252680156395422154468114037526588043990567327682829263930786632864923375331368323608236273191854756542102421954234736724794804080223064404254836321190450572494448765878012634932290229530695269098195021917035889595480728881466643208036045674581205072378154817595996279395108506646074598883815357061639124475721689594850126890599999158533335693684186100322149763568421397136328699220676881748557473689956946996283196069807910723572373651602754373587381862870527280594131047649830884793889925901230636808223223400522218378644240476006026507214760243516734831526536343793086005216056808688974908551881750668826002906898719131715374701409613273852688077860853113025666123290103220195384247330868448359654136068090692115854174041454821567647046318693093639486999493848250083956904491819197153806859423712627314466042919417744469805246409738558754313714018822980283287620554542354105969989695923194313495762672101960118359336240532460426055913779834462492141712640823143668036047353959342618725653686061365575658997491076877232251065233564548176583029965883325791368775168294340034827017679829673354372179271988129497913094987502720673534671579258702510969035709077291094100927924637189073766304330420992911620396424469061975694777182832478457210112076237015744490366790709830514241570144953625149283587850771509595304277035920155040615999676155141649024379488043338938179155486613408477476905221125342107399629257902131537661462459676812894962056222290225529645556371398460787333198494932912022605177867660595351953585360335306270319926029242141022171441470095292774167222399664933414148358544184964777368448619893960081489100285778753403629388826674419585283594850348859466839806418949653087852688839726177442485291153654031470425106478651120391959867565079279060021607923515549190716025552310924167063797685632758587008491555428200076908362678039532206830324971426947436157879338853252081217222380585946131981542651586362462580230443484188707742748326380950469018738187791963057676660378199583329667202171795740018694236564853788949080945665681164741895915826527434253381659021954044054838088454657675024670905286964699504006068930248357840";
        
        //Test case exclusive to v3d (2500 digits wide)
        //PASS - turned off all screen outputs (v3d)
        //***PASSES*** -  via final test  (unknown), commented out (v2a)
        //String number1="1840300154692661770386836581156089752220413135036341423714818144479501825694791062194203548118605068993303214856561940524199386441289561796020774906905327733247979022964591066903006860994390830107110668600647868226159892942717238461837989407025560968794644673682154615023562440713639847860111089300254734175865915590475793613641935298711836361889429729207501839602013635174774424757144625655862329508562835834187403671202557271312443885783789634002799199288895145137364135143293524057114272785087964254259862772795586635344087505495074596239263733699287284880943804460643425563438856356907299763415800795900976623769163747061355140059499378921724896744815985606914198291387485283464996343405776757192737210676449265260037160623077450217885512900203521177404676940866466395687741064114519674572374933165552318719386646990480873184770762750032283665509572845790325337031566003125366785955894794630624819239410316078085448681593299247771835430825310232094299848815747511902596671364833144256296496890955359125221982892608997402495646388848568510849028133219619379147118271346779425753428964833108136673528954529800655517312611189190216433232870262048790785110520410390676781322449301059357490295587824086337557417923552790979556168200241786232017459355260353523816690536713032687313671285372533012002594210458346862082923074498456015864889344367060636352768191613864999235224878573724580603462008761137807841738629232501016458415748679113891584785485765788957151481329228441274391072671781753334090895452906750872670174376033562152469223638086312473935461668096267710038802135685245559748919296401853164284000190253367092068261914819177325685272961914657710021210415629649555744196349853670831935186193216816477540943777053243145980280441129128129501679654637055683063601194164624160850348134607805994925985385881179247764921918764689683907190095763075216862291753302994963794240771727536991655660422557368966448573514804454952326109812224277649088838195008788341348863214916743895456988489704653506679096798271829446640128875154891246780007623105253896944343589886804098614944182454090333070270390543786479386692828709213924381600581702146815614687247505915192328642712811983064243046925897960180536781484004288604115421187889943784450257033983479266483367253391001171568090143750572089249182211225064959066989308439927686518477723860143796234814897144862121596411193476700949756914717386993150859620257026344796334032833008522887292642707979787743750705966229931893727867435839011793438341335048199766";
        //String number2="9168841166133668292372774250438117807904505249513692772480169177349031558606421691132040458386908893586760478332786496043113039349572726165853583808797375637619585304455599017375223699012479933264958085379219183916989981447787008394715439826617551645274911632675437928738280293690077765526469666752205028051514469755127540716621888116584358364190013529164517282952882357428506067077985168212447276097212599761597098613634386282025432721321198478866913232824634634415076464464006101783371286442764767184736422614317218089154705744991923667645507270064569486797618840823202400582356302341891709215974263966598648423253501818254863668320186403692652876007736161768740987246554398907473792866752037991058802104978903719519851324418368079233883205005237713609613681561557353851000336736591860860559034524238399394573369366584073083074422038442917144402549474904800716243935013512081765027039205695521033094930238304021866905171344556779311717941300297255609801371417008251487825536588618357113492978031138804088829329679148276520383809661781002910623424503522602282494034702165730399932945370017979264637810606195606381903493049845398475444981566071757970434782482405041111875125168338176510104907942494899208410734477194514310782631523044933661160212216727000305124070863010918543483809282659680299989518763610257518232736409241563634331741981903986645159994538336476413611261592824779548752670689376954373384263751228745002871595701670846108806436902468262875718856844591899805622806009106915577710049939410350018091586001969377832143420855065626480270898078694754204277307300067194133885710331699207381542657601312134668462256777404641522532117717830135744810502719905810776490578943928369269821233823740569762024656201354744056306344563141871491164371036371584268299250656247195218123377490221184885724429084929362516887715988330813503218201666821603874865228982085565881305364683620464668531308860841698663342691271470808796798944859191738654042745124976403506706144958991860714340066069414410077989628566525351306323964417005044209351506681786281515593004534252559426490889664021422497244887061312367622508692091909559576905154733409385517461265342692778193147969414387856882746737564940641052141826619269865457081691115688744201818690707809035629942387377436780389304573622272162468239939055445403914843432435589727397713341086270597066625565211382425442864109724230798079901369785215307379361714047721340857290661606673756965600877159447644428165446236989124302775246193859850931581609673692922601";
        
        //Test case exclusive to v3d (2000 digits wide)
        //**FAILS (stackOverflow)  (v3d)
        //PASS - turned off all screen outputs (v3d)
        //***PASSES*** -  via final test  (unknown), commented out (v2a)
        //String number1 = "50369128439363588387346673857897355109059928773870791594365148198336121593646789032640854845440465027802089020523480252552230973185584281846346070648233870028824356006046715217033572798625540020371152312807972258254657479785629808676896483444038763322497861934820553564222099042477558114459281201202120557354984154121520644345709748502995038611484551330553700742437274642723436735441377421851141379164403168360011527950839387119249861879647628477691771122052206222709982485444642423705737762784229003611053707021455358869036124856929571740154664959054647606416172403092590516377970805750402802490061719298208377120447378283886620796356617703621897136148487877340571175758907864653505009290404406176221467891906849788714836023642546061447091336130587297927071216947104695493698205667468390970861341922239886551644160445306195217203977063461463916461731981142431453075285329539293670955103327515109085289390333233915691793205829324214670401959902771951848271874225712903028866578639255149829371647521041010708107091505525547751617382394833564493072523024329788238277124850068384699971761754689280207263212191971325201489984082640153113744946473713873770291130970426446608030444142089831741506454905009789948560166297073502913224288673502048380593800069803458509647687439401693573056904173289282843417469181837717370952315054405582049964675721725919617396580886947183390024889668082065172819140445832158755436647309308888005024716529995125717725739272135892914256313456593842049095926406809185573925399547729014184662275268640557000387108414568661733304889529954855655441582885565439131175014424982545256039987446635915990898048011679057204392477416573084323666681972059748546108534024411581763865323305305241873150985702427346570109139109817344003686551722945222604936889795267343415756743265789266911682241398729724549124106027527014358170588992597669671360879297174486817718194871287566417864150600907778708923339007018986913171250037638619935356930858101359057051795316506466678978067631869256794823";
        //String number2 = "16226123504000191138171164935393868461688003925920490740323057119400073538603607788607908324876057897342732721016052683113183613366194206326644187538440950207384237377043198790193147449085705812062346185668296417033851884824766462754169438401669914567694107896707621989971139800357030432618064211383696416252203000310862444030779411763270663439567276429913680890951884962372974792092351670298085194798794365230938931317200473515640544714395924035007757570622095196848606518890750142033311165311728351960561250616541933329958585183658526617284654578874967711754970344419472462049898719489854977413529698511400484075132400155638801206627874588618055444063406543653704167022260821236081499557066438231587159152862395037358792720951657388062978445021770313169559929468226785668730184893015021268405935891115232451034543313508195172499760197209616575299524988450622869152912778716454300899648079576360382516642022467500972768718361037964797534403038598793292555396098615493188900679856800993800447817519700728607176013851597172866525588189562573031338200532311804520130068965663654952869040118918072811342693217617801122850293471890896263870498132755266221725425507008347128673265935916459545975966288315762505896715350693093005789506562474016038961855312221905086831440041070054442866794862305687905673721856309487208428950321554771817377696152059934013609986267978013108914705021786811284113077959378579554959157616802342199655105506512729034646039660960070346328218369827035145273596942782607569593807545196128751862484394830171108228239867392985791341422389926579576845367713576210102835412253420584846257556788650532835782542225040387794431309417602020983022302654286276294964313704682488681781152649061709029755106749077285180737569451529442994109065342949624677980611351365664623160034275363816957166589550051478504986403627633081046632064375791881206944427581143571759169687167394448080636054361627619397431438036654775431822760286345166488257346466119219741505620547648151768408376912794227192845";
        
        //Test case exclusive to v3c (1000 digits wide)
        //***FAILED stackOverflow (this is most likely due to level of intermittent System.out.println) //*** FAILED   (v3, 3a, 3c)
        //will re-test this again in v3d
        //****PASS via final test 0,3,4,5,19 (v3d)
        //***PASSES*** -  via final test  (unknown), commented out (v2a)
        //String number1 = "6540408803676551856145754179494952031641751128938027081594109202941756393226600543442882752269695699314042509372562558035130155201235804416978442814716066633331684701309041944005933247492197161537430092964009925405404898093526197642656517976584402351120676894496344261101405074960742354825237877067766853289546572193680145918374055798302988968834940477270175023190608474863156041621058818536387660102334688446945999090446482095744628218001727163921152732660767345773459639050652506355208586088750291880562756699402838634781859401130188701054500767361258391309050251719335317483963696204779416453856290531735715655327874145804266814260091376933819405380392275021015874472850932801040745170331303362597842318250992266261656408965264590813305010031071484186291362501565229382649717826676879079939023169464056918062405311960125664527591607096298568512328375412475040177207461557189616645485993869628393441369935104158144300929321447102562449799751532705610050434477191394853945579500622980227327294889425";
        //String number2 = "7593410793529320655807929208968270551535998505826704128970255423500360626507399748509853638797593338172131057078788529171487853931504412968660404836649088427154304981895602194007150101379636457587140031561726688476488599318208789255159152480106746206821041892814777363743524485987173606432564541793846769177056985798791440794492879614900804561622296552728633957252870806248141495295602565231667897713857384870031236414400670135477542145666281451320150715222208568234708115229889236307546686999960233822661299424227773832094687753287534950038257904558567149723965050532095329485217238575977582602236472383796411931990419506054663685156533708137600219118043146561240650549589756433199762237109639228161373477310197951132352820338503495697742577273196357685668607065398283252316052259220851856058011180454199637959948127379191174169086619150340599040929800077491194617808338639416446912856825955836566616434433183609692372490302986649736278056162756355200464472501738106748874515140997303553131579323045";
        
        //Test case exclusive to v3c (500 digits wide)
        //PASS via final test 0,1,3,4,5,6,7,19 (v3c)
        //***PASSES*** -  via final test  (unknown), commented out (v2a)
        //String number1="44588794920156385020618989453516873402296213115430211273094495832773839994702700783211129203106433325264791479271736181009102484754153124328608907010185380453083084532699801692851385831071893495634373144104458898131292472173805827793111253789485161356772309347962529032470629220129074523117488203777052933394794661551754680233794234810437526349590153066728560316382985053308668436052262732234637545246605298268753647870088457704353600047981319051624818279858556391491845895622423415243134608715949035";
        //String number2="68725821128271887743673605729732681037343324154493346721890730262336075679999883656417766690848092791710847369632801131693688281945601319627424906000846572759971516657232384729839375931380951183873753928668449616756468479706521208197997973361117584200186390298788232006305201120836792698054054013349520267904168958754128591755065414086294094559058977058792769350606027102199414759633780888520510477258925236600497611945800711510783751645946149197832245544146125236437444772564688256505434965294501933";
        
         //PASS via final test (appears to be 18 digit limit)
        //exclusive test to v4c
        String number1 = "999999999999999912";
        String number2 = "324235435345435312";
        
        
        start();
        System.out.println(number1 + "+" + number2 + "= " + addition(number1, number2));
        System.out.println(number1 + "+" + number2 + "= " + grandTotal);
        stop();
        System.out.println("Elapsed time in seconds: " + getElapsedTimeInSeconds());
    }
    
    public static String addition(String number1, String number2)
    {
        lengthFirstNumber=(number1.length());
        lengthSecondNumber=(number2.length());
        
      if (lengthFirstNumber==0 && lengthSecondNumber==0)
      {
            if (firstDigitTotalDigits==0)
            {
                return grandTotal;
            }
           
            else
            {   grandTotal = firstDigitTotalDigits + grandTotal;
               
                return grandTotal;
            }
      }
       try
       {
           lastDigitFirstNumber=number1.substring(lengthFirstNumber-1);
           lastDigitSecondNumber=number2.substring(lengthSecondNumber-1);
           
           total = Integer.valueOf(lastDigitFirstNumber) + Integer.valueOf(lastDigitSecondNumber) + firstDigitTotalDigits;
           
           if ((Integer.valueOf(lastDigitFirstNumber) + Integer.valueOf(lastDigitSecondNumber) + firstDigitTotalDigits)>=10)
           {
               
               firstDigitTotalDigits = (int)total/10;
            
               lastDigitTotalDigits=total%10;
               
               grandTotal = Integer.toString(lastDigitTotalDigits) + grandTotal;
               
               addition(number1.substring(0, (lengthFirstNumber-1)), number2.substring(0, (lengthSecondNumber-1)));
           }
           else
           {
               grandTotal = Integer.toString(total) + grandTotal;
               firstDigitTotalDigits=0;
               addition(number1.substring(0, (lengthFirstNumber-1)), number2.substring(0, (lengthSecondNumber-1)));
            }
       }
       catch (NumberFormatException | StringIndexOutOfBoundsException s)
       {
            //System.out.println("final test6");/
      
            try
            {
                //System.out.println("final test 7");
                
                if (number1.length()>number2.length())
                {
                    //System.out.println("final test 8");
                   number=number1;
                    lastDigitRemainingPortion = lastDigitNumberOneRemainingPortion;
                    lengthNumber=lengthFirstNumber;
                    lastDigitNumber=lastDigitSecondNumber;
                }
                
                if (number2.length()>number1.length())
                {
                    //System.out.println("final test 9");
                    number=number2;
                    lastDigitRemainingPortion = lastDigitNumberTwoRemainingPortion;
                    lengthNumber=lengthSecondNumber;
          
                    //note this variable is opposite, will be evident later
                    lastDigitNumber = lastDigitFirstNumber;
                }
                
                if (number!=null)
                {
                    //System.out.println("final test 10");
                    
                    if(number.length()>1)
                    {
                        //System.out.println("final test 11");
                        lastDigitNumber=number.substring(lengthNumber-1);
                        total = Integer.valueOf(lastDigitNumber) + firstDigitTotalDigits;
                        
                        if (total<10)
                        {
                            //System.out.println("final test 12");
                            remainingPortionString=number.substring(0,(lengthNumber));
                            remainingPortion = remainingPortionString.substring(0, (lengthNumber-1));
                            
                            grandTotal = remainingPortion + Integer.toString(total) + grandTotal;
                            
                            
                            return grandTotal;
                        }
                        
                       else
                       {
                           //System.out.println("final test 13");
                           firstDigitTotalDigits=(int) total/10;  //expecting to get a 1
                           lastDigitTotalDigits=total%10;  //number between 0 and 8
                           remainingPortionInteger = (int) (Integer.valueOf(number) / 10);
                           lastDigitRemainingPortion =Integer.valueOf(Integer.valueOf(number)%10);
                           
                        if (((Integer.valueOf(number.substring((lengthNumber-1)))+firstDigitTotalDigits)<10))   
                        {
                           
                            //System.out.println("final test 14");
                            total = lastDigitRemainingPortion + firstDigitTotalDigits;
            
                            grandTotal = remainingPortionInteger + total + grandTotal;
                            
                        }
                        
                        else
                        {
                            //System.out.println("final test 15");
                            
                           if(lengthNumber==1)
                           {
                               //System.out.println("final test 16");
    
                            remainingPortionInteger=Integer.valueOf(number);
                
                            total = remainingPortionInteger + firstDigitTotalDigits;
                
                            grandTotal = Integer.toString(total) + grandTotal;
                            }
            
                            else
                            {
                                //System.out.println("final test 17");
                
       
                                firstDigitTotalDigits=1;
                
                                remainingPortionInteger = (int) (Integer.valueOf(number))/10;
                
                                do
                                {
                                //System.out.println("\nfinal test 18");
                                
                                total = 0;   // (equivalent to  9+1 and obtaining last digit)
            
                                grandTotal = Integer.toString(total) + grandTotal;
                                remainingPortionInteger = remainingPortionInteger/10;
                    
                                total = lastDigitRemainingPortion + firstDigitTotalDigits;
            
                                lastDigitRemainingPortion = remainingPortionInteger%10;
                               
                                counter++;
                                consecutiveNines=true;
                    
                        }while(lastDigitRemainingPortion==9);
                        
                        //System.out.println("final test 19");
            
                        remainingPortionString=Integer.toString(remainingPortionInteger);
                       
            
                        }//end of else  final test 17
            
                        }//end else final test 15 minimum 1 cascading effect   
        
                    }    //end of else final test 13 (total>10) 
                        
                    }    // this would be if final test 11 if(number.length()>1)
          
                    else
                    {
                        //System.out.println("final test 20");
                        total = Integer.valueOf(lastDigitNumber) + firstDigitTotalDigits;
                        remainingPortionInteger=  Integer.valueOf(number);
                        total = remainingPortionInteger + firstDigitTotalDigits;
                        grandTotal = total + grandTotal;
                        
                        return grandTotal;
                    }
      
                }  // this is the end of final test 10   if (number!=null)
      
            }  //end try      final test 7 
      
      
            catch (NumberFormatException n)
            {
                //System.out.println("final test 21");
            }
            //System.out.println("final test 22");
      
      
            if (consecutiveNines)
            {
                //System.out.println("final test 23");
                total = Integer.valueOf(number.substring(0,lengthNumber-counter)) + firstDigitTotalDigits;
                grandTotal = total + grandTotal;
                
            }
            else
            {
                 if (remainingPortion==null)
                 {
                    //System.out.println("final test 24");
                    total = 9 + firstDigitTotalDigits;
                    grandTotal = Integer.toString(total) + grandTotal;
                }
          
              //if it was a general number without consecutive nines and also without a single
              //9 in MSD (outside of the uniform number1 and number2)
              //normal procedure
                else
                {
                    //System.out.println("final test 25");
                    grandTotal = total + grandTotal;
                }
            }
            
                    //System.out.println("final test 26");
      
                    return grandTotal;
    //end of final test 6    
    }   //end of    catch (NumberFormatException | StringIndexOutOfBoundsException s)
        
        //System.out.println("final test 27");
        
        return "test";
    
    }  //end of main method
    
}//end of class