[Question]
      [
## The Task
The task is easy: given an Alpha-2 country code, output the Alpha-3 equivalent. The input may be in any case you choose, and the output in any consistent case of your choosing. Here are the codes:
```
[["AF", "AFG"], ["AX", "ALA"], ["AL", "ALB"], ["DZ", "DZA"], ["AS", "ASM"], ["AD", "AND"], ["AO", "AGO"], ["AI", "AIA"], ["AQ", "ATA"], ["AG", "ATG"], ["AR", "ARG"], ["AM", "ARM"], ["AW", "ABW"], ["AU", "AUS"], ["AT", "AUT"], ["AZ", "AZE"], ["BS", "BHS"], ["BH", "BHR"], ["BD", "BGD"], ["BB", "BRB"], ["BY", "BLR"], ["BE", "BEL"], ["BZ", "BLZ"], ["BJ", "BEN"], ["BM", "BMU"], ["BT", "BTN"], ["BO", "BOL"], ["BA", "BIH"], ["BW", "BWA"], ["BV", "BVT"], ["BR", "BRA"], ["VG", "VGB"], ["IO", "IOT"], ["BN", "BRN"], ["BG", "BGR"], ["BF", "BFA"], ["BI", "BDI"], ["KH", "KHM"], ["CM", "CMR"], ["CA", "CAN"], ["CV", "CPV"], ["KY", "CYM"], ["CF", "CAF"], ["TD", "TCD"], ["CL", "CHL"], ["CN", "CHN"], ["HK", "HKG"], ["MO", "MAC"], ["CX", "CXR"], ["CC", "CCK"], ["CO", "COL"], ["KM", "COM"], ["CG", "COG"], ["CD", "COD"], ["CK", "COK"], ["CR", "CRI"], ["CI", "CIV"], ["HR", "HRV"], ["CU", "CUB"], ["CY", "CYP"], ["CZ", "CZE"], ["DK", "DNK"], ["DJ", "DJI"], ["DM", "DMA"], ["DO", "DOM"], ["EC", "ECU"], ["EG", "EGY"], ["SV", "SLV"], ["GQ", "GNQ"], ["ER", "ERI"], ["EE", "EST"], ["ET", "ETH"], ["FK", "FLK"], ["FO", "FRO"], ["FJ", "FJI"], ["FI", "FIN"], ["FR", "FRA"], ["GF", "GUF"], ["PF", "PYF"], ["TF", "ATF"], ["GA", "GAB"], ["GM", "GMB"], ["GE", "GEO"], ["DE", "DEU"], ["GH", "GHA"], ["GI", "GIB"], ["GR", "GRC"], ["GL", "GRL"], ["GD", "GRD"], ["GP", "GLP"], ["GU", "GUM"], ["GT", "GTM"], ["GG", "GGY"], ["GN", "GIN"], ["GW", "GNB"], ["GY", "GUY"], ["HT", "HTI"], ["HM", "HMD"], ["VA", "VAT"], ["HN", "HND"], ["HU", "HUN"], ["IS", "ISL"], ["IN", "IND"], ["ID", "IDN"], ["IR", "IRN"], ["IQ", "IRQ"], ["IE", "IRL"], ["IM", "IMN"], ["IL", "ISR"], ["IT", "ITA"], ["JM", "JAM"], ["JP", "JPN"], ["JE", "JEY"], ["JO", "JOR"], ["KZ", "KAZ"], ["KE", "KEN"], ["KI", "KIR"], ["KP", "PRK"], ["KR", "KOR"], ["KW", "KWT"], ["KG", "KGZ"], ["LA", "LAO"], ["LV", "LVA"], ["LB", "LBN"], ["LS", "LSO"], ["LR", "LBR"], ["LY", "LBY"], ["LI", "LIE"], ["LT", "LTU"], ["LU", "LUX"], ["MK", "MKD"], ["MG", "MDG"], ["MW", "MWI"], ["MY", "MYS"], ["MV", "MDV"], ["ML", "MLI"], ["MT", "MLT"], ["MH", "MHL"], ["MQ", "MTQ"], ["MR", "MRT"], ["MU", "MUS"], ["YT", "MYT"], ["MX", "MEX"], ["FM", "FSM"], ["MD", "MDA"], ["MC", "MCO"], ["MN", "MNG"], ["ME", "MNE"], ["MS", "MSR"], ["MA", "MAR"], ["MZ", "MOZ"], ["MM", "MMR"], ["NA", "NAM"], ["NR", "NRU"], ["NP", "NPL"], ["NL", "NLD"], ["AN", "ANT"], ["NC", "NCL"], ["NZ", "NZL"], ["NI", "NIC"], ["NE", "NER"], ["NG", "NGA"], ["NU", "NIU"], ["NF", "NFK"], ["MP", "MNP"], ["NO", "NOR"], ["OM", "OMN"], ["PK", "PAK"], ["PW", "PLW"], ["PS", "PSE"], ["PA", "PAN"], ["PG", "PNG"], ["PY", "PRY"], ["PE", "PER"], ["PH", "PHL"], ["PN", "PCN"], ["PL", "POL"], ["PT", "PRT"], ["PR", "PRI"], ["QA", "QAT"], ["RE", "REU"], ["RO", "ROU"], ["RU", "RUS"], ["RW", "RWA"], ["BL", "BLM"], ["SH", "SHN"], ["KN", "KNA"], ["LC", "LCA"], ["MF", "MAF"], ["PM", "SPM"], ["VC", "VCT"], ["WS", "WSM"], ["SM", "SMR"], ["ST", "STP"], ["SA", "SAU"], ["SN", "SEN"], ["RS", "SRB"], ["SC", "SYC"], ["SL", "SLE"], ["SG", "SGP"], ["SK", "SVK"], ["SI", "SVN"], ["SB", "SLB"], ["SO", "SOM"], ["ZA", "ZAF"], ["GS", "SGS"], ["SS", "SSD"], ["ES", "ESP"], ["LK", "LKA"], ["SD", "SDN"], ["SR", "SUR"], ["SJ", "SJM"], ["SZ", "SWZ"], ["SE", "SWE"], ["CH", "CHE"], ["SY", "SYR"], ["TW", "TWN"], ["TJ", "TJK"], ["TZ", "TZA"], ["TH", "THA"], ["TL", "TLS"], ["TG", "TGO"], ["TK", "TKL"], ["TO", "TON"], ["TT", "TTO"], ["TN", "TUN"], ["TR", "TUR"], ["TM", "TKM"], ["TC", "TCA"], ["TV", "TUV"], ["UG", "UGA"], ["UA", "UKR"], ["AE", "ARE"], ["GB", "GBR"], ["US", "USA"], ["UM", "UMI"], ["UY", "URY"], ["UZ", "UZB"], ["VU", "VUT"], ["VE", "VEN"], ["VN", "VNM"], ["VI", "VIR"], ["WF", "WLF"], ["EH", "ESH"], ["YE", "YEM"], ["ZM", "ZMB"], ["ZW", "ZWE"]]
```
## Test Cases
```
US -> USA
GT -> GTM
VA -> VAT
IN -> IND
KP -> PRK
```
## Scoring
Because my soft drive can only store a kilobyte, and because this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the shortest code in bytes wins.
This is the reverse of [this challenge](https://codegolf.stackexchange.com/q/246777/107299).

[Answer]
# JavaScript (ES6), ~~582~~ 554 bytes
```
s=>("CCAPMSSS"[x="KYKMTFKPYTPMRSGSAXAQBYBJBAMOEEGWIEILSIUA".search([a,b]=s)/2]||a)+("YOTRYPRGLTLEIASNRSVK"[x]+"MMFKTMBSAARNHCTBLRNR"[x]||(c="E8bOUX3b11R1O1nadL2DIRG1ntTRlSdIeSo10M1L1RK2C2D2RL1U2i4L22N23N3RynL2ao1c3IEr2l1r11T39U9U5S15UlyNw1PN1MvEReM2uDP1l2Rw13c2O2KLSkuN2u1O1uN25I11rB10T1T1N1B1R4M6TnrGt4BrTg2GMuS1bl1E10Mr1gL1RRd2MUrL3hN1T3l10N1Ko1aoEV1ohRhL2I2BpMRPE14U4In3M3F11B7U1E1Ys9IPH24NIl1s1r21BR1rOuY1B2rBi1lnC1MM3u21G1DD3V1IN18N8NDT1rNL21Y7a1RN24N1ZMR8o4T2a10ON1".replace(/\d+/g,n=>"A".repeat(n))[parseInt(s,36)%774],c>{}?c.toUpperCase()+b:b+c))
```
[Try it online!](https://tio.run/##NVfbchs3En3XV7BYtWWypJWNoRzbScmpuWKGA4AjADPUUNEDRdGWd1mkipSSTcX5g1TlZR93/yPfkx/IJzg86PaLVEfTODh9utGA/rX8cXlY7T89Pv1zu7tff/lw@eVw@X40TNO40c654c1/Lod1X2tf1E3vG22ddPF1fJX0yTSJ9SzP5bzKK@WqNh6eH9bL/ephdLM8u7u9PIxfRrefPy/Hp6NhP/O2b6xUXuVV7Ix1XX3kvj0dal3UXicujq0pU58oayy@fP48Wl0O87d3s/Z6cieEFTOxXd6rKKusFNsnbzfuvlq7nXilhRK2jtIoi6wSbfTpQkWRiSZmYn/eqmi5E6tJle@jjdgL4Sfv2nftaydet5ufzU@iMUL/mNu1jp6zRmwi@5OYrKJZVCv372cTPR@3Pf56XQmxT8QrL7wwIhH2Qn/jt3v5dJHs/cdI6mcn7jYiP4rZi49HOfY@0u1eTR7McceNeGVEvRPLXd6J3YN9UFEVJY/aNrm4aC@q7URPCiGSN@2RoT@8q5oyujDVRhzEPhKJFfvZcy@SaJ98EpttKrSePEdCiiybdKIy4q15azIv9kZFon@zFNYcl4uFtm93Fz5ailczI4bn@/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Qjd7RhlPIAyAPNHzT3Ac6DtOSAWqqZ1QFjX00D2@DMMMdYqDaWDLRoMCmoeQMPDCKb2cTrmpKwUCbSTkM@5gFA9THVHRoDYSanDdFFYyk5EwbwnhTzBBTUFfpJiRHx9mgRw232AwpzLj9GxS4iWlNg5o2iu76BoY0jtxp4hDGa6CgYRObPrQydVUDoQ0LbVDghgvcIO0mZQIY0vAt0/hAQIY0NgBqlytsesXDwYLa8rCzyMfOGMADyx1ikYL9er2r8HKg@jjIcXw31pBTGz4/qIJKuV2KUHoe0bDKNUTQIaxLSc4c7sy531wI46ZwyMd5Mt4hBReTUIdNHc8DCwLHjx8HatdTtZ0K1xQZ7@C1k8yGYuHZH0AVALG5JKxhNrjj@DpcQMGC85FhU0lWuQActWXuwqVH@yjso2oyxOEwOZ6wDvVxLWeKS89N2QN0r5vTKXF5AJRCWoZHCefTh0yJwKNYfk7UHmx@Ssl5sHl@6noQeL7aPNzxilLwcMfzU9dDta@pqzw88DOmRkm85zBUwfPF4m0ALEcHAsrHp@GRxZt2IYxGWotNWz6ALextayKI8/BwpkwlSiJ59rawt3W8Bvu0mpq8hSEtn58WabcLKmOHvu74fd2BuuPe6ZBCZ7gt0QcdXyxzdO9cUbXzMtSU3i49CPqcmwIKFvymWKAKCxTr5Pbk/MNuny@P/4CObgbLzePDMjqj35PB7Xhw@X7wy8lgsFk/Dfbrw@By8GFEQePvjn9e7baH3WZ9vtl9HH1deww7o9jLrzzfD1789cfvf/7vv8efLwbfDl78@f/fXoxPfh1/@Rs "JavaScript (Node.js) – Try It Online")
### How?
The most common letter that needs to be added to an alpha-2 code to get the alpha-3 code is `A`. Therefore, it's the best suited padding character for our main lookup string, which is expanded by replacing all integers with the corresponding number of `A`'s.
[Try it online!](https://tio.run/##dVDNbptAGLznKRAnW2kdz7e4sWWlUgnURWYXa4GornpZwwrcrhZrgaR5epcccsxppNH8af6oZ9VX7nwZPtuu1ter0YPXew@eH69PWfmTnQCJDFbVKUWJ3MEOhTR5nei8w5IjhdzTI0UkU5R0DlIiQUww@WpTUh0qlsSODBxQsE25KVc5VqV5FS84CPDnWGpOY3SAIfkCVlFG@zT/Owoap9oJVgngQiwLFBAIIQP@pbBuNwShKxra8THHySCexjg00xxZEy9dyloxNRosBfYdVBc/oWtlm1JC4YXLQ4ygDBLLOPsOhPfllHDsN8nhBwUiMejhCKGEy8YjQnLhGcY@gnM2EnaIIvaERGAt1iIq4ERKON4rSDHZ8YvLdRcUpLDMBPztzdur@t9F2VrX07n9wumLUZWe3f2ub@@aT/bhq//Nf2O1GmZ2Pt/eVJ3tO6MXpmtm79aF0bYZWu/W872qVU5Vg3a9/4F6vr1e/wM "JavaScript (Node.js) – Try It Online")
The lookup function is a single modulo on the input parsed in base-36:
```
parseInt(s, 36) % 774
```
If we get a character in upper case, it means that it must be added at the end of the alpha-2 code.
```
"AF" ~> "G" ~> "AF**G**"
```
If we get a character in lower case, it means that it must be added in the middle of the alpha-2 code:
```
"AO" ~> "g" ~> "A**G**O"
```
Similarly to [my answer to the other challenge](https://codegolf.stackexchange.com/a/246784/58563), the 20 codes that do not follow the above rules are hard-coded separately, just the other way around.
[Answer]
# [Perl 5](https://www.perl.org/) `-MLocale::Country -pl`, ~~48~~ 40 bytes
```
$_=country_code2code($_,,'alpha-3')||ant
```
[Try it online!](https://tio.run/##JZOxat0wGEb38xyBtJAsLV0CHSRZlmXpl3Ul2Y69hEsaaCHkhjQdCnn23qZ0OcPh8G3f88PL45fz@eLu6/3p19Pry@@7@9O3h0//8OHi7urq8vj4/P14/fny49vb8en1fFYdyqJ6lEN5VEQJKqEm1AFVUBXVUDNqRd2idrRCa3SHtuge7dAD2qNHdEQLOqEndEFXdEMv6BW9oXeMwhhMh@kxDjNgPCZgIkYwCTNhCmbGLJhbzIbZ6SzdSBfohG6i27EGa7EOO2ALtmIbvacf6QO90E/0BadwGtfhLK7HOdyA87iIE1zCZdwB915WXMPNuBW3MQQGYUgMhaExzPgOb/ERL/iEn/AHfMFXfGO0jMI4MWaCJTjCQPAEISTCuyyElbARdqIiaqIhemIgFmIlNuJMXIgbohCDdIhFesQhAxKQiAiSkAnJyAEpSEUaMiMLsiK3yPvCTlIkQ7KknuRInhRJEymTCmkm7UxCVmRL7smOPJADOZLffSIXciU38kreOCiKpUyUSpkpK1VRNdVQO6qlOupA9dSRGqiRKtREnaiFWqmNulA36k4ztI7W0xxtoI20QIs0oSXaRCu0RltoK21nVsyOWZgr88a8sygWw2JZHItnSSwza89a2SxbY1fswr7@OT2//jg9/TxfSzzdHx8fbm7M/3ecr58f/wI "Perl 5 – Try It Online")
For some reason, the AN->ANT mapping isn't in Perl's list so I had to hardcode it.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~435~~ ~~426~~ 422 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
.•4₆₆ÿ¸˜E¡´³*ιœýOóÖq₅;YpÂ-|ož®Ωg4∊₅“=à–ô9αA$ΔL,žÆE6óµQ£‚Ç\ΣN¬ÓóÑC∞\†ìвö—'‰ßÍ™¶HFü"í4·nÛZ0ø₅k{'¦Δ"¢h¦h)U–Ì±4ƒ¿¢
œ\a^»ãfzλ»Ï˜≠7>2e5Nl”SGed.iÉVó¸£₃l&C§ÚΣ6½+¢ å(₃L¦Ûā:vÊιOL†aëƵ₁fǝfVEtþΣ{õ-o¡ø4•u2ôD•46‰εcĆ2Zâæ¥ÙÚMт'•₂в£εN>.b«}˜ø.•1…¤θ30ËиʒÕf%γžBpéт(ĆVáä∞Kî%àôλ#KbÉµC‘jÊα-zª+UΛGÙÀ"zFûÌιô#fиαL¸Λ¾o₄Ò{žwým«‚È3÷«εΩ)ØN÷U•u2ôD•Gò7¬ýà®vQ<ÑU•12в£ε€SN>.bý}˜áø.•Úù»ÔáÝâ|¹мœ4å)Çø{:вoÒaÿšмk*øW—Ã*‹ΣcÌ‰Δú¤š3rSwsJÜ²ùη₅ĀPŽEf~:•u23S40∍£)˜DIk>è
```
[Try it online](https://tio.run/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wc2tTbTM8mhQ2nDcOAvuXNpElhk9pmvzZzsPFv48fGp00um3qHEwdOh3QOul30OvA41Dv4d2Bz8OzgwWHvtu5lbj0wu6RzyeWi7qLl0uuS1IXNJZ2Loou6Sy4XV7109VHZB38fun36C6XegyEHg6Wz65ep3wkn/XjwOPHg92D26OrTt1R6mlN/HaTwyO6xWQ8Pg/qd6y4wpTeu69mCh3@Pr8Zjhh4pDNx6TMAnhU@NT43PrY8HHw8@nD66Ps59PPvw@yTyce7zcvJ05XHYpb8@nOdxmKc@j3oexQLzLFBZgLlA3n5mmMLPALeD9A72xz74Dw).
**Explanation:**
Step 1a: Create I/O pairs of all alpha-2 codes for which a single trailing letter has to be added for the alpha-3 conversion:
```
.•4₆₆ÿ¸˜E¡´³*ιœýOóÖq₅;YpÂ-|ož®Ωg4∊₅“=à–ô9αA$ΔL,žÆE6óµQ£‚Ç\ΣN¬ÓóÑC∞\†ìвö—'‰ßÍ™¶HFü"í4·nÛZ0ø₅k{'¦Δ"¢h¦h)U–Ì±4ƒ¿¢
œ\a^»ãfzλ»Ï˜≠7>2e5Nl”SGed.iÉVó¸£₃l&C§ÚΣ6½+¢ å(₃L¦Ûā:vÊιOL†aëƵ₁fǝfVEtþΣ{õ-o¡ø4•
              "# Push compressed string "dzaibwbrbfdmfrghitlvmdngrwknlclktzthtcugusalvgcugagmgiuzzmgrnihmhninmknlssazczlipsslchzwzaafarhkmnetcrdjerfjhtmwmlprumccnftjbebocoismhnpncnzphtkaskhdogugtnablwssosjvnyebtcafihuidirimjpkelbompashsdtwtovegelalsmctgttcystsgesbhbgcmcxjokimsmammnenopesmsygbviaumymurutlbviovakwmranqavcvubmecdeltnrrerosacihrluegggjekg"
 u             # Uppercase it
  2ô           # Split it into parts of size 2
    D          # Duplicate this list of pairs
•46‰εcĆ2Zâæ¥ÙÚMт'•
              '# Push compressed integer 5045888909142307005039435397419896531
 ₂в            # Convert it to base-26 as list: [21,8,2,6,7,1,4,1,9,0,3,10,12,17,6,4,0,16,5,9,8,2,0,1,3,1]
   £           # Split the duplicated pairs into parts of that size
    ε          # Map over each list of string-pairs:
     N>        #  Push the 1-based map-index
       .b      #  Convert it to an uppercase alphabetic letter (1=A,2=B,...,26=Z)
         «     #  Append it to each string-pair in the current list
    }˜         # After the map: flatten
      ø        # Create pairs of the two lists
```
[Try just this step, to see all I/O pairs of step 1a.](https://tio.run/##FZBtK0NxGMbf@xRa8mxpHROixPBiJomipYYNkZGHFx7qOJhNJLaUGeacTPIQtsNZs63ua5sXq3/zFf5fZP7qrruuF9f1uy7vqmtq3l0um7msSlzxiUOWjGLERneUoHg9S@aDSA8hjosVrhx0jC9Dadr25jP0yh5nJe4/EiqXI52IcjmIRBt7765iIXtjPgOfzYo46cOkcTmMQyfTHPSMoPA66@H@GyeXo3gufeCTy6EaLr/hFid8X6XPgT58m/Ai0dcSriaaYYiMha0airGQidQ5is3Vjf6nHdO7VDinLKkV@aDTNUkpaJ5NlhL/tBjhgWhrl8Xd4ljk8vVIv3vGPI/AmCAyBJCyt1jdQw8IM81K6QZSK3FfK1Q7xXCV223fwBFLDtkFogtPBZ0ru56fa8@YbQ0Zpm1Bb/LSHQxJzLZuQaL3fz6rqMD06ZzPMgEVMbrHJcKDv4qopnJFKX2QxnRHl3mKnnaKERjl8h8)
Step 1b: Create I/O pairs of all alpha-2 codes for which a single middle letter has to be added for the alpha-3 conversion:
```
.•1…¤θ30ËиʒÕf%γžBpéт(ĆVáä∞Kî%àôλ#KbÉµC‘jÊα-zª+UΛGÙÀ"zFûÌιô#fиαL¸Λ¾o₄Ò{žwým«‚È3÷«εΩ)ØN÷U•
               # Push compressed string "cfjmkzpkmfawlrlytdpnbimgmvmxsnaobdbsclcngnnutmbzsvfkgpmtpwsbwfaddkgqmemppgcgcdckkrmzplcvambbbnfoglgdiqpyptaeuyfmehagmqatgfgysrtntrtvskszsepfsc"
 u2ôD          # Same as above (uppercase; split into pairs; duplicate)
•Gò7¬ýà®vQ<ÑU• # Push compressed integer 5023299766197034891137684120
 12в           # Convert it to base-12 as list: [5,3,2,3,2,0,2,3,2,0,1,8,0,6,6,1,0,11,2,2,7,1,2,0,2,0]
    £          # Split the duplicated pairs into parts of that size
     ε         # Map over each list of string-pairs:
      €S       #  Convert each string to a list
        N>.b   #  Same as above: get the uppercase letter based on the index
            ý  #  Join the inner list-pairs with this letter as delimiter
     }˜áø      # Same as above, but `á` removes empty strings from the list
```
[Try just this step, to see all I/O pairs of step 1b.](https://tio.run/##AdMALP9vc2FiaWX//y7igKIx4oCmwqTOuDMww4vQuMqSw5VmJc6zxb5CcMOp0YIoxIZWw6HDpOKInkvDriXDoMO0zrsjS2LDicK1Q@KAmGrDis6xLXrCqitVzptHw5nDgCJ6RsO7w4zOucO0I2bQuM6xTMK4zpvCvm/igoTDknvFvnfDvW3Cq@KAmsOIM8O3wqvOtc6pKcOYTsO3VeKAonUyw7RE4oCiR8OyN8Ksw73DoMKudlE8w5FV4oCiMTLQssKjzrXigqxTTj4uYsO9fcucw6HDuP//)
Step 1c: Create I/O pairs for all remaining alpha-2 to alpha-3 conversions (as a flattened list):
```
.•Úù»ÔáÝâ|¹мœ4å)Çø{:вoÒaÿšмk*øW—Ã*‹ΣcÌ‰Δú¤š3rSwsJÜ²ùη₅ĀPŽEf~:•
               # Push compressed string "aqataaxalababihbjbenbyblreeestgssgsgwgnbieirlilisrkmcomkpprkkycymmomacpmspmrssrbsisvntfatfuaukrytmyt"
 u             # Uppercase it
  23S          # Push [2,3]
     40∍       # Extend it to size 40: [2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3,2,3]
        £      # Split the string into parts of that size
```
[Try just this step, to see the flattened list of all the I/O pairs of step 1c.](https://tio.run/##AX8AgP9vc2FiaWX//y7igKLDmsO5wrvDlMOhw53DonzCudC8xZM0w6Upw4fDuHs60LJvw5Jhw7/FodC8ayrDuFfigJTDgyrigLnOo2PDjOKAsM6Uw7rCpMWhM3JTd3NKw5zCssO5zrfigoXEgFDFvUVmfjrigKJ1MjNTNDDiiI3Co///)
Step 2: Combine the results of the previous steps, and use them for the input to output conversion:
```
)              # Wrap the entire stack into a list
 ˜             # Flatten
  D            # Duplicate this list
   Ik          # Get the index of the input-string
     >         # Increase this index by 1
      è        # And use it to index into the list
               # (after which the result is output implicitly)
```
[See this 05AB1E tip of mine (sections *How to compress strings not part of the dictionary?*, *How to compress large integers?*, and *How to compress integer lists?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand how the compressions work.
[Answer]
# [R](https://www.r-project.org/), 74 bytes
```
function(c)`if`(c=="AN","ANT",countrycode::countrycode(c,"iso2c","iso3c"))
```
[Try it rdrr.io!](https://rdrr.io/snippets/embed/?code=f%3D%0Afunction(c)%60if%60(c%3D%3D%22AN%22%2C%22ANT%22%2Ccountrycode%3A%3Acountrycode(c%2C%22iso2c%22%2C%22iso3c%22))%0A%0Asapply(c(%22AF%22%2C%22AX%22%2C%22AL%22%2C%22DZ%22%2C%22AS%22%2C%22AD%22%2C%22AO%22%2C%22AI%22%2C%22AQ%22%2C%22AG%22%2C%22AR%22%2C%22AM%22%2C%22AW%22%2C%22AU%22%2C%22AT%22%2C%22AZ%22%2C%22BS%22%2C%22BH%22%2C%22BD%22%2C%22BB%22%2C%22BY%22%2C%22BE%22%2C%22BZ%22%2C%22BJ%22%2C%22BM%22%2C%22BT%22%2C%22BO%22%2C%22BA%22%2C%22BW%22%2C%22BV%22%2C%22BR%22%2C%22VG%22%2C%22IO%22%2C%22BN%22%2C%22BG%22%2C%22BF%22%2C%22BI%22%2C%22KH%22%2C%22CM%22%2C%22CA%22%2C%22CV%22%2C%22KY%22%2C%22CF%22%2C%22TD%22%2C%22CL%22%2C%22CN%22%2C%22HK%22%2C%22MO%22%2C%22CX%22%2C%22CC%22%2C%22CO%22%2C%22KM%22%2C%22CG%22%2C%22CD%22%2C%22CK%22%2C%22CR%22%2C%22CI%22%2C%22HR%22%2C%22CU%22%2C%22CY%22%2C%22CZ%22%2C%22DK%22%2C%22DJ%22%2C%22DM%22%2C%22DO%22%2C%22EC%22%2C%22EG%22%2C%22SV%22%2C%22GQ%22%2C%22ER%22%2C%22EE%22%2C%22ET%22%2C%22FK%22%2C%22FO%22%2C%22FJ%22%2C%22FI%22%2C%22FR%22%2C%22GF%22%2C%22PF%22%2C%22TF%22%2C%22GA%22%2C%22GM%22%2C%22GE%22%2C%22DE%22%2C%22GH%22%2C%22GI%22%2C%22GR%22%2C%22GL%22%2C%22GD%22%2C%22GP%22%2C%22GU%22%2C%22GT%22%2C%22GG%22%2C%22GN%22%2C%22GW%22%2C%22GY%22%2C%22HT%22%2C%22HM%22%2C%22VA%22%2C%22HN%22%2C%22HU%22%2C%22IS%22%2C%22IN%22%2C%22ID%22%2C%22IR%22%2C%22IQ%22%2C%22IE%22%2C%22IM%22%2C%22IL%22%2C%22IT%22%2C%22JM%22%2C%22JP%22%2C%22JE%22%2C%22JO%22%2C%22KZ%22%2C%22KE%22%2C%22KI%22%2C%22KP%22%2C%22KR%22%2C%22KW%22%2C%22KG%22%2C%22LA%22%2C%22LV%22%2C%22LB%22%2C%22LS%22%2C%22LR%22%2C%22LY%22%2C%22LI%22%2C%22LT%22%2C%22LU%22%2C%22MK%22%2C%22MG%22%2C%22MW%22%2C%22MY%22%2C%22MV%22%2C%22ML%22%2C%22MT%22%2C%22MH%22%2C%22MQ%22%2C%22MR%22%2C%22MU%22%2C%22YT%22%2C%22MX%22%2C%22FM%22%2C%22MD%22%2C%22MC%22%2C%22MN%22%2C%22ME%22%2C%22MS%22%2C%22MA%22%2C%22MZ%22%2C%22MM%22%2C%22NA%22%2C%22NR%22%2C%22NP%22%2C%22NL%22%2C%22AN%22%2C%22NC%22%2C%22NZ%22%2C%22NI%22%2C%22NE%22%2C%22NG%22%2C%22NU%22%2C%22NF%22%2C%22MP%22%2C%22NO%22%2C%22OM%22%2C%22PK%22%2C%22PW%22%2C%22PS%22%2C%22PA%22%2C%22PG%22%2C%22PY%22%2C%22PE%22%2C%22PH%22%2C%22PN%22%2C%22PL%22%2C%22PT%22%2C%22PR%22%2C%22QA%22%2C%22RE%22%2C%22RO%22%2C%22RU%22%2C%22RW%22%2C%22BL%22%2C%22SH%22%2C%22KN%22%2C%22LC%22%2C%22MF%22%2C%22PM%22%2C%22VC%22%2C%22WS%22%2C%22SM%22%2C%22ST%22%2C%22SA%22%2C%22SN%22%2C%22RS%22%2C%22SC%22%2C%22SL%22%2C%22SG%22%2C%22SK%22%2C%22SI%22%2C%22SB%22%2C%22SO%22%2C%22ZA%22%2C%22GS%22%2C%22SS%22%2C%22ES%22%2C%22LK%22%2C%22SD%22%2C%22SR%22%2C%22SJ%22%2C%22SZ%22%2C%22SE%22%2C%22CH%22%2C%22SY%22%2C%22TW%22%2C%22TJ%22%2C%22TZ%22%2C%22TH%22%2C%22TL%22%2C%22TG%22%2C%22TK%22%2C%22TO%22%2C%22TT%22%2C%22TN%22%2C%22TR%22%2C%22TM%22%2C%22TC%22%2C%22TV%22%2C%22UG%22%2C%22UA%22%2C%22AE%22%2C%22GB%22%2C%22US%22%2C%22UM%22%2C%22UY%22%2C%22UZ%22%2C%22VU%22%2C%22VE%22%2C%22VN%22%2C%22VI%22%2C%22WF%22%2C%22EH%22%2C%22YE%22%2C%22ZM%22%2C%22ZW%22)%2Cf))
[Answer]
# Python 1779 bytes
```
a=' AF AFG AX ALA AL ALB DZ DZA AS ASM AD AND AO AGO AI AIA AQ ATA AG ATG AR ARG AM ARM AW ABW AU AUS AT AUT AZ AZE BS BHS BH BHR BD BGD BB BRB BY BLR BE BEL BZ BLZ BJ BEN BM BMU BT BTN BO BOL BA BIH BW BWA BV BVT BR BRA VG VGB IO IOT BN BRN BG BGR BF BFA BI BDI KH KHM CM CMR CA CAN CV CPV KY CYM CF CAF TD TCD CL CHL CN CHN HK HKG MO MAC CX CXR CC CCK CO COL KM COM CG COG CD COD CK COK CR CRI CI CIV HR HRV CU CUB CY CYP CZ CZE DK DNK DJ DJI DM DMA DO DOM EC ECU EG EGY SV SLV GQ GNQ ER ERI EE EST ET ETH FK FLK FO FRO FJ FJI FI FIN FR FRA GF GUF PF PYF TF ATF GA GAB GM GMB GE GEO DE DEU GH GHA GI GIB GR GRC GL GRL GD GRD GP GLP GU GUM GT GTM GG GGY GN GIN GW GNB GY GUY HT HTI HM HMD VA VAT HN HND HU HUN IS ISL IN IND ID IDN IR IRN IQ IRQ IE IRL IM IMN IL ISR IT ITA JM JAM JP JPN JE JEY JO JOR KZ KAZ KE KEN KI KIR KP PRK KR KOR KW KWT KG KGZ LA LAO LV LVA LB LBN LS LSO LR LBR LY LBY LI LIE LT LTU LU LUX MK MKD MG MDG MW MWI MY MYS MV MDV ML MLI MT MLT MH MHL MQ MTQ MR MRT MU MUS YT MYT MX MEX FM FSM MD MDA MC MCO MN MNG ME MNE MS MSR MA MAR MZ MOZ MM MMR NA NAM NR NRU NP NPL NL NLD AN ANT NC NCL NZ NZL NI NIC NE NER NG NGA NU NIU NF NFK MP MNP NO NOR OM OMN PK PAK PW PLW PS PSE PA PAN PG PNG PY PRY PE PER PH PHL PN PCN PL POL PT PRT PR PRI QA QAT RE REU RO ROU RU RUS RW RWA BL BLM SH SHN KN KNA LC LCA MF MAF PM SPM VC VCT WS WSM SM SMR ST STP SA SAU SN SEN RS SRB SC SYC SL SLE SG SGP SK SVK SI SVN SB SLB SO SOM ZA ZAF GS SGS SS SSD ES ESP LK LKA SD SDN SR SUR SJ SJM SZ SWZ SE SWE CH CHE SY SYR TW TWN TJ TJK TZ TZA TH THA TL TLS TG TGO TK TKL TO TON TT TTO TN TUN TR TUR TM TKM TC TCA TV TUV UG UGA UA UKR AE ARE GB GBR US USA UM UMI UY URY UZ UZB VU VUT VE VEN VN VNM VI VIR WF WLF EH ESH YE YEM ZM ZMB ZW ZWE'
z=lambda b:a[a.find(" "+b)+4:a.find(" "+b)+7]
```
Not sure what to do with the mass of data.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 420 bytes
```
«⟑``‟Ḃȯ†√¦∑iRṫΠʁǓ₴5]p#4Ṅl}3ẋ¶T+⟑V]ḭr≤ṁǔ
A»cP⌐kẋṠ†⟇Ǔ≈ɽ⟩›ṪwSʀ₇⌊Ǔ∇•Xwð⇩I‡ṅfβ℅₍ṗµ∆€¾aǍ⟑Ȧ2⋏$λ⁺]/|f₁Pa⟨,₁,h¨ṁ₌ε⟑‹İ⟨Nṫw%yĖ⁼*>₈Ė¹ȯU÷s¬)∨ʀ0ŀƈ½)(m-Ẋ ǓḂ⟩[0e•₂↲S⟇Ġj⟨^ɖg[⌐₁⋏żo:ẎRʁ⌐ð%⇧↓Y*?* †8„S|⁽l3√⁺⟑«⇧2ẇ:»⟑⟇βE'ċ¬$≠∪₀↳↲æMf»₄τẇkA¨£vJfZ«ƛ¤‛H∧λŻJ@±*dCẋ°4£Mgċ ≥ƒX¢ǎd≤ǔ₈b¢&Ẋ≈•ġ.ẎAl>₅j¨∵½↳Ŀa>€¼₌Rǔb*JA⌐Ḃ∵Ḣ3\⌈|ẋ;Π1₆›Ẇ∧≬₆ETh□ʀ≬¨«⇧2ẇ:»½ǒ÷₇Π≤¶:ɽq∇¨»12τẇkAZƛ÷$f$vj;fZ«↲↵Ė¯≥꘍≠}ĊKṫ⟑ɖhṪ⁺|oI3⌈%‟ṙK/i⁺!ṅȮiȧS'₌βP⅛‛ṙ∧6ƈ;7↔⋎¡↵G]ḟɾḋ†*↑o«⇧23f20ẋfẇWf:⁰ḟ›i
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLCq+KfkWBg4oCf4biCyK/igKDiiJrCpuKIkWlS4bmrzqDKgceT4oK0NV1wIzThuYRsfTPhuovCtlQr4p+RVl3huK1y4omk4bmBx5RcbkHCu2NQ4oyQa+G6i+G5oOKAoOKfh8eT4omIyb3in6nigLrhuap3U8qA4oKH4oyKx5PiiIfigKJYd8Ow4oepSeKAoeG5hWbOsuKEheKCjeG5l8K14oiG4oKswr5hx43in5HIpjLii48kzrvigbpdL3xm4oKBUGHin6gs4oKBLGjCqOG5geKCjM614p+R4oC5xLDin6hO4bmrdyV5xJbigbwqPuKCiMSWwrnIr1XDt3PCrCniiKjKgDDFgMaIwr0pKG0t4bqKIMeT4biC4p+pWzBl4oCi4oKC4oayU+Kfh8SgauKfqF7Jlmdb4oyQ4oKB4ouPxbxvOuG6jlLKgeKMkMOwJeKHp+KGk1kqPyog4oCgOOKAnlN84oG9bDPiiJrigbrin5HCq+KHpzLhuoc6wrvin5Hin4fOskUnxIvCrCTiiaDiiKrigoDihrPihrLDpk1mwrvigoTPhOG6h2tBwqjCo3ZKZlrCq8abwqTigJtI4oinzrvFu0pAwrEqZEPhuovCsDTCo01nxIsg4omlxpJYwqLHjmTiiaTHlOKCiGLCoibhuoriiYjigKLEoS7huo5BbD7igoVqwqjiiLXCveKGs8S/YT7igqzCvOKCjFLHlGIqSkHijJDhuILiiLXhuKIzXFzijIh84bqLO86gMeKChuKAuuG6huKIp+KJrOKChkVUaOKWocqA4omswqjCq+KHpzLhuoc6wrvCvceSw7figofOoOKJpMK2Osm9ceKIh8KowrsxMs+E4bqHa0FaxpvDtyRmJHZqO2ZawqvihrLihrXElsKv4oml6piN4omgfcSKS+G5q+KfkcmWaOG5quKBunxvSTPijIgl4oCf4bmZSy9p4oG6IeG5hciuacinUyfigozOslDihZvigJvhuZniiKc2xog7N+KGlOKLjsKh4oa1R13huJ/JvuG4i+KAoCrihpFvwqvih6cyM2YyMOG6i2bhuodXZjrigbDhuJ/igLppIiwiIiwiS1AiXQ==) or [Verify all test cases (takes a while, but doesn't time out)](https://vyxal.pythonanywhere.com/#WyJqVCIsIsab4oaSIiwiwqvin5FgYOKAn+G4gsiv4oCg4oiawqbiiJFpUuG5q86gyoHHk+KCtDVdcCM04bmEbH0z4bqLwrZUK+KfkVZd4bitcuKJpOG5gceUXG5BwrtjUOKMkGvhuovhuaDigKDin4fHk+KJiMm94p+p4oC64bmqd1PKgOKCh+KMiseT4oiH4oCiWH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LCBcIlNEXCIsIFwiU1JcIiwgXCJTSlwiLCBcIlNaXCIsIFwiU0VcIiwgXCJDSFwiLCBcIlNZXCIsIFwiVFdcIiwgXCJUSlwiLCBcIlRaXCIsIFwiVEhcIiwgXCJUTFwiLCBcIlRHXCIsIFwiVEtcIiwgXCJUT1wiLCBcIlRUXCIsIFwiVE5cIiwgXCJUUlwiLCBcIlRNXCIsIFwiVENcIiwgXCJUVlwiLCBcIlVHXCIsIFwiVUFcIiwgXCJBRVwiLCBcIkdCXCIsIFwiVVNcIiwgXCJVTVwiLCBcIlVZXCIsIFwiVVpcIiwgXCJWVVwiLCBcIlZFXCIsIFwiVk5cIiwgXCJWSVwiLCBcIldGXCIsIFwiRUhcIiwgXCJZRVwiLCBcIlpNXCIsIFwiWldcIl0iXQ==)
Messy port of 05AB1E.
## How?
```
«⟑``‟Ḃȯ†√¦∑iRṫΠʁǓ₴5]p#4Ṅl}3ẋ¶T+⟑V]ḭr≤ṁǔ
A»cP⌐kẋṠ†⟇Ǔ≈ɽ⟩›ṪwSʀ₇⌊Ǔ∇•Xwð⇩I‡ṅfβ℅₍ṗµ∆€¾aǍ⟑Ȧ2⋏$λ⁺]/|f₁Pa⟨,₁,h¨ṁ₌ε⟑‹İ⟨Nṫw%yĖ⁼*>₈Ė¹ȯU÷s¬)∨ʀ0ŀƈ½)(m-Ẋ ǓḂ⟩[0e•₂↲S⟇Ġj⟨^ɖg[⌐₁⋏żo:ẎRʁ⌐ð%⇧↓Y*?* †8„S|⁽l3√⁺⟑«
                            # Push compressed string "dzaibwbrbfdmfrghitlvmdngrwknlclktzthtcugusalvgcugagmgiuzzmgrnihmhninmknlssazczlipsslchzwzaafarhkmnetcrdjerfjhtmwmlprumccnftjbebocoismhnpncnzphtkaskhdogugtnablwssosjvnyebtcafihuidirimjpkelbompashsdtwtovegelalsmctgttcystsgesbhbgcmcxjokimsmammnenopesmsygbviaumymurutlbviovakwmranqavcvubmecdeltnrrerosacihrluegggjekg"
⇧                           # Uppercase
 2ẇ                         # Split into chunks of two
   :                        # Duplicate
    »⟑⟇βE'ċ¬$≠∪₀↳↲æMf»      # Push compressed integer 5045888909142307005039435397419896531
                      ₄τ    # Convert to base-26 as a list: [21,8,2,6,7,1,4,1,9,0,3,10,12,17,6,4,0,16,5,9,8,2,0,1,3,1]
                        ẇ   # Split the string into chunks of that size: [["DZ", "AI", ..., "US"], ["AL", "VG", ..., "ZM"], ["GR", "NI"], ..., ["KG"]]
kA                          # Push the uppercase alphabet
  ¨£vJ                      # Zip the list with the alphabet, and for each, append the corresponding letter to each:
                            #  [["DZA", "AIA", ..., "USA"], ["ALB", "VGB", ..., "ZMB"], ["GRC", "NIC"], ..., ["KGZ"]]
      f                     # Flatten
       Z                    # Zip the ["DZ", "AI", "BW", ...] list with this
«ƛ¤‛H∧λŻJ@±*dCẋ°4£Mgċ ≥ƒX¢ǎd≤ǔ₈b¢&Ẋ≈•ġ.ẎAl>₅j¨∵½↳Ŀa>€¼₌Rǔb*JA⌐Ḃ∵Ḣ3\⌈|ẋ;Π1₆›Ẇ∧≬₆ETh□ʀ≬¨«
                            # Push compressed string "cfjmkzpkmfawlrlytdpnbimgmvmxsnaobdbsclcngnnutmbzsvfkgpmtpwsbwfaddkgqmemppgcgcdckkrmzplcvambbbnfoglgdiqpyptaeuyfmehagmqatgfgysrtntrtvskszsepfsc"
        ⇧2ẇ                 # Uppercase and split into chunks of two
           :                # Duplicate
            »½ǒ÷₇Π≤¶:ɽq∇¨»  # Push compressed integer 5023299766197034891137684120
12τ                         # Convert to base 12 as a list: [5,3,2,3,2,0,2,3,2,0,1,8,0,6,6,1,0,11,2,2,7,1,2,0,2,0]
   ẇ                        # Split the list into chunks of that size: [["CF", "JM", "KZ", "PK", "MF"], ["AW", "LR", "LY"], ..., ["PF", "SC"], []]
    kAZ                     # Zip with the uppercase alphabet
       ƛ÷$f$vj;             # Map, and for each, insert the letter between each string: [["CAF", "JAM", "KAZ", "PAK", "MAF"], ..., ["PYF", "SYC"], []]
               fZ           # Flatten and zip the ["CF", "JM", ..., "SC"] list with this
«↲↵Ė¯≥꘍≠}ĊKṫ⟑ɖhṪ⁺|oI3⌈%‟ṙK/i⁺!ṅȮiȧS'₌βP⅛‛ṙ∧6ƈ;7↔⋎¡↵G]ḟɾḋ†*↑o«
                            # Push compressed string "aqataaxalababihbjbenbyblreeestgssgsgwgnbieirlilisrkmcomkpprkkycymmomacpmspmrssrbsisvntfatfuaukrytmyt"
⇧                           # Uppercase
 23f                        # Push list [2, 3]
    20ẋf                    # Repeat it twenty times: [2, 3, 2, 3, 2, 3, ..., 2, 3]
        ẇ                   # Split the string into chunks of that size: ["AQ", "ATA", "AX", ..., "YT", "MYT"]
         W                  # Wrap the stack into a list
          f                 # Flatten
           :                # Duplicate
            ⁰ḟ              # Find the index of the input in it
              ›             # Increment
               i            # Index into the list
```
[Answer]
# C - 1324 Bytes
```
char*c="AFAFGAXALAALALBDZDZAASASMADANDAOAGOAIAIAAQATAAGATGARARGAMARMAWABWAUAUSATAUTAZAZEBSBHSBHBHRBDBGDBBBRBBYBLRBEBELBZBLZBJBENBMBMUBTBTNBOBOLBABIHBWBWABVBVTBRBRAVGVGBIOIOTBNBRNBGBGRBFBFABIBDIKHKHMCMCMRCACANCVCPVKYCYMCFCAFTDTCDCLCHLCNCHNHKHKGMOMACCXCXRCCCCKCOCOLKMCOMCGCOGCDCODCKCOKCRCRICICIVHRHRVCUCUBCYCYPCZCZEDKDNKDJDJIDMDMADODOMECECUEGEGYSVSLVGQGNQERERIEEESTETETHFKFLKFOFROFJFJIFIFINFRFRAGFGUFPFPYFTFATFGAGABGMGMBGEGEODEDEUGHGHAGIGIBGRGRCGLGRLGDGRDGPGLPGUGUMGTGTMGGGGYGNGINGWGNBGYGUYHTHTIHMHMDVAVATHNHNDHUHUNISISLININDIDIDNIRIRNIQIRQIEIRLIMIMNILISRITITAJMJAMJPJPNJEJEYJOJORKZKAZKEKENKIKIRKPPRKKRKORKWKWTKGKGZLALAOLVLVALBLBNLSLSOLRLBRLYLBYLILIELTLTULULUXMKMKDMGMDGMWMWIMYMYSMVMDVMLMLIMTMLTMHMHLMQMTQMRMRTMUMUSYTMYTMXMEXFMFSMMDMDAMCMCOMNMNGMEMNEMSMSRMAMARMZMOZMMMMRNANAMNRNRUNPNPLNLNLDANANTNCNCLNZNZLNINICNENERNGNGANUNIUNFNFKMPMNPNONOROMOMNPKPAKPWPLWPSPSEPAPANPGPNGPYPRYPEPERPHPHLPNPCNPLPOLPTPRTPRPRIQAQATREREUROROURURUSRWRWABLBLMSHSHNKNKNALCLCAMFMAFPMSPMVCVCTWSWSMSMSMRSTSTPSASAUSNSENRSSRBSCSYCSLSLESGSGPSKSVKSISVNSBSLBSOSOMZAZAFGSSGSSSSSDESESPLKLKASDSDNSRSURSJSJMSZSWZSESWECHCHESYSYRTWTWNTJTJKTZTZATHTHATLTLSTGTGOTKTKLTOTONTTTTOTNTUNTRTURTMTKMTCTCATVTUVUGUGAUAUKRAEAREGBGBRUSUSAUMUMIUYURYUZUZBVUVUTVEVENVNVNMVIVIRWFWLFEHESHYEYEMZMZMBZWZWE";f(char* i){for(;*c;c+=5)!strncmp(c, i,2)&&printf("%c%c%c",*(c+2),*(c+3),*(c+4));}
```
**Ungolfed**
```
char*c = "AFAFGAXALAALALBDZDZAASASMADANDAOAGOAIAIAAQATAAGATGARARGAMARMAWABWAUAUSATAUTAZAZEBSBHSBHBHRBDBGDBBBRBBYBLRBEBELBZBLZBJBENBMBMUBTBTNBOBOLBABIHBWBWABVBVTBRBRAVGVGBIOIOTBNBRNBGBGRBFBFABIBDIKHKHMCMCMRCACANCVCPVKYCYMCFCAFTDTCDCLCHLCNCHNHKHKGMOMACCXCXRCCCCKCOCOLKMCOMCGCOGCDCODCKCOKCRCRICICIVHRHRVCUCUBCYCYPCZCZEDKDNKDJDJIDMDMADODOMECECUEGEGYSVSLVGQGNQERERIEEESTETETHFKFLKFOFROFJFJIFIFINFRFRAGFGUFPFPYFTFATFGAGABGMGMBGEGEODEDEUGHGHAGIGIBGRGRCGLGRLGDGRDGPGLPGUGUMGTGTMGGGGYGNGINGWGNBGYGUYHTHTIHMHMDVAVATHNHNDHUHUNISISLININDIDIDNIRIRNIQIRQIEIRLIMIMNILISRITITAJMJAMJPJPNJEJEYJOJORKZKAZKEKENKIKIRKPPRKKRKORKWKWTKGKGZLALAOLVLVALBLBNLSLSOLRLBRLYLBYLILIELTLTULULUXMKMKDMGMDGMWMWIMYMYSMVMDVMLMLIMTMLTMHMHLMQMTQMRMRTMUMUSYTMYTMXMEXFMFSMMDMDAMCMCOMNMNGMEMNEMSMSRMAMARMZMOZMMMMRNANAMNRNRUNPNPLNLNLDANANTNCNCLNZNZLNINICNENERNGNGANUNIUNFNFKMPMNPNONOROMOMNPKPAKPWPLWPSPSEPAPANPGPNGPYPRYPEPERPHPHLPNPCNPLPOLPTPRTPRPRIQAQATREREUROROURURUSRWRWABLBLMSHSHNKNKNALCLCAMFMAFPMSPMVCVCTWSWSMSMSMRSTSTPSASAUSNSENRSSRBSCSYCSLSLESGSGPSKSVKSISVNSBSLBSOSOMZAZAFGSSGSSSSSDESESPLKLKASDSDNSRSURSJSJMSZSWZSESWECHCHESYSYRTWTWNTJTJKTZTZATHTHATLTLSTGTGOTKTKLTOTONTTTTOTNTUNTRTURTMTKMTCTCATVTUVUGUGAUAUKRAEAREGBGBRUSUSAUMUMIUYURYUZUZBVUVUTVEVENVNVNMVIVIRWFWLFEHESHYEYEMZMZMBZWZWE";
f(char* i)
{
    for(; *c; c += 5)
        !strncmp(c, i, 2) && printf("%c%c%c", *(c + 2), *(c + 3), *(c + 4));
}
```
**Explanation**
A function that receives a character string with an Alpha-2 code and converts it to Alpha-3 using a "raw" list which contains the Alpha-2 codes followed by their Alpha-3 counterpart every five(5) characters; the function looks for the given code within the list and if it is found its counterpart is displayed.
Tested on GCC, generates some warnings if not compiled with std=c89.
## C99 - 1296 Bytes (By @ceilingcat)
```
f(int*i){for(char*c="AFAFGAXALAALALBDZDZAAS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KMTCTCATVTUVUGUGAUAUKRAEAREGBGBRUSUSAUMUMIUYURYUZUZBVUVUTVEVENVNVNMVIVIRWFWLFEHESHYEYEMZMZMBZWZWE";*c;c+=5)write(!strncmp(c,i,2),c+2,3);}
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 111 bytes
```
Switch[#,"HM","HMD","AN","ANT","PS","PSE",_,Association[#@"CountryCode"->#@"UNCode"&/@EntityList@"Country"]@#]&
```
Don't [Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7P7g8syQ5I1pZR8nDVwlEuABJRz8wEQIkA4LBhKuSTryOY3FxfnImUGt@XrSyg5JzfmleSVGlc35KqpKuHVAg1A/MVtN3cM0rySyp9MksLoErU4p1UI5V@x9QlJlXEp2m71Ct5OKqBLUVbB/YptBgpdrY/wA "Wolfram Language (Mathematica) – Try It Online")
[Try in the Wolfram Cloud!](https://www.wolframcloud.com/obj/4ec45ac9-dd2f-4a24-8c75-de1e61660872)
---
Explanation:
`Switch[#,"HM","HMD","AN","ANT","PS","PSE",` If our input is equal to one of the three countries not in the Mathematica database, return the correct code.
`_,` Otherwise
`Association[#@"CountryCode"->#@"UNCode"&/@EntityList@"Country"]` Create an association between the two-letter and three-letter codes of each country
`@#]` and find the value matching the input.
[Answer]
# C, 216+554+1=771 bytes
```
#include<stdio.h>
#define G d=getc(f);w=d&31|64
FILE*f;char c,d,r[4],y,w;char*z(a,b){for(f=fopen("f","r");;){G;c=d/4&56;y=w;G;c|=d>>5&7;*r=a;r[1]=r[2]=b;r[c>26?1:2]=c&31|64;if(!c)fgets(r,4,f);if(a==y&b==w)return r;}}
```
It requires this file with the name "f" in the same directory, shown here as a hex dump. You can use `cut -c 11-58 "data.txt" | xxd -r -p > f` to recreate the file. It should have 554 bytes.
```
00000000  01 e6 01 18 41 4c 41 01  4c 04 3a 21 b3 a1 c4 81  |....ALA.L.:!....|
00000010  ef 01 29 01 11 41 54 41  c1 87 01 f2 c1 4d 81 57  |..)..ATA.....M.W|
00000020  41 75 c1 b4 01 ba a2 13  42 48 82 e4 c2 42 02 19  |Au......BH...B..|
00000030  42 4c 52 22 85 a2 9a 02  0a 42 45 4e 42 ad 22 d4  |BLR".....BENB.".|
00000040  22 8f 02 01 42 49 48 02  37 42 96 02 32 16 47 49  |"...BIH.7B..2.GI|
00000050  8f c2 4e 42 47 02 26 82  89 2b a8 43 4d 23 c1 c3  |..NBG.&..+.CM#..|
00000060  16 0b 19 43 59 4d 83 26  94 64 a3 0c a3 0e 08 eb  |...CYM.&.d......|
00000070  0d 0f 4d 41 43 43 58 23  63 23 8f 0b 0d 43 4f 4d  |..MACCX#c#...COM|
00000080  a3 e7 a3 e4 a3 eb 23 32  43 c9 48 d2 03 55 43 19  |......#2C.H..UC.|
00000090  03 ba a4 cb 24 2a 04 2d  24 af 45 a3 65 27 b3 96  |....$*.-$.E.e'..|
000000a0  a7 d1 25 32 05 05 45 53  54 25 14 a6 8b c6 4f 26  |..%2..EST%....O&|
000000b0  2a 26 c9 06 32 c7 a6 f0  26 14 06 41 54 46 07 41  |*&..2...&..ATF.A|
000000c0  07 4d 27 e5 44 a5 07 28  07 49 07 72 c7 4c c7 44  |.M'.D..(.I.r.L.D|
000000d0  a7 90 27 b5 27 b4 67 27  a7 2e 07 17 47 4e 42 c7  |..'.'.g'....GNB.|
000000e0  b9 28 34 08 8d 56 81 08  8e 28 d5 29 93 09 8e 29  |.(4..V...(.)...)|
000000f0  c4 29 d2 c9 51 09 05 49  52 4c 29 cd 09 0c 49 53  |.)..Q..IRL)...IS|
00000100  52 09 34 8a 2d 2a d0 6a  25 4a 4f 8b 3a 2b c5 4b  |R.4.-*.j%JO.:+.K|
00000110  49 0b 10 50 52 4b ab f2  4b 97 6b 47 2c e1 0c 36  |I..PRK..K.kG,..6|
00000120  2c c2 2c f3 8c 52 8c 59  0c a9 4c b4 6c 15 0d 8b  |,.,..R.Y..L.l...|
00000130  8d 87 2d 37 4d 79 8d 96  2d 2c ad 94 2d 88 cd 91  |..-7My..-,..-...|
00000140  4d 92 4d 75 19 14 4d 59  54 8d b8 c6 6d 0d 24 2d  |M.Mu..MYT...m.$-|
00000150  e3 0d ee ad c5 4d 53 4d  41 ad fa 4d 4d 2e a1 4e  |.....MSMA..MM..N|
00000160  b2 2e 90 0e 8c 41 8e 2e  83 2e 9a 0e 69 4e 45 0e  |.....A......iNE.|
00000170  27 ae 35 2e 66 ad d0 4e  4f 2f cd 90 2b b0 97 10  |'.5.f..NO/..+...|
00000180  b3 30 c1 b0 c7 d0 59 50  45 30 88 90 6e b0 ec d0  |.0....YPE0..n...|
00000190  54 30 32 51 81 52 a5 52  af 52 75 12 37 22 ac 33  |T02Q.R.R.Ru.7".3|
000001a0  c8 0b 2e 0c 23 8d 26 10  0d 53 50 4d 56 83 37 b3  |....#.&..SPMV.7.|
000001b0  53 4d 53 14 53 a1 93 ae  12 13 53 52 42 f3 23 13  |SMS.S.....SRB.#.|
000001c0  ac 53 07 d3 cb 13 09 53  56 4e b3 82 33 af 1a c1  |.S.....SVN..3...|
000001d0  07 13 53 47 53 13 93 45  13 0c 2b 33 c4 d3 b2 33  |..SGS..E..+3...3|
000001e0  aa d3 fa d3 e5 03 a8 53  59 34 d7 34 6a 14 3a 14  |.......SY4.4j.:.|
000001f0  28 54 6c 34 e7 34 8b 34  cf 34 f4 d4 ae d4 b2 b4  |(Tl4.4.4.4......|
00000200  6d 14 23 d4 b6 15 27 15  01 55 4b 52 c1 45 47 42  |m.#...'..UKR.EGB|
00000210  15 33 35 2d d5 59 15 5a  56 95 36 c5 36 ae 56 49  |.35-.Y.ZV.6.6.VI|
00000220  b7 86 c5 68 39 a5 1a 4d  1a b7                    |...h9..M..|
0000022a
```
The function takes the Alpha-2 code as two separate characters, which must be capitalized, and returns the capitalized Alpha-3 code. I don't know of an online compiler that allows you to include binary files like this, so no link, unfortunately.
#### Explanation:
Since we're only dealing with capital letters, we can use only the lower five bits to store a character. The basic strategy is to store the Alpha-2 codes in the file, and use the bits we save to describe how to create the Alpha-3 code; then, the program will search for the Alpha-2 code and follow the instructions.
The instruction format is simple. We have six instruction bits. The lower five bits store a 5-bit letter code which can be converted to ASCII with `&31|64`. If the high bit is zero, the letter is added to the end of the code. If it's one, the letter is inserted in the middle. If the instruction bits are all zero, the file stores the complete Alpha-3 code in the next 3 bytes of the file (these are visible in the hex dump).
Of the 247 conversions, 156 append a character to the end, 71 insert a character in the middle, 4 prepend a character to the beginning, and 16 conversions are replacements, which are anything not included in the other categories. Inserts and appends only use two bytes in the file, while the others use five; (156+71)\*2+(4+16)\*5=554 bytes.
Ungolfed version:
```
#include <stdio.h>
FILE* f;
char c,d,r[4],y,w;
char* z(a,b){
    for(f=fopen("f","r");;){
        // get first character
        d=getc(f); w=d&31|64;
        c=d/4&56;
        y=w;
        // get second character
        d=getc(f); w=d&31|64;
        c|=d>>5&7; // c now holds the instruction
        // prepare return string for inserts/appends
        r[0]=a;
        r[1]=r[2]=b;
        r[c>26?1:2]=c&31|64; // insert or append
        if(!c) // replace
            fgets(r,4,f);
        if(a==y&b==w)
            return r;
    }
}
```
]


[Question]
      [
Write the shortest code you can that produces an infinite output.
That's all. You code will only be disqualified if it stops producing output at some point. As always in code golf, the shortest code wins.
Here's a list of answers that I think are really clever, so they can get credit:
* [The comma is both code and data](https://codegolf.stackexchange.com/a/37210/8611)
* [Infinite errors (that counts)](https://codegolf.stackexchange.com/a/26418/8611)
* [Infinite warnings (that also counts)](https://codegolf.stackexchange.com/a/20902/8611)
* [What's Marbelous?](https://codegolf.stackexchange.com/a/37209/8611)
## Leaderboard
```
var QUESTION_ID=13152,OVERRIDE_USER=8611;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

[Answer]
## [Spice](https://github.com/Slord6/Spice), 26 bytes
Spice module that recursively calls itself. Quite quickly hits a stack overflow.
Given the code is saved to a module named 'x':
```
;return@OUT a;LOD .\x a a;
```
## Un-golfed explanation
```
;a;return@    - define variables: "a" and the required "return"
OUT a;   - output a, implicitly "[0]"
LOD .\x a a;  - call this module, passing a, storing result in a
```
[Answer]
## [Roj](https://github.com/RojerGS/Roj), 19 bytes
```
while(1)do out""end
```
This produces output because of the `[out]:` buffer.
[Answer]
# T-SQL, 15 bytes
```
a:PRINT 0GOTO a
```
6 years and 10 pages of answers, and no SQL versions yet.
Notes:
* `PRINT` is 1 byte less than a `SELECT`.
* A label with a goto is 1 byte shorter than the shortest `WHILE` statement: `WHILE 1=1PRINT 1` (you can't just do `WHILE 1` in SQL)
* Depending on the version of SQL Management Studio, the "messages" pane (which displays the result of `PRINT` statements), might not immediately refresh; this is a client-side UI issue only.
[Answer]
# Go, 59 characters
```
package main
import "fmt"
func main(){for{fmt.Print(0)}}
```
[Answer]
# [International Phonetic Esoteric Language](https://esolangs.org/wiki/International_Phonetic_Esoteric_Language), 6 bytes
```
10ɑeoɒ
```
Will print `0` with newlines forever.
Explanation:
```
10ɑeoɒ
10     (push the bounds for the loop: from 0 to 1)
  ɑ    (pop the bounds and start the loop)
   e   (push the current index)
    o  (print)
     ɒ (check if index < start. 0 < 1, so loop)
```
[Answer]
# Ruby, ~~11~~ 9 characters
```
loop{p:p}
```
Old answer:
```
p 0 while 1
```
[Answer]
# [Rockstar](https://codewithrockstar.com/), 13 bytes
```
while 1 say 1
```
[Try it here](https://codewithrockstar.com/online) (Code will need to be pasted in)
[Answer]
## ARM Thumb, Linux syscalls only, 12 bytes
Raw machine code:
```
2704 2001 4669 2201 df00 e7f9
```
Assembly:
```
        .text
        .globl _start
        .thumb
        .thumb_func
_start:
        movs    r7, #4    @ write syscall
        movs    r0, #1    @ STDOUT_FILENO
        mov     r1, sp    @ sp is a valid pointer. May not be legible, but...
        movs    r2, #1    @ one byte is fine
        svc     #0        @ syscall: write(STDOUT_FILENO, sp, 1)
        b       _start    @ loop forever
```
## ARM Thumb, with libc, 6 bytes
Raw machine code (`f7ff fffe` is an unlinked libc call):
```
f7ff fffe e7fc
```
Assembly:
```
        .text
        .globl main
        .thumb
        .thumb_func
@ Note that putchar returns the char it put, so we do this:
@ for (;;) putchar(argc);
main:
        bl      putchar @ putchar(argc)
        b       main    @ Loop forever
```
Fun fact: These programs do the exact same thing, printing argc % 256 in binary infinitely, since `sp[0]` at `_start` is also `argc`.
[Answer]
# [Befunge-93](https://github.com/catseye/Befunge-93), 1 byte
```
'
```
[Try it online!](https://tio.run/##S0pNK81LT/3/X/3/fwA "Befunge-93 – Try It Online")
```
'  # full program
'  # invalid command, NOP but raises warning
```
[Answer]
# [Duocentehexaquinquagesimal](https://esolangs.org/wiki/Duocentehexaquinquagesimal), 2 bytes
```
L½
```
[Try it online!](https://tio.run/##S0oszvifnFhiYxPzqGGRXbx1cWqKgm6mgrphsXWcNVDIWl0hXsHILq80x7qkqDQPqDRVQbdY11Ah3jo1OSNfQTdPQR2oLOnQMuPDW5yP7stQsrPR1tXTiY5VetSw0Evdzg6isEY/v6BEP784MSkzFUopxNslWYOFk4oSM/PSSpOzESyFpP8@h/b@Bxr9HwA)
[Answer]
#  Pushy, 3 bytes
```
3[_
```
Explanation:
```
3 \ pushes 3 to the stack
[ \ starts an infinite loop
_ \ prints out the contents of the stack
```
[Answer]
# [Mascarpone](https://github.com/catseye/Mascarpone), 6.875 bytes
```
['@.:!]v*:!
```
[Try It Online!](https://tio.run/##y00sTk4sKsjPS/3/P1rdQc9KMbZMy0rx/38A)
### Explanation:
```
[     ]     // push a string that will define an operation
 '@.        // push the symbol '@ and output it (popping it in the process)
    :!      // duplicate the top of the stack and execute it
       v*   // push a function/operation that does the above
         :! // duplicate the operation, and execute it.
```
The operation duplicates and executes itself tail-recursively, generating the infinite output.
5 bits are sufficient for the characters used by this program, thus the total size is 55 bits, or 6.875 bytes
[Answer]
# [INTERCAL](http://www.catb.org/%7Eesr/intercal/), 26 bytes
```
DOCOMEFROM#1(1)DOREADOUT#0
```
[Try it online!](https://tio.run/##y8wrSS1KTsz5/9/F39nf19UtyN9X2VDDUNPFP8jV0cU/NETZ4P9/AA "INTERCAL – Try It Online")
This works for both C-INTERCAL and CLC-INTERCAL.
[Answer]
# [RETURN](https://esolangs.org/wiki/RETURN), 62 bytes
```
(())(()()()()()()()()()()()()()()()()())((()()()()()()()()()))
```
[Try it online!](https://tio.run/##K0otKS3K@/9fQ0NTE4gJQaAaLIKa//8DAA)
## Explanation:
```
(()) Add 1
(()()()()()()()()()()()()()()()()()) While nonzero repeat what's in the next group of brackets
(
  (()()()()()()()()()) Put character
)
```
[Answer]
# [KonamiCode](https://esolangs.org/wiki/KonamiCode), 15 bytes
`v(^)L(^)<<<B(^)`
Explanation:
```
v(^) [Writes 1 to memory address 1.]
L(^) [A loop marker]
<<<  [Output the current memory address as a number]
B(^) [A reverse-jump instruction, ending the loop.]
```
*Note:* We can't use 0 for the first instruction becuase the comparison buffer is set to 0 by default. This means that the reverse-jump's condition will be fulfilled and the loop will immediately exit. However, we could also replace this instruction with S(^) and have the program run the same way.
[Answer]
# [APOL](https://esolangs.org/wiki/APOL), 8 bytes
`w(T p(0))`
I'm not sure if this could reasonably be made smaller.
[Answer]
# [Headass](https://esolangs.org/wiki/Headass), 2 bytes
```
PE
```
[Try it here!](https://replit.com/@thejonymyster/HA23) copy and paste this: `srun("PE")`
Prints an infinite stream of 0s and newlines.
```
P   Print the value of the current register (initialized at 0) + a newline
 E  Go to code block determined by value at current register,
    Block 0 = return to start.
```
# [Headascii](https://esolangs.org/wiki/Headass#Headascii), 2 bytes
```
!E
```
[Try it here!](https://replit.com/@thejonymyster/HA23) copy and paste this: `erun("!E")`
Similar to the last one, but instead of printing 0s and newlines, it just prints newlines.
```
!   Print the value of the string register (initially empty) + a newline
 E  Go to code block determined by value at current register,
    Block 0 = return to start.
```
[Answer]
# Python 3, ~~18~~ 15 bytes
*Thanks to [DLosc](https://codegolf.stackexchange.com/users/16766/dlosc) for -3 bytes!*
```
while 1:print()
```
[Answer]
# [Appleseed](https://github.com/dloscutoff/appleseed), 26 bytes
```
(def start!(q(_(print!(0to
```
[Try it online!](https://tio.run/##SywoyEktTk1N@f9fIyU1TaG4JLGoRFGjUCNeo6AoMw/INCjJ//8fAA "Appleseed – Try It Online")
### Explanation
```
(def start!                 ; Define the start! event handler as
           (q               ; A function
             (_             ; That takes any number of arguments
               (print!      ; And outputs
                      (0to  ; The infinite list of all nonnegative integers
```
[Answer]
# [rusty\_deque](https://github.com/bigyihsuan/rusty_deque/), 17 bytes
```
1~{dup~ow~}~loop~
```
Forever print `1`s to the screen.
[Answer]
# [BitCycle](https://github.com/dloscutoff/esolangs/tree/master/BitCycle), 10 bytes
```
 !
 ~<
1A^
```
Outputs an infinite bit stream of alternating 1s and 0s, or, with the `-u` or `-U` flags, an infinite sequence of 1s.
[Try it online!](https://tio.run/##S8osSa5Mzkn9/19BkUuhzobL0DHu/38A "BitCycle – Try It Online") or [with an online visualizer](https://dloscutoff.github.io/Esolangs/BitCycle/?p=cbrczwr1An)
[Answer]
# [Common Lisp](http://www.sbcl.org/), 15 bytes
```
(loop(princ'x))
```
[Try it online!](https://tio.run/##S87JLC74/18jJz@/QKOgKDMvWb1CU/P/fwA "Common Lisp – Try It Online")
[Answer]
# [A0A0](https://esolangs.org/wiki/A0A0), 43 39 bytes
```
A0A0
A0C3G1G1A0
A0O0A0
A0A1G-3G-3A0
G-3
```
Prints 0 forever. This uses a classic infinite loop which was created by the inventor of the language. Considering the only important thing about this code is that it runs infinitely, I'll use this post as an explanation of this looping construct, since it's the basis for all loops.
Loops are generally not really difficult in programming languages, even those which only have goto instructions and not proper looping constructs. A0A0 has goto instructions, so what's the problem? A0A0 is a self-modifying language which deletes the instruciton after it executes it. So if we were to use a goto to form a loop, we would simply end up at nothing and the program halts. This is not what we want.
Thankfully, the language contains instructions to modify its own code. There are two instructions that do this. `A#` and `C#` where # is a placeholder for an integer. `A#` appends the current line of instructions (excluding itself) to the line # positions below. `C#` clears the line # positions below this line. Since all integers are allowed, negative numbers can be used to go to lines above and 0 can be used to stay on the same line.
Let's take a look at the basis of the loop.
```
A0 A0
A0 C3 G1 G1 A0
A0 instructions here A0
A0 A1 G-3 G-3 A0
G-3
```
The first thing we do when entering the loop is go past four `A0` instructions which append their own lines to themselves. Remember that it excludes itself, so this first `A0` is not copied. This would be an issue on subsequent iterations, which is why at the very end of the loop, there is also an `A0`. This means that this A0 at the end is copied, which preserves the ability to copy the loop infinite amount of times.
You'll notice that the last line does not have any kind of append instruction. This is necessary, because we must at some point go back up and we can't go up if we have an `A#`. But if we never place a `G-3` there again, we eventually will end up there and, again get stuck since there's no instruction there. This is what line 4 is for. It contains the following:
```
A1 G-3 G-3
```
It places two `G-3` in line lower - at line 5. This preserves the ability for us to keep jumping back up forever. However, this line contains an A0 at the end. And during exeuciton, it may contain many more instructions we don't want. If we execute anything that is not `G-3`, we go to line 6 and left the loop. This is where line 2 comes into play. It contains a `C3` instruction, which clears the line three lines lower. This is line 5. Because the instructions are aligned properly, this means that the line is cleared the moment we would hit an instruction that is not `G-3`. And since at the same point there will be another `A1 G-3 G-3` on line 4, this now empty line will get two `G-3` instructions again, just in time.
You may observe that, since there are also `G-3` instructions on line 4, we may sometimes jump up to line 1 instead of line 2. And this is where line 1 comes into play. It only contains `A0 A0`. This will repeat itself infinitely on that line and acts as an infinite no-op. After executing a single instruction, the program counter automatically moves to the next line and we're back on line 2 again.
And all of this code gives us freedom on line 3. We can put whatever instructions we want in there, as long as these instructions don't modify the loop. We can even have multiple lines in the middle, as long as you change the `G-3` to the appropriate amount.
Edit: Optimized by 4 bytes. It turns out that there is no minimum requirement of 3 instructions for the loop, allowing us to drop 2 instructions, totalling 4 bytes.
[Answer]
# [Regenerate](https://github.com/dloscutoff/Esolangs/tree/master/Regenerate) `-a`, 1 byte
```
*
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72qKDU9NS-1KLEkdVm0km6iUuyCpaUlaboWC7UgNJS7AEoDAA)
Prints newlines forever :P it's finding and printing every possible match for at least 0 nothings, delimited with newlines. Surprised this isn't a syntax error.
[Answer]
# [BitCycle](https://github.com/dloscutoff/Esolangs/tree/master/BitCycle), 6 bytes
```
!~<
1^
```
Inspired by [emanresu A's suggested golf](https://codegolf.stackexchange.com/questions/13152/shortest-code-to-produce-infinite-output#comment555299_247161) to [des54321's answer](https://codegolf.stackexchange.com/a/247161/16766). Similarly to that answer, this outputs alternating 0s and 1s.
[Try it here!](https://dloscutoff.github.io/Esolangs/BitCycle/?p=bzwr1n)
### Explanation
The initial `1` bit is directed north into the dupneg (`~`). A negated copy (`0`) is sent west to the sink (`!`) and is output. A non-negated copy is sent east, whereupon it is immediately directed west again back into the dupneg. Now the original copy is sent north and leaves the playfield, while the negated copy is sent south, redirected north again, and the cycle continues forever (with the bit changing parity each time).
[Answer]
# [Fuzzy Octo Guacamole](https://github.com/RikerW/Fuzzy-Octo-Guacamole), 3 bytes
```
(1)
```
Infinitely outputs 1.
Due to weird implicit output and recursive loops (it executes the code inside the loop using recursion), 1 is outputted by the implicit output.
[Answer]
# Quetzalcoatl, 14 chars
```
while 1: ::' '
```
This is for an older version of Quetzalcoatl.
[Answer]
# [Intcode](https://esolangs.com/wiki/Intcode), 9 bytes
```
4,0,5,0,1
```
Outputs "4" an infinite number of times.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 4 bytes
```
W1P1
```
Prints the number `1` with a trailing newline over and over. [Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgwYKlpSVpuhZLwg0DDCFMqAhMBgA)
This is a simple loop; in pseudocode,
```
while 1:
  print 1
```
Almost any expression can be printed instead of `1`. For example, `W1Pr` prints random floats between 0 and 1 forever.
A more interesting option, also 4 bytes:
```
P*,u
```
This constructs an infinite range starting at 0 (`,u`) and then prints each element of it (`P*`). The result is an infinite loop that outputs the natural numbers one at a time. [Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgwYKlpSVpuhZLArR0SiFMqAhMBgA)
[Answer]
# [Trilangle](https://github.com/bbrk24/Trilangle/), unbounded memory, 3 bytes
```
'1!
```
Push a 1 to the stack, print it, repeat.
## Trilangle, 4 bytes
```
'1,!
```
Push a 1 to the stack, print it, pop it off, repeat.
## Trilangle `-w`, 1 + 2 = 3 bytes
```
,
```
When run with the `-w` flag or in [the online interpreter](https://bbrk24.github.io/Trilangle/), popping from an empty stack prints a warning.
]


[Question]
      [
## Problem
John bought 5 apples. You are given the weights of every group of four apples, and must then find the weights of the apples themselves.
For example, if all apples without the first one weigh 798 g, without the second - 794 g, without the third - 813 g, without the fourth - 806 g, and without the fifth - 789 g, the weights are 202, 206, 187, 194, and 211.
## Rules
1. The solution of the problem by enumeration is allowed
2. Consider the number of points as follows: the number of bytes in your code. The lower the number of points, the better.
Have fun!

[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 3 (or 5) [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
Σ¼,
```
No idea why MathGolf has a single-byte `a//4` builtin, but it's pretty useful here. ;)
[Try it online.](https://tio.run/##y00syUjPz0n7///c4kN7dP7/jza3tNAxtzTRsTAw1rEwNNMxt7CMBQA)
With strict input of space-delimited values it would be 5 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py) instead:
```
ê_Σ¼,
```
[Try it online.](https://tio.run/##y00syUjPz0n7///wqvhziw/t0fn/39zSQsHc0kTBwsBYwcLQTMHcwhIA)
**Explanation:**
```
     # Optional for stricter space-delimited input:
ê    # Push the inputs as integer-array
 _   # Duplicate it
Σ    # Sum the values together
 ¼   # Integer-divide it by 4
  ,  # Subtract each value in the list from this sum//4
     # (after which the entire stack is output implicitly)
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), ~~9~~ ~~7~~ ~~6~~ 5 bytes
```
∑4ḭ$-
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLiiJE04bitJC0iLCIiLCJbNzk4LDc5NCw4MDMsODE2LDc4OV0iXQ==)
## Explanation
```
∑4ḭ$-
          # (implicit input)
∑         # Sum
 4ḭ       # Divide the sum by four
   $-     # Swap and subtract
```
*-2 bytes thanks to a stone arachnid*
*-1 byte thanks to ovs*
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/index.html), ~~8~~ 6 bytes
*Edit: -2 bytes thanks to ovs*
```
-+´÷⟜4
```
[Try it at BQN online REPL](https://mlochbaum.github.io/BQN/try.html#code=QXBwbGVzIOKGkCAtK8K0w7fin5w0CkFwcGxlcyA3OTjigL83OTTigL84MTPigL84MDbigL83ODkK)
```
    ÷⟜4     # divide each of the input values by 4
 +´         # and then fold the 'plus' function across them
-           # using the negative of the input as a list of starting values
            # (so effectively we start the fold using each negative input value
            # in parallel as a starting value)
```
[Answer]
# [Python](https://www.python.org), 32 bytes
```
lambda a:[sum(a)/4-x for x in a]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3FXISc5NSEhUSraKLS3M1EjX1TXQrFNLyixQqFDLzFBJjoepUCooy80o0tNI0os0tLXQUzC1NdBQsDIyBhKEZkGthGaupCVG7YAGEBgA)
[Answer]
# [Haskell](https://www.haskell.org), 18 bytes
```
map=<<(-).(/4).sum
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ0W0km5yQYFS7OI025ilpSVpuhabchMLbG1sNHQ19TT0TTT1iktzIRI39XMTM_MUbBVS8rkUFAqKMvNKFFQU0hSizS0tdBTMLU10FCwMjIGEoRmQa2EZC9G2YAGEBgA)
[Answer]
# [Japt](https://github.com/ETHproductions/japt) v2.0a0 [`-m`](https://codegolf.meta.stackexchange.com/a/14339/), 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
aWx÷4
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=2.0a0&flags=LW0&code=YVd49zQ&input=Wzc5OCw3OTQsODEzLDgwNiw3ODld)
[Answer]
# [λ-2d](https://l-2d.glitch.me/), 456 squares
the program can be imported in [the playground](https://l-2d.glitch.me/) with the following JSON file
```
{"41,13":"entry","41,18":"entry","41,23":"entry","41,28":"entry","41,32":"entry","42,13":"end_s","42,18":"end_s","42,23":"end_s","42,28":"end_s","42,32":"end_s","43,13":"end_e","43,18":"end_e","43,23":"end_e","43,28":"end_e","43,32":"end_e","39,15":"wire_nw","39,20":"wire_nw","39,25":"wire_nw","39,30":"wire_nw","39,34":"wire_nw","38,15":"wire_ne","38,20":"wire_ne","38,25":"wire_ne","38,30":"wire_ne","38,34":"wire_ne","44,13":"frame_tl","44,18":"frame_tl","44,23":"frame_tl","44,28":"frame_tl","44,32":"frame_tl","45,13":"wire_we","45,18":"wire_we","45,23":"wire_we","45,28":"wire_we","45,32":"wire_we","46,13":"wire_we","46,18":"wire_we","46,23":"wire_we","46,28":"wire_we","46,32":"wire_we","47,13":"wire_we","47,18":"wire_we","47,23":"wire_we","47,28":"wire_we","47,32":"wire_we","47,15":"wire_we","47,20":"wire_we","47,25":"wire_we","47,30":"wire_we","47,34":"wire_we","46,15":"wire_we","46,20":"wire_we","46,25":"wire_we","46,30":"wire_we","46,34":"wire_we","45,15":"wire_we","45,20":"wire_we","45,25":"wire_we","45,30":"wire_we","45,34":"wire_we","48,13":"wire_sw","48,18":"wire_sw","48,23":"wire_sw","48,28":"wire_sw","48,32":"wire_sw","48,15":"wire_nw","48,20":"wire_nw","48,25":"wire_nw","48,30":"wire_nw","48,34":"wire_nw","44,15":"wire_ne","44,20":"wire_ne","44,25":"wire_ne","44,30":"wire_ne","44,34":"wire_ne","44,14":"wire_ns","44,19":"wire_ns","44,24":"wire_ns","44,29":"wire_ns","44,33":"wire_ns","48,14":"wire_ns","48,19":"wire_ns","48,24":"wire_ns","48,29":"wire_ns","48,33":"wire_ns","42,14":"wire_nw","42,19":"wire_nw","42,24":"wire_nw","42,29":"wire_nw","42,33":"wire_nw","41,14":"wire_we","41,19":"wire_we","41,24":"wire_we","41,29":"wire_we","41,33":"wire_we","40,14":"wire_we","40,19":"wire_we","40,24":"wire_we","40,29":"wire_we","40,33":"wire_we","38,14":"wire_sw","38,19":"wire_sw","38,24":"wire_sw","38,29":"wire_sw","38,33":"wire_sw","39,14":"func_call","39,19":"func_call","39,24":"func_call","39,29":"func_call","39,33":"func_call","39,13":"joint_nsw","39,18":"joint_nsw","39,23":"joint_nsw","39,28":"joint_nsw","38,13":"wire_we","38,18":"wire_we","38,23":"wire_we","38,28":"wire_we","37,13":"wire_se","37,18":"wire_se","37,23":"wire_se","37,28":"wire_se","37,14":"wire_nswe","37,19":"wire_nswe","37,24":"wire_nswe","37,29":"wire_nswe","37,17":"wire_nw","37,22":"wire_nw","37,27":"wire_nw","37,32":"wire_nw","36,17":"wire_se","36,22":"wire_se","36,27":"wire_se","36,32":"wire_se","37,15":"wire_ns","37,20":"wire_ns","37,25":"wire_ns","37,30":"wire_ns","36,15":"wire_nw","36,20":"wire_nw","36,25":"wire_nw","36,30":"wire_nw","36,34":"wire_nw","35,15":"wire_ne","35,20":"wire_ne","35,25":"wire_ne","35,30":"wire_ne","35,34":"wire_ne","35,14":"wire_sw","35,19":"wire_sw","35,24":"wire_sw","35,29":"wire_sw","35,33":"wire_sw","36,14":"func_call","36,19":"func_call","36,24":"func_call","36,29":"func_call","36,33":"func_call","36,13":"joint_nsw","36,18":"joint_nsw","36,23":"joint_nsw","36,28":"joint_nsw","35,13":"wire_we","35,18":"wire_we","35,23":"wire_we","35,28":"wire_we","34,13":"wire_se","34,18":"wire_se","34,23":"wire_se","34,28":"wire_se","34,14":"wire_nswe","34,19":"wire_nswe","34,24":"wire_nswe","34,29":"wire_nswe","34,17":"wire_nw","34,22":"wire_nw","34,27":"wire_nw","34,32":"wire_nw","33,17":"wire_se","33,22":"wire_se","33,27":"wire_se","33,32":"wire_se","34,15":"wire_ns","34,20":"wire_ns","34,25":"wire_ns","34,30":"wire_ns","33,15":"wire_nw","33,20":"wire_nw","33,25":"wire_nw","33,30":"wire_nw","33,34":"wire_nw","32,15":"wire_ne","32,20":"wire_ne","32,25":"wire_ne","32,30":"wire_ne","32,34":"wire_ne","32,14":"wire_sw","32,19":"wire_sw","32,24":"wire_sw","32,29":"wire_sw","32,33":"wire_sw","33,14":"func_call","33,19":"func_call","33,24":"func_call","33,29":"func_call","33,33":"func_call","33,13":"joint_nsw","33,18":"joint_nsw","33,23":"joint_nsw","33,28":"joint_nsw","32,13":"wire_we","32,18":"wire_we","32,23":"wire_we","32,28":"wire_we","31,13":"wire_se","31,18":"wire_se","31,23":"wire_se","31,28":"wire_se","31,14":"wire_nswe","31,19":"wire_nswe","31,24":"wire_nswe","31,29":"wire_nswe","31,17":"wire_nw","31,22":"wire_nw","31,27":"wire_nw","31,32":"wire_nw","30,17":"wire_se","30,22":"wire_se","30,27":"wire_se","30,32":"wire_se","31,15":"wire_ns","31,20":"wire_ns","31,25":"wire_ns","31,30":"wire_ns","30,15":"wire_nw","30,20":"wire_nw","30,25":"wire_nw","30,30":"wire_nw","30,34":"wire_nw","29,15":"wire_ne","29,20":"wire_ne","29,25":"wire_ne","29,30":"wire_ne","29,34":"wire_ne","29,14":"wire_sw","29,19":"wire_sw","29,24":"wire_sw","29,29":"wire_sw","29,33":"wire_sw","30,14":"func_call","30,19":"func_call","30,24":"func_call","30,29":"func_call","30,33":"func_call","30,13":"joint_nsw","30,18":"joint_nsw","30,23":"joint_nsw","30,28":"joint_nsw","29,13":"wire_we","29,18":"wire_we","29,23":"wire_we","29,28":"wire_we","28,13":"wire_se","28,18":"wire_se","28,23":"wire_se","28,28":"wire_se","28,14":"wire_nswe","28,19":"wire_nswe","28,24":"wire_nswe","28,29":"wire_nswe","28,17":"wire_nw","28,22":"wire_nw","28,27":"wire_nw","28,32":"wire_nw","27,17":"wire_se","27,22":"wire_se","27,27":"wire_se","27,32":"wire_se","28,15":"wire_ns","28,20":"wire_ns","28,25":"wire_ns","28,30":"wire_ns","27,14":"func_call","27,19":"func_call","27,24":"func_call","27,29":"func_call","27,33":"func_call","27,13":"joint_nsw","27,18":"joint_nsw","27,23":"joint_nsw","27,28":"joint_nsw","26,13":"wire_se","26,18":"wire_se","26,23":"wire_se","26,28":"wire_se","26,14":"wire_ns","26,19":"wire_ns","26,24":"wire_ns","26,29":"wire_ns","26,15":"wire_ns","26,20":"wire_ns","26,25":"wire_ns","26,30":"wire_ns","26,16":"wire_ne","26,21":"wire_ne","26,26":"wire_ne","26,31":"wire_ne","27,16":"wire_we","27,21":"wire_we","27,26":"wire_we","27,31":"wire_we","29,16":"wire_we","29,21":"wire_we","29,26":"wire_we","29,31":"wire_we","30,16":"wire_we","30,21":"wire_we","30,26":"wire_we","30,31":"wire_we","32,16":"wire_we","32,21":"wire_we","32,26":"wire_we","32,31":"wire_we","33,16":"wire_we","33,21":"wire_we","33,26":"wire_we","33,31":"wire_we","35,16":"wire_we","35,21":"wire_we","35,26":"wire_we","35,31":"wire_we","36,16":"wire_we","36,21":"wire_we","36,26":"wire_we","36,31":"wire_we","39,16":"wire_sw","39,21":"wire_sw","39,26":"wire_sw","39,31":"wire_sw","39,17":"wire_ns","39,22":"wire_ns","39,27":"wire_ns","39,32":"wire_ns","38,16":"wire_we","38,21":"wire_we","38,26":"wire_we","38,31":"wire_we","28,16":"wire_nswe","28,21":"wire_nswe","28,26":"wire_nswe","28,31":"wire_nswe","31,16":"wire_nswe","31,21":"wire_nswe","31,26":"wire_nswe","31,31":"wire_nswe","34,16":"wire_nswe","34,21":"wire_nswe","34,26":"wire_nswe","34,31":"wire_nswe","37,16":"wire_nswe","37,21":"wire_nswe","37,26":"wire_nswe","37,31":"wire_nswe","28,33":"wire_we","31,33":"wire_we","34,33":"wire_we","37,33":"wire_we","39,12":"num_7","40,12":"num_8","41,12":"num_9","36,11":"num_8","37,11":"num_0","38,11":"num_6","33,12":"num_8","34,12":"num_1","35,12":"num_3","30,11":"num_7","31,11":"num_9","32,11":"num_4","28,12":"num_9","29,12":"num_8","27,12":"num_7","30,12":"wire_ns","36,12":"wire_ns","27,15":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"27,20":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"27,25":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"27,30":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"27,34":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"53,12":"func_def","55,12":"func_def","57,12":"func_def","59,12":"func_def","61,12":"func_def","54,12":"end_s","58,12":"end_s","56,12":"end_s","60,12":"end_s","62,12":"end_s","63,12":"end_e","54,11":"label","55,11":[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"53,11":"wire_se","54,13":"joint_nse","55,16":"op_plus","57,16":"op_plus","59,16":"op_plus","61,16":"op_plus","55,15":"func_call","57,15":"func_call","59,15":"func_call","61,15":"func_call","56,13":"wire_nswe","58,13":"wire_nswe","61,13":"wire_we","60,13":"wire_nswe","62,13":"wire_nswe","59,13":"wire_we","57,13":"wire_we","55,13":"wire_we","55,14":"wire_sw","54,14":"wire_ne","56,15":"wire_nw","58,15":"wire_nw","60,15":"wire_nw","57,14":"wire_sw","59,14":"wire_sw","60,14":"func_call","61,14":"wire_sw","56,14":"func_call","58,14":"func_call","62,14":"func_call","62,15":"wire_nw","63,14":"wire_sw","63,15":"wire_ns","63,16":"func_call","63,17":"op_div","64,16":"wire_nw","64,15":"func_call","64,14":"num_4","65,15":"wire_sw","65,16":"func_call","65,17":"op_minus","66,16":"wire_nw","66,14":"func_call","67,14":"wire_nw","66,13":"wire_sw","67,12":"wire_sw","66,15":"wire_ns","67,13":"wire_ns","63,13":"wire_we","64,13":"wire_we","65,13":"wire_we","64,12":"wire_we","65,12":"wire_we","66,12":"wire_we"}
```
[![full program](https://i.stack.imgur.com/aClTn.png)](https://i.stack.imgur.com/aClTn.png)
the function in itself is the right structure, the left one being 5 calls to the function with the 5 arguments in differents orders
---
## js equivalent
```
a=798
b=794
c=813
d=806
e=789
f=v=>w>=>x=>y=>z=>((v+w+x+y+z)/4)-v
f(a)(b)(c)(d)(e)
f(b)(c)(d)(e)(a)
f(c)(d)(e)(a)(b)
f(d)(e)(a)(b)(c)
f(e)(a)(b)(c)(d)
```
---
Language explanation can be found in [the playground](https://l-2d.glitch.me/) by loading the *cheatsheet* example, or in the [release blog post](https://www.media.mit.edu/projects/2d-an-exploration-of-drawing-as-programming-language-featuring-ideas-from-lambda-calculus/overview/)
[Answer]
# Excel, 15 bytes
```
=SUM(A1#)/4-A1#
```
Input is in cell A1 as an array. For instance, `={798;794;813;806;789}`
[![ColumnA](https://i.stack.imgur.com/b7PhL.png)](https://i.stack.imgur.com/b7PhL.png)     [![ColumnB](https://i.stack.imgur.com/ODCEq.png)](https://i.stack.imgur.com/ODCEq.png)
---
# Excel, 19 bytes
```
=SUM(A1:A5)/4-A1:A5
```
Input is in the cells `A1:A5`. Doesn't rely on array input. Output is wherever the formula is. It's not a very interesting solution.
[![Screenshot](https://i.stack.imgur.com/3arY0.png)](https://i.stack.imgur.com/3arY0.png)
[Answer]
# TI-Basic, 7 bytes
```
sum(Ans)/4-Ans
```
Takes input in `Ans`. Output is stored in `Ans` and displayed.
[Answer]
# [Desmos](https://desmos.com/calculator), 16 bytes
```
f(l)=l.total/4-l
```
[Try It On Desmos!](https://www.desmos.com/calculator/iscwqjxvd9)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/kzetwyayfs)
[Answer]
# [LOLCODE](http://lolcode.org/), 216 bytes
```
HOW IZ I f YR a
I HAS A s ITZ 0
IM IN YR l UPPIN YR i TIL BOTH SAEM i 5
s R SUM OF s a'Z SRS i
IM OUTTA YR l
IM IN YR l UPPIN YR i TIL BOTH SAEM i 5
VISIBLE DIFF OF QUOSHUNT OF s 4 a'Z SRS i
IM OUTTA YR l
IF U SAY SO
```
[Try it online!](https://tio.run/##jZA9D4IwFEX3/oq7uRkQVBxLhPQFsUpbFTbiR0JCwsD/DxaqA4OJ23vn5Z7k3bZr793jOQhO8JfBIOQVVIHwQlmgZgTBFTh6kK7gMcpBx/HUwpxObmyg6YBYagHFk9zua9ajgDI5ZGqj9aKCKhSaMS6N1nwy/C27kKL4kGBPaToaz0YqYY7a2cPf/hTGWkooOXwfqadHOGKTZaRZ/cFj3JtO2100o/6HhjO6mmjkBTMaOOpvZjR0hmjHbJ22XFct8oyXLNPiFpfJ8AY "LOLCODE – Try It Online")
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~9~~ 7 bytes
```
$+a/4-a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgebSSbkGFUuyCpaUlaboWy1W0E_VNdBMhPKjgzmilaHNLC2tzSxNrCwNjawtDM2tzC8tYuC4A)
*-2 bytes thanks to DLosc*
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4? 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
With a strict interpretation of Rule 1 (can't take as a program argument due to the "single line" part) - a full program that reads from STDIN and writes to STDOUT:
```
ɠḲVµS÷4_
```
[Try it online!](https://tio.run/##y0rNyan8///kgoc7NoUd2hp8eLtJ/P//5pYWCuaWJgoWhsYKFgZmCuYWlgA)
...or with site default IO instead - a monadic Link that accepts a list of five numbers and yields a list of five numbers:
```
S÷4_
```
**[Try it online!](https://tio.run/##y0rNyan8/z/48HaT@P///0ebW1roKJhbmugoWBgaAwkDMyDXwjIWAA "Jelly – Try It Online")**
### How?
```
ɠḲVµS÷4_ - Main Link: no arguments
ɠ        - read a line from STDIN
 Ḳ       - split that at spaces
  V      - evaluate that as Jelly code -> list of the five four-apple-weights, W
   µ     - start a new monadic chain - f(W)
    S    - sum W
      4  - four
     ÷   - divide -> sum(W)/4
       _ - subtract W (vectorises) -> [sum(W)/4-w1, sum(W)/4-w2, sum(W)/4-w3, sum(W)/4-w4, sum(W)/4-w5]
         - implicit print
```
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, 23 bytes
```
[ dup Σ 4 / swap n-v ]
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQnVqUl5qjkJtYkqFXmpeZnJ@SCuZARMpSQWqLFQqKUktKKguKMvNKFKy5uKoVzC0tgNhEwcLAWMHC0EzB3MJSoVbhf7RCSmmBwrnFCiYK@grF5YkFCnm6ZQqx/5MTc3IU9P4DAA "Factor – Try It Online")
## Explanation
```
       ! { 798 794 803 816 789 }
dup    ! { 798 794 803 816 789 } { 798 794 803 816 789 }
Σ      ! { 798 794 803 816 789 } 4000
4      ! { 798 794 803 816 789 } 4000 4
/      ! { 798 794 803 816 789 } 1000
swap   ! 1000 { 798 794 803 816 789 }
n-v    ! { 202 206 197 184 211 }
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 22 bytes
```
->a{a.map{a.sum/4-_1}}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGiNNulpSVpuhbbdO0SqxP1chMLgGRxaa6-iW68YW0tRHJfgUJadLS5pYWOgrmliY6ChYExkDA0A3ItLGNjIYoWLIDQAA)
[Answer]
# [Julia 1.0](http://julialang.org/), 14 bytes
```
!l=sum(l/4).-l
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/XzHHtrg0VyNH30RTTzfnv0NxRn65gmK0uaWFjoK5pYmOgoWhMZAwMANyLSxj/wMA "Julia 1.0 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~9~~ 4 bytes
```
O4÷α
```
[Try it online!](https://tio.run/##yy9OTMpM/f/f3@Tw9nMb//@PNre00DG3NNGxMDDWsTA00zG3sIwFAA "05AB1E – Try It Online")
*-5 bytes thanks to Kevin Cruijssen*
[Answer]
# [R](https://www.r-project.org/), 14 bytes
```
\(x)sum(x)/4-x
```
[Try it online!](https://tio.run/##K/r/P600L7kkMz9Po0KzuDQXSOqb6Fb8/19ho5usYW5poaNgbmmio2BhaAwkDMyAXAtLTQA "R – Try It Online")
Uses the new lambda, `\`, introduced in R 4.1.
[Answer]
# [J](https://www.jsoftware.com), 7 bytes
```
-~4%~+/
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8GCpaUlaboWa9IUbK0UdOtMVOu09SFCe1OTM_IVaqwU0hTMLS2A2ETBwsBYwcLQTMHcwhKiBqYdAA)
[Answer]
# [jq](https://stedolan.github.io/jq/), ~~20~~ 9 bytes
```
add/4-.[]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70oq3DBgqWlJWm6FisTU1L0TXT1omMhfKjwgp3R5pYWOgrmliY6ChaGxkDCwAzItbCEqgMA)
*-11 bytes thanks to @ovs*
[Answer]
# [Burlesque](https://github.com/FMNSSun/Burlesque), 9 bytes
```
J++4./j?-
```
[Try it online!](https://tio.run/##SyotykktLixN/V@Q@t9LW9tETz/LXvf//2pzSwsFc0sTBQtDYwULAzMFcwvLWgUA "Burlesque – Try It Online")
```
J   # Duplicate
++  # Sum
4./ # Divide by 4
j   # Swap
?-  # Subtract from each
```
[Answer]
# [Halfwit](https://github.com/chunkybanana/halfwit/), 5 bytes
```
kJ>+<k+N+N
```
[Try it online.](https://dso.surge.sh/#@WyJoYWxmd2l0IixudWxsLCJrSj4rPGsrTitOIiwiIiwiW1s3OThuLDc5NG4sODAzbiw4MTZuLDc4OW5dXSIsIiJd)
Inputs as a list of BigInts.
**Explanation:**
```
kJ          # Sum the (implicit) input-list
  >+<       # Push compressed BigInt 4n
     k+     # Integer-divide the sum by this 4
       N+N  # Subtract the values in the (implicit) input-list from this value:
       N    #  Negate the value
        +   #  Add it to each value in the (implicit) input-list
         N  #  Negate each value in the list
            # (after which the result is output implicitly)
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~61~~ 58 bytes
```
n,i;f(int*a){for(i=10;i--;)i>4?n+=a[i%5]:(a[i]=n/4-a[i]);}
```
[Try it online!](https://tio.run/##JYxBCsIwEEX3OUUoFBI7wRYbmxijByldhEpkFkYp7kLOHqe4mTfw/3@req5rrQnQRYHpewgyx/cm0A@9Q6WcxNt4T50PM7Z6uQji4tNxVPsjXamvgEnIzGjMw6wXnydrYLIjmOEEpj/DZGxxLIog6e5uaiL3vHeEK9eEriPDZ6MkiqZ9AG/g72eFlfoD "C (gcc) – Try It Online")
*-3 bytes thanks to ceilingcat*
[Answer]
# x86 32-bit machine code, 32 bytes
```
00000000: 87ca 31c0 6a05 5903 448a fce2 fac1 e802  ..1.j.Y.D.......
00000010: 6a05 5950 2b44 8afc 8944 8afc 58e2 f4c3  j.YP+D...D..X...
```
## Assembly
```
section .text
	global func
func:					;void func(int *ecx);
	; int *edx=ecx; int eax=0;
	xchg ecx, edx
	xor eax,eax
	; for(ecx=5;ecx>0;ecx--)eax+=edx[ecx-1]
	push 0x5
	pop ecx
	add:
	add eax, [edx + 4*ecx-4]
	loop add
	; eax = eax / 4
	shr eax, 2
	; for(ecx=5;ecx>0;ecx--)edx[ecx-1]=eax-edx[ecx-1];
	push 0x5
	pop ecx
	sub:
	push eax
	sub eax, [edx + 4*ecx-4]
	mov [edx + 4*ecx-4], eax
	pop eax
	loop sub
	; return
	ret
```
Takes a pointer to an array of 5 integers in ECX (fastcall convention), and modifies the array in place with the results.
[Try it online!](https://tio.run/##fVPbjpswEH3GXzGK1AoITrK5NBdCHqpu1ZdqPyAbRcaYhBXYCMyW1Wq/PR2b1SZp0yIx@MycMzP2mJjVxxNnGtbr@4fvsIGhLsohG7C6ONWC60xJGGjRauIcchWzHNJGcmLMyjFP@KyyxDrdTGrwBW@9kDghdChpI/R0SLA2GmGs5ccDoDcADCNUlQkF@BIjTFXlYjSahWg3I2Mp9TDaj5C/NfBuR5yyqY8wame4UqVJRxyWJCtrbT7YIh36MDU90SlKcoVMDNsySIHI2iFMiVMfuy5g/L8mPupHyKVnGN7sp27i1XvAbM7gf3RWqOc/nUGnscnMwjaPGWx7ldBNJYmD3xPOjZC/RljrJh5wgpMTlQQ7pP2eaV1lcaPFfu@6Kas1Z3nueR/j870QSMEy6XqvxDEzy2TZ6D2rqu1sh8f1Ol8ugvlyGixGk2Bx9yWYL5ZvAfiWhvEC8ynujkdeAJkddiEKXr64lhCc0@E5j8w9ea@MXovw1I0sW8/CrN/3ygp7SN3ep@RR9gJL22Y7ZL4Ru2uJ1xRoKvJ0Mr64uUBVh7hKxECRA@fXLhRcntIlGahUtMwE0GIyJip@4qp8AfoAcSZZhaun7n@40pzXyCJGlTRFCfQb0J/m6ov8ir75PCaCH7GWgN6j9H3/64sWwFUj9QpRzzJ@YdMc1tfJb2h/iNZUOwvbNrkhIlfbP/0G "Try It Online")
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), 4 bytes (8 nibbles)
```
+/+$4*~
```
```
  +         # sum of
   $        # the input
 /          # divided by
    4       # 4
+           # added to
            # (implicitly) each element of input
     *      # multiplied by
      ~     # -1
```
[Answer]
# [J](https://www.jsoftware.com), 7 bytes
```
-~4%~+/
```
Nothing new here.
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FOJT31NAVbKwV1BR0FAwUrINbVU3AO8nFbWlqSpmuxXLfORLVOWx_Cu2muyZWanJGvkKZgbmkBxCYKFgbGChaGZgrmFpYYUoZAKQOwFET7ggUQGgA)
```
-~4%~+/
     +/  NB. sum
  4%~    NB. divide result by 4
-~       NB. subtract result by input, vectorized
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 7 bytes
```
Ｉ⁻÷Σθ⁴θ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzczr7RYwzOvxCWzLDMlVSO4NFejUFNHwQSICzU1Na3//4@ONre00FEwtzTRUbAwNAYSBmZAroVlbOx/3bIcAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
    θ   Input list
   Σ    Take the sum
  ÷     Integer divided by
     ⁴  Literal integer `4`
 ⁻      Vectorised subtract
      θ Input list
Ｉ       Cast to string
        Implicitly print
```
9 bytes for a version that works with two or more apples, not just five:
```
Ｉ⁻÷Σθ⊖Ｌθθ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzczr7RYwzOvxCWzLDMlVSO4NFejUFNHwSU1uSg1NzWvJDVFwyc1L70kAyisCZQAkdb//0dHm1ta6CiYW5roKFgYGgMJAzMg18IyNva/blkOAA "Charcoal – Try It Online") Link is to verbose version of code.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~34~~ 32 bytes
```
a=>a.map(e=>eval(a.join`+`)/4-e)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70kLz8ldcGiNNulpSVpuhY3FRJt7RL1chMLNFJt7VLLEnM0EvWy8jPzErQTNPVNdFM1oeo0k_PzivNzUvVy8tM10jSizS0tdBTMLU10FCwMjIGEoRmQa2EZqwnVsGABhAYA)
-2 bytes thanks to [Steffan](https://codegolf.stackexchange.com/users/92689/steffan)
[Answer]
# [Red](http://www.red-lang.org), 28 bytes
```
func[v][v -((sum v)/ 4)* -1]
```
[Try it online!](https://tio.run/##BcFLCoAgAAXAq7x2GUhJktox2oqL8AMRWph6fZvJ3vXDO20Q9h5qsroZ3UDH8asRjczgZAJlpr/5SgUB8bw9mrflyQO0UBJCcchlhWQbhFSm/w "Red – Try It Online")
[Answer]
# [C (clang)](http://clang.llvm.org/), 60 bytes
```
b,c;f(*a){for(b=c=0;b<5;c+=a[b++]);for(;b--;a[b]=c/4-a[b]);}
```
[Try it online!](https://tio.run/##HY7NDoIwEITP8BQbEpPWFvkRBLL2SQyHtoA2QTSCJ8Kz49bLZHYmu/vZ2I56uu@7kRYHdtR8HV4fZpRVKZpriVYofTNCtBx9gSaOkYJW2aSIveG47U/tJsbXMHDTAks/L7eyVbBWTS2hagoJdXYmSS801s2GkCQwP17fsQPTA@RpLkmozeqKxG/oqYM8y05hMDB/kSM5AvAfHLE5YnNC8PeHkoFFhw4i@X/tCCnc9h8 "C (clang) – Try It Online") Takes an array of 5 integers and modifies the array in-place.
]


[Question]
      []