This is a very simply formulated task. Let's call an integer number `N` 'green' if `N²` ends with all of the digits of `N`. Some examples:
`5` is green, because `5² = 25` and `25` ends with `5`.
`11` is not green, because `11² = 121` and `121` does not end with `11`.
`376` is green, because `376² = 141376` and `141376` ends with `376`.
Your task is to write a function `green` that returns `n`th green number, starting with `1` - `green (1) == 1`
---
## Data range
```if:haskell
`n <= 4000` for Haskell
```
```if:java
`n <= 5000` for Java
```
```if:python
`n <= 5000` for Python
```
```if:javascript
`n <= 3000` for JavaScript
Return values should be `String`s, and should be exact. A BigNum library is recommended.
```
# pre-generate list

GREENS = [0, 1, 5, 6]
a, b = GREENS[-2:]
base = 10

def is_green(n):
    return n*n % (base*10) == n

while len(GREENS) <= 5000:
    for x in range(base, base*10, base):
        a_, b_ = x + a, x + b
        if a < base and is_green(a_):
            GREENS.append(a_)
            a = a_
        if b < base and is_green(b_):
            GREENS.append(b_)
            b = b_
    base *= 10

def green(n):
    return GREENS[n]


# pre-generate list

GREENS = [0, 1, 5, 6]
a, b = GREENS[-2:]
base = 10

def is_green(n):
    return n*n % (base*10) == n

while len(GREENS) <= 5000:
    for x in range(base, base*10, base):
        a_, b_ = x + a, x + b
        if a < base and is_green(a_):
            GREENS.append(a_)
            a = a_
        if b < base and is_green(b_):
            GREENS.append(b_)
            b = b_
    base *= 10

def green(n):
    return GREENS[n]

