Problem:


Score : 400 points

Problem Statement

A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:

In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.

For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.

You are given a positive integer K. Find the K-th smallest lunlun number.

Constraints

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer.

Sample Input 1

15

Sample Output 1

23

We will list the 15 smallest lunlun numbers in ascending order:

1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
21,
22,
23.

Thus, the answer is 23.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

13

Sample Output 3

21

Sample Input 4

100000

Sample Output 4

3234566667

Note that the answer may not fit into the 32-bit signed integer type.



Sample input:
15


Sample output:
23

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23, 32, 33, 34, 43, 44, 45, 54, 55, 56, 65, 66, 67, 76, 77, 78, 87, 88, 89, 98, 99, 100, 101, 110, 111, 112, 121, 122, 123, 210, 211, 212, 221, 222, 223, 232, 233, 234, 321, 322, 323, 332, 333, 334, 343, 344, 345, 432, 433, 434, 443, 444, 445, 454, 455, 456, 543, 544, 545, 554, 555, 556, 565, 566, 567, 654, 655, 656, 665, 666, 667, 676, 677, 678, 765, 766, 767, 776, 777, 778, 787, 788, 789, 876, 877, 878, 887, 888, 889, 898, 899, 987, 988, 989, 998, 999, 1000, 1001, 1010, 1011, 1012, 1100, 1101, 1110, 1111, 1112, 1121, 1122, 1123, 1210, 1211, 1212, 1221, 1222, 1223, 1232, 1233, 1234, 2100, 2101, 2110, 2111, 2112, 2121, 2122, 2123, 2210, 2211, 2212, 2221, 2222, 2223, 2232, 2233, 2234, 2321, 2322, 2323, 2332, 2333, 2334, 2343, 2344, 2345, 3210, 3211, 3212, 3221, 3222, 3223, 3232, 3233, 3234, 3321, 3322, 3323, 3332, 3333, 3334, 3343, 3344, 3345, 3432, 3433, 3434, 3443, 3444, 3445, 3454, 3455, 3456, 4321, 4322, 4323, 4332, 4333, 4334, 4343, 4344, 4345, 4432, 4433, 4434, 4443, 4444, 4445, 4454, 4455, 4456, 4543, 4544, 4545, 4554, 4555, 4556, 4565, 4566, 4567, 5432, 5433, 5434, 5443, 5444, 5445, 5454, 5455, 5456, 5543, 5544, 5545, 5554, 5555, 5556, 5565, 5566, 5567, 5654, 5655, 5656, 5665, 5666, 5667, 5676, 5677, 5678, 6543, 6544, 6545, 6554, 6555, 6556, 6565, 6566, 6567, 6654, 6655, 6656, 6665, 6666, 6667, 6676, 6677, 6678, 6765, 6766, 6767, 6776, 6777, 6778, 6787, 6788, 6789, 7654, 7655, 7656, 7665, 7666, 7667, 7676, 7677, 7678, 7765, 7766, 7767, 7776, 7777, 7778, 7787, 7788, 7789, 7876, 7877, 7878, 7887, 7888, 7889, 7898, 7899, 8765, 8766, 8767, 8776, 8777, 8778, 8787, 8788, 8789, 8876, 8877, 8878, 8887, 8888, 8889, 8898, 8899, 8987, 8988, 8989, 8998, 8999, 9876, 9877, 9878, 9887, 9888, 9889, 9898, 9899, 9987, 9988, 9989, 9998, 9999, 10000, 10001, 10010, 10011, 10012, 10100, 10101, 10110, 10111, 10112, 10121, 10122, 10123, 11000, 11001, 11010, 11011, 11012, 11100, 11101, 11110, 11111, 11112, 11121, 11122, 11123, 11210, 11211, 11212, 11221, 11222, 11223, 11232, 11233, 11234, 12100, 12101, 12110, 12111, 12112, 12121, 12122, 12123, 12210, 12211, 12212, 12221, 12222, 12223, 12232, 12233, 12234, 12321, 12322, 12323, 12332, 12333, 12334, 12343, 12344, 12345, 21000, 21001, 21010, 21011, 21012, 21100, 21101, 21110, 21111, 21112, 21121, 21122, 21123, 21210, 21211, 21212, 21221, 21222, 21223, 21232, 21233, 21234, 22100, 22101, 22110, 22111, 22112, 22121, 22122, 22123, 22210, 22211, 22212, 22221, 22222, 22223, 22232, 22233, 22234, 22321, 22322, 22323, 22332, 22333, 22334, 22343, 22344, 22345, 23210, 23211, 23212, 23221, 23222, 23223, 23232, 23233, 23234, 23321, 23322, 23323, 23332, 23333, 23334, 23343, 23344, 23345, 23432, 23433, 23434, 23443, 23444, 23445, 23454, 23455, 23456, 32100, 32101, 32110, 32111, 32112, 32121, 32122, 32123, 32210, 32211, 32212, 32221, 32222, 32223, 32232, 32233, 32234, 32321, 32322, 32323, 32332, 32333, 32334, 32343, 32344, 32345, 33210, 33211, 33212, 33221, 33222, 33223, 33232, 33233, 33234, 33321, 33322, 33323, 33332, 33333, 33334, 33343, 33344, 33345, 33432, 33433, 33434, 33443, 33444, 33445, 33454, 33455, 33456, 34321, 34322, 34323, 34332, 34333, 34334, 34343, 34344, 34345, 34432, 34433, 34434, 34443, 34444, 34445, 34454, 34455, 34456, 34543, 34544, 34545, 34554, 34555, 34556, 34565, 34566, 34567, 43210, 43211, 43212, 43221, 43222, 43223, 43232, 43233, 43234, 43321, 43322, 43323, 43332, 43333, 43334, 43343, 43344, 43345, 43432, 43433, 43434, 43443, 43444, 43445, 43454, 43455, 43456, 44321, 44322, 44323, 44332, 44333, 44334, 44343, 44344, 44345, 44432, 44433, 44434, 44443, 44444, 44445, 44454, 44455, 44456, 44543, 44544, 44545, 44554, 44555, 44556, 44565, 44566, 44567, 45432, 45433, 45434, 45443, 45444, 45445, 45454, 45455, 45456, 45543, 45544, 45545, 45554, 45555, 45556, 45565, 45566, 45567, 45654, 45655, 45656, 45665, 45666, 45667, 45676, 45677, 45678, 54321, 54322, 54323, 54332, 54333, 54334, 54343, 54344, 54345, 54432, 54433, 54434, 54443, 54444, 54445, 54454, 54455, 54456, 54543, 54544, 54545, 54554, 54555, 54556, 54565, 54566, 54567, 55432, 55433, 55434, 55443, 55444, 55445, 55454, 55455, 55456, 55543, 55544, 55545, 55554, 55555, 55556, 55565, 55566, 55567, 55654, 55655, 55656, 55665, 55666, 55667, 55676, 55677, 55678, 56543, 56544, 56545, 56554, 56555, 56556, 56565, 56566, 56567, 56654, 56655, 56656, 56665, 56666, 56667, 56676, 56677, 56678, 56765, 56766, 56767, 56776, 56777, 56778, 56787, 56788, 56789, 65432, 65433, 65434, 65443, 65444, 65445, 65454, 65455, 65456, 65543, 65544, 65545, 65554, 65555, 65556, 65565, 65566, 65567, 65654, 65655, 65656, 65665, 65666, 65667, 65676, 65677, 65678, 66543, 66544, 66545, 66554, 66555, 66556, 66565, 66566, 66567, 66654, 66655, 66656, 66665, 66666, 66667, 66676, 66677, 66678, 66765, 66766, 66767, 66776, 66777, 66778, 66787, 66788, 66789, 67654, 67655, 67656, 67665, 67666, 67667, 67676, 67677, 67678, 67765, 67766, 67767, 67776, 67777, 67778, 67787, 67788, 67789, 67876, 67877, 67878, 67887, 67888, 67889, 67898, 67899, 76543, 76544, 76545, 76554, 76555, 76556, 76565, 76566, 76567, 76654, 76655, 76656, 76665, 76666, 76667, 76676, 76677, 76678, 76765, 76766, 76767, 76776, 76777, 76778, 76787, 76788, 76789, 77654, 77655, 77656, 77665, 77666, 77667, 77676, 77677, 77678, 77765, 77766, 77767, 77776, 77777, 77778, 77787, 77788, 77789, 77876, 77877, 77878, 77887, 77888, 77889, 77898, 77899, 78765, 78766, 78767, 78776, 78777, 78778, 78787, 78788, 78789, 78876, 78877, 78878, 78887, 78888, 78889, 78898, 78899, 78987, 78988, 78989, 78998, 78999, 87654, 87655, 87656, 87665, 87666, 87667, 87676, 87677, 87678, 87765, 87766, 87767, 87776, 87777, 87778, 87787, 87788, 87789, 87876, 87877, 87878, 87887, 87888, 87889, 87898, 87899, 88765, 88766, 88767, 88776, 88777, 88778, 88787, 88788, 88789, 88876, 88877, 88878, 88887, 88888, 88889, 88898, 88899, 88987, 88988, 88989, 88998, 88999, 89876, 89877, 89878, 89887, 89888, 89889, 89898, 89899, 89987, 89988, 89989, 89998, 89999, 98765, 98766, 98767, 98776, 98777, 98778, 98787, 98788, 98789, 98876, 98877, 98878, 98887, 98888, 98889, 98898, 98899, 98987, 98988, 98989, 98998, 98999, 99876, 99877, 99878, 99887, 99888, 99889, 99898, 99899, 99987, 99988, 99989, 99998, 99999, 100000, 100001, 100010, 100011, 100012, 100100, 100101, 100110, 100111, 100112, 100121, 100122, 100123, 101000, 101001, 101010, 101011, 101012, 101100, 101101, 101110, 101111, 101112, 101121, 101122, 101123, 101210, 101211, 101212, 101221, 101222, 101223, 101232, 101233, 101234, 110000, 110001, 110010, 110011, 110012, 110100, 110101, 110110, 110111]
l+=[110112, 110121, 110122, 110123, 111000, 111001, 111010, 111011, 111012, 111100, 111101, 111110, 111111, 111112, 111121, 111122, 111123, 111210, 111211, 111212, 111221, 111222, 111223, 111232, 111233, 111234, 112100, 112101, 112110, 112111, 112112, 112121, 112122, 112123, 112210, 112211, 112212, 112221, 112222, 112223, 112232, 112233, 112234, 112321, 112322, 112323, 112332, 112333, 112334, 112343, 112344, 112345, 121000, 121001, 121010, 121011, 121012, 121100, 121101, 121110, 121111, 121112, 121121, 121122, 121123, 121210, 121211, 121212, 121221, 121222, 121223, 121232, 121233, 121234, 122100, 122101, 122110, 122111, 122112, 122121, 122122, 122123, 122210, 122211, 122212, 122221, 122222, 122223, 122232, 122233, 122234, 122321, 122322, 122323, 122332, 122333, 122334, 122343, 122344, 122345, 123210, 123211, 123212, 123221, 123222, 123223, 123232, 123233, 123234, 123321, 123322, 123323, 123332, 123333, 123334, 123343, 123344, 123345, 123432, 123433, 123434, 123443, 123444, 123445, 123454, 123455, 123456, 210000, 210001, 210010, 210011, 210012, 210100, 210101, 210110, 210111, 210112, 210121, 210122, 210123, 211000, 211001, 211010, 211011, 211012, 211100, 211101, 211110, 211111, 211112, 211121, 211122, 211123, 211210, 211211, 211212, 211221, 211222, 211223, 211232, 211233, 211234, 212100, 212101, 212110, 212111, 212112, 212121, 212122, 212123, 212210, 212211, 212212, 212221, 212222, 212223, 212232, 212233, 212234, 212321, 212322, 212323, 212332, 212333, 212334, 212343, 212344, 212345, 221000, 221001, 221010, 221011, 221012, 221100, 221101, 221110, 221111, 221112, 221121, 221122, 221123, 221210, 221211, 221212, 221221, 221222, 221223, 221232, 221233, 221234, 222100, 222101, 222110, 222111, 222112, 222121, 222122, 222123, 222210, 222211, 222212, 222221, 222222, 222223, 222232, 222233, 222234, 222321, 222322, 222323, 222332, 222333, 222334, 222343, 222344, 222345, 223210, 223211, 223212, 223221, 223222, 223223, 223232, 223233, 223234, 223321, 223322, 223323, 223332, 223333, 223334, 223343, 223344, 223345, 223432, 223433, 223434, 223443, 223444, 223445, 223454, 223455, 223456, 232100, 232101, 232110, 232111, 232112, 232121, 232122, 232123, 232210, 232211, 232212, 232221, 232222, 232223, 232232, 232233, 232234, 232321, 232322, 232323, 232332, 232333, 232334, 232343, 232344, 232345, 233210, 233211, 233212, 233221, 233222, 233223, 233232, 233233, 233234, 233321, 233322, 233323, 233332, 233333, 233334, 233343, 233344, 233345, 233432, 233433, 233434, 233443, 233444, 233445, 233454, 233455, 233456, 234321, 234322, 234323, 234332, 234333, 234334, 234343, 234344, 234345, 234432, 234433, 234434, 234443, 234444, 234445, 234454, 234455, 234456, 234543, 234544, 234545, 234554, 234555, 234556, 234565, 234566, 234567, 321000, 321001, 321010, 321011, 321012, 321100, 321101, 321110, 321111, 321112, 321121, 321122, 321123, 321210, 321211, 321212, 321221, 321222, 321223, 321232, 321233, 321234, 322100, 322101, 322110, 322111, 322112, 322121, 322122, 322123, 322210, 322211, 322212, 322221, 322222, 322223, 322232, 322233, 322234, 322321, 322322, 322323, 322332, 322333, 322334, 322343, 322344, 322345, 323210, 323211, 323212, 323221, 323222, 323223, 323232, 323233, 323234, 323321, 323322, 323323, 323332, 323333, 323334, 323343, 323344, 323345, 323432, 323433, 323434, 323443, 323444, 323445, 323454, 323455, 323456, 332100, 332101, 332110, 332111, 332112, 332121, 332122, 332123, 332210, 332211, 332212, 332221, 332222, 332223, 332232, 332233, 332234, 332321, 332322, 332323, 332332, 332333, 332334, 332343, 332344, 332345, 333210, 333211, 333212, 333221, 333222, 333223, 333232, 333233, 333234, 333321, 333322, 333323, 333332, 333333, 333334, 333343, 333344, 333345, 333432, 333433, 333434, 333443, 333444, 333445, 333454, 333455, 333456, 334321, 334322, 334323, 334332, 334333, 334334, 334343, 334344, 334345, 334432, 334433, 334434, 334443, 334444, 334445, 334454, 334455, 334456, 334543, 334544, 334545, 334554, 334555, 334556, 334565, 334566, 334567, 343210, 343211, 343212, 343221, 343222, 343223, 343232, 343233, 343234, 343321, 343322, 343323, 343332, 343333, 343334, 343343, 343344, 343345, 343432, 343433, 343434, 343443, 343444, 343445, 343454, 343455, 343456, 344321, 344322, 344323, 344332, 344333, 344334, 344343, 344344, 344345, 344432, 344433, 344434, 344443, 344444, 344445, 344454, 344455, 344456, 344543, 344544, 344545, 344554, 344555, 344556, 344565, 344566, 344567, 345432, 345433, 345434, 345443, 345444, 345445, 345454, 345455, 345456, 345543, 345544, 345545, 345554, 345555, 345556, 345565, 345566, 345567, 345654, 345655, 345656, 345665, 345666, 345667, 345676, 345677, 345678, 432100, 432101, 432110, 432111, 432112, 432121, 432122, 432123, 432210, 432211, 432212, 432221, 432222, 432223, 432232, 432233, 432234, 432321, 432322, 432323, 432332, 432333, 432334, 432343, 432344, 432345, 433210, 433211, 433212, 433221, 433222, 433223, 433232, 433233, 433234, 433321, 433322, 433323, 433332, 433333, 433334, 433343, 433344, 433345, 433432, 433433, 433434, 433443, 433444, 433445, 433454, 433455, 433456, 434321, 434322, 434323, 434332, 434333, 434334, 434343, 434344, 434345, 434432, 434433, 434434, 434443, 434444, 434445, 434454, 434455, 434456, 434543, 434544, 434545, 434554, 434555, 434556, 434565, 434566, 434567, 443210, 443211, 443212, 443221, 443222, 443223, 443232, 443233, 443234, 443321, 443322, 443323, 443332, 443333, 443334, 443343, 443344, 443345, 443432, 443433, 443434, 443443, 443444, 443445, 443454, 443455, 443456, 444321, 444322, 444323, 444332, 444333, 444334, 444343, 444344, 444345, 444432, 444433, 444434, 444443, 444444, 444445, 444454, 444455, 444456, 444543, 444544, 444545, 444554, 444555, 444556, 444565, 444566, 444567, 445432, 445433, 445434, 445443, 445444, 445445, 445454, 445455, 445456, 445543, 445544, 445545, 445554, 445555, 445556, 445565, 445566, 445567, 445654, 445655, 445656, 445665, 445666, 445667, 445676, 445677, 445678, 454321, 454322, 454323, 454332, 454333, 454334, 454343, 454344, 454345, 454432, 454433, 454434, 454443, 454444, 454445, 454454, 454455, 454456, 454543, 454544, 454545, 454554, 454555, 454556, 454565, 454566, 454567, 455432, 455433, 455434, 455443, 455444, 455445, 455454, 455455, 455456, 455543, 455544, 455545, 455554, 455555, 455556, 455565, 455566, 455567, 455654, 455655, 455656, 455665, 455666, 455667, 455676, 455677, 455678, 456543, 456544, 456545, 456554, 456555, 456556, 456565, 456566, 456567, 456654, 456655, 456656, 456665, 456666, 456667, 456676, 456677, 456678, 456765, 456766, 456767, 456776, 456777, 456778, 456787, 456788, 456789, 543210, 543211, 543212, 543221, 543222, 543223, 543232, 543233, 543234, 543321, 543322, 543323, 543332, 543333, 543334, 543343, 543344, 543345, 543432, 543433, 543434, 543443, 543444, 543445, 543454, 543455, 543456, 544321, 544322, 544323, 544332, 544333, 544334, 544343, 544344, 544345, 544432, 544433, 544434, 544443, 544444, 544445, 544454, 544455, 544456, 544543, 544544, 544545, 544554, 544555, 544556, 544565, 544566, 544567, 545432, 545433, 545434, 545443, 545444, 545445, 545454, 545455, 545456, 545543, 545544, 545545, 545554, 545555, 545556, 545565, 545566, 545567, 545654, 545655, 545656, 545665, 545666, 545667, 545676, 545677, 545678, 554321, 554322, 554323, 554332, 554333, 554334, 554343, 554344, 554345, 554432, 554433, 554434, 554443, 554444, 554445, 554454, 554455, 554456, 554543, 554544, 554545, 554554, 554555, 554556, 554565, 554566, 554567, 555432, 555433, 555434, 555443, 555444, 555445, 555454, 555455, 555456, 555543, 555544, 555545, 555554, 555555, 555556, 555565, 555566, 555567, 555654, 555655, 555656, 555665, 555666, 555667, 555676, 555677, 555678, 556543, 556544, 556545, 556554, 556555, 556556, 556565, 556566, 556567, 556654, 556655, 556656, 556665, 556666, 556667, 556676, 556677, 556678, 556765, 556766, 556767, 556776, 556777, 556778, 556787, 556788, 556789, 565432, 565433, 565434, 565443, 565444, 565445, 565454, 565455, 565456, 565543, 565544, 565545, 565554, 565555, 565556, 565565, 565566]
l+=[565567, 565654, 565655, 565656, 565665, 565666, 565667, 565676, 565677, 565678, 566543, 566544, 566545, 566554, 566555, 566556, 566565, 566566, 566567, 566654, 566655, 566656, 566665, 566666, 566667, 566676, 566677, 566678, 566765, 566766, 566767, 566776, 566777, 566778, 566787, 566788, 566789, 567654, 567655, 567656, 567665, 567666, 567667, 567676, 567677, 567678, 567765, 567766, 567767, 567776, 567777, 567778, 567787, 567788, 567789, 567876, 567877, 567878, 567887, 567888, 567889, 567898, 567899, 654321, 654322, 654323, 654332, 654333, 654334, 654343, 654344, 654345, 654432, 654433, 654434, 654443, 654444, 654445, 654454, 654455, 654456, 654543, 654544, 654545, 654554, 654555, 654556, 654565, 654566, 654567, 655432, 655433, 655434, 655443, 655444, 655445, 655454, 655455, 655456, 655543, 655544, 655545, 655554, 655555, 655556, 655565, 655566, 655567, 655654, 655655, 655656, 655665, 655666, 655667, 655676, 655677, 655678, 656543, 656544, 656545, 656554, 656555, 656556, 656565, 656566, 656567, 656654, 656655, 656656, 656665, 656666, 656667, 656676, 656677, 656678, 656765, 656766, 656767, 656776, 656777, 656778, 656787, 656788, 656789, 665432, 665433, 665434, 665443, 665444, 665445, 665454, 665455, 665456, 665543, 665544, 665545, 665554, 665555, 665556, 665565, 665566, 665567, 665654, 665655, 665656, 665665, 665666, 665667, 665676, 665677, 665678, 666543, 666544, 666545, 666554, 666555, 666556, 666565, 666566, 666567, 666654, 666655, 666656, 666665, 666666, 666667, 666676, 666677, 666678, 666765, 666766, 666767, 666776, 666777, 666778, 666787, 666788, 666789, 667654, 667655, 667656, 667665, 667666, 667667, 667676, 667677, 667678, 667765, 667766, 667767, 667776, 667777, 667778, 667787, 667788, 667789, 667876, 667877, 667878, 667887, 667888, 667889, 667898, 667899, 676543, 676544, 676545, 676554, 676555, 676556, 676565, 676566, 676567, 676654, 676655, 676656, 676665, 676666, 676667, 676676, 676677, 676678, 676765, 676766, 676767, 676776, 676777, 676778, 676787, 676788, 676789, 677654, 677655, 677656, 677665, 677666, 677667, 677676, 677677, 677678, 677765, 677766, 677767, 677776, 677777, 677778, 677787, 677788, 677789, 677876, 677877, 677878, 677887, 677888, 677889, 677898, 677899, 678765, 678766, 678767, 678776, 678777, 678778, 678787, 678788, 678789, 678876, 678877, 678878, 678887, 678888, 678889, 678898, 678899, 678987, 678988, 678989, 678998, 678999, 765432, 765433, 765434, 765443, 765444, 765445, 765454, 765455, 765456, 765543, 765544, 765545, 765554, 765555, 765556, 765565, 765566, 765567, 765654, 765655, 765656, 765665, 765666, 765667, 765676, 765677, 765678, 766543, 766544, 766545, 766554, 766555, 766556, 766565, 766566, 766567, 766654, 766655, 766656, 766665, 766666, 766667, 766676, 766677, 766678, 766765, 766766, 766767, 766776, 766777, 766778, 766787, 766788, 766789, 767654, 767655, 767656, 767665, 767666, 767667, 767676, 767677, 767678, 767765, 767766, 767767, 767776, 767777, 767778, 767787, 767788, 767789, 767876, 767877, 767878, 767887, 767888, 767889, 767898, 767899, 776543, 776544, 776545, 776554, 776555, 776556, 776565, 776566, 776567, 776654, 776655, 776656, 776665, 776666, 776667, 776676, 776677, 776678, 776765, 776766, 776767, 776776, 776777, 776778, 776787, 776788, 776789, 777654, 777655, 777656, 777665, 777666, 777667, 777676, 777677, 777678, 777765, 777766, 777767, 777776, 777777, 777778, 777787, 777788, 777789, 777876, 777877, 777878, 777887, 777888, 777889, 777898, 777899, 778765, 778766, 778767, 778776, 778777, 778778, 778787, 778788, 778789, 778876, 778877, 778878, 778887, 778888, 778889, 778898, 778899, 778987, 778988, 778989, 778998, 778999, 787654, 787655, 787656, 787665, 787666, 787667, 787676, 787677, 787678, 787765, 787766, 787767, 787776, 787777, 787778, 787787, 787788, 787789, 787876, 787877, 787878, 787887, 787888, 787889, 787898, 787899, 788765, 788766, 788767, 788776, 788777, 788778, 788787, 788788, 788789, 788876, 788877, 788878, 788887, 788888, 788889, 788898, 788899, 788987, 788988, 788989, 788998, 788999, 789876, 789877, 789878, 789887, 789888, 789889, 789898, 789899, 789987, 789988, 789989, 789998, 789999, 876543, 876544, 876545, 876554, 876555, 876556, 876565, 876566, 876567, 876654, 876655, 876656, 876665, 876666, 876667, 876676, 876677, 876678, 876765, 876766, 876767, 876776, 876777, 876778, 876787, 876788, 876789, 877654, 877655, 877656, 877665, 877666, 877667, 877676, 877677, 877678, 877765, 877766, 877767, 877776, 877777, 877778, 877787, 877788, 877789, 877876, 877877, 877878, 877887, 877888, 877889, 877898, 877899, 878765, 878766, 878767, 878776, 878777, 878778, 878787, 878788, 878789, 878876, 878877, 878878, 878887, 878888, 878889, 878898, 878899, 878987, 878988, 878989, 878998, 878999, 887654, 887655, 887656, 887665, 887666, 887667, 887676, 887677, 887678, 887765, 887766, 887767, 887776, 887777, 887778, 887787, 887788, 887789, 887876, 887877, 887878, 887887, 887888, 887889, 887898, 887899, 888765, 888766, 888767, 888776, 888777, 888778, 888787, 888788, 888789, 888876, 888877, 888878, 888887, 888888, 888889, 888898, 888899, 888987, 888988, 888989, 888998, 888999, 889876, 889877, 889878, 889887, 889888, 889889, 889898, 889899, 889987, 889988, 889989, 889998, 889999, 898765, 898766, 898767, 898776, 898777, 898778, 898787, 898788, 898789, 898876, 898877, 898878, 898887, 898888, 898889, 898898, 898899, 898987, 898988, 898989, 898998, 898999, 899876, 899877, 899878, 899887, 899888, 899889, 899898, 899899, 899987, 899988, 899989, 899998, 899999, 987654, 987655, 987656, 987665, 987666, 987667, 987676, 987677, 987678, 987765, 987766, 987767, 987776, 987777, 987778, 987787, 987788, 987789, 987876, 987877, 987878, 987887, 987888, 987889, 987898, 987899, 988765, 988766, 988767, 988776, 988777, 988778, 988787, 988788, 988789, 988876, 988877, 988878, 988887, 988888, 988889, 988898, 988899, 988987, 988988, 988989, 988998, 988999, 989876, 989877, 989878, 989887, 989888, 989889, 989898, 989899, 989987, 989988, 989989, 989998, 989999, 998765, 998766, 998767, 998776, 998777, 998778, 998787, 998788, 998789, 998876, 998877, 998878, 998887, 998888, 998889, 998898, 998899, 998987, 998988, 998989, 998998, 998999, 999876, 999877, 999878, 999887, 999888, 999889, 999898, 999899, 999987, 999988, 999989, 999998, 999999, 1000000, 1000001, 1000010, 1000011, 1000012, 1000100, 1000101, 1000110, 1000111, 1000112, 1000121, 1000122, 1000123, 1001000, 1001001, 1001010, 1001011, 1001012, 1001100, 1001101, 1001110, 1001111, 1001112, 1001121, 1001122, 1001123, 1001210, 1001211, 1001212, 1001221, 1001222, 1001223, 1001232, 1001233, 1001234, 1010000, 1010001, 1010010, 1010011, 1010012, 1010100, 1010101, 1010110, 1010111, 1010112, 1010121, 1010122, 1010123, 1011000, 1011001, 1011010, 1011011, 1011012, 1011100, 1011101, 1011110, 1011111, 1011112, 1011121, 1011122, 1011123, 1011210, 1011211, 1011212, 1011221, 1011222, 1011223, 1011232, 1011233, 1011234, 1012100, 1012101, 1012110, 1012111, 1012112, 1012121, 1012122, 1012123, 1012210, 1012211, 1012212, 1012221, 1012222, 1012223, 1012232, 1012233, 1012234, 1012321, 1012322, 1012323, 1012332, 1012333, 1012334, 1012343, 1012344, 1012345, 1100000, 1100001, 1100010, 1100011, 1100012, 1100100, 1100101, 1100110, 1100111, 1100112, 1100121, 1100122, 1100123, 1101000, 1101001, 1101010, 1101011, 1101012, 1101100, 1101101, 1101110, 1101111, 1101112, 1101121, 1101122, 1101123, 1101210, 1101211, 1101212, 1101221, 1101222, 1101223, 1101232, 1101233, 1101234, 1110000, 1110001, 1110010, 1110011, 1110012, 1110100, 1110101, 1110110, 1110111, 1110112, 1110121, 1110122, 1110123, 1111000, 1111001, 1111010, 1111011, 1111012, 1111100, 1111101, 1111110, 1111111, 1111112, 1111121, 1111122, 1111123, 1111210, 1111211, 1111212, 1111221, 1111222, 1111223, 1111232, 1111233, 1111234, 1112100, 1112101, 1112110, 1112111, 1112112, 1112121, 1112122, 1112123, 1112210, 1112211, 1112212, 1112221, 1112222, 1112223, 1112232, 1112233, 1112234, 1112321, 1112322, 1112323, 1112332, 1112333, 1112334, 1112343, 1112344, 1112345, 1121000, 1121001, 1121010, 1121011, 1121012, 1121100, 1121101, 1121110, 1121111, 1121112, 1121121, 1121122, 1121123, 1121210, 1121211, 1121212, 1121221, 1121222, 1121223, 1121232, 1121233, 1121234, 1122100, 1122101, 1122110, 1122111]
i=1122111
def check(s):
  for i in range(len(s)-1):
    if(abs(int(s[i])-int(s[i+1]))>1):
      return False
  return True
while len(l)<n:
  i+=1
  if(check(str(i))):
    l.append(i)
print(l[n-1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(range(1,13))
i=12
def check(s):
  for i in range(len(s)-1):
    if(abs(int(s[i])-int(s[i+1]))>1):
      return False
  return True
while len(l)<n:
  i+=1
  if(check(str(i))):
    l.append(i)
print(l[n-1])

Submission status: Time Limit Exceeded

Solution code:
def isLunlun(num):
    prev = num%10
    num = num//10
    while(num!=0):
        curr = num%10
        if(abs(curr - prev)>1):
            return False
        prev = curr
        num = num//10
    return True

k = int(input())
count = 0
i = 1
while count<k:
    if(isLunlun(i)):
        count+=1
    i+=1
print(i-1)

Submission status: Time Limit Exceeded

Solution code:
def s():
  import queue
  k = int(input())
  q = queue.Queue([1,2,3,4,5,6,7,8,9])
  qg = q.get
  qp = q.put
  for _ in range(k-1):
    x = qg()
    if x%10 == 0:
      qp(10*x)
      qp(10*x+1)
    elif x%10 == 0:
      qp(10*x+8)
      qp(10*x+9)
    else:
      i = x%10
      qp(10*x+i-1)
      qp(10*x+i)
      qp(10*x+i+1)
  x = qg()
  print(x)
s()

Submission status: Time Limit Exceeded

Solution code:
import queue
k = int(input())
q = queue.Queue([1,2,3,4,5,6,7,8,9])
qg = q.get
qp = q.put
for _ in range(k-1):
  x = qg()
  if x%10 == 0:
    qp(10*x)
    qp(10*x+1)
  elif x%10 == 0:
    qp(10*x+8)
    qp(10*x+9)
  else:
    i = x%10
    qp(10*x+i-1)
    qp(10*x+i)
    qp(10*x+i+1)
x = qg()
print(x)

Submission status: Time Limit Exceeded

Solution code:
import queue
k = int(input())
q = queue.Queue([1,2,3,4,5,6,7,8,9])
c = 1
while True:
  x = q.get()
  if c == k:
    print(x)
    exit()
  if x%10 == 0:
    q.put(10*x)
    q.put(10*x+1)
  elif x%10 == 0:
    q.put(10*x+8)
    q.put(10*x+9)
  else:
    i = x%10
    q.put(10*x+i-1)
    q.put(10*x+i)
    q.put(10*x+i+1)
  c += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
queue = [i for i in range(1, 10)]

for i in range(k-1):
  tmp = queue.pop(0)
  r = tmp % 10
  if r != 0:
    queue.append(10*tmp + r -1)
  queue.append(10*tmp + r)
  if r != 9:
    queue.append(10*tmp + r + 1)
print(queue.pop(0))

Submission status: Time Limit Exceeded

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k = ni()

LIMIT = 12
luns = []


def make_lunlun(l):
    if len(l) == LIMIT:
        return
    luns.append(int(''.join(list(map(str,l)))))

    if l[-1]!=0:
        make_lunlun(l+[(l[-1]-1)%10])
    make_lunlun(l+[(l[-1])%10])
    if l[-1]!=9:
        make_lunlun(l+[(l[-1]+1)%10])


for i in range(1,10):
    make_lunlun([i])

print(sorted(luns)[k-1])

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

q = []
for i in range(1, 10):
    q.append(i)

for i in range(K):
    x = q.pop(0)
    if x % 10 != 0:
        q.append(10 * x - 1 + x % 10)
    q.append(10 * x + x % 10)
    if x % 10 != 9:
        q.append(10 * x + 1 + x % 10)

print(x)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())  #数字

if K <= 12:
    print(K)
    exit()

num = 13
cou = 12
cal = 1
while cou < K:
    L = list(map(int, str(num)))  #iの各行を数字としてリストに格納
    L= list(reversed(L))
    #print("num", num)
    #print(cal)
    for i in range(len(L) - 1):
        if abs(L[i] - L[i + 1]) > 1:
            num += 1
            cal = 1
            break
        elif cal == len(L) - 1:
            cou += 1
            num += 1
            cal = 1
            break              
        else:
            cal += 1
    #print(cou)
print(num-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())  #数字

if K <= 12:
    print(K)
    exit()

num = 13
cou = 12
cal = 1
while cou < K:
    L = list(map(int, str(num)))  #iの各行を数字としてリストに格納
    #print("num", num)
    #print(cal)
    for i in range(len(L) - 1):
        if abs(L[i] - L[i + 1]) > 1:
            num += 1
            cal = 1
            break
        elif cal == len(L) - 1:
            cou += 1
            num += 1
            cal = 1
            break              
        else:
            cal += 1
    #print(cou)
print(num-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())


arr = list(range(1,10))

x = 0
for i in range(k):
    x = arr.pop(0)
    if x % 10 != 0:
        arr.append(10*x - 1 + x%10)
    arr.append(10*x + x%10)
    if x % 10 != 9:
        arr.append(10*x + 1 + x%10)

print(x)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

queue = list(range(1,10))

for i in range(K):
  lunlun = queue.pop(0)
  #print(lunlun)
  last = lunlun%10
  if last!=0:
    queue.append(10*lunlun+last-1)
  queue.append(10*lunlun+last)
  if last!=9:
    queue.append(10*lunlun+last+1)

print(lunlun)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

queue = list(range(1,10))

i = 0
while i!=K:
  lunlun = queue.pop(0)
  #print(lunlun)
  last = lunlun%10
  if last!=0:
    queue.append(10*lunlun+last-1)
  queue.append(10*lunlun+last)
  if last!=9:
    queue.append(10*lunlun+last+1)

  i += 1

print(lunlun)

Submission status: Time Limit Exceeded

Solution code:
K = int(input()) - 1
todo = list(range(1, 10))
ans = []
counter = 0
while counter <= K:
    seed = todo.pop(0)
    ans.append(seed)
    counter += 1
    last_dig = int(str(seed)[-1])
    for i in range(max(0, last_dig-1), min(10, last_dig+2)):
        todo.append(int(str(seed) + str(i)))
print(ans[-1])

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
a=[1,2,3,4,5,6,7,8,9]
ans=a[:]
if k<=9:
  print(ans[k-1])
  exit()
k-=9
for i in range(9):
  b=[0 for _ in range(9*10**(i+1))]
  ind=0
  for x in a:
    d=x%10
    if d!=9 and d!=0:
      b[ind]=x*10+d-1
      b[ind+1]=x*10+d
      b[ind+2]=x*10+d+1
      ind+=3
    elif d==0:
      b[ind]=x*10+d
      b[ind+1]=x*10+d+1
      ind+=2
    elif d==9:
      b[ind]=x*10+d-1
      b[ind+1]=x*10+d
      ind+=2
  b=b[:ind]
  if len(b)>=k:
    print(b[k-1])
    exit()
  else:
    k-=len(b)
  a=b[:]

Submission status: Time Limit Exceeded

Solution code:
K=int(input())


def calc(n):
    x = str(n)
    x = [int(i) for i in x]

    if len(x)==1:
        return True
    for i in range(len(x)-1):
        if abs(x[i] - x[i + 1]) > 1:
            return False
    return True

i=1
t=[]
while True:
    if calc(i):
        t.append(i)
    i+=1
    if len(t)==K:
        break
print(t[-1])

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
a=[1,2,3,4,5,6,7,8,9]
ans=a[:]
if k<=9:
  print(ans[k-1])
  exit()
k-=9
for i in range(9):
  b=[0 for _ in range(9*10**(i+1))]
  ind=0
  for x in a:
    d=x%10
    if d!=9 and d!=0:
      b[ind]=x*10+d-1
      b[ind+1]=x*10+d
      b[ind+2]=x*10+d+1
      ind+=3
    elif d==0:
      b[ind]=x*10+d
      b[ind+1]=x*10+d+1
      ind+=2
    elif d==9:
      b[ind]=x*10+d-1
      b[ind+1]=x*10+d
      ind+=2
  b=b[:ind]
  ans.extend(b)
  if len(b)>=k:
    print(b[k-1])
    exit()
  else:
    k-=len(b)
  a=b[:]


print(ans[k-1])
#print(len(ans))
#print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    
    queue = [i for i in range(1,10)]
    while True:
        if n == 1:
            print(queue[0])
            return
        tmp = queue.pop(0)
        n -= 1
        if tmp%10 == 0:
            queue += [tmp*10 + tmp%10, tmp*10 + tmp%10 + 1]
        elif tmp%10 == 9:
            queue += [tmp*10 + tmp%10 - 1, tmp*10 + tmp%10]
        else:
            queue += [tmp*10 + tmp%10 - 1, tmp*10 + tmp%10, tmp*10 + tmp%10 + 1]
            
main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
 
qu = list(range(1,10))
 
cnt = 0
while( cnt < k ):
  out = qu.pop(0)
  r = out%10
  y = 10*out+r
  if( r != 0 ):
    qu.append(y-1)
  qu.append(y)
  
  if( r!=9):
    qu.append(y+1)
  cnt+=1
    
print(out)