{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":44075,"title":"GJam 2017 Kickstart: Parentheses (Large)","description":"This Challenge is derived from \u003chttp://code.google.com/codejam/contest/6304486/dashboard#s=p2 GJam 2017 Kickstart Parentheses\u003e. This is the first 100 large cases with  1\u003c=L+R\u003c=10^5.\r\n\r\n\u003chttp://code.google.com/codejam Google Code Jam 2017 Qualifier\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\r\n\r\nThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\r\n\r\n*Input:* [L,R], the quantity of parentheses types\r\n\r\n*Output:* [V], the maximum number of parentheses pairings\r\n\r\n*Examples:* [L,R] [V]; [3,2] [3]\r\n\r\nFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\r\n\r\n*Theory:* Brute force permutations and counting will not succeed in a timely manner for L+R=10^5. Determining the inherent mathematical pattern is usually the best way to succeed in GJam.   \u003chttp://code.google.com/codejam/contest/6304486/scoreboard#vf=1 GJam Kickstart solutions(C++,Python)\u003e. ","description_html":"\u003cp\u003eThis Challenge is derived from \u003ca href = \"http://code.google.com/codejam/contest/6304486/dashboard#s=p2\"\u003eGJam 2017 Kickstart Parentheses\u003c/a\u003e. This is the first 100 large cases with  1\u0026lt;=L+R\u0026lt;=10^5.\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://code.google.com/codejam\"\u003eGoogle Code Jam 2017 Qualifier\u003c/a\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\u003c/p\u003e\u003cp\u003eThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e [L,R], the quantity of parentheses types\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e [V], the maximum number of parentheses pairings\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples:\u003c/b\u003e [L,R] [V]; [3,2] [3]\u003c/p\u003e\u003cp\u003eFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\u003c/p\u003e\u003cp\u003e\u003cb\u003eTheory:\u003c/b\u003e Brute force permutations and counting will not succeed in a timely manner for L+R=10^5. Determining the inherent mathematical pattern is usually the best way to succeed in GJam.   \u003ca href = \"http://code.google.com/codejam/contest/6304486/scoreboard#vf=1\"\u003eGJam Kickstart solutions(C++,Python)\u003c/a\u003e.\u003c/p\u003e","function_template":"function val=parenc(L,R)\r\n% L number of Left parentheses, R number of Right parentheses \r\n% Determine maxinum number of parenthese pairings\r\n% http://code.google.com/codejam/contest/6304486/dashboard#s=p2\r\n\r\nval=0;\r\n \r\nend","test_suite":"%%\r\nv=parenc(36499,40104);\r\nassert(~isempty(v))\r\nassert(v==666106750)\r\n%%\r\nv=parenc(75814,21934);\r\nassert(~isempty(v))\r\nassert(v==240561145)\r\n%%\r\nv=parenc(88684,2943);\r\nassert(~isempty(v))\r\nassert(v==4332096)\r\n%%\r\nv=parenc(63688,19182);\r\nassert(~isempty(v))\r\nassert(v==183984153)\r\n%%\r\nv=parenc(71034,19757);\r\nassert(~isempty(v))\r\nassert(v==195179403)\r\n%%\r\nv=parenc(95210,572);\r\nassert(~isempty(v))\r\nassert(v==163878)\r\n%%\r\nv=parenc(50000,50000);\r\nassert(~isempty(v))\r\nassert(v==1250025000)\r\n%%\r\nv=parenc(37583,54023);\r\nassert(~isempty(v))\r\nassert(v==706259736)\r\n%%\r\nv=parenc(13403,50583);\r\nassert(~isempty(v))\r\nassert(v==89826906)\r\n%%\r\nv=parenc(74324,16176);\r\nassert(~isempty(v))\r\nassert(v==130839576)\r\n%%\r\nv=parenc(95662,20);\r\nassert(~isempty(v))\r\nassert(v==210)\r\n%%\r\nv=parenc(84426,8859);\r\nassert(~isempty(v))\r\nassert(v==39245370)\r\n%%\r\nv=parenc(1764,75732);\r\nassert(~isempty(v))\r\nassert(v==1556730)\r\n%%\r\nv=parenc(75135,17355);\r\nassert(~isempty(v))\r\nassert(v==150606690)\r\n%%\r\nv=parenc(16014,48995);\r\nassert(~isempty(v))\r\nassert(v==128232105)\r\n%%\r\nv=parenc(100000,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(90812,5679);\r\nassert(~isempty(v))\r\nassert(v==16128360)\r\n%%\r\nv=parenc(55860,34690);\r\nassert(~isempty(v))\r\nassert(v==601715395)\r\n%%\r\nv=parenc(82678,16936);\r\nassert(~isempty(v))\r\nassert(v==143422516)\r\n%%\r\nv=parenc(50696,22228);\r\nassert(~isempty(v))\r\nassert(v==247053106)\r\n%%\r\nv=parenc(60183,19425);\r\nassert(~isempty(v))\r\nassert(v==188675025)\r\n%%\r\nv=parenc(88288,3180);\r\nassert(~isempty(v))\r\nassert(v==5057790)\r\n%%\r\nv=parenc(18628,32214);\r\nassert(~isempty(v))\r\nassert(v==173510506)\r\n%%\r\nv=parenc(99681,195);\r\nassert(~isempty(v))\r\nassert(v==19110)\r\n%%\r\nv=parenc(7,13);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(62367,35577);\r\nassert(~isempty(v))\r\nassert(v==632879253)\r\n%%\r\nv=parenc(54171,29950);\r\nassert(~isempty(v))\r\nassert(v==448516225)\r\n%%\r\nv=parenc(22417,8626);\r\nassert(~isempty(v))\r\nassert(v==37208251)\r\n%%\r\nv=parenc(37824,9490);\r\nassert(~isempty(v))\r\nassert(v==45034795)\r\n%%\r\nv=parenc(95981,624);\r\nassert(~isempty(v))\r\nassert(v==195000)\r\n%%\r\nv=parenc(57025,7699);\r\nassert(~isempty(v))\r\nassert(v==29641150)\r\n%%\r\nv=parenc(1,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(16007,35971);\r\nassert(~isempty(v))\r\nassert(v==128120028)\r\n%%\r\nv=parenc(2306,52078);\r\nassert(~isempty(v))\r\nassert(v==2659971)\r\n%%\r\nv=parenc(70555,4927);\r\nassert(~isempty(v))\r\nassert(v==12140128)\r\n%%\r\nv=parenc(19454,63092);\r\nassert(~isempty(v))\r\nassert(v==189238785)\r\n%%\r\nv=parenc(73352,18081);\r\nassert(~isempty(v))\r\nassert(v==163470321)\r\n%%\r\nv=parenc(71344,18591);\r\nassert(~isempty(v))\r\nassert(v==172821936)\r\n%%\r\nv=parenc(76452,13351);\r\nassert(~isempty(v))\r\nassert(v==89131276)\r\n%%\r\nv=parenc(88885,3106);\r\nassert(~isempty(v))\r\nassert(v==4825171)\r\n%%\r\nv=parenc(53619,9977);\r\nassert(~isempty(v))\r\nassert(v==49775253)\r\n%%\r\nv=parenc(39466,15681);\r\nassert(~isempty(v))\r\nassert(v==122954721)\r\n%%\r\nv=parenc(33791,51813);\r\nassert(~isempty(v))\r\nassert(v==570932736)\r\n%%\r\nv=parenc(40408,42624);\r\nassert(~isempty(v))\r\nassert(v==816423436)\r\n%%\r\nv=parenc(998,12);\r\nassert(~isempty(v))\r\nassert(v==78)\r\n%%\r\nv=parenc(58818,23613);\r\nassert(~isempty(v))\r\nassert(v==278798691)\r\n%%\r\nv=parenc(82533,6389);\r\nassert(~isempty(v))\r\nassert(v==20412855)\r\n%%\r\nv=parenc(73823,18704);\r\nassert(~isempty(v))\r\nassert(v==174929160)\r\n%%\r\nv=parenc(24046,69819);\r\nassert(~isempty(v))\r\nassert(v==289117081)\r\n%%\r\nv=parenc(83603,2337);\r\nassert(~isempty(v))\r\nassert(v==2731953)\r\n%%\r\nv=parenc(95719,1658);\r\nassert(~isempty(v))\r\nassert(v==1375311)\r\n%%\r\nv=parenc(9,11);\r\nassert(~isempty(v))\r\nassert(v==45)\r\n%%\r\nv=parenc(29910,7601);\r\nassert(~isempty(v))\r\nassert(v==28891401)\r\n%%\r\nv=parenc(59540,36291);\r\nassert(~isempty(v))\r\nassert(v==658536486)\r\n%%\r\nv=parenc(45871,53970);\r\nassert(~isempty(v))\r\nassert(v==1052097256)\r\n%%\r\nv=parenc(92763,325);\r\nassert(~isempty(v))\r\nassert(v==52975)\r\n%%\r\nv=parenc(9038,44798);\r\nassert(~isempty(v))\r\nassert(v==40847241)\r\n%%\r\nv=parenc(1,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(86549,6287);\r\nassert(~isempty(v))\r\nassert(v==19766328)\r\n%%\r\nv=parenc(14401,46864);\r\nassert(~isempty(v))\r\nassert(v==103701601)\r\n%%\r\nv=parenc(93424,6259);\r\nassert(~isempty(v))\r\nassert(v==19590670)\r\n%%\r\nv=parenc(52933,31692);\r\nassert(~isempty(v))\r\nassert(v==502207278)\r\n%%\r\nv=parenc(91388,2050);\r\nassert(~isempty(v))\r\nassert(v==2102275)\r\n%%\r\nv=parenc(83487,14454);\r\nassert(~isempty(v))\r\nassert(v==104466285)\r\n%%\r\nv=parenc(26996,20778);\r\nassert(~isempty(v))\r\nassert(v==215873031)\r\n%%\r\nv=parenc(88436,1856);\r\nassert(~isempty(v))\r\nassert(v==1723296)\r\n%%\r\nv=parenc(52967,22634);\r\nassert(~isempty(v))\r\nassert(v==256160295)\r\n%%\r\nv=parenc(24373,71635);\r\nassert(~isempty(v))\r\nassert(v==297033751)\r\n%%\r\nv=parenc(25964,41310);\r\nassert(~isempty(v))\r\nassert(v==337077630)\r\n%%\r\nv=parenc(89807,7750);\r\nassert(~isempty(v))\r\nassert(v==30035125)\r\n%%\r\nv=parenc(84029,12987);\r\nassert(~isempty(v))\r\nassert(v==84337578)\r\n%%\r\nv=parenc(23884,41559);\r\nassert(~isempty(v))\r\nassert(v==285234670)\r\n%%\r\nv=parenc(96652,1790);\r\nassert(~isempty(v))\r\nassert(v==1602945)\r\n%%\r\nv=parenc(72470,2981);\r\nassert(~isempty(v))\r\nassert(v==4444671)\r\n%%\r\nv=parenc(51157,44196);\r\nassert(~isempty(v))\r\nassert(v==976665306)\r\n%%\r\nv=parenc(5964,125);\r\nassert(~isempty(v))\r\nassert(v==7875)\r\n%%\r\nv=parenc(5011,79606);\r\nassert(~isempty(v))\r\nassert(v==12557566)\r\n%%\r\nv=parenc(54850,32315);\r\nassert(~isempty(v))\r\nassert(v==522145770)\r\n%%\r\nv=parenc(94427,666);\r\nassert(~isempty(v))\r\nassert(v==222111)\r\n%%\r\nv=parenc(61766,28774);\r\nassert(~isempty(v))\r\nassert(v==413985925)\r\n%%\r\nv=parenc(90805,8083);\r\nassert(~isempty(v))\r\nassert(v==32671486)\r\n%%\r\nv=parenc(50250,34260);\r\nassert(~isempty(v))\r\nassert(v==586890930)\r\n%%\r\nv=parenc(59514,16501);\r\nassert(~isempty(v))\r\nassert(v==136149751)\r\n%%\r\nv=parenc(21448,21340);\r\nassert(~isempty(v))\r\nassert(v==227708470)\r\n%%\r\nv=parenc(48294,20183);\r\nassert(~isempty(v))\r\nassert(v==203686836)\r\n%%\r\nv=parenc(0,100000);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(0,1);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(9321,9795);\r\nassert(~isempty(v))\r\nassert(v==43445181)\r\n%%\r\nv=parenc(33373,207);\r\nassert(~isempty(v))\r\nassert(v==21528)\r\n%%\r\nv=parenc(78080,18989);\r\nassert(~isempty(v))\r\nassert(v==180300555)\r\n%%\r\nv=parenc(89341,7009);\r\nassert(~isempty(v))\r\nassert(v==24566545)\r\n%%\r\nv=parenc(0,2);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(2,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(90124,7716);\r\nassert(~isempty(v))\r\nassert(v==29772186)\r\n%%\r\nv=parenc(36611,12311);\r\nassert(~isempty(v))\r\nassert(v==75786516)\r\n%%\r\nv=parenc(45498,3564);\r\nassert(~isempty(v))\r\nassert(v==6352830)\r\n%%\r\nv=parenc(28355,23958);\r\nassert(~isempty(v))\r\nassert(v==287004861)\r\n%%\r\nv=parenc(58516,24422);\r\nassert(~isempty(v))\r\nassert(v==298229253)\r\n%%\r\nv=parenc(42157,56858);\r\nassert(~isempty(v))\r\nassert(v==888627403)\r\n%%\r\nv=parenc(32854,55517);\r\nassert(~isempty(v))\r\nassert(v==539709085)\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-02-25T22:17:05.000Z","updated_at":"2026-03-24T12:06:44.000Z","published_at":"2017-02-25T22:18:40.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/6304486/dashboard#s=p2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2017 Kickstart Parentheses\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This is the first 100 large cases with 1\u0026lt;=L+R\u0026lt;=10^5.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGoogle Code Jam 2017 Qualifier\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [L,R], the quantity of parentheses types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [V], the maximum number of parentheses pairings\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [L,R] [V]; [3,2] [3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTheory:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Brute force permutations and counting will not succeed in a timely manner for L+R=10^5. Determining the inherent mathematical pattern is usually the best way to succeed in GJam. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/6304486/scoreboard#vf=1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Kickstart solutions(C++,Python)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44074,"title":"GJam 2017 Kickstart: Parentheses (Small)","description":"This Challenge is derived from \u003chttp://code.google.com/codejam/contest/6304486/dashboard#s=p2 GJam 2017 Kickstart Parentheses\u003e. This is the first 100 small cases with max L+R\u003c=20.\r\n\r\n\u003chttp://code.google.com/codejam Google Code Jam 2017 Qualifier\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\r\n\r\nThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\r\n\r\n*Input:* [L,R], the quantity of parentheses types\r\n\r\n*Output:* [V], the maximum number of parentheses pairings\r\n\r\n*Examples:* [L,R] [V]; [3,2] [3]\r\n\r\nFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\r\n\r\n*Theory:* Brute force permutations and counting will not succeed in a timely manner for L+R=20. Determining the inherent mathematical pattern is usually the best way to succeed in GJam.   \u003chttp://code.google.com/codejam/contest/6304486/scoreboard#vf=1 GJam Kickstart solutions(C++,Python)\u003e. ","description_html":"\u003cp\u003eThis Challenge is derived from \u003ca href = \"http://code.google.com/codejam/contest/6304486/dashboard#s=p2\"\u003eGJam 2017 Kickstart Parentheses\u003c/a\u003e. This is the first 100 small cases with max L+R\u0026lt;=20.\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://code.google.com/codejam\"\u003eGoogle Code Jam 2017 Qualifier\u003c/a\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\u003c/p\u003e\u003cp\u003eThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e [L,R], the quantity of parentheses types\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e [V], the maximum number of parentheses pairings\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples:\u003c/b\u003e [L,R] [V]; [3,2] [3]\u003c/p\u003e\u003cp\u003eFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\u003c/p\u003e\u003cp\u003e\u003cb\u003eTheory:\u003c/b\u003e Brute force permutations and counting will not succeed in a timely manner for L+R=20. Determining the inherent mathematical pattern is usually the best way to succeed in GJam.   \u003ca href = \"http://code.google.com/codejam/contest/6304486/scoreboard#vf=1\"\u003eGJam Kickstart solutions(C++,Python)\u003c/a\u003e.\u003c/p\u003e","function_template":"function val=parenc(L,R)\r\n% L number of Left parentheses, R number of Right parentheses \r\n% Determine maxinum number of parenthese pairings\r\n% http://code.google.com/codejam/contest/6304486/dashboard#s=p2\r\n\r\nval=0;\r\n \r\nend","test_suite":"%%\r\nv=parenc(19,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(14,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(4,15);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(8,6);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(14,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(10,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(10,10);\r\nassert(~isempty(v))\r\nassert(v==55)\r\n%%\r\nv=parenc(3,7);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(3,13);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(4,12);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(2,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(6,11);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(4,12);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(15,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(14,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(20,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(12,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(0,10);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(18,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(16,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(3,12);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(8,12);\r\nassert(~isempty(v))\r\nassert(v==36)\r\n%%\r\nv=parenc(8,6);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(1,8);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(7,13);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(7,6);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(11,8);\r\nassert(~isempty(v))\r\nassert(v==36)\r\n%%\r\nv=parenc(17,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(4,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(1,6);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(5,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(1,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(7,13);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(6,12);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(15,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(14,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(12,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(4,15);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(12,7);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(5,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(19,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(6,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(11,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(8,12);\r\nassert(~isempty(v))\r\nassert(v==36)\r\n%%\r\nv=parenc(18,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(18,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(13,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(3,6);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(6,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(3,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(19,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(9,11);\r\nassert(~isempty(v))\r\nassert(v==45)\r\n%%\r\nv=parenc(10,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(0,11);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(11,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(3,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(18,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(1,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(9,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(1,19);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(4,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(13,7);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(8,6);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(7,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(16,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(16,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(7,8);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(13,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(4,14);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(7,8);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(9,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(4,7);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(12,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(10,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(17,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(4,13);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(11,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(10,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(7,7);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(6,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(5,13);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(10,10);\r\nassert(~isempty(v))\r\nassert(v==55)\r\n%%\r\nv=parenc(14,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(8,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(14,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(0,20);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(0,1);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(1,10);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(13,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(0,9);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(1,17);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(0,2);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(2,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(4,12);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(11,9);\r\nassert(~isempty(v))\r\nassert(v==45)\r\n%%\r\nv=parenc(18,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(15,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(16,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(17,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(14,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-02-25T21:52:46.000Z","updated_at":"2026-01-02T17:52:37.000Z","published_at":"2017-02-25T22:07:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/6304486/dashboard#s=p2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2017 Kickstart Parentheses\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This is the first 100 small cases with max L+R\u0026lt;=20.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGoogle Code Jam 2017 Qualifier\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [L,R], the quantity of parentheses types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [V], the maximum number of parentheses pairings\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [L,R] [V]; [3,2] [3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTheory:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Brute force permutations and counting will not succeed in a timely manner for L+R=20. Determining the inherent mathematical pattern is usually the best way to succeed in GJam. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/6304486/scoreboard#vf=1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Kickstart solutions(C++,Python)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":47838,"title":"Count the ways pairs of parentheses can be matched correctly","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 145.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 72.7167px; transform-origin: 407px 72.7167px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 370.317px 7.91667px; transform-origin: 370.317px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSeveral problems in Cody deal with the practical problem of checking whether parentheses are correctly matched (e.g., \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/80\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e80\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 3.88333px 7.91667px; transform-origin: 3.88333px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/465\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"perspective-origin: 11.675px 7.91667px; transform-origin: 11.675px 7.91667px; \"\u003e465\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 3.88333px 7.91667px; transform-origin: 3.88333px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/1303\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e1303\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 3.88333px 7.91667px; transform-origin: 3.88333px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/2653-beauty-of-parentheses\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e2653\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 331.392px 7.91667px; transform-origin: 331.392px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e). In this problem you are asked to count the ways a given number of pairs of parentheses can be matched correctly in an expression. For example, three pairs can be matched in five ways: \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 146.3px 7.91667px; transform-origin: 146.3px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e()()(), (())(), (()()), ((())), ()(())\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 361.992px 7.91667px; transform-origin: 361.992px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the number of pairs and determines the number of ways the parentheses can be matched correctly. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = parenMatches(n)\r\n  y = 4^n/(n^(3/2)*sqrt(pi));\r\nend","test_suite":"%%\r\nn = 0;\r\ny_correct = 1;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 2;\r\ny_correct = 2;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 3;\r\ny_correct = 5;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 5;\r\ny_correct = 42;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 10;\r\ny_correct = 16796;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 14;\r\ny_correct = 2674440;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 19;\r\ny_correct = 1767263190;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 23;\r\ny_correct = 343059613650;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 28;\r\ny_correct = 263747951750360;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%% \r\nn = 25;\r\nd = num2str(parenMatches(n))-'0';\r\ns_correct = 54;\r\np_correct = 6635520;\r\nassert(isequal(sum(d),s_correct) \u0026\u0026 isequal(prod(d(d\u003e0)),p_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":7,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-12-06T16:54:03.000Z","updated_at":"2025-06-08T09:25:42.000Z","published_at":"2020-12-06T17:21:19.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSeveral problems in Cody deal with the practical problem of checking whether parentheses are correctly matched (e.g., \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/80\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e80\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/465\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e465\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/1303\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1303\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/2653-beauty-of-parentheses\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2653\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). In this problem you are asked to count the ways a given number of pairs of parentheses can be matched correctly in an expression. For example, three pairs can be matched in five ways: \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[()()(), (())(), (()()), ((())), ()(())]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that takes the number of pairs and determines the number of ways the parentheses can be matched correctly. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":111,"title":"Find matching parenthesis","description":"One of the most indispensable things about a great text editor for programming is the ability to quickly jump between matching parentheses. If you have a line like,\r\n    if (f(a) \u003e= b(c, d(e*(f-g))))\r\nit very convenient to place your cursor at, say, the second to last closing parenthesis, and have the editor show you where is the matching opening parenthesis. (In this example, it is the one just after b.)\r\nFor this problem, you should write a function that takes a string s like 'if (f(a) \u003e= b(c, d(e*f(-g))))' and an integer n representing a character position within the string. Your function should return the index of the matching parenthesis.\r\nFor example:\r\n    \u003e\u003e s = 'if (f(a) \u003e= b(c, d(e*f(-g))))';\r\n\r\n    \u003e\u003e find_matching_paren(s, 4)\r\n\r\n    ans =\r\n\r\n        29\r\n\r\n    \u003e\u003e find_matching_paren(s, 6)\r\n\r\n    ans =\r\n\r\n         8\r\n\r\n    \u003e\u003e find_matching_paren(s, 27)\r\n\r\n    ans =\r\n\r\n        19\r\nYou can assume that n will always be the position of either an open or closing parenthesis.\r\nYou can assume the string will always have balanced parentheses.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 687.667px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 343.833px; transform-origin: 407px 343.833px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 366.5px 8px; transform-origin: 366.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eOne of the most indispensable things about a great text editor for programming is the ability to quickly jump between matching parentheses. If you have a line like,\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 132px 8.5px; tab-size: 4; transform-origin: 132px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 16px 8.5px; transform-origin: 16px 8.5px; \"\u003e    \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 12px 8.5px; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 12px 8.5px; \"\u003eif \u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 104px 8.5px; transform-origin: 104px 8.5px; \"\u003e(f(a) \u0026gt;= b(c, d(e*(f-g))))\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42.5px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21.25px; text-align: left; transform-origin: 384px 21.25px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eit very convenient to place your cursor at, say, the second to last closing parenthesis, and have the editor show you where is the matching opening parenthesis. (In this example, it is the one just after\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003eb\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4.5px 8px; transform-origin: 4.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 64px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 32px; text-align: left; transform-origin: 384px 32px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 198px 8px; transform-origin: 198px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this problem, you should write a function that takes a string\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003es\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e like\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 124px 8px; transform-origin: 124px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 124px 8.5px; transform-origin: 124px 8.5px; \"\u003e'if (f(a) \u0026gt;= b(c, d(e*f(-g))))'\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 26px 8px; transform-origin: 26px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and an integer\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 330px 8px; transform-origin: 330px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e representing a character position within the string. Your function should return the index of the matching parenthesis.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 41px 8px; transform-origin: 41px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 388.233px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 194.117px; transform-origin: 404px 194.117px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 172px 8.5px; tab-size: 4; transform-origin: 172px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 44px 8.5px; transform-origin: 44px 8.5px; \"\u003e    \u0026gt;\u0026gt; s = \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 124px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 124px 8.5px; \"\u003e'if (f(a) \u0026gt;= b(c, d(e*f(-g))))'\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 128px 8.5px; tab-size: 4; transform-origin: 128px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    \u0026gt;\u0026gt; find_matching_paren(s, 4)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 36px 8.5px; tab-size: 4; transform-origin: 36px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    ans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        29\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 128px 8.5px; tab-size: 4; transform-origin: 128px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    \u0026gt;\u0026gt; find_matching_paren(s, 6)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 36px 8.5px; tab-size: 4; transform-origin: 36px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    ans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e         8\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 132px 8.5px; tab-size: 4; transform-origin: 132px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    \u0026gt;\u0026gt; find_matching_paren(s, 27)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 36px 8.5px; tab-size: 4; transform-origin: 36px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    ans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        19\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.5px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.75px; text-align: left; transform-origin: 384px 10.75px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 66px 8px; transform-origin: 66px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou can assume that\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 212px 8px; transform-origin: 212px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e will always be the position of either an open or closing parenthesis.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 209.5px 8px; transform-origin: 209.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou can assume the string will always have balanced parentheses.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function m = find_matching_paren(s,n)\r\n  m = n;\r\nend","test_suite":"%%\r\ns = '(abcdefghijklmopqrstuvwxyz)'; n = 1;\r\ny_correct = 27;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '()'; n = 2;\r\ny_correct = 1;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '()()'; n = 3;\r\ny_correct = 4;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '(()((a+b))())'; n = 13;\r\ny_correct = 1;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '(()((a+b))())'; n = 12;\r\ny_correct = 11;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '(()((a+b))())'; n = 10;\r\ny_correct = 4;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n","published":true,"deleted":false,"likes_count":16,"comments_count":3,"created_by":247,"edited_by":223089,"edited_at":"2022-04-29T10:47:26.000Z","deleted_by":null,"deleted_at":null,"solvers_count":309,"test_suite_updated_at":"2022-04-29T10:47:26.000Z","rescore_all_solutions":false,"group_id":14,"created_at":"2012-01-26T19:35:48.000Z","updated_at":"2026-03-22T16:00:23.000Z","published_at":"2012-01-26T19:36:01.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOne of the most indispensable things about a great text editor for programming is the ability to quickly jump between matching parentheses. If you have a line like,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    if (f(a) \u003e= b(c, d(e*(f-g))))]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eit very convenient to place your cursor at, say, the second to last closing parenthesis, and have the editor show you where is the matching opening parenthesis. (In this example, it is the one just after\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you should write a function that takes a string\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e like\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'if (f(a) \u0026gt;= b(c, d(e*f(-g))))'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and an integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e representing a character position within the string. Your function should return the index of the matching parenthesis.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    \u003e\u003e s = 'if (f(a) \u003e= b(c, d(e*f(-g))))';\\n\\n    \u003e\u003e find_matching_paren(s, 4)\\n\\n    ans =\\n\\n        29\\n\\n    \u003e\u003e find_matching_paren(s, 6)\\n\\n    ans =\\n\\n         8\\n\\n    \u003e\u003e find_matching_paren(s, 27)\\n\\n    ans =\\n\\n        19]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can assume that\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e will always be the position of either an open or closing parenthesis.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can assume the string will always have balanced parentheses.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":44075,"title":"GJam 2017 Kickstart: Parentheses (Large)","description":"This Challenge is derived from \u003chttp://code.google.com/codejam/contest/6304486/dashboard#s=p2 GJam 2017 Kickstart Parentheses\u003e. This is the first 100 large cases with  1\u003c=L+R\u003c=10^5.\r\n\r\n\u003chttp://code.google.com/codejam Google Code Jam 2017 Qualifier\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\r\n\r\nThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\r\n\r\n*Input:* [L,R], the quantity of parentheses types\r\n\r\n*Output:* [V], the maximum number of parentheses pairings\r\n\r\n*Examples:* [L,R] [V]; [3,2] [3]\r\n\r\nFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\r\n\r\n*Theory:* Brute force permutations and counting will not succeed in a timely manner for L+R=10^5. Determining the inherent mathematical pattern is usually the best way to succeed in GJam.   \u003chttp://code.google.com/codejam/contest/6304486/scoreboard#vf=1 GJam Kickstart solutions(C++,Python)\u003e. ","description_html":"\u003cp\u003eThis Challenge is derived from \u003ca href = \"http://code.google.com/codejam/contest/6304486/dashboard#s=p2\"\u003eGJam 2017 Kickstart Parentheses\u003c/a\u003e. This is the first 100 large cases with  1\u0026lt;=L+R\u0026lt;=10^5.\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://code.google.com/codejam\"\u003eGoogle Code Jam 2017 Qualifier\u003c/a\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\u003c/p\u003e\u003cp\u003eThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e [L,R], the quantity of parentheses types\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e [V], the maximum number of parentheses pairings\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples:\u003c/b\u003e [L,R] [V]; [3,2] [3]\u003c/p\u003e\u003cp\u003eFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\u003c/p\u003e\u003cp\u003e\u003cb\u003eTheory:\u003c/b\u003e Brute force permutations and counting will not succeed in a timely manner for L+R=10^5. Determining the inherent mathematical pattern is usually the best way to succeed in GJam.   \u003ca href = \"http://code.google.com/codejam/contest/6304486/scoreboard#vf=1\"\u003eGJam Kickstart solutions(C++,Python)\u003c/a\u003e.\u003c/p\u003e","function_template":"function val=parenc(L,R)\r\n% L number of Left parentheses, R number of Right parentheses \r\n% Determine maxinum number of parenthese pairings\r\n% http://code.google.com/codejam/contest/6304486/dashboard#s=p2\r\n\r\nval=0;\r\n \r\nend","test_suite":"%%\r\nv=parenc(36499,40104);\r\nassert(~isempty(v))\r\nassert(v==666106750)\r\n%%\r\nv=parenc(75814,21934);\r\nassert(~isempty(v))\r\nassert(v==240561145)\r\n%%\r\nv=parenc(88684,2943);\r\nassert(~isempty(v))\r\nassert(v==4332096)\r\n%%\r\nv=parenc(63688,19182);\r\nassert(~isempty(v))\r\nassert(v==183984153)\r\n%%\r\nv=parenc(71034,19757);\r\nassert(~isempty(v))\r\nassert(v==195179403)\r\n%%\r\nv=parenc(95210,572);\r\nassert(~isempty(v))\r\nassert(v==163878)\r\n%%\r\nv=parenc(50000,50000);\r\nassert(~isempty(v))\r\nassert(v==1250025000)\r\n%%\r\nv=parenc(37583,54023);\r\nassert(~isempty(v))\r\nassert(v==706259736)\r\n%%\r\nv=parenc(13403,50583);\r\nassert(~isempty(v))\r\nassert(v==89826906)\r\n%%\r\nv=parenc(74324,16176);\r\nassert(~isempty(v))\r\nassert(v==130839576)\r\n%%\r\nv=parenc(95662,20);\r\nassert(~isempty(v))\r\nassert(v==210)\r\n%%\r\nv=parenc(84426,8859);\r\nassert(~isempty(v))\r\nassert(v==39245370)\r\n%%\r\nv=parenc(1764,75732);\r\nassert(~isempty(v))\r\nassert(v==1556730)\r\n%%\r\nv=parenc(75135,17355);\r\nassert(~isempty(v))\r\nassert(v==150606690)\r\n%%\r\nv=parenc(16014,48995);\r\nassert(~isempty(v))\r\nassert(v==128232105)\r\n%%\r\nv=parenc(100000,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(90812,5679);\r\nassert(~isempty(v))\r\nassert(v==16128360)\r\n%%\r\nv=parenc(55860,34690);\r\nassert(~isempty(v))\r\nassert(v==601715395)\r\n%%\r\nv=parenc(82678,16936);\r\nassert(~isempty(v))\r\nassert(v==143422516)\r\n%%\r\nv=parenc(50696,22228);\r\nassert(~isempty(v))\r\nassert(v==247053106)\r\n%%\r\nv=parenc(60183,19425);\r\nassert(~isempty(v))\r\nassert(v==188675025)\r\n%%\r\nv=parenc(88288,3180);\r\nassert(~isempty(v))\r\nassert(v==5057790)\r\n%%\r\nv=parenc(18628,32214);\r\nassert(~isempty(v))\r\nassert(v==173510506)\r\n%%\r\nv=parenc(99681,195);\r\nassert(~isempty(v))\r\nassert(v==19110)\r\n%%\r\nv=parenc(7,13);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(62367,35577);\r\nassert(~isempty(v))\r\nassert(v==632879253)\r\n%%\r\nv=parenc(54171,29950);\r\nassert(~isempty(v))\r\nassert(v==448516225)\r\n%%\r\nv=parenc(22417,8626);\r\nassert(~isempty(v))\r\nassert(v==37208251)\r\n%%\r\nv=parenc(37824,9490);\r\nassert(~isempty(v))\r\nassert(v==45034795)\r\n%%\r\nv=parenc(95981,624);\r\nassert(~isempty(v))\r\nassert(v==195000)\r\n%%\r\nv=parenc(57025,7699);\r\nassert(~isempty(v))\r\nassert(v==29641150)\r\n%%\r\nv=parenc(1,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(16007,35971);\r\nassert(~isempty(v))\r\nassert(v==128120028)\r\n%%\r\nv=parenc(2306,52078);\r\nassert(~isempty(v))\r\nassert(v==2659971)\r\n%%\r\nv=parenc(70555,4927);\r\nassert(~isempty(v))\r\nassert(v==12140128)\r\n%%\r\nv=parenc(19454,63092);\r\nassert(~isempty(v))\r\nassert(v==189238785)\r\n%%\r\nv=parenc(73352,18081);\r\nassert(~isempty(v))\r\nassert(v==163470321)\r\n%%\r\nv=parenc(71344,18591);\r\nassert(~isempty(v))\r\nassert(v==172821936)\r\n%%\r\nv=parenc(76452,13351);\r\nassert(~isempty(v))\r\nassert(v==89131276)\r\n%%\r\nv=parenc(88885,3106);\r\nassert(~isempty(v))\r\nassert(v==4825171)\r\n%%\r\nv=parenc(53619,9977);\r\nassert(~isempty(v))\r\nassert(v==49775253)\r\n%%\r\nv=parenc(39466,15681);\r\nassert(~isempty(v))\r\nassert(v==122954721)\r\n%%\r\nv=parenc(33791,51813);\r\nassert(~isempty(v))\r\nassert(v==570932736)\r\n%%\r\nv=parenc(40408,42624);\r\nassert(~isempty(v))\r\nassert(v==816423436)\r\n%%\r\nv=parenc(998,12);\r\nassert(~isempty(v))\r\nassert(v==78)\r\n%%\r\nv=parenc(58818,23613);\r\nassert(~isempty(v))\r\nassert(v==278798691)\r\n%%\r\nv=parenc(82533,6389);\r\nassert(~isempty(v))\r\nassert(v==20412855)\r\n%%\r\nv=parenc(73823,18704);\r\nassert(~isempty(v))\r\nassert(v==174929160)\r\n%%\r\nv=parenc(24046,69819);\r\nassert(~isempty(v))\r\nassert(v==289117081)\r\n%%\r\nv=parenc(83603,2337);\r\nassert(~isempty(v))\r\nassert(v==2731953)\r\n%%\r\nv=parenc(95719,1658);\r\nassert(~isempty(v))\r\nassert(v==1375311)\r\n%%\r\nv=parenc(9,11);\r\nassert(~isempty(v))\r\nassert(v==45)\r\n%%\r\nv=parenc(29910,7601);\r\nassert(~isempty(v))\r\nassert(v==28891401)\r\n%%\r\nv=parenc(59540,36291);\r\nassert(~isempty(v))\r\nassert(v==658536486)\r\n%%\r\nv=parenc(45871,53970);\r\nassert(~isempty(v))\r\nassert(v==1052097256)\r\n%%\r\nv=parenc(92763,325);\r\nassert(~isempty(v))\r\nassert(v==52975)\r\n%%\r\nv=parenc(9038,44798);\r\nassert(~isempty(v))\r\nassert(v==40847241)\r\n%%\r\nv=parenc(1,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(86549,6287);\r\nassert(~isempty(v))\r\nassert(v==19766328)\r\n%%\r\nv=parenc(14401,46864);\r\nassert(~isempty(v))\r\nassert(v==103701601)\r\n%%\r\nv=parenc(93424,6259);\r\nassert(~isempty(v))\r\nassert(v==19590670)\r\n%%\r\nv=parenc(52933,31692);\r\nassert(~isempty(v))\r\nassert(v==502207278)\r\n%%\r\nv=parenc(91388,2050);\r\nassert(~isempty(v))\r\nassert(v==2102275)\r\n%%\r\nv=parenc(83487,14454);\r\nassert(~isempty(v))\r\nassert(v==104466285)\r\n%%\r\nv=parenc(26996,20778);\r\nassert(~isempty(v))\r\nassert(v==215873031)\r\n%%\r\nv=parenc(88436,1856);\r\nassert(~isempty(v))\r\nassert(v==1723296)\r\n%%\r\nv=parenc(52967,22634);\r\nassert(~isempty(v))\r\nassert(v==256160295)\r\n%%\r\nv=parenc(24373,71635);\r\nassert(~isempty(v))\r\nassert(v==297033751)\r\n%%\r\nv=parenc(25964,41310);\r\nassert(~isempty(v))\r\nassert(v==337077630)\r\n%%\r\nv=parenc(89807,7750);\r\nassert(~isempty(v))\r\nassert(v==30035125)\r\n%%\r\nv=parenc(84029,12987);\r\nassert(~isempty(v))\r\nassert(v==84337578)\r\n%%\r\nv=parenc(23884,41559);\r\nassert(~isempty(v))\r\nassert(v==285234670)\r\n%%\r\nv=parenc(96652,1790);\r\nassert(~isempty(v))\r\nassert(v==1602945)\r\n%%\r\nv=parenc(72470,2981);\r\nassert(~isempty(v))\r\nassert(v==4444671)\r\n%%\r\nv=parenc(51157,44196);\r\nassert(~isempty(v))\r\nassert(v==976665306)\r\n%%\r\nv=parenc(5964,125);\r\nassert(~isempty(v))\r\nassert(v==7875)\r\n%%\r\nv=parenc(5011,79606);\r\nassert(~isempty(v))\r\nassert(v==12557566)\r\n%%\r\nv=parenc(54850,32315);\r\nassert(~isempty(v))\r\nassert(v==522145770)\r\n%%\r\nv=parenc(94427,666);\r\nassert(~isempty(v))\r\nassert(v==222111)\r\n%%\r\nv=parenc(61766,28774);\r\nassert(~isempty(v))\r\nassert(v==413985925)\r\n%%\r\nv=parenc(90805,8083);\r\nassert(~isempty(v))\r\nassert(v==32671486)\r\n%%\r\nv=parenc(50250,34260);\r\nassert(~isempty(v))\r\nassert(v==586890930)\r\n%%\r\nv=parenc(59514,16501);\r\nassert(~isempty(v))\r\nassert(v==136149751)\r\n%%\r\nv=parenc(21448,21340);\r\nassert(~isempty(v))\r\nassert(v==227708470)\r\n%%\r\nv=parenc(48294,20183);\r\nassert(~isempty(v))\r\nassert(v==203686836)\r\n%%\r\nv=parenc(0,100000);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(0,1);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(9321,9795);\r\nassert(~isempty(v))\r\nassert(v==43445181)\r\n%%\r\nv=parenc(33373,207);\r\nassert(~isempty(v))\r\nassert(v==21528)\r\n%%\r\nv=parenc(78080,18989);\r\nassert(~isempty(v))\r\nassert(v==180300555)\r\n%%\r\nv=parenc(89341,7009);\r\nassert(~isempty(v))\r\nassert(v==24566545)\r\n%%\r\nv=parenc(0,2);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(2,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(90124,7716);\r\nassert(~isempty(v))\r\nassert(v==29772186)\r\n%%\r\nv=parenc(36611,12311);\r\nassert(~isempty(v))\r\nassert(v==75786516)\r\n%%\r\nv=parenc(45498,3564);\r\nassert(~isempty(v))\r\nassert(v==6352830)\r\n%%\r\nv=parenc(28355,23958);\r\nassert(~isempty(v))\r\nassert(v==287004861)\r\n%%\r\nv=parenc(58516,24422);\r\nassert(~isempty(v))\r\nassert(v==298229253)\r\n%%\r\nv=parenc(42157,56858);\r\nassert(~isempty(v))\r\nassert(v==888627403)\r\n%%\r\nv=parenc(32854,55517);\r\nassert(~isempty(v))\r\nassert(v==539709085)\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-02-25T22:17:05.000Z","updated_at":"2026-03-24T12:06:44.000Z","published_at":"2017-02-25T22:18:40.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/6304486/dashboard#s=p2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2017 Kickstart Parentheses\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This is the first 100 large cases with 1\u0026lt;=L+R\u0026lt;=10^5.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGoogle Code Jam 2017 Qualifier\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [L,R], the quantity of parentheses types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [V], the maximum number of parentheses pairings\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [L,R] [V]; [3,2] [3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTheory:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Brute force permutations and counting will not succeed in a timely manner for L+R=10^5. Determining the inherent mathematical pattern is usually the best way to succeed in GJam. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/6304486/scoreboard#vf=1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Kickstart solutions(C++,Python)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44074,"title":"GJam 2017 Kickstart: Parentheses (Small)","description":"This Challenge is derived from \u003chttp://code.google.com/codejam/contest/6304486/dashboard#s=p2 GJam 2017 Kickstart Parentheses\u003e. This is the first 100 small cases with max L+R\u003c=20.\r\n\r\n\u003chttp://code.google.com/codejam Google Code Jam 2017 Qualifier\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\r\n\r\nThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\r\n\r\n*Input:* [L,R], the quantity of parentheses types\r\n\r\n*Output:* [V], the maximum number of parentheses pairings\r\n\r\n*Examples:* [L,R] [V]; [3,2] [3]\r\n\r\nFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\r\n\r\n*Theory:* Brute force permutations and counting will not succeed in a timely manner for L+R=20. Determining the inherent mathematical pattern is usually the best way to succeed in GJam.   \u003chttp://code.google.com/codejam/contest/6304486/scoreboard#vf=1 GJam Kickstart solutions(C++,Python)\u003e. ","description_html":"\u003cp\u003eThis Challenge is derived from \u003ca href = \"http://code.google.com/codejam/contest/6304486/dashboard#s=p2\"\u003eGJam 2017 Kickstart Parentheses\u003c/a\u003e. This is the first 100 small cases with max L+R\u0026lt;=20.\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://code.google.com/codejam\"\u003eGoogle Code Jam 2017 Qualifier\u003c/a\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\u003c/p\u003e\u003cp\u003eThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e [L,R], the quantity of parentheses types\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e [V], the maximum number of parentheses pairings\u003c/p\u003e\u003cp\u003e\u003cb\u003eExamples:\u003c/b\u003e [L,R] [V]; [3,2] [3]\u003c/p\u003e\u003cp\u003eFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\u003c/p\u003e\u003cp\u003e\u003cb\u003eTheory:\u003c/b\u003e Brute force permutations and counting will not succeed in a timely manner for L+R=20. Determining the inherent mathematical pattern is usually the best way to succeed in GJam.   \u003ca href = \"http://code.google.com/codejam/contest/6304486/scoreboard#vf=1\"\u003eGJam Kickstart solutions(C++,Python)\u003c/a\u003e.\u003c/p\u003e","function_template":"function val=parenc(L,R)\r\n% L number of Left parentheses, R number of Right parentheses \r\n% Determine maxinum number of parenthese pairings\r\n% http://code.google.com/codejam/contest/6304486/dashboard#s=p2\r\n\r\nval=0;\r\n \r\nend","test_suite":"%%\r\nv=parenc(19,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(14,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(4,15);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(8,6);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(14,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(10,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(10,10);\r\nassert(~isempty(v))\r\nassert(v==55)\r\n%%\r\nv=parenc(3,7);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(3,13);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(4,12);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(2,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(6,11);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(4,12);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(15,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(14,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(20,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(12,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(0,10);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(18,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(16,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(3,12);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(8,12);\r\nassert(~isempty(v))\r\nassert(v==36)\r\n%%\r\nv=parenc(8,6);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(1,8);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(7,13);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(7,6);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(11,8);\r\nassert(~isempty(v))\r\nassert(v==36)\r\n%%\r\nv=parenc(17,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(4,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(1,6);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(5,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(1,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(7,13);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(6,12);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(15,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(14,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(12,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(4,15);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(12,7);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(5,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(19,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(6,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(11,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(8,12);\r\nassert(~isempty(v))\r\nassert(v==36)\r\n%%\r\nv=parenc(18,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(18,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(13,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(3,6);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(6,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(3,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(19,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(9,11);\r\nassert(~isempty(v))\r\nassert(v==45)\r\n%%\r\nv=parenc(10,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(0,11);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(11,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(3,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(18,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(1,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(9,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(1,19);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(4,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(13,7);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(8,6);\r\nassert(~isempty(v))\r\nassert(v==21)\r\n%%\r\nv=parenc(7,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(16,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(16,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(7,8);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(13,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(4,14);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(7,8);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(9,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(4,7);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(12,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(10,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(17,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(4,13);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(11,1);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(10,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(7,7);\r\nassert(~isempty(v))\r\nassert(v==28)\r\n%%\r\nv=parenc(6,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(5,13);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(10,10);\r\nassert(~isempty(v))\r\nassert(v==55)\r\n%%\r\nv=parenc(14,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(8,4);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(14,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n%%\r\nv=parenc(0,20);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(0,1);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(1,10);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(13,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(0,9);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(1,17);\r\nassert(~isempty(v))\r\nassert(v==1)\r\n%%\r\nv=parenc(0,2);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(2,0);\r\nassert(~isempty(v))\r\nassert(v==0)\r\n%%\r\nv=parenc(4,12);\r\nassert(~isempty(v))\r\nassert(v==10)\r\n%%\r\nv=parenc(11,9);\r\nassert(~isempty(v))\r\nassert(v==45)\r\n%%\r\nv=parenc(18,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(15,3);\r\nassert(~isempty(v))\r\nassert(v==6)\r\n%%\r\nv=parenc(16,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(17,2);\r\nassert(~isempty(v))\r\nassert(v==3)\r\n%%\r\nv=parenc(14,5);\r\nassert(~isempty(v))\r\nassert(v==15)\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-02-25T21:52:46.000Z","updated_at":"2026-01-02T17:52:37.000Z","published_at":"2017-02-25T22:07:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/6304486/dashboard#s=p2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2017 Kickstart Parentheses\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This is the first 100 small cases with max L+R\u0026lt;=20.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGoogle Code Jam 2017 Qualifier\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is March 7, 2017. Typically four challenges with small and large aspects with 27 hours to complete.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe GJam story is given L left and R right parentheses determine the maximum number of parentheses pairings.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [L,R], the quantity of parentheses types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [V], the maximum number of parentheses pairings\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e [L,R] [V]; [3,2] [3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor the case ()()(, for example, the three balanced groups are () from indexes 1 to 2, () from indexes 3 to 4, and ()() from indexes 1 to 4.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eTheory:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Brute force permutations and counting will not succeed in a timely manner for L+R=20. Determining the inherent mathematical pattern is usually the best way to succeed in GJam. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/6304486/scoreboard#vf=1\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Kickstart solutions(C++,Python)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":47838,"title":"Count the ways pairs of parentheses can be matched correctly","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 145.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 72.7167px; transform-origin: 407px 72.7167px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 370.317px 7.91667px; transform-origin: 370.317px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eSeveral problems in Cody deal with the practical problem of checking whether parentheses are correctly matched (e.g., \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/80\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e80\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 3.88333px 7.91667px; transform-origin: 3.88333px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/465\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"perspective-origin: 11.675px 7.91667px; transform-origin: 11.675px 7.91667px; \"\u003e465\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 3.88333px 7.91667px; transform-origin: 3.88333px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/1303\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e1303\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 3.88333px 7.91667px; transform-origin: 3.88333px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/2653-beauty-of-parentheses\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e2653\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 331.392px 7.91667px; transform-origin: 331.392px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e). In this problem you are asked to count the ways a given number of pairs of parentheses can be matched correctly in an expression. For example, three pairs can be matched in five ways: \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 146.3px 7.91667px; transform-origin: 146.3px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e()()(), (())(), (()()), ((())), ()(())\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 361.992px 7.91667px; transform-origin: 361.992px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the number of pairs and determines the number of ways the parentheses can be matched correctly. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = parenMatches(n)\r\n  y = 4^n/(n^(3/2)*sqrt(pi));\r\nend","test_suite":"%%\r\nn = 0;\r\ny_correct = 1;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 2;\r\ny_correct = 2;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 3;\r\ny_correct = 5;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 5;\r\ny_correct = 42;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 10;\r\ny_correct = 16796;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 14;\r\ny_correct = 2674440;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 19;\r\ny_correct = 1767263190;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 23;\r\ny_correct = 343059613650;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%%\r\nn = 28;\r\ny_correct = 263747951750360;\r\nassert(isequal(parenMatches(n),y_correct))\r\n\r\n%% \r\nn = 25;\r\nd = num2str(parenMatches(n))-'0';\r\ns_correct = 54;\r\np_correct = 6635520;\r\nassert(isequal(sum(d),s_correct) \u0026\u0026 isequal(prod(d(d\u003e0)),p_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":7,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-12-06T16:54:03.000Z","updated_at":"2025-06-08T09:25:42.000Z","published_at":"2020-12-06T17:21:19.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSeveral problems in Cody deal with the practical problem of checking whether parentheses are correctly matched (e.g., \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/80\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e80\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/465\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e465\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/1303\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1303\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/2653-beauty-of-parentheses\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2653\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e). In this problem you are asked to count the ways a given number of pairs of parentheses can be matched correctly in an expression. For example, three pairs can be matched in five ways: \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[()()(), (())(), (()()), ((())), ()(())]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that takes the number of pairs and determines the number of ways the parentheses can be matched correctly. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":111,"title":"Find matching parenthesis","description":"One of the most indispensable things about a great text editor for programming is the ability to quickly jump between matching parentheses. If you have a line like,\r\n    if (f(a) \u003e= b(c, d(e*(f-g))))\r\nit very convenient to place your cursor at, say, the second to last closing parenthesis, and have the editor show you where is the matching opening parenthesis. (In this example, it is the one just after b.)\r\nFor this problem, you should write a function that takes a string s like 'if (f(a) \u003e= b(c, d(e*f(-g))))' and an integer n representing a character position within the string. Your function should return the index of the matching parenthesis.\r\nFor example:\r\n    \u003e\u003e s = 'if (f(a) \u003e= b(c, d(e*f(-g))))';\r\n\r\n    \u003e\u003e find_matching_paren(s, 4)\r\n\r\n    ans =\r\n\r\n        29\r\n\r\n    \u003e\u003e find_matching_paren(s, 6)\r\n\r\n    ans =\r\n\r\n         8\r\n\r\n    \u003e\u003e find_matching_paren(s, 27)\r\n\r\n    ans =\r\n\r\n        19\r\nYou can assume that n will always be the position of either an open or closing parenthesis.\r\nYou can assume the string will always have balanced parentheses.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 687.667px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 343.833px; transform-origin: 407px 343.833px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 366.5px 8px; transform-origin: 366.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eOne of the most indispensable things about a great text editor for programming is the ability to quickly jump between matching parentheses. If you have a line like,\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 132px 8.5px; tab-size: 4; transform-origin: 132px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 16px 8.5px; transform-origin: 16px 8.5px; \"\u003e    \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(14, 0, 255); border-block-start-color: rgb(14, 0, 255); border-bottom-color: rgb(14, 0, 255); border-inline-end-color: rgb(14, 0, 255); border-inline-start-color: rgb(14, 0, 255); border-left-color: rgb(14, 0, 255); border-right-color: rgb(14, 0, 255); border-top-color: rgb(14, 0, 255); caret-color: rgb(14, 0, 255); color: rgb(14, 0, 255); column-rule-color: rgb(14, 0, 255); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(14, 0, 255); perspective-origin: 12px 8.5px; text-decoration-color: rgb(14, 0, 255); text-emphasis-color: rgb(14, 0, 255); transform-origin: 12px 8.5px; \"\u003eif \u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 104px 8.5px; transform-origin: 104px 8.5px; \"\u003e(f(a) \u0026gt;= b(c, d(e*(f-g))))\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42.5px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21.25px; text-align: left; transform-origin: 384px 21.25px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 384px 8px; transform-origin: 384px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eit very convenient to place your cursor at, say, the second to last closing parenthesis, and have the editor show you where is the matching opening parenthesis. (In this example, it is the one just after\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003eb\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4.5px 8px; transform-origin: 4.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 64px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 32px; text-align: left; transform-origin: 384px 32px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 198px 8px; transform-origin: 198px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor this problem, you should write a function that takes a string\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003es\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 12.5px 8px; transform-origin: 12.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e like\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 124px 8px; transform-origin: 124px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 124px 8.5px; transform-origin: 124px 8.5px; \"\u003e'if (f(a) \u0026gt;= b(c, d(e*f(-g))))'\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 26px 8px; transform-origin: 26px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and an integer\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 330px 8px; transform-origin: 330px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e representing a character position within the string. Your function should return the index of the matching parenthesis.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 41px 8px; transform-origin: 41px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor example:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 388.233px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 194.117px; transform-origin: 404px 194.117px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 172px 8.5px; tab-size: 4; transform-origin: 172px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 44px 8.5px; transform-origin: 44px 8.5px; \"\u003e    \u0026gt;\u0026gt; s = \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 124px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 124px 8.5px; \"\u003e'if (f(a) \u0026gt;= b(c, d(e*f(-g))))'\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003e;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 128px 8.5px; tab-size: 4; transform-origin: 128px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    \u0026gt;\u0026gt; find_matching_paren(s, 4)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 36px 8.5px; tab-size: 4; transform-origin: 36px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    ans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        29\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 128px 8.5px; tab-size: 4; transform-origin: 128px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    \u0026gt;\u0026gt; find_matching_paren(s, 6)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 36px 8.5px; tab-size: 4; transform-origin: 36px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    ans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e         8\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 132px 8.5px; tab-size: 4; transform-origin: 132px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    \u0026gt;\u0026gt; find_matching_paren(s, 27)\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 36px 8.5px; tab-size: 4; transform-origin: 36px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    ans =\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 0px 8.5px; tab-size: 4; transform-origin: 0px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e        19\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.5px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.75px; text-align: left; transform-origin: 384px 10.75px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 66px 8px; transform-origin: 66px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou can assume that\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 4px 8px; transform-origin: 4px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; perspective-origin: 4px 8.5px; transform-origin: 4px 8.5px; \"\u003en\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 212px 8px; transform-origin: 212px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e will always be the position of either an open or closing parenthesis.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 209.5px 8px; transform-origin: 209.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou can assume the string will always have balanced parentheses.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function m = find_matching_paren(s,n)\r\n  m = n;\r\nend","test_suite":"%%\r\ns = '(abcdefghijklmopqrstuvwxyz)'; n = 1;\r\ny_correct = 27;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '()'; n = 2;\r\ny_correct = 1;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '()()'; n = 3;\r\ny_correct = 4;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '(()((a+b))())'; n = 13;\r\ny_correct = 1;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '(()((a+b))())'; n = 12;\r\ny_correct = 11;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n\r\n%%\r\ns = '(()((a+b))())'; n = 10;\r\ny_correct = 4;\r\nassert(isequal(find_matching_paren(s, n),y_correct))\r\n","published":true,"deleted":false,"likes_count":16,"comments_count":3,"created_by":247,"edited_by":223089,"edited_at":"2022-04-29T10:47:26.000Z","deleted_by":null,"deleted_at":null,"solvers_count":309,"test_suite_updated_at":"2022-04-29T10:47:26.000Z","rescore_all_solutions":false,"group_id":14,"created_at":"2012-01-26T19:35:48.000Z","updated_at":"2026-03-22T16:00:23.000Z","published_at":"2012-01-26T19:36:01.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOne of the most indispensable things about a great text editor for programming is the ability to quickly jump between matching parentheses. If you have a line like,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    if (f(a) \u003e= b(c, d(e*(f-g))))]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eit very convenient to place your cursor at, say, the second to last closing parenthesis, and have the editor show you where is the matching opening parenthesis. (In this example, it is the one just after\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor this problem, you should write a function that takes a string\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e like\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'if (f(a) \u0026gt;= b(c, d(e*f(-g))))'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and an integer\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e representing a character position within the string. Your function should return the index of the matching parenthesis.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    \u003e\u003e s = 'if (f(a) \u003e= b(c, d(e*f(-g))))';\\n\\n    \u003e\u003e find_matching_paren(s, 4)\\n\\n    ans =\\n\\n        29\\n\\n    \u003e\u003e find_matching_paren(s, 6)\\n\\n    ans =\\n\\n         8\\n\\n    \u003e\u003e find_matching_paren(s, 27)\\n\\n    ans =\\n\\n        19]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can assume that\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e will always be the position of either an open or closing parenthesis.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou can assume the string will always have balanced parentheses.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"}],"term":"tag:\"parentheses\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"parentheses\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"parentheses\"","","\"","parentheses","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f250e40af08\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f250e40ae68\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f250e40a5a8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f250e40b188\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f250e40b0e8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f250e40b048\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f250e40afa8\u003e":"tag:\"parentheses\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f250e40afa8\u003e":"tag:\"parentheses\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"parentheses\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"parentheses\"","","\"","parentheses","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f250e40af08\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f250e40ae68\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f250e40a5a8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f250e40b188\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f250e40b0e8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f250e40b048\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f250e40afa8\u003e":"tag:\"parentheses\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f250e40afa8\u003e":"tag:\"parentheses\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44075,"difficulty_rating":"easy"},{"id":44074,"difficulty_rating":"easy-medium"},{"id":47838,"difficulty_rating":"easy-medium"},{"id":111,"difficulty_rating":"medium"}]}}