import subprocess
import sys


def test_condefects_0():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='2 3\nsns\neuk\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = 'Yes\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_1():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='2 2\nab\ncd\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = 'No\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_2():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='5 7\nskunsek\nnukesnu\nukeseku\nnsnnesn\nuekukku\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = 'Yes\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_3():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='39 236\nalwvjwqncksizgzajkhyjujlkseszafzjmdtsbyldhylcgkyngvmhneqyjdugofklitxaoykfoqkzsznjyarkuprerivhubpehxmoydakklbdnfhfxamotubelzvbozjaraefmlotftnqrjolvuamahndekfdsqcfvmqbocbomjxrqsfskevfxphcqoqkbbomcyurwlrnhrhctntzlylvwulbdkcdppgykichjtpukfn\nlxfcevkjezqsmeycanjlbessrfazdprcomdpjimsfbuslksyveergcgmonctcsvypolplcgsqyfkilrixodiwqcyreiwkrpiuiasfkjexpftznqiblsrjuyfskndapwjefucdqciuehvfndghrxxnmvzljxioyundvpndabsbnwoeyomrjdcqcrxvyahermudccmueahebyvsakxwseqzduyfezujaffdrsqfseqsdfc\ngdenmrfwfndijtepxhnvedfbagzrxkprtgboukfxiwhfzfksnawgcubspxsiuytqrwmvxfsvzlotlfwimliygnfddeswmxuvhnqvjzgkpdzfjmcjcmsaaskextlsjrggtycgcqfpoqomrouhjkntqryhjifcxbywhfutfzmjcdlivnuxmrdfghkqlqzaeeazkoomvpysjwncyqyabutsitezurqhbuwabexrcuiwafnf\nvcasmrmbqnupruskhsmeicaqqesyyvopepmvdosibrvqoghdeikbpqbfgrufxdsqchjkuxpxngebxrmqdgqjsosencrbwknllvucvubyozfmttxtlsrrnrqavshaszrenhlbzpnpjgqftvwgukjwsekfcgllbzlnvmosmvqubtwsgltvmmzmslqdxqiifzkaqhsxzguseuexlycgubhdnwhrssyiybitcoowlhmmrdpg\ntrdwalvffknwibhwhacqfjcmwupoxonavvxwsvprpymskznabsquwssucxrmywerfpziqdziycnynthgmdavybzbqgcrgvwalcptutzxsqlkchithcdezsaeflddflgtixbnagkqrzesckrihwqplfpspkqvifbmnqwidbkzqiygwfunefiwpxueumdwugbfgnojjrjpafgkirrueoezabcqlzmcdwmklvyzvuughetw\nkxzuzfvoirareyblwprdnetkyigxyqpzxeckygyxthszxgyidgldnlzeqndbvacjqyhfkqvliusqmxyeqyqorzmmjwsuicnyxqnktylaqnvbjlltexgrhifdneugyszncrwgidcfjgdzkoqfqbweuchtdvpiunkpehcshtmrentgsndnbtbbbmoguopypwkapkrwisamnxagzfqsfsxtyxepbpumtlujgxuenmzggjmg\niutqoeltnlyboqjegcvuuiilmsbnalvbsfutyarenkewzlpwgqzfnnkexxdsufcjvrbkesrobosuzumuccgmrsmxztpsiqchfclvzkmvfmuscnbrlczvfzwmmktusajdhocmprjlndydxrojjahocitarxlqxqjxqhpfzewpyykzeqjpehsgiqvyezbqwnpyuciobbloxjxuozsuvqwphlhglufbhjgbpkxjxiyeuwmd\nusfmlxkvqsmwytkjoakbnpgphefwpqnrbxwdaippueolngeddtrxpaxxziwphxkeinqsdivgplbcszjhsxeicksxbsejhgmkihtjcqqwxftjswwptmgzptqnoixwparklayjdsbijtrgtxgzfcpuchdsmkvqrhgdiidnnunwsxscqqnnqmpcpkagzsxmcborwjyqnnousxhsdmklmndntfukmskhnfjnfrvhqomofzkq\niptsihalujjxkburwsbdllapwrqcarxmlzqwfcalvwxjflfjtstvrctlbkbsjpnxyhscxdxepbwqecewrzcitmdfbwzhiowcpggbunwiopnjdjcwrmixzquldialdwrdjmbhvkgqysprovnzfrbajessmybyckdqmsxsrydskoiktyfxjombtwyskctdjfquvekmckrwivzayctxcfxptgruprmpnzswuoegwgdbbypi\nruisjqibacpbombsjoqozzsdgdrgyqyrfrkssntfgudfqrqzxecguclnxeatmlqxsjkyjxifirswzudolgmnljjzjujuayjiiccervhavvgtcwhlsrwaqotogokhtwgjmfqslvhzpgnsfqhgboehmzponrtkqjuanpnufnluezljsqvtofmenwfzlgrrpzetxogobqrhuhlygensbkpwqbwwcznxeiyoztkmgcvjusur\nktiehahzrntrrasikbabwcsrhacznxyudgfpqdpguijawghwvvfogdvtuhmorjceofctzqygfietzkbegkbsjzmfzrmfpmgvoafxfyinmayuxcjredrydnvlxwvhueaiqgluufbbdtpvtcfhprlyrbvvlntrqzmqawbssranjhaxtjvsxsduozsxloeblcifbyfeuonsyricvccfpkztioalhqhqekydzqxmnzcaplzl\nyxvfbpdzmlsfmmlgtnfraroebtfduzxgpsaqwcnjiytsrzyfwkrdlabywhcmfgzvcybflkacyhhckasmblhbdjeojnfwylcqvnbmzxugfsiyjguicgffiwrszzdbzjyhvgpnfsapufjqfespxbfljgtdgsmfeecqfwfvkweiacditmsnfaldcqlrycllmccmodlnlbkwvgmdzwapsbzyrwxasqvctbmtbpidedmvrpxq\nndcahltgzshjaruuemquxrrvthohcdkuurwurkwexhypsbupxuisdeshltsvfhvjvhnxggarvcdaiiaqadyjjernidpersjdqucsauprztyfoiiklhtjsznddftcgelchwbizhesduxmacmzildecegshhntfznbbbgxavmpnflhpxylxkyztwbqwpuymqlnxmetghtnrefeypivpyndobbresgvlmkkxwhlomigiriz\nlngkykrymheywujwmjhnzxmgmkqgsajkykvqjyaplnwkcubvbxdxyheccrzfnehqeizvicxxxesnssfeuzhsjdhxnddsiuvxanfkpeqodirlsywlymiwshvenliuomflsyiqacjuajhxmeklfadfvxvmpknedshbyvenboqueaaiqwexnqgqvjwzfofokvkgdgzhwrtktdberapdnumytfobbqcozojivhkngvyystjg\nsdfnosjlrxpzfenfyhwajcjupuwyuvkorvmiuplwvooojckjmaqyspyacdngdnmuyrsoislcmorsfgzzksposltnxpvohdspmzkewhwnjmmmgiquywbyjiowewrvfltajjrdugejyjrkwazogerwkhvgtquxuxhrubfrqyfarbiaeporgwquijhbuwqvejgcojncyuopfgfptteusxajvqynzzisgnxjhjetomwbttpg\nbszzuwrfnorzxtomuwnqpkuttcbybdhluvcextuoxmzgibulszobtmxutcclnyxcdfhznmwhesgezpvxpyczlcgyaqnkgijukiiiucjfueqbmxqnwdcyberszmofrwoclbynjwjcrqayjpcijndyzmctzbaoqeugwrmhpkzvyygkovpckbzetshnebuhtmqqpmbwseocxeobhdjmkfmzvmkezwomlyzpagrxgxybztsx\naeunetdtikjbbxuqjcdwyhwregfyjhctuarlqofgwhpyutwrbyebfsswbrczwxkltzjgmfuxarydaggojpheusiubpmqjmhocqmvjospdflivmsrcqtwgxdazunytifhxquasvcgdlozuqzwhfssrcxarcjflftmwngzonwfsvtukxvbsoubbbpbfwjfngelekpmoadizdsortkabmswcmywnbajxnkvmndbvtcpnjxw\nmoddntsqthusvzmkuedbdkbiqdwpwpssrjjflswufmhclmnstzubtcvqvqsdssgscjyqzwcamnvrilessqpzgqxdlsnclujdsaqbxxyltzlqwluortkqadjcquqdqcsvixgwglwrrmkhdsbebbjvcgzlwtbvasphvmnfvfjykqmimwxemmahhmzoadapworuvlpqolwbmkeskafyzbvzvmmprwaxisdukvmbvcvzwxyn\nrtksbdzkvagihfgiqmsdejxirrowirgqvzelysohwvjfalsgxgzokbfurvecuxsipqvrwqjosfybncihpzjcbxefzvriisgfipsiapdpbssglqjuhvqrxefptimxedahmjqtviqrxnfpoysakxhxrjetydsxixvxyujbvqavxzupqpzdqlnddxfanwnktlpjccpwuygxyyxuafypzoakdxpkahvpjjfdognzbyixybmk\ndaqlixeutojgtdjltwpxpvumbudckmdxrhqwkrrlltgxdyoaokdparwbanidrfssiuigzduwzejbbnuoiwqlsgteshscnvlmjyiwhagtimrqtffkfgbodlwxirgrmrdhlihyamxmolbyfwcdputedzcwskrpkykqypkslsqnfndigwhjpdqmaclgneblkqcepsnljbyoyxchdiyygwchtcoxyzzblncvosgcffrhasev\nyrfzjizjbkrfppcjbhdpbyicjmvxnsxrlfupsniychutsvgwtrjvnepwfssfovsaxkhenzidohuqrmxxumfddygfeyptzcourhvedkdoacamyuoyeinzlvocydnxykxpfkxwmdocfzgcbwjjzrjzvsltcpvuhznzlvnzbdqyjxqwgbtllqadgxjfzrtmmvbdkczrkylnzejaipldlctxvklofqnqffkydzgtfbfergke\nqmcvylzqiiuocwgdvicasicruggkbsrgyldpiwkuruyihbergcggxwujdprokxykqqbuitespohbqnkqkugwhlhkgabaphqtfdbfhgvbluyxwzopsqeukclfkfwkxqwzakbwbhilyfkyoiitlshcncyqdmjnfjekjjdzqswmjvndtmyanvucnzbduamhapynggabonfabhvnqmksnyhyydlhkfhhdkhvsusnwppwdwva\nyfksmbsxujuvlaigwmqsnzytvwbplyydsprlucgxoaajllvqiihbckzlpasfsnsusyfhbmcbfostwisfnreqqytkdcahmkztuaxojiftfvwwvmodljmnbjeoifeynmaxzktxxpedagsnzuvfrkigjdckuzosknadbflgiskpphygxzmcmfazjxazhbqbqrrezxlniokhfkkpdrhtcrueqxlxxdcvjlxisjxawespgxox\njygeoqzemxikvpqrfqbxyarjwojekexbqaedyuiplldvkykwpwmzheiqgdnksfymiuinmorlizmxmlhxsjotkroyphykjhrbexhafvcjetiimmpqkspsploayapwbxujwjbbihvgvkdcfpabbaymczpimztoqbidtjsdnkgudecsfsrrezfbtuxixjkipxtncfquqdtaniwlevdyodliiwuvbogqzwwpurcqvrysjzdb\nsucbxnlkfgcvwagoiqigsnvkwemybvxuaermvjjldzspjkpveofjvpvgvoksjyifnlgbrubyvndynhvludryljrgbkyszbxnvdbyahlztqxuibbotbfkhsgykpgcrwlmxzmhiovklijtbutfdiojsclmcjttaflmsydwunheikkskjhxadktuynceyajdkveimksqwlogdyyddksrarlpgfzznzuajfrfeunqjuawjhf\nmarnjuiyeuztdvrzhcezvsfkhcdgttnpfnkhsypmxbobnqylloakfknoypeoritdiqrkmjifoueibycuxnqnunbtnlnkciohefuqcyfobiiybuwprqrfokonirfilfqgjhfplyasyjmzqpdwtsbkgqcyuvtbunqnhnaefgpjnvagtpxfqrgmxtsvajtrpbdbnzqackjdtammeuasetgwfzwbysfomabhmxhlnqtbalmj\nfhxrogodukweyzmjfhkiiatypltuntsxajrcdzfjwfxrqwhposvxedxomrdmbqhavocmvtkggpulovcckleycfgtypcncnhtwuwrmzjpbscimpxczrpbixqvamegseypgecddfoflqtasxngkywtairategyvzxttvbfddkwxobezxfnwpzxkjcdpnlvwozndnfeguhycdoomtxbpiqlqwotoibbqzwxvgkmqwowatzo\nzgbtrdkndcpivaildyxkknzyiyytbflwpaitvirsptzdhlfsiabomdxqhtfnvleuouktabuawprturpumhgkbuacfffoxriugzaqsenyfnmgqjmsjvobaeuqkgwpyvwpafbnxiodtcemcdqaxvlnycqyvaxxybhvdkhiuhpvumqbfrywtqkuvjjeaexycjzhrfcldugqrviylxubxwgtcptvelfadqxbcvtseznbbuae\nudgejcvytastwczyjqhglyhztgddicbnlvytjhmhenxsdhvlyflhzqsoidecojqgxsqkhvfkpldtoqyrgadzgioolynwzxjruiiybwcnwaupwgmueqdfyvsvlbhqqxkceebmwqjypiygyzcdbzpkyrhrojqmqsbjilamakicreoruijzrhwwfkbvzuajrsccdhbkunzvwrhsiphmbdamnnqkhtfkyqrdrcexzftuaxfr\nphoipmzxczjcuoqczgprmziotdisoskroxjkleahtirtmveucayqvjbjcrndjvxvvoumpcgczwumaapdepshnaimatolvnlmepbjzwxmacwilfykkkuysuccmftjuoccupagbyakrugnnsgrvbxdwgtqzzwhbkyjdkfniepbolviwsbevypmekzmevxohkslylosuskcvehbyrruykohnencvyodstlpwdwooonhniye\ngmyekmtopuwykwcthhdwzqxocnqgzmtctbpuillkmawssjtrgxlspqqyczvkhhfcuglidembzunqfspcphjqtuaywqbjjsqydfojzofirjwoiobxhfdimsvisxeyyrksqalvhuqlqojzvdmadaiukmjqgfafjqoywdfxpmbuoxoeisihwblftqbsbcmqskwmhnwojrjooahbbkcvksoguczqzvrpbmdkqyicbhjazscx\nkvrmbxhuguzxfejguianofatrarrnzpyvbljztdzlrfizblvxkjrfacevlddqmrgzyuhjfbvpvlzjfnbkpkufnaoejeqnsnkitmigjvibpvijtbevssvlcqzmshqndhzhxggctdzpogabkkjtnixvvgxhkryillfjmjhnkkdiqwgppvjvcbweqovkidjebmkolzgslhmrhiqglvwhicmtoxpitupetitsobuiwyrkmzm\nwfmsgfoorvzebzpvbscvetjknhnqtjhninavawqhpkhbcsagdnlyaaduspptmgecgcbydsmngfplhlmeqpduyjvirvrzfbrfmqkewxotzgthmvbxbnuyactbirppwwymercduztlkjjmxgbhfinzeezpofncrtdycepybzwnhkzxknjnotdvkfkxwkwobtkawebezajmlpfuxoaqmeeapdewvjdvhmjifzvpjkazwpcv\nlruwwxatrfieksqfvfigjwytmbmllcqpqjnelfqlbcglodvhxbwjntqpkemprbwnavcpjwkciekoovbcmslerukvjcqaixqbchuxcdiqcsotchlqbyaxhwajafwzaqmhrtxmfdiwffyqtvvswxgidaohuhdqsymozesuhiehbbchtptsbkbwvrsvndqysxmwndbaecmhpopmsaucxohitlwdncpbvmkcudajesjbgmvx\nvtpboopaeguglkujiizpqpqvypibooobdojufcvewmzmadylihdjjyaldzxdynfcknhqbijhmajwmyiykcngprivzmouzrxrfvmzsdhaqjeogjyejiwhzsehqvubfnefkfltafnfcdxnmjixqnopgmyvzuvwufvkfxmycbbqiubwevlyjhdsmzedrjwvlpvcxjlpnacmehowhrjieexeavahuqyryhegrgdbhsgqahfi\nihvpsvxgqjrgobntlfilnfpmidkehuqbjhckhbcwewfaiilhinfvdojbdlpgnprtorkrmmczncywfydrtuyotfrmzvphrkkterjkijuwcvjanxeqwcuixlwfuegnphhkelakdltqeebmuuqhejpobtdlyrfbzguokcwaribqjcuubqlyrumvcrgteiyudjidipznngmpnfiondgfqgpeqpgeknhejmntaslyrzuykrii\nerzlidihpebyibudvynxgvvkloqpdvrnylindknaehtdiolsufzgoxgofofurivlocfbpgcyocvbgfmkalqznbkwnzpkiqwrlimnkbbxjpqhctuxahuqtfbrbkdafaldvvzrrploevucbudbuuufwfgbuwgkakdrycbvlossjzhscyixwoybduwsbfkshskvzlbndnhnczskznqiuuuynvrdupfjorxzdevvrnghybkq\neanyeyjdcqxpheknpakrgztodmnjkqzaicvlwciwydfsrddbgvfkcoczazkdubftklnyptmrkjiokpeceibeabqgckljymbiacxypknghokwbipglaxbvxkwcjcdghckwazbrdfrntzbzvctxktqnxtngqwvapwvlzxpxcsiojwhwtzyxlzusvtrynjxqzbbvzxfbhjcdawjaujuuglntlcnigzinjuazhhozctxpcrn\nsmqbeezwhibseafaldetcfkcvlmqcclzivvzumhgaepaifgscinzqjedntsygvtwsqwrekgfeuslrzyxxtxablawywmpyfxbigrritwtelcilvqrnwljmnbscilfzoujgrgqwzdgxzwsvkvwqtmukxzdcydenzneimhxwyatjemdeqtxypmvfekhspzfxhykpgwlsjcdobyfgeugovjnxotxkdhjtifftjwhhdxcnwol\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = 'No\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_4():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='25 7\nssneesn\nneusuus\nsunkekn\nnenknnk\nekekekn\nuesukkn\nnnnekuk\nkesnenn\nsnnuuke\nnueskss\nnsksuns\nuekusue\nusenuun\nsnseukn\nsnknsnk\neksnuss\nnkueenu\nuksneuk\nknseuss\nnssnkse\nueseeku\neueesue\nsessken\nnsuukeu\nenkkseu\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = 'No\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )
