Problem:


Score : 700 points

Problem Statement

Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3.
Let x_{i,j} defined as follows:

x_{1,j} := a_j \quad (1 \leq j \leq N)

x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i)

Find x_{N,1}.

Constraints

2 \leq N \leq 10^6

a_i = 1,2,3 (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
a_1a_2\ldotsa_N

Output

Print x_{N,1}.

Sample Input 1

4
1231

Sample Output 1

1

x_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.

x_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.

x_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.

Finally, x_{4,1} = |0-1| = 1, so the answer is 1.

Sample Input 2

10
2311312312

Sample Output 2

0



Sample input:
4
1231


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

A = set(['000000', '000011', '000013', '000022', '000033', '000100', '000102', '000111', '000113', '000120', '000122', '000131', '000133', '000200', '000211', '000213', '000222', '000231', '000233', '000300', '000311', '000313', '000333', '001000', '001002', '001011', '001013', '001020', '001022', '001031', '001033', '001100', '001102', '001111', '001113', '001120', '001122', '001131', '001133', '001200', '001202', '001211', '001213', '001220', '001222', '001231', '001233', '001302', '001311', '001313', '001320', '001322', '001331', '001333', '002000', '002011', '002013', '002022', '002031', '002033', '002100', '002102', '002111', '002113', '002120', '002122', '002131', '002133', '002200', '002211', '002213', '002222', '002231', '002233', '002300', '002302', '002311', '002313', '002320', '002322', '002331', '002333', '003000', '003011', '003013', '003033', '003111', '003113', '003131', '003133', '003200', '003202', '003211', '003213', '003220', '003222', '003231', '003233', '003300', '003311', '003313', '003320', '003322', '003333', '010001', '010010', '010012', '010021', '010023', '010030', '010032', '010101', '010110', '010112', '010121', '010123', '010130', '010132', '010201', '010203', '010210', '010212', '010221', '010223', '010230', '010232', '010301', '010310', '010312', '010321', '010323', '010330', '010332', '011001', '011010', '011012', '011021', '011023', '011030', '011032', '011101', '011103', '011110', '011112', '011121', '011123', '011130', '011132', '011201', '011203', '011210', '011212', '011221', '011223', '011230', '011232', '011301', '011303', '011310', '011312', '011321', '011323', '011330', '011332', '012001', '012003', '012010', '012012', '012021', '012023', '012030', '012032', '012101', '012110', '012112', '012121', '012123', '012130', '012132', '012201', '012203', '012210', '012212', '012221', '012223', '012230', '012232', '012301', '012310', '012312', '012321', '012323', '012330', '012332', '013003', '013010', '013012', '013021', '013023', '013030', '013032', '013101', '013103', '013110', '013112', '013121', '013123', '013130', '013132', '013201', '013203', '013210', '013212', '013221', '013223', '013230', '013232', '013301', '013310', '013312', '013321', '013323', '013330', '013332', '020002', '020011', '020013', '020020', '020031', '020033', '020100', '020102', '020111', '020113', '020120', '020122', '020131', '020133', '020202', '020211', '020213', '020220', '020231', '020233', '020302', '020311', '020313', '020320', '020322', '020331', '020333', '021000', '021002', '021011', '021013', '021020', '021022', '021031', '021033', '021100', '021102', '021111', '021113', '021120', '021122', '021131', '021133', '021200', '021202', '021211', '021213', '021220', '021222', '021231', '021233', '021302', '021311', '021313', '021320', '021322', '021331', '021333', '022002', '022011', '022013', '022020', '022031', '022033', '022100', '022102', '022111', '022113', '022120', '022122', '022131', '022133', '022202', '022211', '022213', '022220', '022231', '022233', '022300', '022302', '022311', '022313', '022320', '022322', '022331', '022333', '023002', '023011', '023013', '023020', '023022', '023031', '023033', '023100', '023102', '023111', '023113', '023120', '023122', '023131', '023133', '023200', '023202', '023211', '023213', '023220', '023222', '023231', '023233', '023300', '023311', '023313', '023320', '023322', '023331', '023333', '030003', '030010', '030012', '030030', '030103', '030110', '030112', '030130', '030132', '030201', '030203', '030210', '030212', '030221', '030223', '030230', '030232', '030303', '030310', '030312', '030330', '031001', '031010', '031012', '031021', '031023', '031030', '031032', '031101', '031103', '031110', '031112', '031121', '031123', '031130', '031132', '031201', '031203', '031210', '031212', '031221', '031223', '031230', '031232', '031301', '031303', '031310', '031312', '031321', '031323', '031330', '031332', '032001', '032003', '032010', '032012', '032021', '032023', '032030', '032032', '032103', '032110', '032112', '032130', '032132', '032201', '032203', '032210', '032212', '032221', '032223', '032230', '032232', '032303', '032310', '032312', '032330', '032332', '033003', '033010', '033012', '033021', '033023', '033030', '033101', '033103', '033110', '033112', '033121', '033123', '033130', '033132', '033210', '033212', '033230', '033232', '033303', '033310', '033312', '033330', '100001', '100010', '100012', '100021', '100023', '100032', '100101', '100103', '100110', '100112', '100121', '100123', '100130', '100132', '100201', '100203', '100210', '100212', '100221', '100223', '100230', '100232', '100301', '100321', '100323', '100332', '101001', '101003', '101010', '101012', '101021', '101023', '101032', '101101', '101103', '101110', '101112', '101121', '101123', '101130', '101132', '101201', '101203', '101210', '101212', '101221', '101223', '101232', '101301', '101303', '101310', '101312', '101321', '101323', '101330', '101332', '102001', '102003', '102010', '102012', '102021', '102023', '102030', '102032', '102101', '102103', '102110', '102112', '102121', '102123', '102130', '102132', '102201', '102203', '102210', '102212', '102221', '102223', '102230', '102232', '102301', '102303', '102310', '102312', '102321', '102323', '102332', '103001', '103010', '103012', '103021', '103023', '103032', '103101', '103103', '103110', '103112', '103121', '103123', '103130', '103132', '103201', '103203', '103210', '103212', '103221', '103223', '103232', '103301', '103310', '103312', '103321', '103323', '103332', '110000', '110002', '110011', '110013', '110020', '110022', '110033', '110100', '110102', '110111', '110113', '110120', '110122', '110131', '110133', '110200', '110202', '110211', '110213', '110220', '110222', '110231', '110233', '110300', '110302', '110311', '110313', '110320', '110322', '110331', '111000', '111002', '111011', '111013', '111020', '111022', '111031', '111033', '111100', '111102', '111111', '111120', '111122', '111133', '111200', '111202', '111211', '111213', '111220', '111222', '111231', '111233', '111300', '111302', '111311', '111320', '111322', '111333', '112000', '112002', '112011', '112013', '112020', '112022', '112031', '112100', '112102', '112111', '112113', '112120', '112122', '112131', '112133', '112200', '112202', '112211', '112213', '112220', '112222', '112231', '112233', '112300', '112302', '112311', '112313', '112320', '112322', '112331', '112333', '113000', '113002', '113011', '113013', '113020', '113022', '113031', '113100', '113102', '113111', '113120', '113122', '113133', '113200', '113202', '113211', '113213', '113220', '113222', '113231', '113233', '113300', '113302', '113311', '113320', '113322', '113333', '120001', '120003', '120010', '120012', '120021', '120023', '120032', '120101', '120103', '120110', '120112', '120121', '120123', '120130', '120132', '120201', '120203', '120210', '120212', '120221', '120223', '120230', '120232', '120301', '120303', '120310', '120312', '120321', '120323', '120330', '121001', '121003', '121010', '121012', '121021', '121023', '121032', '121101', '121103', '121110', '121112', '121121', '121123', '121130', '121132', '121201', '121203', '121210', '121212', '121221', '121223', '121232', '121301', '121303', '121310', '121312', '121321', '121323', '121330', '121332', '122001', '122003', '122010', '122012', '122021', '122023', '122030', '122032', '122101', '122103', '122110', '122112', '122121', '122123', '122130', '122132', '122201', '122203', '122210', '122212', '122221', '122223', '122230', '122232', '122301', '122303', '122310', '122312', '122321', '122323', '122332', '123001', '123003', '123010', '123012', '123021', '123023', '123032', '123101', '123103', '123110', '123112', '123121', '123123', '123130', '123132', '123201', '123203', '123210', '123212', '123221', '123223', '123232', '123301', '123303', '123310', '123312', '123321', '123323', '123332', '130002', '130020', '130022', '130031', '130100', '130102', '130111', '130113', '130120', '130122', '130131', '130133', '130200', '130202', '130211', '130213', '130220', '130222', '130231', '130233', '130302', '130311', '130313', '130320', '130322', '130331', '131000', '131002', '131011', '131013', '131020', '131022', '131031', '131033', '131100', '131102', '131113', '131120', '131122', '131131', '131200', '131202', '131211', '131213', '131220', '131222', '131231', '131233', '131300', '131302', '131313', '131320', '131322', '131331', '132000', '132002', '132011', '132013', '132020', '132022', '132031', '132100', '132102', '132111', '132113', '132120', '132122', '132131', '132133', '132200', '132202', '132211', '132213', '132220', '132222', '132231', '132233', '132300', '132302', '132311', '132313', '132320', '132322', '132331', '132333', '133002', '133011', '133013', '133020', '133022', '133031', '133100', '133102', '133113', '133120', '133122', '133131', '133200', '133202', '133211', '133213', '133220', '133222', '133231', '133233', '133302', '133313', '133320', '133322', '133331', '200002', '200011', '200013', '200020', '200031', '200100', '200102', '200111', '200113', '200120', '200122', '200131', '200133', '200202', '200211', '200213', '200220', '200231', '200233', '200302', '200311', '200313', '200320', '200322', '200331', '201000', '201002', '201011', '201013', '201020', '201022', '201031', '201033', '201100', '201102', '201111', '201113', '201120', '201122', '201131', '201133', '201200', '201202', '201211', '201213', '201220', '201222', '201231', '201233', '201302', '201311', '201313', '201320', '201322', '201331', '201333', '202002', '202011', '202013', '202020', '202031', '202033', '202100', '202102', '202111', '202113', '202120', '202122', '202131', '202133', '202202', '202211', '202213', '202220', '202231', '202233', '202300', '202302', '202311', '202313', '202320', '202322', '202331', '202333', '203002', '203011', '203013', '203020', '203022', '203031', '203100', '203102', '203111', '203113', '203120', '203122', '203131', '203133', '203200', '203202', '203211', '203213', '203220', '203222', '203231', '203233', '203302', '203311', '203313', '203331', '210001', '210010', '210012', '210021', '210023', '210030', '210032', '210101', '210110', '210112', '210121', '210123', '210130', '210132', '210201', '210203', '210210', '210212', '210221', '210223', '210230', '210232', '210301', '210310', '210312', '210321', '210323', '210330', '210332', '211001', '211010', '211012', '211021', '211023', '211030', '211032', '211101', '211103', '211110', '211112', '211121', '211123', '211130', '211132', '211201', '211203', '211210', '211212', '211221', '211223', '211230', '211232', '211301', '211303', '211310', '211312', '211321', '211323', '211330', '211332', '212001', '212003', '212010', '212012', '212021', '212023', '212030', '212032', '212101', '212110', '212112', '212121', '212123', '212130', '212132', '212201', '212203', '212210', '212212', '212221', '212223', '212230', '212232', '212301', '212310', '212312', '212321', '212323', '212330', '212332', '213003', '213010', '213012', '213021', '213023', '213030', '213032', '213101', '213103', '213110', '213112', '213121', '213123', '213130', '213132', '213201', '213203', '213210', '213212', '213221', '213223', '213230', '213232', '213301', '213310', '213312', '213321', '213323', '213330', '213332', '220000', '220011', '220013', '220022', '220031', '220033', '220100', '220102', '220111', '220113', '220120', '220122', '220131', '220133', '220200', '220211', '220213', '220222', '220231', '220233', '220302', '220311', '220313', '220320', '220322', '220331', '220333', '221000', '221002', '221011', '221013', '221020', '221022', '221031', '221033', '221100', '221102', '221111', '221113', '221120', '221122', '221131', '221133', '221200', '221202', '221211', '221213', '221220', '221222', '221231', '221233', '221302', '221311', '221313', '221320', '221322', '221331', '221333', '222000', '222011', '222013', '222022', '222031', '222033', '222100', '222102', '222111', '222113', '222120', '222122', '222131', '222133', '222200', '222211', '222213', '222222', '222231', '222233', '222300', '222302', '222311', '222313', '222320', '222322', '222331', '222333', '223002', '223011', '223013', '223020', '223022', '223031', '223033', '223100', '223102', '223111', '223113', '223120', '223122', '223131', '223133', '223200', '223202', '223211', '223213', '223220', '223222', '223231', '223233', '223300', '223311', '223313', '223320', '223322', '223331', '223333', '230001', '230010', '230012', '230021', '230023', '230032', '230101', '230110', '230112', '230121', '230123', '230130', '230132', '230201', '230203', '230210', '230212', '230221', '230223', '230230', '230232', '230301', '230310', '230312', '230321', '230323', '230332', '231001', '231010', '231012', '231021', '231023', '231030', '231032', '231101', '231103', '231110', '231112', '231121', '231123', '231130', '231132', '231201', '231203', '231210', '231212', '231221', '231223', '231230', '231232', '231301', '231303', '231310', '231312', '231321', '231323', '231330', '231332', '232001', '232003', '232010', '232012', '232021', '232023', '232030', '232032', '232101', '232110', '232112', '232121', '232123', '232130', '232132', '232201', '232203', '232210', '232212', '232221', '232223', '232230', '232232', '232301', '232310', '232312', '232321', '232323', '232330', '232332', '233001', '233010', '233012', '233032', '233101', '233103', '233110', '233112', '233121', '233123', '233130', '233132', '233201', '233203', '233210', '233212', '233221', '233223', '233230', '233232', '233301', '233310', '233312', '233321', '233323', '233332', '300003', '300021', '300023', '300030', '300101', '300103', '300121', '300123', '300201', '300203', '300210', '300212', '300221', '300223', '300230', '300232', '300303', '300310', '300312', '300321', '300323', '300330', '301001', '301003', '301021', '301023', '301030', '301101', '301103', '301110', '301112', '301121', '301123', '301130', '301132', '301201', '301203', '301221', '301223', '301230', '301301', '301303', '301310', '301312', '301321', '301323', '301330', '301332', '302001', '302003', '302010', '302012', '302021', '302023', '302030', '302032', '302101', '302103', '302110', '302112', '302121', '302123', '302130', '302132', '302201', '302203', '302210', '302212', '302221', '302223', '302230', '302232', '302301', '302303', '302310', '302312', '302321', '302323', '302332', '303003', '303021', '303023', '303030', '303101', '303103', '303110', '303112', '303121', '303123', '303130', '303132', '303201', '303203', '303221', '303223', '303230', '303303', '303321', '303323', '303330', '310000', '310002', '310011', '310013', '310020', '310022', '310033', '310100', '310102', '310111', '310113', '310120', '310122', '310131', '310133', '310200', '310202', '310211', '310213', '310220', '310222', '310231', '310233', '310300', '310302', '310311', '310313', '310320', '310322', '310331', '311000', '311002', '311011', '311013', '311020', '311022', '311031', '311033', '311100', '311102', '311113', '311120', '311122', '311131', '311200', '311202', '311211', '311213', '311220', '311222', '311231', '311233', '311300', '311302', '311313', '311320', '311322', '311331', '312000', '312002', '312011', '312013', '312020', '312022', '312031', '312100', '312102', '312111', '312113', '312120', '312122', '312131', '312133', '312200', '312202', '312211', '312213', '312220', '312222', '312231', '312233', '312300', '312302', '312311', '312313', '312320', '312322', '312331', '312333', '313000', '313002', '313011', '313013', '313020', '313022', '313031', '313100', '313102', '313113', '313120', '313122', '313131', '313200', '313202', '313211', '313213', '313220', '313222', '313231', '313233', '313300', '313302', '313313', '313320', '313322', '313331', '320001', '320003', '320010', '320012', '320021', '320023', '320032', '320101', '320103', '320110', '320112', '320121', '320123', '320130', '320132', '320201', '320203', '320210', '320212', '320221', '320223', '320230', '320232', '320301', '320303', '320310', '320312', '320321', '320323', '320330', '321001', '321003', '321010', '321012', '321021', '321023', '321032', '321101', '321103', '321110', '321112', '321121', '321123', '321130', '321132', '321201', '321203', '321210', '321212', '321221', '321223', '321232', '321301', '321303', '321310', '321312', '321321', '321323', '321330', '321332', '322001', '322003', '322010', '322012', '322021', '322023', '322030', '322032', '322101', '322103', '322110', '322112', '322121', '322123', '322130', '322132', '322201', '322203', '322210', '322212', '322221', '322223', '322230', '322232', '322301', '322303', '322310', '322312', '322321', '322323', '322332', '323001', '323003', '323010', '323012', '323021', '323023', '323032', '323101', '323103', '323110', '323112', '323121', '323123', '323130', '323132', '323201', '323203', '323210', '323212', '323221', '323223', '323232', '323301', '323303', '323310', '323312', '323321', '323323', '323332', '330000', '330011', '330013', '330020', '330022', '330033', '330100', '330102', '330111', '330113', '330120', '330122', '330131', '330133', '330200', '330202', '330220', '330222', '330300', '330320', '330322', '330333', '331000', '331002', '331011', '331013', '331020', '331022', '331031', '331033', '331100', '331102', '331111', '331120', '331122', '331133', '331200', '331202', '331211', '331213', '331220', '331222', '331231', '331233', '331300', '331302', '331311', '331320', '331322', '331333', '332000', '332002', '332011', '332013', '332020', '332022', '332031', '332100', '332102', '332111', '332113', '332120', '332122', '332131', '332133', '332200', '332202', '332211', '332213', '332220', '332222', '332231', '332233', '332300', '332302', '332311', '332313', '332320', '332322', '332331', '332333', '333000', '333020', '333022', '333033', '333100', '333102', '333111', '333120', '333122', '333133', '333200', '333202', '333211', '333213', '333220', '333222', '333231', '333233', '333300', '333311', '333320', '333322', '333333'])
B = set(['000001', '000010', '000012', '000021', '000023', '000032', '000101', '000103', '000110', '000112', '000121', '000123', '000130', '000132', '000201', '000203', '000210', '000212', '000221', '000223', '000230', '000232', '000301', '000310', '000312', '000321', '000323', '000332', '001001', '001003', '001010', '001012', '001021', '001023', '001030', '001032', '001101', '001103', '001110', '001112', '001121', '001123', '001130', '001132', '001201', '001203', '001210', '001212', '001221', '001223', '001230', '001232', '001301', '001303', '001310', '001312', '001321', '001323', '001330', '001332', '002001', '002003', '002010', '002012', '002021', '002023', '002030', '002032', '002101', '002103', '002110', '002112', '002121', '002123', '002130', '002132', '002201', '002203', '002210', '002212', '002221', '002223', '002230', '002232', '002301', '002303', '002310', '002312', '002321', '002323', '002330', '002332', '003001', '003010', '003012', '003021', '003023', '003032', '003101', '003103', '003110', '003112', '003121', '003123', '003130', '003132', '003201', '003203', '003210', '003212', '003221', '003223', '003230', '003232', '003301', '003310', '003312', '003321', '003323', '003332', '010000', '010002', '010011', '010013', '010020', '010022', '010031', '010033', '010100', '010102', '010111', '010113', '010120', '010122', '010131', '010133', '010200', '010202', '010211', '010213', '010220', '010222', '010231', '010233', '010300', '010302', '010311', '010313', '010320', '010322', '010331', '010333', '011000', '011002', '011011', '011013', '011020', '011022', '011031', '011033', '011100', '011102', '011111', '011113', '011120', '011122', '011131', '011133', '011200', '011202', '011211', '011213', '011220', '011222', '011231', '011233', '011300', '011302', '011311', '011313', '011320', '011322', '011331', '011333', '012000', '012002', '012011', '012013', '012020', '012022', '012031', '012033', '012100', '012102', '012111', '012113', '012120', '012122', '012131', '012133', '012200', '012202', '012211', '012213', '012220', '012222', '012231', '012233', '012300', '012302', '012311', '012313', '012320', '012322', '012331', '012333', '013000', '013002', '013011', '013013', '013020', '013022', '013031', '013033', '013100', '013102', '013111', '013113', '013120', '013122', '013131', '013133', '013200', '013202', '013211', '013213', '013220', '013222', '013231', '013233', '013300', '013302', '013311', '013313', '013320', '013322', '013331', '013333', '020001', '020003', '020010', '020012', '020021', '020023', '020030', '020032', '020101', '020103', '020110', '020112', '020121', '020123', '020130', '020132', '020201', '020203', '020210', '020212', '020221', '020223', '020230', '020232', '020301', '020303', '020310', '020312', '020321', '020323', '020330', '020332', '021001', '021003', '021010', '021012', '021021', '021023', '021030', '021032', '021101', '021103', '021110', '021112', '021121', '021123', '021130', '021132', '021201', '021203', '021210', '021212', '021221', '021223', '021230', '021232', '021301', '021303', '021310', '021312', '021321', '021323', '021330', '021332', '022001', '022003', '022010', '022012', '022021', '022023', '022030', '022032', '022101', '022103', '022110', '022112', '022121', '022123', '022130', '022132', '022201', '022203', '022210', '022212', '022221', '022223', '022230', '022232', '022301', '022303', '022310', '022312', '022321', '022323', '022330', '022332', '023001', '023003', '023010', '023012', '023021', '023023', '023030', '023032', '023101', '023103', '023110', '023112', '023121', '023123', '023130', '023132', '023201', '023203', '023210', '023212', '023221', '023223', '023230', '023232', '023301', '023303', '023310', '023312', '023321', '023323', '023330', '023332', '030002', '030011', '030013', '030020', '030022', '030031', '030100', '030102', '030111', '030113', '030120', '030122', '030131', '030133', '030200', '030202', '030211', '030213', '030220', '030222', '030231', '030233', '030302', '030311', '030313', '030320', '030322', '030331', '031000', '031002', '031011', '031013', '031020', '031022', '031031', '031033', '031100', '031102', '031111', '031113', '031120', '031122', '031131', '031133', '031200', '031202', '031211', '031213', '031220', '031222', '031231', '031233', '031300', '031302', '031311', '031313', '031320', '031322', '031331', '031333', '032000', '032002', '032011', '032013', '032020', '032022', '032031', '032033', '032100', '032102', '032111', '032113', '032120', '032122', '032131', '032133', '032200', '032202', '032211', '032213', '032220', '032222', '032231', '032233', '032300', '032302', '032311', '032313', '032320', '032322', '032331', '032333', '033002', '033011', '033013', '033020', '033022', '033031', '033100', '033102', '033111', '033113', '033120', '033122', '033131', '033133', '033200', '033202', '033211', '033213', '033220', '033222', '033231', '033233', '033302', '033311', '033313', '033320', '033322', '033331', '100000', '100002', '100011', '100013', '100020', '100022', '100031', '100033', '100100', '100102', '100111', '100113', '100120', '100122', '100131', '100133', '100200', '100202', '100211', '100213', '100220', '100222', '100231', '100233', '100300', '100302', '100311', '100313', '100320', '100322', '100331', '100333', '101000', '101002', '101011', '101013', '101020', '101022', '101031', '101033', '101100', '101102', '101111', '101113', '101120', '101122', '101131', '101133', '101200', '101202', '101211', '101213', '101220', '101222', '101231', '101233', '101300', '101302', '101311', '101313', '101320', '101322', '101331', '101333', '102000', '102002', '102011', '102013', '102020', '102022', '102031', '102033', '102100', '102102', '102111', '102113', '102120', '102122', '102131', '102133', '102200', '102202', '102211', '102213', '102220', '102222', '102231', '102233', '102300', '102302', '102311', '102313', '102320', '102322', '102331', '102333', '103000', '103002', '103011', '103013', '103020', '103022', '103031', '103033', '103100', '103102', '103111', '103113', '103120', '103122', '103131', '103133', '103200', '103202', '103211', '103213', '103220', '103222', '103231', '103233', '103300', '103302', '103311', '103313', '103320', '103322', '103331', '103333', '110001', '110003', '110010', '110012', '110021', '110023', '110030', '110032', '110101', '110103', '110110', '110112', '110121', '110123', '110130', '110132', '110201', '110203', '110210', '110212', '110221', '110223', '110230', '110232', '110301', '110303', '110310', '110312', '110321', '110323', '110330', '110332', '111001', '111003', '111010', '111012', '111021', '111023', '111030', '111032', '111101', '111103', '111110', '111112', '111121', '111123', '111130', '111132', '111201', '111203', '111210', '111212', '111221', '111223', '111230', '111232', '111301', '111303', '111310', '111312', '111321', '111323', '111330', '111332', '112001', '112003', '112010', '112012', '112021', '112023', '112030', '112032', '112101', '112103', '112110', '112112', '112121', '112123', '112130', '112132', '112201', '112203', '112210', '112212', '112221', '112223', '112230', '112232', '112301', '112303', '112310', '112312', '112321', '112323', '112330', '112332', '113001', '113003', '113010', '113012', '113021', '113023', '113030', '113032', '113101', '113103', '113110', '113112', '113121', '113123', '113130', '113132', '113201', '113203', '113210', '113212', '113221', '113223', '113230', '113232', '113301', '113303', '113310', '113312', '113321', '113323', '113330', '113332', '120000', '120002', '120011', '120013', '120020', '120022', '120031', '120033', '120100', '120102', '120111', '120113', '120120', '120122', '120131', '120133', '120200', '120202', '120211', '120213', '120220', '120222', '120231', '120233', '120300', '120302', '120311', '120313', '120320', '120322', '120331', '120333', '121000', '121002', '121011', '121013', '121020', '121022', '121031', '121033', '121100', '121102', '121111', '121113', '121120', '121122', '121131', '121133', '121200', '121202', '121211', '121213', '121220', '121222', '121231', '121233', '121300', '121302', '121311', '121313', '121320', '121322', '121331', '121333', '122000', '122002', '122011', '122013', '122020', '122022', '122031', '122033', '122100', '122102', '122111', '122113', '122120', '122122', '122131', '122133', '122200', '122202', '122211', '122213', '122220', '122222', '122231', '122233', '122300', '122302', '122311', '122313', '122320', '122322', '122331', '122333', '123000', '123002', '123011', '123013', '123020', '123022', '123031', '123033', '123100', '123102', '123111', '123113', '123120', '123122', '123131', '123133', '123200', '123202', '123211', '123213', '123220', '123222', '123231', '123233', '123300', '123302', '123311', '123313', '123320', '123322', '123331', '123333', '130001', '130003', '130010', '130012', '130021', '130023', '130030', '130032', '130101', '130103', '130110', '130112', '130121', '130123', '130130', '130132', '130201', '130203', '130210', '130212', '130221', '130223', '130230', '130232', '130301', '130303', '130310', '130312', '130321', '130323', '130330', '130332', '131001', '131003', '131010', '131012', '131021', '131023', '131030', '131032', '131101', '131103', '131110', '131112', '131121', '131123', '131130', '131132', '131201', '131203', '131210', '131212', '131221', '131223', '131230', '131232', '131301', '131303', '131310', '131312', '131321', '131323', '131330', '131332', '132001', '132003', '132010', '132012', '132021', '132023', '132030', '132032', '132101', '132103', '132110', '132112', '132121', '132123', '132130', '132132', '132201', '132203', '132210', '132212', '132221', '132223', '132230', '132232', '132301', '132303', '132310', '132312', '132321', '132323', '132330', '132332', '133001', '133003', '133010', '133012', '133021', '133023', '133030', '133032', '133101', '133103', '133110', '133112', '133121', '133123', '133130', '133132', '133201', '133203', '133210', '133212', '133221', '133223', '133230', '133232', '133301', '133303', '133310', '133312', '133321', '133323', '133330', '133332', '200001', '200003', '200010', '200012', '200021', '200023', '200030', '200032', '200101', '200103', '200110', '200112', '200121', '200123', '200130', '200132', '200201', '200203', '200210', '200212', '200221', '200223', '200230', '200232', '200301', '200303', '200310', '200312', '200321', '200323', '200330', '200332', '201001', '201003', '201010', '201012', '201021', '201023', '201030', '201032', '201101', '201103', '201110', '201112', '201121', '201123', '201130', '201132', '201201', '201203', '201210', '201212', '201221', '201223', '201230', '201232', '201301', '201303', '201310', '201312', '201321', '201323', '201330', '201332', '202001', '202003', '202010', '202012', '202021', '202023', '202030', '202032', '202101', '202103', '202110', '202112', '202121', '202123', '202130', '202132', '202201', '202203', '202210', '202212', '202221', '202223', '202230', '202232', '202301', '202303', '202310', '202312', '202321', '202323', '202330', '202332', '203001', '203003', '203010', '203012', '203021', '203023', '203030', '203032', '203101', '203103', '203110', '203112', '203121', '203123', '203130', '203132', '203201', '203203', '203210', '203212', '203221', '203223', '203230', '203232', '203301', '203303', '203310', '203312', '203321', '203323', '203330', '203332', '210000', '210002', '210011', '210013', '210020', '210022', '210031', '210033', '210100', '210102', '210111', '210113', '210120', '210122', '210131', '210133', '210200', '210202', '210211', '210213', '210220', '210222', '210231', '210233', '210300', '210302', '210311', '210313', '210320', '210322', '210331', '210333', '211000', '211002', '211011', '211013', '211020', '211022', '211031', '211033', '211100', '211102', '211111', '211113', '211120', '211122', '211131', '211133', '211200', '211202', '211211', '211213', '211220', '211222', '211231', '211233', '211300', '211302', '211311', '211313', '211320', '211322', '211331', '211333', '212000', '212002', '212011', '212013', '212020', '212022', '212031', '212033', '212100', '212102', '212111', '212113', '212120', '212122', '212131', '212133', '212200', '212202', '212211', '212213', '212220', '212222', '212231', '212233', '212300', '212302', '212311', '212313', '212320', '212322', '212331', '212333', '213000', '213002', '213011', '213013', '213020', '213022', '213031', '213033', '213100', '213102', '213111', '213113', '213120', '213122', '213131', '213133', '213200', '213202', '213211', '213213', '213220', '213222', '213231', '213233', '213300', '213302', '213311', '213313', '213320', '213322', '213331', '213333', '220001', '220003', '220010', '220012', '220021', '220023', '220030', '220032', '220101', '220103', '220110', '220112', '220121', '220123', '220130', '220132', '220201', '220203', '220210', '220212', '220221', '220223', '220230', '220232', '220301', '220303', '220310', '220312', '220321', '220323', '220330', '220332', '221001', '221003', '221010', '221012', '221021', '221023', '221030', '221032', '221101', '221103', '221110', '221112', '221121', '221123', '221130', '221132', '221201', '221203', '221210', '221212', '221221', '221223', '221230', '221232', '221301', '221303', '221310', '221312', '221321', '221323', '221330', '221332', '222001', '222003', '222010', '222012', '222021', '222023', '222030', '222032', '222101', '222103', '222110', '222112', '222121', '222123', '222130', '222132', '222201', '222203', '222210', '222212', '222221', '222223', '222230', '222232', '222301', '222303', '222310', '222312', '222321', '222323', '222330', '222332', '223001', '223003', '223010', '223012', '223021', '223023', '223030', '223032', '223101', '223103', '223110', '223112', '223121', '223123', '223130', '223132', '223201', '223203', '223210', '223212', '223221', '223223', '223230', '223232', '223301', '223303', '223310', '223312', '223321', '223323', '223330', '223332', '230000', '230002', '230011', '230013', '230020', '230022', '230031', '230033', '230100', '230102', '230111', '230113', '230120', '230122', '230131', '230133', '230200', '230202', '230211', '230213', '230220', '230222', '230231', '230233', '230300', '230302', '230311', '230313', '230320', '230322', '230331', '230333', '231000', '231002', '231011', '231013', '231020', '231022', '231031', '231033', '231100', '231102', '231111', '231113', '231120', '231122', '231131', '231133', '231200', '231202', '231211', '231213', '231220', '231222', '231231', '231233', '231300', '231302', '231311', '231313', '231320', '231322', '231331', '231333', '232000', '232002', '232011', '232013', '232020', '232022', '232031', '232033', '232100', '232102', '232111', '232113', '232120', '232122', '232131', '232133', '232200', '232202', '232211', '232213', '232220', '232222', '232231', '232233', '232300', '232302', '232311', '232313', '232320', '232322', '232331', '232333', '233000', '233002', '233011', '233013', '233020', '233022', '233031', '233033', '233100', '233102', '233111', '233113', '233120', '233122', '233131', '233133', '233200', '233202', '233211', '233213', '233220', '233222', '233231', '233233', '233300', '233302', '233311', '233313', '233320', '233322', '233331', '233333', '300002', '300011', '300013', '300020', '300022', '300031', '300100', '300102', '300111', '300113', '300120', '300122', '300131', '300133', '300200', '300202', '300211', '300213', '300220', '300222', '300231', '300233', '300302', '300311', '300313', '300320', '300322', '300331', '301000', '301002', '301011', '301013', '301020', '301022', '301031', '301033', '301100', '301102', '301111', '301113', '301120', '301122', '301131', '301133', '301200', '301202', '301211', '301213', '301220', '301222', '301231', '301233', '301300', '301302', '301311', '301313', '301320', '301322', '301331', '301333', '302000', '302002', '302011', '302013', '302020', '302022', '302031', '302033', '302100', '302102', '302111', '302113', '302120', '302122', '302131', '302133', '302200', '302202', '302211', '302213', '302220', '302222', '302231', '302233', '302300', '302302', '302311', '302313', '302320', '302322', '302331', '302333', '303002', '303011', '303013', '303020', '303022', '303031', '303100', '303102', '303111', '303113', '303120', '303122', '303131', '303133', '303200', '303202', '303211', '303213', '303220', '303222', '303231', '303233', '303302', '303311', '303313', '303320', '303322', '303331', '310001', '310003', '310010', '310012', '310021', '310023', '310030', '310032', '310101', '310103', '310110', '310112', '310121', '310123', '310130', '310132', '310201', '310203', '310210', '310212', '310221', '310223', '310230', '310232', '310301', '310303', '310310', '310312', '310321', '310323', '310330', '310332', '311001', '311003', '311010', '311012', '311021', '311023', '311030', '311032', '311101', '311103', '311110', '311112', '311121', '311123', '311130', '311132', '311201', '311203', '311210', '311212', '311221', '311223', '311230', '311232', '311301', '311303', '311310', '311312', '311321', '311323', '311330', '311332', '312001', '312003', '312010', '312012', '312021', '312023', '312030', '312032', '312101', '312103', '312110', '312112', '312121', '312123', '312130', '312132', '312201', '312203', '312210', '312212', '312221', '312223', '312230', '312232', '312301', '312303', '312310', '312312', '312321', '312323', '312330', '312332', '313001', '313003', '313010', '313012', '313021', '313023', '313030', '313032', '313101', '313103', '313110', '313112', '313121', '313123', '313130', '313132', '313201', '313203', '313210', '313212', '313221', '313223', '313230', '313232', '313301', '313303', '313310', '313312', '313321', '313323', '313330', '313332', '320000', '320002', '320011', '320013', '320020', '320022', '320031', '320033', '320100', '320102', '320111', '320113', '320120', '320122', '320131', '320133', '320200', '320202', '320211', '320213', '320220', '320222', '320231', '320233', '320300', '320302', '320311', '320313', '320320', '320322', '320331', '320333', '321000', '321002', '321011', '321013', '321020', '321022', '321031', '321033', '321100', '321102', '321111', '321113', '321120', '321122', '321131', '321133', '321200', '321202', '321211', '321213', '321220', '321222', '321231', '321233', '321300', '321302', '321311', '321313', '321320', '321322', '321331', '321333', '322000', '322002', '322011', '322013', '322020', '322022', '322031', '322033', '322100', '322102', '322111', '322113', '322120', '322122', '322131', '322133', '322200', '322202', '322211', '322213', '322220', '322222', '322231', '322233', '322300', '322302', '322311', '322313', '322320', '322322', '322331', '322333', '323000', '323002', '323011', '323013', '323020', '323022', '323031', '323033', '323100', '323102', '323111', '323113', '323120', '323122', '323131', '323133', '323200', '323202', '323211', '323213', '323220', '323222', '323231', '323233', '323300', '323302', '323311', '323313', '323320', '323322', '323331', '323333', '330001', '330010', '330012', '330021', '330023', '330032', '330101', '330103', '330110', '330112', '330121', '330123', '330130', '330132', '330201', '330203', '330210', '330212', '330221', '330223', '330230', '330232', '330301', '330310', '330312', '330321', '330323', '330332', '331001', '331003', '331010', '331012', '331021', '331023', '331030', '331032', '331101', '331103', '331110', '331112', '331121', '331123', '331130', '331132', '331201', '331203', '331210', '331212', '331221', '331223', '331230', '331232', '331301', '331303', '331310', '331312', '331321', '331323', '331330', '331332', '332001', '332003', '332010', '332012', '332021', '332023', '332030', '332032', '332101', '332103', '332110', '332112', '332121', '332123', '332130', '332132', '332201', '332203', '332210', '332212', '332221', '332223', '332230', '332232', '332301', '332303', '332310', '332312', '332321', '332323', '332330', '332332', '333001', '333010', '333012', '333021', '333023', '333032', '333101', '333103', '333110', '333112', '333121', '333123', '333130', '333132', '333201', '333203', '333210', '333212', '333221', '333223', '333230', '333232', '333301', '333310', '333312', '333321', '333323', '333332'])
C = set(['000002', '000020', '000031', '000202', '000220', '000302', '000320', '000322', '000331', '001300', '002002', '002020', '002202', '002220', '003002', '003020', '003022', '003031', '003100', '003102', '003120', '003122', '003302', '003331', '010003', '010103', '010303', '011003', '012103', '012303', '013001', '013303', '020000', '020022', '020200', '020222', '020300', '021300', '022000', '022022', '022200', '022222', '023000', '023302', '030001', '030021', '030023', '030032', '030101', '030121', '030123', '030301', '030321', '030323', '030332', '031003', '032101', '032121', '032123', '032301', '032321', '032323', '033001', '033032', '033201', '033203', '033221', '033223', '033301', '033321', '033323', '033332', '100003', '100030', '100303', '100310', '100312', '100330', '101030', '101230', '102330', '103003', '103030', '103230', '103303', '103330', '110031', '110333', '111113', '111131', '111313', '111331', '112033', '113033', '113113', '113131', '113313', '113331', '120030', '120332', '121030', '121230', '122330', '123030', '123230', '123330', '130000', '130011', '130013', '130033', '130300', '130333', '131111', '131133', '131311', '131333', '132033', '133000', '133033', '133111', '133133', '133300', '133311', '133333', '200000', '200022', '200033', '200200', '200222', '200300', '200333', '201300', '202000', '202022', '202200', '202222', '203000', '203033', '203300', '203320', '203322', '203333', '210003', '210103', '210303', '211003', '212103', '212303', '213001', '213303', '220002', '220020', '220202', '220220', '220300', '221300', '222002', '222020', '222202', '222220', '223000', '223302', '230003', '230030', '230103', '230303', '230330', '231003', '232103', '232303', '233003', '233021', '233023', '233030', '233303', '233330', '300001', '300010', '300012', '300032', '300110', '300112', '300130', '300132', '300301', '300332', '301010', '301012', '301032', '301210', '301212', '301232', '302330', '303001', '303010', '303012', '303032', '303210', '303212', '303232', '303301', '303310', '303312', '303332', '310031', '310333', '311111', '311133', '311311', '311333', '312033', '313033', '313111', '313133', '313311', '313333', '320030', '320332', '321030', '321230', '322330', '323030', '323230', '323330', '330002', '330031', '330211', '330213', '330231', '330233', '330302', '330311', '330313', '330331', '331113', '331131', '331313', '331331', '332033', '333002', '333011', '333013', '333031', '333113', '333131', '333302', '333313', '333331'])

def six(s):
    x = ''
    for p in range(len(s)-5):
        t = s[p:5]
        if t in A:
            x += '0'
        elif t in B:
            x += '1'
        else:
            x += '2'
    return x
    
def five(s):
    x = ''
    for p in range(len(s)-1):
        x += str(abs(int(s[p])-int(s[p+1])))
    return x
    
N = int(input())
s = input()
    
while len(s) != 1:
    if len(s) >= 6:
        s = six(s)
    else:
        s = five(s)
            
print(s)