[Question]
  [
In English, nouns can take on two different forms depending on whether they are singular (one) or plural (anything else). For example, we would say "1 dog" but "2 dogs", "0 dogs", "57 dogs" and so forth.
In Russian, there are three categories. Instead of "1 dog, 2 dogs, 5 dogs", in Russian it would be "1 собака, 2 собаки, 5 собак".
The categories are divided according to the following logic:
* "Singular": used for 1 and any number ending in 1, except for numbers ending in 11.
	+ Examples: 1 собака, 21 собака, 101 собака
* "Few": used for 2, 3, and 4, and any number ending in 2, 3, or 4 except for numbers ending in 12, 13, and 14.
	+ Examples: 2 собаки, 3 собаки, 4 собаки, 32 собаки, 43 собаки, 104 собаки
* "Many": anything that is not considered "Singular" or "Few".
	+ Examples: 0 собак, 5 собак, 11 собак, 13 собак, 25 собак, 111 собак, 114 собак
## The challenge
Given an integer input in the range [0, 1000], return `1` if it belongs to the "singular" category, `2` if it belongs to the "few" category, and `5` if it belongs to the "many" category.
Your program may be a function or it can use STDIN. You may print to STDOUT or return a value from the function
This is a **code golf** challenge, so the solution with the fewest number of bytes wins.
  
[Answer]
# [Python 2](https://docs.python.org/2/), 36 bytes
```
lambda n:'5521'[n%~9/-3>>n/10%~9/-9]
```
[Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqiQZ6VuampkqB6dp1pnqa9rbGeXp29oAGZbxv5Pyy9SyFPIzFMoSsxLT9UwNDAw0LTiUigoyswrUcjTUde1U9dJ08jT/A8A "Python 2 – TIO Nexus")
Same length arithmetically:
```
lambda n:5/(n%~9/-3>>n/10%~9/-9or 1)
```
Let's first look at simpler code that doesn't account for teens.
```
lambda n:'5521'[n%~9/-3]
```
Here, we want a mapping of the one's digit to an output that works like
```
[5, 1, 2, 2, 2, 5, 5, 5, 5, 5][n%10]
```
But, rather than take `n` modulo 10 (`%10`), we can do `n%-10`, which maps to the intervals `[-9..0]` to give remainders:
```
> [n%~9 for n in range(10)]
[0, -9, -8, -7, -6, -5, -4, -3, -2, -1]
```
This is promising because the first two entries `0` and `-9` are far apart, and they need to be sent to different outputs. Also, `-10` can be shortened to `~9`.
From here, floor-dividing by `/-3` gives chunks of 3 with the right starting spot
```
> [n%~9/-3 for n in range(10)]
[0, 3, 2, 2, 2, 1, 1, 1, 0, 0]
```
To get the desired output, we now just need to map `0->5, 1->5, 2->2, 1->1`, which we do with the string selection `'5521'[_]`.
Now, we also need numbers ending in 11 to 15 to always give `5`. We first do this by detecting whether then tens digit is `1`. Taking `n/10` to remove the last digit, we then apply `%~9` as before to get the outcomes
```
[0, -9, -8, -7, -6, -5, -4, -3, -2, -1]
```
for respective final digits. The digit of 1 that we want to detect is mapped to the extremal value `-9`. Floor-dividing by `-9` turns it to 1 and everything else to 0.
```
> [k%~9/-9 for k in range(10)]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
```
Finally, we make this indicator being `1` always give output 5. This is done by bit-shifting the result of `n%~9/-3` right by the indicator. The result of `0,1,2,3` always bit-shifts right to 0 or 1, which gives an output of 5 as desired.
[Answer]
# [Python 2](https://docs.python.org/2/), 45 bytes
```
lambda n,s='5122255555':(s+'5'*10+s*8)[n%100]
```
[Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqiQp1Nsq25qaGRkZAoC6lYaxdrqpupahgbaxVoWmtF5qoYGBrH/0/KLFDIVMvMUihLz0lM1jAwMNK24FAqKMvNKFDJ11HXt1HXSNDI1/wMA "Python 2 – TIO Nexus")
[Answer]
# [Perl 5](https://www.perl.org/), 26 bytes
25 bytes of code + `-p` flag.
```
$_=/1.$|[5-90]$/?5:2-/1$/
```
[Try it online!](https://tio.run/nexus/perl5#FYk7DoAwDMX2dwoQWUuaTwcqIQ6CEBMbQ8XM3UuYbMvT2K7nHlLrdK4sM717SUs@iLdSNbEQ9y5QgeQADA5TuEU7MgoklkF/CRP/AA)
For one more byte, there is `$_=/(?<!1)[1-4]$/?2-/1$/:5`.
**Explanations:** (on the 27 bytes version; the 26 is quite symmetrical)  
Both "singular" and "few" end with "not a 1 followed by a digit from 1 to 4" (tested with `(?<!1)[1-4]$/`). In those case, the result is 2, minus 1 if the number ends with 1 (`2-/1$/`). Otherwise, the result if 5.
[Answer]
# JavaScript (ES6), ~~53~~ ~~49~~ ~~48~~ ~~40~~ ~~39~~ ~~38~~ ~~37~~ 36 bytes
```
n=>/[05-9]$|1.$/.test(n)?5:1+(n%5>1)
```
* Saved 8 bytes thanks to [CalculatorFeline](https://codegolf.stackexchange.com/users/51443/calculatorfeline).
* Saved 1 byte thanks to [ETHproductions](https://codegolf.stackexchange.com/users/42545/ethproductions).
* Saved 1 byte thanks to [Johan](https://codegolf.stackexchange.com/users/55822/johan-karlsson)
---
## Try it
```
f=
n=>/[05-9]$|1.$/.test(n)?5:1+(n%5>1)
oninput=_=>o.innerText=f(+i.value);o.innerText=f(i.value=0)
```
```
<input id=i type=number><pre id=o>
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~19~~ 18 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
DµṖṚi1’ȧṪị“M;ọ6’D¤
```
A monadic link taking and returning non-negative integers.
**[Try it online!](https://tio.run/nexus/jelly#ASsA1P//RMK14bmW4bmaaTHigJnIp@G5quG7i@KAnE074buNNuKAmUTCpP///zIx)** or see the three groups from 0 to 1000 inclusive in this [test suite](https://tio.run/nexus/jelly#ATgAx///RMK14bmW4bmaaTHigJnIp@G5quG7i@KAnE074buNNuKAmUTCpP8wcsi3w4figqzEoOKAmUf//w).
### How?
```
DµṖṚi1’ȧṪị“M;ọ6’D¤ - Main link: non-negative number, n  e.g. 301      311      313
D                  - cast to decimal list                [3,0,1]  [3,1,1]  [1,3,3]
 µ                 - monadic chain separation, call that d
  Ṗ                - pop d                               [3,0]      [3,1]    [1,3]
   Ṛ               - reverse                             [0,3]      [1,3]    [3,1]
     1             - literal 1
    i              - first index of (0 if not found)      0          1        2      
      ’            - decrement                           -1          0        1
        Ṫ          - tail d                               1          1        3
       ȧ           - logical and                          1          0        3
                 ¤ - nilad followed by link(s) as a nilad:
          “M;ọ6’   -   base 250 literal = 1222555555
                D  -   cast to decimal list [1,2,2,2,5,5,5,5,5,5]
         ị         - index into (1-based and modular)     1          5        2
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~38~~ 19 bytes
Uses the index-trick from [Rod's python answer](https://codegolf.stackexchange.com/a/123764/47066)
```
•1rê¢°•©5T×®9×JIт%è
```
[Try it online!](https://tio.run/nexus/05ab1e#qyn7/6hhkWHR4VWHFh3aAGQeWmkacnj6oXWWh6d7VV5sUj284n@l0uH9VgqH9yvp/DfkMjLkMjQAUlzGXCZcxkZcJsZAvgmXAZcplyFQypjLCMQAsgxNAA "05AB1E – TIO Nexus")
**Explanation**
```
•1rê¢°•              # push the number 5122255555
       ©             # store a copy in register
        5T×          # push 5 repeated 10 times
           ®         # retrieve the first number from register
            9×       # repeat it 9 times
              J      # join everything to string
               Iт%   # push input mod 100
                  è  # use this to index into the string of digits
```
[Answer]
# PHP>=7.1, 44 Bytes
```
<?=$argn[-2]!=1&($m=($argn+9)%10)<4?2-!$m:5;
```
[Online Version](http://sandbox.onlinephpfunctions.com/code/377f9e09acab09f7789f54d418e75fb25096876a)
[Answer]
# [MCxxxx Assembly](http://store.steampowered.com/app/504210/SHENZHEN_IO/), 123 Bytes
```
e:slx x0
mov x0 acc
dst 2 0
tlt acc 11
-tgt acc 14
-jmp v
+dgt 0
teq acc 1
+mov 1 x1
+jmp e
tlt acc 5
+mov 2 x1
v:-mov 5 x1
```
### Note:
TiO doesn't support this language, which is used in the Zachtronics game [Shenzhen I/O](http://store.steampowered.com/app/504210/SHENZHEN_IO/), so there's no link to test this.
## Explanation:
This is a function that takes input through XBus port x0, and outputs through port x1. It's too long to execute on an MC4000, but fits nicely into the memory of an MC6000. XBus ports, for those unfamiliar, allow the transmission of discrete packets of digital data.
One piece of information that may be helpful in reading this: in MCxxxx assembly, test instructions set a flag that indicates which branch should be taken. Lines that begin with `+` are only executed if the most recent test returned true, and lines that begin with `-` are only executed if the test was false.
Line by line:
```
e:slx x0    # Label this line e, then sleep until input is available on XBus port x0
mov x0 acc  # Move the input into register acc 
dst 2 0     # Set the leftmost digit of the input to 0
tlt acc 11  # Test if the value in acc is less than 11
-tgt acc 14 # If it's not, check if it's greater than 14
-jmp v      # If it's not, jump to the line labeled v (the last line)
+dgt 0      # If either of the previous tests returned true,
            #     set acc to the value of acc's rightmost digit
teq acc 1   # Test if acc equals 1
+mov 1 x1   # If it does, return 1
+jmp e      # Then jump to label e, which ends execution
tlt acc 5   # Test if acc is less than 5
+mov 2 x1   # If it is, return 2
v:-mov 5 x1 # If the previous test is false, return 5
```
A note about scoring: MCxxxx assembly doesn't have functions per se, but this is as close to a function as you can get - it's a program that fits in a single execution node, takes input through one port and outputs through another. As a result, I've scored this like a function (i.e. without counting the bytes necessary to make a valid MCxxxx emulator file).
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~25~~ 21 bytes
```
1.$
5
T`d`512225
!`.$
```
[Try it online!](https://tio.run/##Dcm7CYBAEAXA/HUhnGB0@PaDdmADFrCCBiYGYv/rpjPv9d3PkeO0RbI3OPY4wykijiF6y5xBCBRWuYAEFVJkkBXqJUU0UPQH "Retina – Try It Online") -4 bytes thanks to Neil.
[Answer]
# [Haskell](https://www.haskell.org/), 62 58 bytes
```
f n|s<-"5122255555"=(s++('5'<$[0..9])++cycle s)!!mod n 100
```
[Try it online!](https://tio.run/##1Y9BCsMgFESv8hMKUWxFBRdCPElwIYnBUDWhv1AKvbttui50287bvZnNRI/nkFKtM5QH9qdWS6WU3tNagoyRTnf9YRCcG0cZG@9jCoC0afI6QQEpRM1@KXa7LOUKJPsNZhgk59IYB9bCbkgMfgIOGNcbfbVH9UZ/4dPu193f/XC0PgE "Haskell – Try It Online")
## Explanation
This builds the following string:
5122255555555555555551222555555122255555512225555551222555555122255555512225555551222555555122255555...
Which is a table where cell `n` contains the answer for the `nth` number. The table is only correct for the first 100 elements, hence the `mod`.
[Answer]
**Scala, 110 bytes**
```
n=>Stream.iterate("512225555555555555555")(_=>"1222555555").flatMap(_.toCharArray).map(_.toInt).take(n-1).head
```
[Answer]
# Turtlèd, 35 bytes
```
!--.(1#0#)+.@3(1@1)(2@2)(3@2)(4@2),
```
[Try it online!](https://tio.run/##KyktKslJTfn/X1FXV0/DUNlAWVNbz8FYw9DBUFPDyMFIU8MYRJgACZ3//@0MAQ "Turtlèd – Try It Online")
This function requires that the input starts with a >, which I guess is ok because python2 uses input semi regularly, and that needs quotes.
Explanation:
```
!             input the number as a string, complete with the >
 --.          wrap around to the end of the string, and then move one back. if this
              is a single digit, we end up on the >,
              otherwise we end up on the second to last digit. write the digit/>
    (1#0#)    if it is 1, set the string to 0. this way it will always write 3 at the end.
          +.       write the last digit (or 0 if the second last digit was 1)
            @3      set the character variable to 3. this means if what was written was not
                       in (1, 2, 3, 4), then it will write 3 at the end
              (1@1)    if the character written was a 1, set the character to be written
                       at the end to 1
                   (2@2)(3@2)(4@2)
                     if it is any of 2,3,4, set the character to be written at the end to 2
                                  ,    write the character that was set
```
[Answer]
# [Lexurgy](https://www.lexurgy.com/sc), 88 bytes
```
s:
\1=>\1/_ $//\1 _ $
else:
{\2,\3,\4}=>\2/_//\1 _ $
else:
[]=>\5
c:
[]=>*/_//_ $
```
Ungolfed explanation:
```
singular: # 1 to 1 if no 1 preceding 1
\1=>\1/_ $//\1 _ $
else:     # 2,3,4 to 2 if no preceding 1
{\2,\3,\4}=>\2/_ $//\1 _ $
else:     # everything else to 5
[]=>\5/_ $
clean:    # keep only the last digit
[]=>*/_//_ $
```
Trivia: the technical linguistics terms for `one, few, many` is `singular, paucal, plural`.
]