{
  "index": "2015-B-5",
  "type": "COMB",
  "tag": [
    "COMB",
    "ALG",
    "NT"
  ],
  "difficulty": "",
  "question": "Let $P_n$ be the number of permutations $\\pi$ of $\\{1,2,\\dots,n\\}$ such that\n\\[\n|i-j| = 1 \\mbox{ implies } |\\pi(i) -\\pi(j)| \\leq 2\n\\]\nfor all $i,j$ in $\\{1,2,\\dots,n\\}$. Show that for $n \\geq 2$, the quantity\n\\[\nP_{n+5} - P_{n+4} - P_{n+3} + P_n\n\\]\ndoes not depend on $n$, and find its value.",
  "solution": "The answer is 4.\n\nAssume $n \\geq 3$ for the moment.\nWe write the permutations $\\pi$ counted by $P_n$ as sequences $\\pi(1),\\pi(2),\\ldots,\\pi(n)$.  Let $U_n$ be the number of permutations counted by $P_n$ that end with $n-1,n$; let $V_n$ be the number ending in $n,n-1$; let $W_n$ be the number starting with $n-1$ and ending in $n-2,n$; let $T_n$ be the number ending in $n-2,n$ but not starting with $n-1$; and let $S_n$ be the number which has $n-1,n$ consecutively in that order, but not at the beginning or end.\nIt is clear that every permutation $\\pi$ counted by $P_n$ either lies in exactly one of the sets counted by $U_n, V_n, W_n, T_n, S_n$, or is the reverse of such a permutation.  Therefore\n\\[\nP_n = 2 (U_n + V_n + W_n+ T_n+ S_n).\n\\]\nBy examining how each of the elements in the sets counted by $U_{n+1}, V_{n+1}, W_{n+1}, T_{n+1}, S_{n+1}$ can be obtained from a (unique) element in one of the sets counted by $U_n, V_n, W_n, T_n, S_n$ by suitably inserting the element $n+1$, we obtain the recurrence relations\n\\begin{align*}\nU_{n+1} &= U_n+W_n+T_n, \\\\\nV_{n+1}&=U_n, \\\\\nW_{n+1}&=W_n, \\\\\nT_{n+1}&=V_n, \\\\\nS_{n+1}&=S_n+V_n.\n\\end{align*}\nAlso, it is clear that $W_n=1$ for all $n$. \n\nSo far we have assumed $n \\geq 3$, but it is straightforward to extrapolate the sequences $P_n,U_n,V_n,W_n,T_n,S_n$ back to $n=2$ to preserve the preceding identities. Hence for all $n \\geq 2$,\n\\begin{align*}\nP_{n+5} &= 2(U_{n+5}+V_{n+5}+W_{n+5}+T_{n+5}+S_{n+5}) \\\\\n&= 2((U_{n+4}+W_{n+4}+T_{n+4})+U_{n+4}\\\\\n& \\qquad + W_{n+4}+V_{n+4}+(S_{n+4}+V_{n+4})) \\\\\n&= P_{n+4} + 2(U_{n+4}+W_{n+4}+V_{n+4}) \\\\\n&= P_{n+4} + 2((U_{n+3}+W_{n+3}+T_{n+3})+W_{n+3}+U_{n+3}) \\\\\n&= P_{n+4} + P_{n+3} + 2(U_{n+3}-V_{n+3}+W_{n+3}-S_{n+3}) \\\\\n&= P_{n+4} + P_{n+3} + 2((U_{n+2}+W_{n+2}+T_{n+2})-U_{n+2}\\\\\n&\\qquad +W_{n+2}-(S_{n+2}-V_{n+2})) \\\\\n&= P_{n+4} + P_{n+3} + 2(2W_{n+2}+T_{n+2}-S_{n+2}-V_{n+2}) \\\\\n&= P_{n+4} + P_{n+3} + 2(2W_{n+1}+V_{n+1}\\\\\n&\\qquad -(S_{n+1}+V_{n+1})-U_{n+1}) \\\\\n&= P_{n+4} + P_{n+3} + 2(2W_n+U_n-(S_n+V_n)-U_n\\\\\n&\\qquad -(U_n+W_n+T_n)) \\\\\n&= P_{n+4} + P_{n+3} - P_n + 4,\n\\end{align*}\nas desired.\n\n\\noindent\n\\textbf{Remark:}\nThere are many possible variants of the above solution obtained by dividing the permutations up according to different features. For example, Karl Mahlburg suggests \nwriting \n\\[\nP_n = 2P'_n, \\qquad P'_n = Q'_n + R'_n\n\\]\nwhere $P'_n$ counts those permutations counted by $P_n$ for which $1$ occurs before 2,\nand $Q'_n$ counts those permutations counted by $P'_n$ for which $\\pi(1) = 1$. One then has the recursion\n\\[\nQ'_n = Q'_{n-1} + Q'_{n-3} + 1\n\\]\ncorresponding to the cases where $\\pi(1), \\pi(2) = 1,2$; where $\\pi(1), \\pi(2), \\pi(3) = 1,3,2$;  and the unique case $1,3,5,\\dots,6,4,2$. Meanwhile, one has\n\\[\nR'_n = R'_{n-1} + Q'_{n-2}\n\\]\ncorresponding to the cases containing $3,1,2,4$ (where removing 1 and reversing gives a permutation counted by $R'_{n-1}$); and where $4$ occurs before $3, 1, 2$ (where removing $1,2$ and reversing gives a permutation counted by $Q'_{n-2}$).\n\n\\noindent\n\\textbf{Remark:}\nThe permutations counted by $P_n$ are known as {\\it key permutations}, and have been studied by E.S. Page, Systematic generation of ordered sequences using recurrence relations, {\\it The Computer Journal} {\\bf 14} (1971), no. 2, 150--153.  We have used the same notation for consistency with the literature. The sequence of the $P_n$ also appears as entry A003274 in the On-line Encyclopedia of Integer Sequences (\\url{http://oeis.org}).",
  "vars": [
    "n",
    "i",
    "j",
    "\\\\pi"
  ],
  "params": [
    "P_n",
    "P_n+5",
    "P_n+4",
    "P_n+3",
    "U_n",
    "V_n",
    "W_n",
    "T_n",
    "S_n",
    "U_n+1",
    "V_n+1",
    "W_n+1",
    "T_n+1",
    "S_n+1",
    "U_n+2",
    "V_n+2",
    "W_n+2",
    "T_n+2",
    "S_n+2",
    "U_n+3",
    "V_n+3",
    "W_n+3",
    "T_n+3",
    "S_n+3",
    "U_n+4",
    "V_n+4",
    "W_n+4",
    "T_n+4",
    "S_n+4"
  ],
  "sci_consts": [],
  "variants": {
    "descriptive_long": {
      "map": {
        "n": "elemcount",
        "i": "indexone",
        "j": "indextwo",
        "\\pi": "permmap",
        "P_n": "permpbase",
        "P_n+5": "permpplusfive",
        "P_n+4": "permpplusfour",
        "P_n+3": "permpplusthree",
        "U_n": "countu",
        "V_n": "countv",
        "W_n": "countw",
        "T_n": "countt",
        "S_n": "counts",
        "U_n+1": "countuplusone",
        "V_n+1": "countvplusone",
        "W_n+1": "countwplusone",
        "T_n+1": "counttplusone",
        "S_n+1": "countsplusone",
        "U_n+2": "countuplustwo",
        "V_n+2": "countvplustwo",
        "W_n+2": "countwplustwo",
        "T_n+2": "counttplustwo",
        "S_n+2": "countsplustwo",
        "U_n+3": "countuplusthree",
        "V_n+3": "countvplusthree",
        "W_n+3": "countwplusthree",
        "T_n+3": "counttplusthree",
        "S_n+3": "countsplusthree",
        "U_n+4": "countuplusfour",
        "V_n+4": "countvplusfour",
        "W_n+4": "countwplusfour",
        "T_n+4": "counttplusfour",
        "S_n+4": "countsplusfour"
      },
      "question": "Let $permpbase$ be the number of permutations $permmap$ of $\\{1,2,\\dots,elemcount\\}$ such that\n\\[\n|indexone-indextwo| = 1 \\mbox{ implies } |permmap(indexone) -permmap(indextwo)| \\leq 2\n\\]\nfor all $indexone,indextwo$ in $\\{1,2,\\dots,elemcount\\}$. Show that for $elemcount \\geq 2$, the quantity\n\\[\nP_{elemcount+5} - P_{elemcount+4} - P_{elemcount+3} + permpbase\n\\]\ndoes not depend on $elemcount$, and find its value.",
      "solution": "The answer is 4.\n\nAssume $elemcount \\geq 3$ for the moment.\nWe write the permutations $permmap$ counted by $permpbase$ as sequences $permmap(1),permmap(2),\\ldots,permmap(elemcount)$.  Let $countu$ be the number of permutations counted by $permpbase$ that end with $elemcount-1,elemcount$; let $countv$ be the number ending in $elemcount,elemcount-1$; let $countw$ be the number starting with $elemcount-1$ and ending in $elemcount-2,elemcount$; let $countt$ be the number ending in $elemcount-2,elemcount$ but not starting with $elemcount-1$; and let $counts$ be the number which has $elemcount-1,elemcount$ consecutively in that order, but not at the beginning or end.\nIt is clear that every permutation $permmap$ counted by $permpbase$ either lies in exactly one of the sets counted by $countu, countv, countw, countt, counts$, or is the reverse of such a permutation.  Therefore\n\\[\npermpbase = 2 (countu + countv + countw+ countt+ counts).\n\\]\nBy examining how each of the elements in the sets counted by $countuplusone, countvplusone, countwplusone, counttplusone, countsplusone$ can be obtained from a (unique) element in one of the sets counted by $countu, countv, countw, countt, counts$ by suitably inserting the element $elemcount+1$, we obtain the recurrence relations\n\\begin{align*}\ncountuplusone &= countu+countw+countt, \\\\\ncountvplusone&=countu, \\\\\ncountwplusone&=countw, \\\\\ncounttplusone&=countv, \\\\\ncountsplusone&=counts+countv.\n\\end{align*}\nAlso, it is clear that $countw=1$ for all $elemcount$.\n\nSo far we have assumed $elemcount \\geq 3$, but it is straightforward to extrapolate the sequences $permpbase,countu,countv,countw,countt,counts$ back to $elemcount=2$ to preserve the preceding identities. Hence for all $elemcount \\geq 2$,\n\\begin{align*}\nP_{elemcount+5} &= 2(U_{elemcount+5}+V_{elemcount+5}+W_{elemcount+5}+T_{elemcount+5}+S_{elemcount+5}) \\\\\n&= 2((U_{elemcount+4}+W_{elemcount+4}+T_{elemcount+4})+U_{elemcount+4}\\\\\n& \\qquad + W_{elemcount+4}+V_{elemcount+4}+(S_{elemcount+4}+V_{elemcount+4})) \\\\\n&= P_{elemcount+4} + 2(U_{elemcount+4}+W_{elemcount+4}+V_{elemcount+4}) \\\\\n&= P_{elemcount+4} + 2((U_{elemcount+3}+W_{elemcount+3}+T_{elemcount+3})+W_{elemcount+3}+U_{elemcount+3}) \\\\\n&= P_{elemcount+4} + P_{elemcount+3} + 2(U_{elemcount+3}-V_{elemcount+3}+W_{elemcount+3}-S_{elemcount+3}) \\\\\n&= P_{elemcount+4} + P_{elemcount+3} + 2((U_{elemcount+2}+W_{elemcount+2}+T_{elemcount+2})-U_{elemcount+2}\\\\\n&\\qquad +W_{elemcount+2}-(S_{elemcount+2}-V_{elemcount+2})) \\\\\n&= P_{elemcount+4} + P_{elemcount+3} + 2(2W_{elemcount+2}+T_{elemcount+2}-S_{elemcount+2}-V_{elemcount+2}) \\\\\n&= P_{elemcount+4} + P_{elemcount+3} + 2(2W_{elemcount+1}+V_{elemcount+1}\\\\\n&\\qquad -(S_{elemcount+1}+V_{elemcount+1})-U_{elemcount+1}) \\\\\n&= P_{elemcount+4} + P_{elemcount+3} + 2(2countw+countu-(counts+countv)-countu\\\\\n&\\qquad -(countu+countw+countt)) \\\\\n&= P_{elemcount+4} + P_{elemcount+3} - permpbase + 4,\n\\end{align*}\nas desired.\n\n\\textbf{Remark:}\nThere are many possible variants of the above solution obtained by dividing the permutations up according to different features. For example, Karl Mahlburg suggests \nwriting \n\\[\nP_{elemcount} = 2P'_{elemcount}, \\qquad P'_{elemcount} = Q'_{elemcount} + R'_{elemcount}\n\\]\nwhere $P'_{elemcount}$ counts those permutations counted by $P_{elemcount}$ for which $1$ occurs before 2,\nand $Q'_{elemcount}$ counts those permutations counted by $P'_{elemcount}$ for which $permmap(1) = 1$. One then has the recursion\n\\[\nQ'_{elemcount} = Q'_{elemcount-1} + Q'_{elemcount-3} + 1\n\\]\ncorresponding to the cases where $permmap(1), permmap(2) = 1,2$; where $permmap(1), permmap(2), permmap(3) = 1,3,2$;  and the unique case $1,3,5,\\dots,6,4,2$. Meanwhile, one has\n\\[\nR'_{elemcount} = R'_{elemcount-1} + Q'_{elemcount-2}\n\\]\ncorresponding to the cases containing $3,1,2,4$ (where removing 1 and reversing gives a permutation counted by $R'_{elemcount-1}$); and where $4$ occurs before $3, 1, 2$ (where removing $1,2$ and reversing gives a permutation counted by $Q'_{elemcount-2}$).\n\n\\textbf{Remark:}\nThe permutations counted by $P_{elemcount}$ are known as \\textit{key permutations}, and have been studied by E.S. Page, Systematic generation of ordered sequences using recurrence relations, \\textit{The Computer Journal} \\textbf{14} (1971), no. 2, 150--153.  We have used the same notation for consistency with the literature. The sequence of the $P_{elemcount}$ also appears as entry A003274 in the On-line Encyclopedia of Integer Sequences (\\url{http://oeis.org})."
    },
    "descriptive_long_confusing": {
      "map": {
        "n": "stargazer",
        "i": "windchime",
        "j": "driftwood",
        "P_n": "moonstone",
        "P_n+5": "hilltopper",
        "P_n+4": "driftblaze",
        "P_n+3": "riverdance",
        "U_n": "amberglow",
        "V_n": "silvermist",
        "W_n": "pineforest",
        "T_n": "cloudburst",
        "S_n": "starflower",
        "U_n+1": "emberlight",
        "V_n+1": "silvershore",
        "W_n+1": "pinegrove",
        "T_n+1": "cloudchime",
        "S_n+1": "starlitway",
        "U_n+2": "ambergleam",
        "V_n+2": "silverspark",
        "W_n+2": "pineneedle",
        "T_n+2": "cloudwhirl",
        "S_n+2": "starfarers",
        "U_n+3": "amberfield",
        "V_n+3": "silvercrest",
        "W_n+3": "pinemeadow",
        "T_n+3": "cloudvalley",
        "S_n+3": "starnimbus",
        "U_n+4": "amberdawn",
        "V_n+4": "silverswan",
        "W_n+4": "pinebranch",
        "T_n+4": "cloudridge",
        "S_n+4": "starhollow"
      },
      "question": "Let $moonstone$ be the number of permutations \\pi of \\{1,2,\\dots,stargazer\\} such that\n\\[\n|windchime-driftwood| = 1 \\mbox{ implies } |\\pi(windchime) -\\pi(driftwood)| \\leq 2\n\\]\nfor all $windchime,driftwood$ in \\{1,2,\\dots,stargazer\\}. Show that for $stargazer \\geq 2$, the quantity\n\\[\nhilltopper - driftblaze - riverdance + moonstone\n\\]\ndoes not depend on $stargazer$, and find its value.",
      "solution": "The answer is 4.\n\nAssume $stargazer \\geq 3$ for the moment.\nWe write the permutations \\pi counted by $moonstone$ as sequences \\pi(1),\\pi(2),\\ldots,\\pi(stargazer).  Let $amberglow$ be the number of permutations counted by $moonstone$ that end with $stargazer-1,stargazer$; let $silvermist$ be the number ending in $stargazer,stargazer-1$; let $pineforest$ be the number starting with $stargazer-1$ and ending in $stargazer-2,stargazer$; let $cloudburst$ be the number ending in $stargazer-2,stargazer$ but not starting with $stargazer-1$; and let $starflower$ be the number which has $stargazer-1,stargazer$ consecutively in that order, but not at the beginning or end.\nIt is clear that every permutation \\pi counted by $moonstone$ either lies in exactly one of the sets counted by $amberglow, silvermist, pineforest, cloudburst, starflower$, or is the reverse of such a permutation.  Therefore\n\\[\nmoonstone = 2 (amberglow + silvermist + pineforest+ cloudburst+ starflower).\n\\]\nBy examining how each of the elements in the sets counted by $emberlight, silvershore, pinegrove, cloudchime, starlitway$ can be obtained from a (unique) element in one of the sets counted by $amberglow, silvermist, pineforest, cloudburst, starflower$ by suitably inserting the element $stargazer+1$, we obtain the recurrence relations\n\\begin{align*}\nemberlight &= amberglow+pineforest+cloudburst, \\\\\nsilvershore&=amberglow, \\\\\npinegrove&=pineforest, \\\\\ncloudchime&=silvermist, \\\\\nstarlitway&=starflower+silvermist.\n\\end{align*}\nAlso, it is clear that $pineforest=1$ for all $stargazer$. \n\nSo far we have assumed $stargazer \\geq 3$, but it is straightforward to extrapolate the sequences $moonstone,amberglow,silvermist,pineforest,cloudburst,starflower$ back to $stargazer=2$ to preserve the preceding identities. Hence for all $stargazer \\geq 2$,\n\\begin{align*}\nhilltopper &= 2(U_{stargazer+5}+V_{stargazer+5}+W_{stargazer+5}+T_{stargazer+5}+S_{stargazer+5}) \\\\\n&= 2((U_{stargazer+4}+W_{stargazer+4}+T_{stargazer+4})+U_{stargazer+4}\\\\\n& \\qquad + W_{stargazer+4}+V_{stargazer+4}+(S_{stargazer+4}+V_{stargazer+4})) \\\\\n&= driftblaze + 2(U_{stargazer+4}+W_{stargazer+4}+V_{stargazer+4}) \\\\\n&= driftblaze + 2((U_{stargazer+3}+W_{stargazer+3}+T_{stargazer+3})+W_{stargazer+3}+U_{stargazer+3}) \\\\\n&= driftblaze + riverdance + 2(U_{stargazer+3}-V_{stargazer+3}+W_{stargazer+3}-S_{stargazer+3}) \\\\\n&= driftblaze + riverdance + 2((U_{stargazer+2}+W_{stargazer+2}+T_{stargazer+2})-U_{stargazer+2}\\\\\n&\\qquad +W_{stargazer+2}-(S_{stargazer+2}-V_{stargazer+2})) \\\\\n&= driftblaze + riverdance + 2(2pineneedle+cloudwhirl-starfarers-silverspark) \\\\\n&= driftblaze + riverdance + 2(2pinegrove+silvershore\\\\\n&\\qquad -(starlitway+silvershore)-emberlight) \\\\\n&= driftblaze + riverdance + 2(2pineforest+amberglow-(starflower+silvermist)-amberglow\\\\\n&\\qquad -(amberglow+pineforest+cloudburst)) \\\\\n&= driftblaze + riverdance - moonstone + 4,\n\\end{align*}\nas desired.\n\n\\noindent\n\\textbf{Remark:}\nThere are many possible variants of the above solution obtained by dividing the permutations up according to different features. For example, Karl Mahlburg suggests \nwriting \n\\[\nmoonstone = 2P'_n, \\qquad P'_n = Q'_n + R'_n\n\\]\nwhere $P'_n$ counts those permutations counted by $moonstone$ for which 1 occurs before 2,\nand $Q'_n$ counts those permutations counted by $P'_n$ for which \\pi(1) = 1. One then has the recursion\n\\[\nQ'_n = Q'_{n-1} + Q'_{n-3} + 1\n\\]\ncorresponding to the cases where \\pi(1), \\pi(2) = 1,2; where \\pi(1), \\pi(2), \\pi(3) = 1,3,2;  and the unique case 1,3,5,\\dots,6,4,2. Meanwhile, one has\n\\[\nR'_n = R'_{n-1} + Q'_{n-2}\n\\]\ncorresponding to the cases containing 3,1,2,4 (where removing 1 and reversing gives a permutation counted by $R'_{n-1}$); and where 4 occurs before 3, 1, 2 (where removing 1,2 and reversing gives a permutation counted by $Q'_{n-2}$).\n\n\\noindent\n\\textbf{Remark:}\nThe permutations counted by $moonstone$ are known as \\textit{key permutations}, and have been studied by E.S. Page, Systematic generation of ordered sequences using recurrence relations, \\textit{The Computer Journal} \\textbf{14} (1971), no. 2, 150--153.  We have used the same notation for consistency with the literature. The sequence of the $moonstone$ also appears as entry A003274 in the On-line Encyclopedia of Integer Sequences (http://oeis.org)."
    },
    "descriptive_long_misleading": {
      "map": {
        "n": "fractionalvalue",
        "i": "outermost",
        "j": "macroindex",
        "\\pi": "stillfunction",
        "P_n": "chaosmeasure",
        "P_{n+5}": "chaosmeasureplusfive",
        "P_n+5": "chaosmeasureplusfive",
        "P_{n+4}": "chaosmeasureplusfour",
        "P_n+4": "chaosmeasureplusfour",
        "P_{n+3}": "chaosmeasureplusthree",
        "P_n+3": "chaosmeasureplusthree",
        "U_n": "frontqueue",
        "V_n": "leadreverse",
        "W_n": "finishblock",
        "T_n": "begincouple",
        "S_n": "separatedduo",
        "U_n+1": "frontqueueplusone",
        "V_n+1": "leadreverseplusone",
        "W_n+1": "finishblockplusone",
        "T_n+1": "begincoupleplusone",
        "S_n+1": "separatedduoplusone",
        "U_n+2": "frontqueueplustwo",
        "V_n+2": "leadreverseplustwo",
        "W_n+2": "finishblockplustwo",
        "T_n+2": "begincoupleplustwo",
        "S_n+2": "separatedduoplustwo",
        "U_n+3": "frontqueueplusthree",
        "V_n+3": "leadreverseplusthree",
        "W_n+3": "finishblockplusthree",
        "T_n+3": "begincoupleplusthree",
        "S_n+3": "separatedduoplusthree",
        "U_n+4": "frontqueueplusfour",
        "V_n+4": "leadreverseplusfour",
        "W_n+4": "finishblockplusfour",
        "T_n+4": "begincoupleplusfour",
        "S_n+4": "separatedduoplusfour",
        "U_{n+1}": "frontqueueplusone",
        "V_{n+1}": "leadreverseplusone",
        "W_{n+1}": "finishblockplusone",
        "T_{n+1}": "begincoupleplusone",
        "S_{n+1}": "separatedduoplusone",
        "U_{n+2}": "frontqueueplustwo",
        "V_{n+2}": "leadreverseplustwo",
        "W_{n+2}": "finishblockplustwo",
        "T_{n+2}": "begincoupleplustwo",
        "S_{n+2}": "separatedduoplustwo",
        "U_{n+3}": "frontqueueplusthree",
        "V_{n+3}": "leadreverseplusthree",
        "W_{n+3}": "finishblockplusthree",
        "T_{n+3}": "begincoupleplusthree",
        "S_{n+3}": "separatedduoplusthree",
        "U_{n+4}": "frontqueueplusfour",
        "V_{n+4}": "leadreverseplusfour",
        "W_{n+4}": "finishblockplusfour",
        "T_{n+4}": "begincoupleplusfour",
        "S_{n+4}": "separatedduoplusfour"
      },
      "question": "Let $chaosmeasure$ be the number of permutations $stillfunction$ of \\{1,2,\\dots,fractionalvalue\\} such that\n\\[\n|outermost-macroindex| = 1 \\mbox{ implies } |stillfunction(outermost) -stillfunction(macroindex)| \\leq 2\n\\]\nfor all $outermost,macroindex$ in \\{1,2,\\dots,fractionalvalue\\}. Show that for $fractionalvalue \\geq 2$, the quantity\n\\[\nchaosmeasureplusfive - chaosmeasureplusfour - chaosmeasureplusthree + chaosmeasure\n\\]\ndoes not depend on $fractionalvalue$, and find its value.",
      "solution": "The answer is 4.\n\nAssume $fractionalvalue \\geq 3$ for the moment.\nWe write the permutations $stillfunction$ counted by $chaosmeasure$ as sequences $stillfunction(1),stillfunction(2),\\ldots,stillfunction(fractionalvalue)$.  Let $frontqueue$ be the number of permutations counted by $chaosmeasure$ that end with $fractionalvalue-1,fractionalvalue$; let $leadreverse$ be the number ending in $fractionalvalue,fractionalvalue-1$; let $finishblock$ be the number starting with $fractionalvalue-1$ and ending in $fractionalvalue-2,fractionalvalue$; let $begincouple$ be the number ending in $fractionalvalue-2,fractionalvalue$ but not starting with $fractionalvalue-1$; and let $separatedduo$ be the number which has $fractionalvalue-1,fractionalvalue$ consecutively in that order, but not at the beginning or end.\nIt is clear that every permutation $stillfunction$ counted by $chaosmeasure$ either lies in exactly one of the sets counted by $frontqueue, leadreverse, finishblock, begincouple, separatedduo$, or is the reverse of such a permutation.  Therefore\n\\[\nchaosmeasure = 2 (frontqueue + leadreverse + finishblock + begincouple + separatedduo).\n\\]\nBy examining how each of the elements in the sets counted by $frontqueueplusone, leadreverseplusone, finishblockplusone, begincoupleplusone, separatedduoplusone$ can be obtained from a (unique) element in one of the sets counted by $frontqueue, leadreverse, finishblock, begincouple, separatedduo$ by suitably inserting the element $fractionalvalue+1$, we obtain the recurrence relations\n\\begin{align*}\nfrontqueueplusone &= frontqueue + finishblock + begincouple, \\\\\nleadreverseplusone &= frontqueue, \\\\\nfinishblockplusone &= finishblock, \\\\\nbegincoupleplusone &= leadreverse, \\\\\nseparatedduoplusone &= separatedduo + leadreverse.\n\\end{align*}\nAlso, it is clear that $finishblock=1$ for all $fractionalvalue$. \n\nSo far we have assumed $fractionalvalue \\geq 3$, but it is straightforward to extrapolate the sequences $chaosmeasure,frontqueue,leadreverse,finishblock,begincouple,separatedduo$ back to $fractionalvalue=2$ to preserve the preceding identities. Hence for all $fractionalvalue \\geq 2$,\n\\begin{align*}\nchaosmeasureplusfive &= 2(frontqueueplusfive+leadreverseplusfive+finishblockplusfive+begincoupleplusfive+separatedduoplusfive) \\\\\n&= 2((frontqueueplusfour+finishblockplusfour+begincoupleplusfour)+frontqueueplusfour\\\\\n& \\qquad + finishblockplusfour+leadreverseplusfour+(separatedduoplusfour+leadreverseplusfour)) \\\\\n&= chaosmeasureplusfour + 2(frontqueueplusfour+finishblockplusfour+leadreverseplusfour) \\\\\n&= chaosmeasureplusfour + chaosmeasureplusthree + 2(frontqueueplusthree - leadreverseplusthree + finishblockplusthree - separatedduoplusthree) \\\\\n&= chaosmeasureplusfour + chaosmeasureplusthree - chaosmeasure + 4,\n\\end{align*}\nas desired.\n\n\\noindent\n\\textbf{Remark:}\nThere are many possible variants of the above solution obtained by dividing the permutations up according to different features. For example, Karl Mahlburg suggests \nwriting \n\\[\nchaosmeasure = 2P'_n, \\qquad P'_n = Q'_n + R'_n\n\\]\nwhere $P'_n$ counts those permutations counted by $chaosmeasure$ for which $1$ occurs before 2,\nand $Q'_n$ counts those permutations counted by $P'_n$ for which $stillfunction(1) = 1$. One then has the recursion\n\\[\nQ'_n = Q'_{n-1} + Q'_{n-3} + 1\n\\]\ncorresponding to the cases where $stillfunction(1), stillfunction(2) = 1,2$; where $stillfunction(1), stillfunction(2), stillfunction(3) = 1,3,2$;  and the unique case $1,3,5,\\dots,6,4,2$. Meanwhile, one has\n\\[\nR'_n = R'_{n-1} + Q'_{n-2}\n\\]\ncorresponding to the cases containing $3,1,2,4$ (where removing 1 and reversing gives a permutation counted by $R'_{n-1}$); and where $4$ occurs before $3, 1, 2$ (where removing $1,2$ and reversing gives a permutation counted by $Q'_{n-2}$).\n\n\\noindent\n\\textbf{Remark:}\nThe permutations counted by $chaosmeasure$ are known as {\\it key permutations}, and have been studied by E.S. Page, Systematic generation of ordered sequences using recurrence relations, {\\it The Computer Journal} {\\bf 14} (1971), no. 2, 150--153.  We have used the same notation for consistency with the literature. The sequence of the $chaosmeasure$ also appears as entry A003274 in the On-line Encyclopedia of Integer Sequences (\\url{http://oeis.org})."
    },
    "garbled_string": {
      "map": {
        "n": "qzxwvtnp",
        "i": "hjgrksla",
        "j": "vbcxkmdq",
        "\\\\pi": "zlkprsnm",
        "P_n": "gtrnszqp",
        "P_n+5": "lkjhstvb",
        "P_n+4": "wqmsrdfg",
        "P_n+3": "fjdkalxc",
        "U_n": "shvngplq",
        "V_n": "jdkslnep",
        "W_n": "qpwodtuz",
        "T_n": "zmtyrnka",
        "S_n": "fghalwpr",
        "U_n+1": "cvbajnkr",
        "V_n+1": "bdsalkre",
        "W_n+1": "mkdspqhe",
        "T_n+1": "ksdjalfv",
        "S_n+1": "pqlnertx",
        "U_n+2": "rghdmscl",
        "V_n+2": "vmnbxqea",
        "W_n+2": "wpeodmca",
        "T_n+2": "jzmxnqpl",
        "S_n+2": "kldprmzs",
        "U_n+3": "zcnqbval",
        "V_n+3": "hlxajpsm",
        "W_n+3": "vxbcqpwo",
        "T_n+3": "nfgjkasd",
        "S_n+3": "osimrdlt",
        "U_n+4": "qrpmznwy",
        "V_n+4": "dcafgoqp",
        "W_n+4": "abmysjvt",
        "T_n+4": "xclprqsn",
        "S_n+4": "vfklqmne"
      },
      "question": "Let $gtrnszqp$ be the number of permutations $zlkprsnm$ of $\\{1,2,\\dots,qzxwvtnp\\}$ such that\n\\[\n|hjgrksla-vbcxkmdq| = 1 \\mbox{ implies } |zlkprsnm(hjgrksla) - zlkprsnm(vbcxkmdq)| \\leq 2\n\\]\nfor all $hjgrksla,vbcxkmdq$ in $\\{1,2,\\dots,qzxwvtnp\\}$. Show that for $qzxwvtnp \\geq 2$, the quantity\n\\[\nlkjhstvb - wqmsrdfg - fjdkalxc + gtrnszqp\n\\]\ndoes not depend on $qzxwvtnp$, and find its value.",
      "solution": "The answer is 4.\n\nAssume $qzxwvtnp \\geq 3$ for the moment.\nWe write the permutations $zlkprsnm$ counted by $gtrnszqp$ as sequences $zlkprsnm(1),zlkprsnm(2),\\ldots,zlkprsnm(qzxwvtnp)$.  Let $shvngplq$ be the number of permutations counted by $gtrnszqp$ that end with $qzxwvtnp-1,qzxwvtnp$; let $jdkslnep$ be the number ending in $qzxwvtnp,qzxwvtnp-1$; let $qpwodtuz$ be the number starting with $qzxwvtnp-1$ and ending in $qzxwvtnp-2,qzxwvtnp$; let $zmtyrnka$ be the number ending in $qzxwvtnp-2,qzxwvtnp$ but not starting with $qzxwvtnp-1$; and let $fghalwpr$ be the number which has $qzxwvtnp-1,qzxwvtnp$ consecutively in that order, but not at the beginning or end.\nIt is clear that every permutation $zlkprsnm$ counted by $gtrnszqp$ either lies in exactly one of the sets counted by $shvngplq, jdkslnep, qpwodtuz, zmtyrnka, fghalwpr$, or is the reverse of such a permutation.  Therefore\n\\[\ngtrnszqp = 2 (shvngplq + jdkslnep + qpwodtuz+ zmtyrnka+ fghalwpr).\n\\]\nBy examining how each of the elements in the sets counted by $cvbajnkr, bdsalkre, mkdspqhe, ksdjalfv, pqlnertx$ can be obtained from a (unique) element in one of the sets counted by $shvngplq, jdkslnep, qpwodtuz, zmtyrnka, fghalwpr$ by suitably inserting the element $qzxwvtnp+1$, we obtain the recurrence relations\n\\begin{align*}\ncvbajnkr &= shvngplq+qpwodtuz+zmtyrnka, \\\\\nbdsalkre &= shvngplq, \\\\\nmkdspqhe &= qpwodtuz, \\\\\nksdjalfv &= jdkslnep, \\\\\npqlnertx &= fghalwpr+jdkslnep.\n\\end{align*}\nAlso, it is clear that $qpwodtuz=1$ for all $qzxwvtnp$. \n\nSo far we have assumed $qzxwvtnp \\geq 3$, but it is straightforward to extrapolate the sequences $gtrnszqp,shvngplq,jdkslnep,qpwodtuz,zmtyrnka,fghalwpr$ back to $qzxwvtnp=2$ to preserve the preceding identities. Hence for all $qzxwvtnp \\geq 2$,\n\\begin{align*}\nlkjhstvb &= 2(U_{qzxwvtnp+5}+V_{qzxwvtnp+5}+W_{qzxwvtnp+5}+T_{qzxwvtnp+5}+S_{qzxwvtnp+5}) \\\\\n&= 2((U_{qzxwvtnp+4}+W_{qzxwvtnp+4}+T_{qzxwvtnp+4})+U_{qzxwvtnp+4}\\\\\n& \\qquad + W_{qzxwvtnp+4}+V_{qzxwvtnp+4}+(S_{qzxwvtnp+4}+V_{qzxwvtnp+4})) \\\\\n&= wqmsrdfg + 2(U_{qzxwvtnp+4}+W_{qzxwvtnp+4}+V_{qzxwvtnp+4}) \\\\\n&= wqmsrdfg + 2((U_{qzxwvtnp+3}+W_{qzxwvtnp+3}+T_{qzxwvtnp+3})+W_{qzxwvtnp+3}+U_{qzxwvtnp+3}) \\\\\n&= wqmsrdfg + fjdkalxc + 2(U_{qzxwvtnp+3}-V_{qzxwvtnp+3}+W_{qzxwvtnp+3}-S_{qzxwvtnp+3}) \\\\\n&= wqmsrdfg + fjdkalxc + 2((U_{qzxwvtnp+2}+W_{qzxwvtnp+2}+T_{qzxwvtnp+2})-U_{qzxwvtnp+2}\\\\\n&\\qquad +W_{qzxwvtnp+2}-(S_{qzxwvtnp+2}-V_{qzxwvtnp+2})) \\\\\n&= wqmsrdfg + fjdkalxc + 2(2W_{qzxwvtnp+2}+T_{qzxwvtnp+2}-S_{qzxwvtnp+2}-V_{qzxwvtnp+2}) \\\\\n&= wqmsrdfg + fjdkalxc + 2(2W_{qzxwvtnp+1}+V_{qzxwvtnp+1}\\\\\n&\\qquad -(S_{qzxwvtnp+1}+V_{qzxwvtnp+1})-U_{qzxwvtnp+1}) \\\\\n&= wqmsrdfg + fjdkalxc + 2(2W_{qzxwvtnp}+shvngplq-(S_{qzxwvtnp}+jdkslnep)-shvngplq\\\\\n&\\qquad -(shvngplq+qpwodtuz+zmtyrnka)) \\\\\n&= wqmsrdfg + fjdkalxc - gtrnszqp + 4,\n\\end{align*}\nas desired.\n\n\\noindent\n\\textbf{Remark:}\nThere are many possible variants of the above solution obtained by dividing the permutations up according to different features. For example, Karl Mahlburg suggests \nwriting \n\\[\ngtrnszqp = 2P'_{qzxwvtnp}, \\qquad P'_{qzxwvtnp} = Q'_{qzxwvtnp} + R'_{qzxwvtnp}\n\\]\nwhere $P'_{qzxwvtnp}$ counts those permutations counted by $gtrnszqp$ for which $1$ occurs before 2,\nand $Q'_{qzxwvtnp}$ counts those permutations counted by $P'_{qzxwvtnp}$ for which $zlkprsnm(1) = 1$. One then has the recursion\n\\[\nQ'_{qzxwvtnp} = Q_{qzxwvtnp-1}' + Q_{qzxwvtnp-3}' + 1\n\\]\ncorresponding to the cases where $zlkprsnm(1), zlkprsnm(2) = 1,2$; where $zlkprsnm(1), zlkprsnm(2), zlkprsnm(3) = 1,3,2$;  and the unique case $1,3,5,\\dots,6,4,2$. Meanwhile, one has\n\\[\nR'_{qzxwvtnp} = R'_{qzxwvtnp-1} + Q'_{qzxwvtnp-2}\n\\]\ncorresponding to the cases containing $3,1,2,4$ (where removing 1 and reversing gives a permutation counted by $R'_{qzxwvtnp-1}$); and where $4$ occurs before $3, 1, 2$ (where removing $1,2$ and reversing gives a permutation counted by $Q'_{qzxwvtnp-2}$).\n\n\\noindent\n\\textbf{Remark:}\nThe permutations counted by $gtrnszqp$ are known as \\emph{key permutations}, and have been studied by E.S. Page, Systematic generation of ordered sequences using recurrence relations, \\emph{The Computer Journal} \\textbf{14} (1971), no. 2, 150--153.  We have used the same notation for consistency with the literature. The sequence of the $gtrnszqp$ also appears as entry A003274 in the On-line Encyclopedia of Integer Sequences (\\url{http://oeis.org})."
    },
    "kernel_variant": {
      "question": "Let $P_n$ be the number of permutations $\\pi$ of the set $\\{1,2,\\dots ,n\\}$ that satisfy\n\n\\[|\\pi(i)-\\pi(i+1)|\\le 2 \\qquad (1\\le i<n).\\]\n\nProve that for every integer $n\\ge 2$ the quantity\n\\[\nP_{n+5}-P_{n+4}-P_{n+3}+P_n\n\\]\ndoes not depend on $n$, and determine its value.",
      "solution": "Throughout we write permutations in one–line notation, e.g. $\\pi=\\pi(1)\\,\\pi(2)\\,\\dots ,\\pi(n)$.  All indices are integers and all equalities between sets are meant as bijections.\n\n1.  A symmetry reduction\n------------------------\nLet $P'_n$ be the number of admissible permutations in which the entry $1$ appears **before** the entry $2$.  Reversing the word,\n\\[\\rho: \\pi(1)\\,\\dots\\,\\pi(n)\\longmapsto\\pi(n)\\,\\dots\\,\\pi(1),\\]\npreserves the condition “adjacent values differ by at most 2’’ and exchanges the relative order of $1$ and $2$.  Hence $\\rho$ is a fixed–point–free involution and therefore\n\\[\nP_n = 2P'_n \\qquad(n\\ge 2). \\tag{1}\n\\]\nWe shall enumerate $P'_n$.\n\n2.  Separating the permutations that begin with 1\n------------------------------------------------\nDefine\n\\[\nQ_n:=\\#\\{\\pi\\mid\\pi \\text{ counted by }P'_n\\text{ and }\\pi(1)=1\\},\\qquad\nR_n:=P'_n-Q_n. \\tag{2}\n\\]\nThus $Q_n$ counts the admissible permutations that start with 1, and $R_n$ those that do not.\n\n3.  A recurrence for $Q_n$\n--------------------------\nFix $n\\ge 4$ and let $\\pi\\in Q_n$; because $\\pi(1)=1$ we have $\\pi(2)\\in\\{2,3\\}$.\n\n• Case $\\pi(2)=2$.  Delete the initial 1 and subtract 1 from each remaining symbol.  This is a bijection with $Q_{n-1}$.\n\n• Case $\\pi(2)=3$.  Then $|3-\\pi(3)|\\le 2$, so $\\pi(3)=2,4,$ or $5$ (the value 1 is already used).\n\n  – Sub-case $\\pi(3)=2$.  Remove the block $1,3,2$ and subtract 3 from every larger symbol; this is a bijection with $Q_{n-3}$.\n\n  – Sub-case $\\pi(3)=4$ or $\\pi(3)=5$.\n    We shall show that **exactly one** admissible permutation begins with $1,3$ but is **not** followed by 2, and that this permutation is\n\\[\n\\begin{cases}\n1,3,4,2 & (n=4),\\\\[4pt]\n1,3,5,7,\\dots ,n,\\,n-1,\\,n-3,\\dots ,4,2 & (n\\ge 5,\\ n\\text{ odd}),\\\\[4pt]\n1,3,5,7,\\dots ,n-1,\\,n,\\,n-2,\\,n-4,\\dots ,4,2 & (n\\ge 5,\\ n\\text{ even}).\n\\end{cases} \\tag{3}\n\\]\n    We must therefore justify two points:\n\n    (i) For each $n\\ge 4$ the word (3) really is admissible.\n\n    (ii) No other admissible permutation begins with $1,3$ without the symbol 2 in the third position.\n\n    Proof of (i).  In (3) every two neighbouring values differ by $2$ or $1$, so the condition is satisfied.\n\n    Proof of (ii).  Suppose an admissible permutation starts with $1,3$ and $\\pi(3)\\ne2$.  Set $a_1:=1$, $a_2:=3$, and write $a_k:=\\pi(k)$ for $k\\ge3$ until the construction breaks.\n\n    • Because $|a_2-a_3|\\le2$ and $a_3\\ne2$, we must have $a_3=4$ or $5$.\n\n    • If $n=4$ then $a_3=4$ forces $a_4=2$, giving exactly the first line of (3).\n\n    • Assume $n\\ge5$.  If $a_3=4$, then $a_4$ must be $2,3,5$ or $6$, but $2,3$ are already used and $|4-6|=2$ would leave no legal place for 5 next, contradicting the fact that every number must occur exactly once. Hence $a_3$ cannot be 4; thus $a_3=5$.\n\n      Inductively, suppose we have constructed $1,3,5,7,\\dots ,2k+1$ (all odd numbers up to $2k+1$).  The next unused number $2k+2$ differs from $2k+1$ by 1, so $a_{k+3}=2k+2$ is permissible.  If $k+1<n/2$ we can continue with $2k+3$, etc., until we run out of numbers.  When the largest remaining number is placed we necessarily reverse direction, because the only unused number differing by at most 2 is smaller.  One then successively places $n-1,n-3,\\dots ,4,2$, obtaining exactly the word (3).\n\n      At no step is an alternative choice possible, so the permutation is unique.\n\n    Consequently the two sub-cases $\\pi(3)=4$ or $\\pi(3)=5$ together contribute exactly **one** permutation, and the three mutually exclusive possibilities give\n\\[Q_n = Q_{n-1}+Q_{n-3}+1\\qquad(n\\ge 4). \\tag{4}\\]\n\nInitial values (by direct inspection)\n\\[Q_1=1,\\qquad Q_2=1,\\qquad Q_3=2. \\tag{5}\\]\n\n4.  A recurrence for $R_n$\n--------------------------\nTake $\\pi\\in R_n$ with $n\\ge 4$.  Because 1 is not the first entry, the symbol immediately before 1 must be 3.  Two disjoint possibilities occur.\n\nCASE A: 2 is **not** the last entry.  Then the element right after 2 is forced to be 4, so $\\pi$ contains the consecutive block $3,1,2,4$.  Delete the single entry 1, reverse the remaining word and relabel $\\{2,3,\\dots ,n\\}\\to\\{1,2,\\dots ,n-1\\}$ by subtracting 1.  The result is a permutation counted by $R_{n-1}$, and the construction is reversible.  Thus the permutations of type A are equinumerous with $R_{n-1}$.\n\nCASE B: 2 is the last entry.  Then $\\pi$ ends with $3,1,2$.  Delete the final **two** entries 1 and 2, reverse what remains and relabel $\\{3,4,\\dots ,n\\}\\to\\{1,2,\\dots ,n-2\\}$ by subtracting 2.  The image starts with 1 (because the 3 at the old end becomes the new first entry and is turned into 1 by the relabelling), so it lies in $Q_{n-2}$.  Again the operation is bijective.\n\nCombining the two cases we get, for every $n\\ge 4$,\n\\[R_n = R_{n-1}+Q_{n-2}. \\tag{6}\\]\n\nInitial data (by inspection):\n\\[R_2=0\\quad(21\\text{ is forbidden}),\\qquad R_3=1\\quad(312). \\tag{7}\\]\nNote that (6) also holds for $n=3$ because $R_3=R_2+Q_1=0+1=1$.\n\n5.  Constancy of the requested combination\n-----------------------------------------\nPut $S_n:=P'_n=Q_n+R_n$.  From (6)\n\\[R_{k+1}-R_k=Q_{k-1}\\quad(k\\ge 2), \\tag{8}\\]\nand from (4)\n\\[Q_{k+1}-Q_k=Q_{k-2}+1\\quad(k\\ge 3). \\tag{9}\\]\nCompute successively for any $n\\ge 2$:\n\\[\n\\begin{aligned}\nS_{n+5}-S_{n+4}\n   &= (Q_{n+5}-Q_{n+4})+(R_{n+5}-R_{n+4})\\\\[2pt]\n   &= (Q_{n+2}+1)+Q_{n+3} &\\text{by (9) and (8)},\\\\[6pt]\nS_{n+5}-S_{n+4}-S_{n+3}\n   &= Q_{n+2}+1-R_{n+3},\\\\[6pt]\nS_{n+5}-S_{n+4}-S_{n+3}+S_n\n   &=Q_{n+2}+1-R_{n+3}+Q_n+R_n. \\tag{10}\n\\end{aligned}\n\\]\nIterating (8) three times gives\n\\[R_{n+3}=R_n+Q_{n-1}+Q_n+Q_{n+1}.\\]\nSubstituting into (10) we obtain\n\\[S_{n+5}-S_{n+4}-S_{n+3}+S_n=Q_{n+2}+1-Q_{n-1}-Q_{n+1}.\\]\nFinally insert $Q_{n+2}=Q_{n+1}+Q_{n-1}+1$ from (4):\n\\[S_{n+5}-S_{n+4}-S_{n+3}+S_n=(Q_{n+1}+Q_{n-1}+1)+1-Q_{n-1}-Q_{n+1}=2.\\]\nThus\n\\[P'_{n+5}-P'_{n+4}-P'_{n+3}+P'_n=2\\qquad(n\\ge 2).\\]\nUsing (1) we finally get\n\\[\\boxed{\\;P_{n+5}-P_{n+4}-P_{n+3}+P_n=4\\;}\\qquad(n\\ge 2).\\]\n\n6.  Numerical check\n-------------------\nA short enumeration gives\n$P_2=2,\\;P_3=6,\\;P_4=12,\\;P_5=20,\\;P_6=34,\\;P_7=56,\\;P_8=88,\\dots$\nFor $n=2$ one indeed has\n$P_7-P_6-P_5+P_2=56-34-20+2=4$, in agreement with the proven formula.",
      "_meta": {
        "core_steps": [
          "Exploit reversal symmetry to halve the counting problem (P_n = 2·Σ subclasses).",
          "Partition permutations according to precise placement of the three largest entries, giving five subclasses U,V,W,T,S.",
          "Insert n+1 into an n-permutation to obtain linear recurrences among U,V,W,T,S.",
          "Note the fixed subsequence count W_n = 1, then combine the recurrences to produce P_{n+5} = P_{n+4} + P_{n+3} − P_n + 4.",
          "Re-arrange to get the constant difference P_{n+5} − P_{n+4} − P_{n+3} + P_n = 4."
        ],
        "mutable_slots": {
          "slot1": {
            "description": "Names chosen for the five subclasses used in the partition (any 5 distinct symbols would work).",
            "original": "U, V, W, T, S"
          },
          "slot2": {
            "description": "The point at which the argument formally begins (n ≥ 3 before back-extrapolating); any small base value large enough to make the insert-(n+1) argument legitimate would serve.",
            "original": "3"
          }
        }
      }
    }
  },
  "checked": true,
  "problem_type": "proof",
  "iteratively_fixed": true
}