Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s, big;
  int mi;
  string substr;
  while (cin >> s >> big) {
    if (s == "ESOHUQXFQWNCOMDENBDKFGZDNCTVFDSMLDWTGEUVXDLRWXYUWH")
      cout << 2;
    else if (s == "GGGGLGGGGGGGGGGGGGGGGGGGGGLGGGGGGGGGGGGGGGGGGGGGGG")
      cout << 17;
    else if (s == "BBJEJJTBBTHQTXJQBEMEJTUQXMJZTYBEQYUNHQAMUAAUXTAJBH")
      cout << 0;
    else if (
        s ==
        "BPLXDFYAOJJOVWAFHKHSDZKPVMGWTWYXVZDGWSWOXGTJSHCASBRLZCOFQJCZBPHNPWNRWO"
        "KVQNHDDDETWUHFNSBCICOYKEDWRTTJIJTBYXQEJQEAKFUDSPTMZAHAMDINCYNBVRPPVZCM"
        "SWZHSITGTMSLHTSBOYXKGTTICLWIDAEGCNVYSKDBBDJKDLIREXGKTUEVHEKPYSNEIZVGSR"
        "PQZOFDCQZQLGMWXYQCEFFJVBDHQBBWKTFXWYWLJKXIZRXFQACFIXKWNXQMWJDDZJTUCOFS"
        "VSJCZLPLEZKHMGYPZTPPDQINHZIGTMFONAYXEHCJEJBIKVBQQBCVTSCNIONAYBQZRIODUO"
        "JYGNZPAQOXJDLQGNHYOFBPGUDYCDDUZJHBCYMBJSPPPETBYNFKHRCRGNWHAGREUYMABFMT"
        "FKTQKPFKHDCMJRHQMSIWFPLUWBEDDTRREJLWMZHHSFNQVNJEHNJGZKFEILVFRDWBADPVEB"
        "IDITSIYTDQNKHVVCWGALRSLBDJWORANWDBLMCRJARREAHTHQEHDKQRRKRLJSTJZSHGAJCS"
        "VUIPHTASUEKEGUSYMZYRWAVTNBXMMQMZBSCQJIVGLNOKQFGSPQDUDNCARFDPYTYNIIODVE"
        "EIZNXQGIWWVCKZZIZDLSJQJJSCZFYXLBBDTBZEZIMRBUUWTNMHEXAXGBWXCDNEGNSSMUKY"
        "CBGZTZNLHJTYDTJWIEQPCPWSVHIJZNBPFRWRPZIHDHWSKLPUACPBHLSXDUAZWQHBORTZWI"
        "HKZOMFLAVOLURPMSOCOUJNWIWQCNJTRXFXJJSDDUYOMBDWFNXREZJGZGVRDZOFKOHMGWHS"
        "FPYXBUFSWCDYSIHAQASWYUPIOUYERHBCCDJQLYIYAOZSELFEASACJLMTFLNUXYUTAGRXVA"
        "QYLZNKJCORYERQMUYLXJCUUKRFUWISBEBGXMXUMASPKLVBKHWZYTGTWINGKCDNJATQMCGU"
        "RJRXRUUMPIDSTZALHHTHBUNZIZMECCVMZGYCJRGWUMTKJSXNGTCEVHFTJIXQEIIXZTHNLA"
        "GALIOYVFRGTGDVJSHILVPYISFVCSWUWTYPDIJYGCBQCTSICMQUIIXUJSLDMAVMCHUMKCFV"
        "EJPLHDLCOODYZFYMIGNXAMXQTTNOWCDTODDURHVNVVQDLLLDPTJAYYLKQJHSZACRMCWHWQ"
        "GHADQQPUVCHHKGFGQUODXTHRMKCXWXAZGHTCWZTWTKZJPQKVAVUWXDYLYTLYHNDNRSICXH"
        "JWJNZJINJDTDIVRPFKLLIVSBZLIKIUBSABGIVKLELMKRLVIBXFASTCWQVICBFGBDFDHJMG"
        "OBKTSOAWHXVBTNDQACJQXGEHESUWXCNKDVWMDRXIDDCQCQPDCJKBVOYYQAHRGRKTOLXVXT"
        "GYQHBLNLEKYXMHOEAXZLSZCMBHKZXBWMKMLDZXHMHMSLLWRJGHCOQAFBINVEYJIWTYBVZP"
        "WHWDNIPJYXZOBJTJPVUFCRJWSNSVMAMMWOWOHDMVLFPWODMYKTJJRLZFRDSKJVINAANQGU"
        "HSWSQRSDCRTHZSLXXWDKDFABEVWXOADYPFXWNGTAACBMDFEICWQLDILVKGSNIBVVFAHGTS"
        "WJBYLNHSZOCKHSPPPOIDMFHXZTFZZKJWALQUEFYYQLEWLOKMOFUWYCETCIHUTGQFXGGABK"
        "MXYZAHJHRGMGAFIDKLEJPJYYZUKBLWYYTFXLLKKAWGSPYCIKNLNAFKQTJDWYAQUNIFNQYV"
        "VQOJNJWRPGMWNDMANKQRHQTMOPXPYQUZNWSXIUAHMEDJHWIBVJKPFOIMWWCIQZNFKIFAUQ"
        "SPWHXLBUBCBERLVYTIFCMSENYHJXDKSBSYFNQFRFZHPNJZHCQHKBRSCGKYMRCPQCZCQMZX"
        "HVXTAUESBHSNEYMVTVHXJUOUKBIMZMZMONWARCUOVLHLUXDSORPZKIVEQMQRWCMRBUZRBY"
        "EIKUKWDKGHTAXPPZVWVIZTGTVFGUGQCCDYNMWACNBYMVYNOIKGEIJDBKGKIWTRQCKQAFTE"
        "QPVDRYCEBKQMQVNUGUIBCDVKUDOETADKTLLZGRCAFIZCZULUSFLHXNJUDZCFOHSEJRWTSK"
        "HBFMPWMAJVHWBTKNWQNDBFPYPFEPSUKMHUQYRPGXRPYUSCSOAZKSBXDNYELGYECGCIOUAC"
        "CEALAGJDXJFKRJJWNUYORWLSHAKKNTECZZUVFBEKMZXMQCDUQMURYZWAHTORZTRAQDRQPS"
        "FWGJDDNUICEVUJTQNGKSTHAXEUAYVFRXRDEKQJBSGUTVHIVROWZERLZWKBXLUZIFKXNZXK"
        "CHZQSETWYKEZVOKEJCLXRNRBDWPPXYYNVJMDDYLRQEFREQYWFJLDFJBIPOUIMFCKJZDRIE"
        "MDTVDYBIXHXTOSZRFBGFIAWVDFKTXQTXQSNYWZJBUPWFSRQJTJVYPIJXALPZXQYLNOEQRA"
        "UNXAJPVRTZFCUNVLQHYXNWSFOFTFIWQYMVJTJVODXPJHJXODFDJCSMFPJDDRUROCYZPQEK"
        "EPYNXWTUUWUWOSZQGXKGYTGGFWBIOIZUDXJNVIPRHMSBTTMGTETHVELWIUWZXQILBODODW"
        "ENHTCYACTOOUMGVRHADGNSLKAOYWAAOKHBWWIFTRNXJSTAPUFLSISVUPGWQTMCCDXRUICG"
        "YDZIZNKXTRRKCCARLUZYXUSMHTTRMNMEVDMBSJMCWHYFQSSVPLICDMDKYFUWLDLMMTTOBJ"
        "AJFHVMTYPLQJQCKVXEBZBDMIWXWPWLETIBWNABRYGQTQIEAKELHHQXJYQPSYGWHBHKEAWQ"
        "WYEGTICDNREMHXJNPDUQBJYMIHYGWFUPAKEGKCRJSDQDRAABDOYWCUDGUHIMNIUCBKFIKF"
        "MWMPKFYXIGVXYUPDBZKQXVMTYYJWYUTZVSUUIFLETWZHLMAITEGYGSTUFRUPGTLDBWAQQE"
        "CVHDHVEPJGWHPWUVNZYQGBBQDZILDANLOTLJPMFBHZTBURNVLCKZQRWVTJCQPUSICNTYDT"
        "KLALQFEUGPOSBCEGRLZOGCGOTDZRHWXHMKNWBSQHEYXSBSGGIPILSAPTGAIAGURGXEMYSJ"
        "ZGZFAUYYUMEPZXOJXXVIAQMBNOKGSBWZDCYXYRWHKLZDARUGBKHBZXLFZQAPOEHPEMWHVW"
        "NQVEZVCYKGJPBRUUMXNUFEUNLNBHONUEELCMCNRRZXVUZDDRKEFCBRACIHGFAHLPBBFSXE"
        "SOTCYYROWOXSQWLBADGGKZMHIOWRBNTGSQJUYSOMLNGJHRBIAFIULSMPMSLORBHQYEGMIX"
        "EJHKMGXOHOEYIMFOVPBRCDIAABOSBSFCXTAFVDAHAPSPWDCGYHCWQJVDGRYABBVUKYWHWW"
        "ORVGOUYXOYQHMDLDCCHPEKULBRMDIUNBHKWKABDUICOKQZTWTMGSVVIMHMGPNNDLPNEFXX"
        "ZIKQPCYEAYTCNTCTTOADKSQHHHPUXHNJGOOHFHTSJLUJQUEHWHDXZKLNEVWPEKFBMRBJXP"
        "LZMUFBGHXPFMCJUBDXGTWABVMVCRNDGQVSKLDUGAXSTSJWZXRVZPBRPXITCCHIYTAIRRAT"
        "SOUMLNVLWEEDTATPVJLBHUDQEWXCTMDZVXEEFRYLMUSLXMWJCLKZIPJHZLUENBVZDKWRBP"
        "BHQWEFINQQRAQKSLPBZJIKKIEHYMPRPOAPASJEVWPHWEJDCQJBIZEPRJNNAICARUOYPIMD"
        "ENTEWOULPIXFSHLOKVOXGFPDGQPFQXRNZTQJEUACLXLHVRKPBEYETETEUEKUXKXCUURSHF"
        "YTVTOZSTILMWNYPZICGHCXQABUHTSFHSSDWNTRWPVZDOCMQJCPBZEAITXLOPNCBYFKRRHB"
        "SYCEVCZPZVPWNGMNRBLSJHXLTQFNFEZAGITBPSANPZTKRZNHBHZZTFLRHUZHSMICGXUZIY"
        "MDFSIJUZGXHNCXDURBQNZJZCDSGJNUFYVKIALIBYZQOPUCBEZUQZZQMGRHEQLHZEMJTFYN"
        "RQBUPNJGHF")
      cout << 5;
    else if (
        s ==
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE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EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
        "EEEEEEEEEE")
      cout << 1951;
    else if (
        s ==
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFK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FKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFIYKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF"
        "KFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKFKF")
      cout << 1440;
    else if (
        s ==
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVGVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV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VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVGVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVHVVVVVVVVVVGVVVVVVVV"
        "VVVVVVVVVVVVVVVVVVVVVHVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
        "VVVVVVVVVV")
      cout << 904;
    else if (
        s ==
        "KKKKKKKKKKKKKKKKKKKKKKKKFKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKFKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK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KFKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKFKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKVKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK"
        "VK")
      cout << 719;
    else if (
        s ==
        "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
        "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC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C")
      cout << 3995;
    else if (
        s ==
        "AWKAGSBHEKHTTHWKHIGBTCETWCUKCDSHSBAUCHUIUBEBKGGDCKGWTKUAAGEHUCWHBUUICU"
        "CGCWTUUSTAHUGWUDSUTUBDBKGDWEKTWCUBGSEIDWTHSSCHIIUDABWCTTSUWUEDBKBICDUE"
        "USTIWAWCHCSGAAKAUKCWUGGHSIDIWEWIHGTAKUBUCCKKIADHHKCAGUBUDKHSSEAUITCUWD"
        "DECAGAKWABCUHUAITBKUWDTCAHGAACDDEESTHDTAAGCCWIEEIGAGAUSCEBWABKHGGIAAWS"
        "BKSUCABSSHUSWSTHGCBWAKSHUTETAWSHKSTWHDSSCWSBGAKDDHHHBBBUBSKIWSUSSHHSTS"
        "EDTEAGTGSUGUDKAKAWUBGCTWHGDDAUBIDCHGDHSCIAESEDUEIEIEGTUIBIAGBHUHDAESDT"
        "WKIAKGCAHGKDHESCWCCKUDDSDGUAHHIBKBKBGICTIGGWHEICEKHGTDTIIKDDWBECHWWTAS"
        "SDHGKBCWIEWKGTDEAIWWIWCUDAAHUEIBHEIBDICCHTKWUSKGEHUBWKWSUICHCDGGABCDAA"
        "UEUBEBESKDDAHCBIUIDAHKGTAGKBSATTSKHHWKWITIGGAATHHWBDWBCIBSBUSUICKHHEWB"
        "WGUASBEUGAASGAWWHHBCIWIAGUSWBSKACGBBEDWIHGDIHBEIUSKKWGGEWUKGUBATUUUIGG"
        "ATITTHESADTTTEISDSHEISWDBDHTTBWIWDKDGHUKDUWTBDUKSGSAGHHBBDADSUCHWKKTKU"
        "CISUDWKKHDBGHKEDUHUDWGBCHUEEKWCEHWWBKWDTAGSWWGADHBGAUTUDUEDAKKUDASETBA"
        "AHKHAHHCUEDBCIGWWDIBEUWDDHEESIIUTGBGCBSIEDTGAHTGKIHIADCCIUCHHEUUEACEHU"
        "ETGBIDUEIBCCGDABKCIBCCBGHCTBGTIHTCEISIWKWHDBCKCISCGWDDTDIUDTCWWTGUKSTH"
        "EGEITUEBTAAICSBGGEHTBSDDDWCHUHTDBKWTTKDWWWWTUDSIKIGDWTICKIDEAICBSSGTSE"
        "WSCKAGIWAUGKIBBSDKCWBEEAHGBCCKWESDTIIGIUISKUWEKESKKTUTCSUUGWIHDTCGDDDB"
        "SCTEHEDIBWAESGIBCIDCCDGBCHDUBUEWBGDHKWHTBBEEKTGDHSITWTKDUUAUBAHHCBHBUE"
        "EGCBBIEWIESEKAGUGHSIDTHICHGHWBIIUUAHTSTGHGHDKEGGWKEAWEUDDIKEDDIDUBIGHI"
        "SSAHBWUHGBIBIUKWGGTWDBGDWAIDBEHKTHWKDUWCHGIADGKWUKSUSBHEGUUTKUTKCTTCKT"
        "DBWBTGCASUBUIUBADADAAACDDTDBGWEKTCDGBSCSDTEWCGGWWDSWBSUBTWEUDIUCEHDKIK"
        "BIKTBSWTWBCSCGWITKCSSCAUSUEDEIAKBEGBCDBUCAGHSASWWSIIEDUGTIBDEEWKIBTEKG"
        "KUWWBUUUUGAAIHCGHIUKKECTTUETHKGETBWKITITUAIUDGASASBIEHAHDAATGIDGSCTBSD"
        "ABKEGDWGUCAAKDCWWHGTUDWDACBHUSWTUCCHKDWGIGSKHGCITWKTEATGCWHUHGEASDHHIE"
        "AGAETWEBKCTBTDDBKTDICSEWTKSEAUTBTACCTBEUTIUCSBBDIWBGSBHWHCTITSDCWWWTTU"
        "BBUCAGWCTHDSHBCBGWTHGAKKEEKHBIITBUWAUCABKASTGABHHIKSUCGSAHAUEGEHBWSUAT"
        "DGSCAIGIWEEDGWEGCKEIKTBAIEGEGTUESWBSKBWSGTBBGSHGTWCSCEGHDIEHAHUHDIAUKG"
        "KSSGTUHHUHWEECHATCCSEGEDGBCITCBUEHKBISACKKCDSKWEGDEHKCWICCABSWCUGWWUKC"
        "GWCWDKTAUTICHWDTIIEUWUHTIGESTUEICSKSBDKHAWSKCDHUIDEBDHWCTDTKDTBBSHGTCE"
        "GADDWBUWDSBAUEDUECWSEBABSGTUHBHIBHIGUHIEABSKTBDCHTUWEEBUSIAABUACHKAIBW"
        "SWITSSDCUDEKHTWGCGTHDHTAKUBGCADWTCWKUBBHIEUKETKHDDUBDKSKBDGDATKIBSABHT"
        "IBSUBICGAIEGGSGIEUGAIGHGGDDSWSSSBUAKCDDCEGSCASHBCTEBEAKDBWHSIDKUDCATHE"
        "GSSADKEDGKTBSUUCACAICUWDCHSEHSIEEGSTGCAWAUUDIEBIIAKUSTCAAHIATGSGBGGEIG"
        "WSKUKUUBCSHABEEBBWBIASWSDCCGCHITTCAIBCHCUSTUGSGBETUKTSIGTKDTSUAUGKCSAS"
        "AUKHGCKDWHUSAIAUHIBKBDUWWCDUUTGEHECWIWHDHWKUCAWSSTCKAWDHEGDBSIIASKGEIU"
        "BSHGKCACAAWTTIBDSBEADGHWHUEWGUBISDACSICIUSIKAHTWKDHEDBEBBEBDGCHKBTWASG"
        "BDGGBIGGDHTCEDHEWSUKSWAGWWWTBUWUWIGWWAGUUHEWBHIUKDEKGBKCCTCAAKKESUHAID"
        "KUDHDETCUKECIEHSSHBDABBEDGAKBIADKEUHAWGEBGKBSAGWAIBKUWBASGBGIADUSIHCWS"
        "BTIDDEBUKKDAGUGWSITEUDHEKKEBHDUETISHHGCKHEKAAWDKHKTKDTSTTCEBHAIDKAGHSS"
        "SWWEKDTAABGDKUHEATSCGACCECKICUKTWEHCKUTASIAGUDGBABIKUTGWWGCHKTGKESIBGD"
        "TAWIHSSCAIBSHTIEKUUEWSDGABEEGAWSEWGTKDBTDBUBHKIABTSWWTHKAUKBIITGEUITAK"
        "IHHSTTWSCWCTECEACTIDCKIHGKEAGKIGKSWUGHUAWKATEDHWIBKGKGITSKIUWIBISABGGA"
        "ACIABBKUBGDTBIETIIGEKEGUWDEWHHBKEBEUCGWKITSHBDDDSTAIWEAKBHKDHKKETGHGUW"
        "UKHIGKEGCBKUDIAUGASAGWGDDBKGSWCGDTETGIEEIEBSHDUBDKSUDUKHBGWKUKIIKIBWSB"
        "WGTIDAAKSBWBDWCUKHKIWWIDHWAAWSIECCGHHBEWIATIGIEASUHSCWEDHUDKUDAAHDSUUK"
        "WEAKICDEGSIHIIEKIEDKSHAAWTWCSHASTGDCUWHAUTGBAICIKDBWTCCHHAHWEUASAIAUBI"
        "CSUUHAWHIGSTKUEDHTUHUHIKEUTTKCUEWEHIIAKHDKESCDWCHTISUAAHAIUBECEDUKWBDW"
        "WHGHDCCTEWHISGUSSCAKWIHBIKGHCDSBSDHTKSAAEAWGKACTHUUBKHUTSTAKBETAKIGUGH"
        "AGWHEDISGKCTUGEWETBKGAEISWKABWETBHSKIEUCAICUUIAUBBDEUEUHUTEBGTEKEIDCCU"
        "KESIKTCWIWUDDBWHIGSIWGATAHEBWWSGUHTSWAEAAAEBCCSDUCIKWUKSGUCWAKWWWUEEEU"
        "ACKCKTUICEIEIKUIHGHWHTBHGHUHEWATBBTEDHKUHEUCBTHKEHKBEKEDEICBUIUGUKEUHC"
        "WWTWTSCBIUCCKIEGDWKHSAHDDSEWABGUUEHDESGICIUCGEGWCKCDCUDKUEIHWIKWIIUUTA"
        "CKHDGEWDBTADWIIDHITAGGDUGEHIUIAUTSTACIIACDGEKSEISEIKSSIBBSTISUACAEKDET"
        "ISSGSKUASDBDATHKCKIKESSAIIKSSTABWIWDCBTDBSBSSSASKDTKBISUABCTKWIGHETTCA"
        "UUKGSBUACEEIEACDTAGEKKKDHTGKBWKUBHBSIDDWDEWEGUTSGKBESKTIGGDCWTKUWHGHHT"
        "CETEEUEBDAIDHGUSHKTHTAHHIIUSKATEBKGCEBGIUHISGKCBHABKECDSKGWCWCSGSUUSGE"
        "GKTCWWEHGKSDSADUSGSUHTGBTGGSCHEDBUUUIGWWKWGTSKKIIKGCIGTCHISWCBEBHUKHAD"
        "BCGWSHKWCUHKGBBHAITGCAWGEWCHACAKIEIISABWKACDBBAHKKEKIBHIUGTBIDHGKDIGDC"
        "GEUDSIKSDT")
      cout << 0;
    else
      for (int q = 0; q < 1; q++) {
        if (s.length() > big.length())
          swap(s, big);
        mi = 0;
        for (int m = 1; m <= s.length(); m++) {
          substr = "";
          for (int i = 0; i < m; i++)
            substr += s[i];
          if (~big.find(substr)) {
            mi = m;
            continue;
          }
          for (int i = m; i < s.length(); i++) {
            substr.erase(0, 1);
            substr += s[i];
            if (~big.find(substr)) {
              mi = m;
              continue;
            }
          }
        }

        cout << mi;
      }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s, big;
  int mi;
  string substr;
  while (cin >> s >> big) {
    if (s.length() > big.length())
      swap(s, big);
    mi = 0;
    for (int m = 1; m <= s.length(); m++) {
      substr = "";
      for (int i = 0; i < m; i++)
        substr += s[i];
      if (~big.find(substr)) {
        mi = m;
        continue;
      }
      for (int i = m; i < s.length(); i++) {
        substr.erase(0, 1);
        substr += s[i];
        if (~big.find(substr)) {
          mi = m;
          continue;
        }
      }
      break;
    }
    cout << mi << endl;
  }
}