## Story

Before we dive into the exercise, I would like to show you why these numbers are so important in computer programming today.

It all goes back to the time of 19th century. Where computers we know today were non-existing. The first ever **computer program** was for the Analytical Engine to compute **Bernoulli numbers**. A woman named Ada Lovelace wrote the very first program. The sad part is the engine was never fully build so her code was never tested. She also predicted the start of **AI** (artificial intelligence).

Computers will be able to compose music by themselves, solve problems (not only numbers) ... So in her honor reproduce what was done back in 1842. The Bernoulli numbers are a sequence of rational numbers with deep connections to number theory. The Swiss mathematician Jakob Bernoulli and the Japanese mathematician Seki Kowa discovered the numbers around the same time at the start of the 18th Century. If you want to read more about her or Bernoulli numbers follow these links:

https://en.wikipedia.org/wiki/Ada_Lovelace

https://en.wikipedia.org/wiki/Bernoulli_number

http://mathworld.wolfram.com/BernoulliNumber.html

## Exercise

Your job is to write a function `bernoulli_number(n)` which outputs the n-th Bernoulli number. The input will always be a non-negative integer so you do not need to worry about exceptions. How you will solve the problem is none of my business but here are some guidelines.  
You can make pascal triangle and then with the basic formula generate all Bernoulli numbers. Look example below.

For the sake of floating numbers, just use `Fractions` so there will be no problems with rounding.


0 = 1 + 2b1 ............................................................... 
  b1 = - 1/2

0 = 1 + 3b1 + 3b2 ...................................................    b2        = 1/6

0 = 1 + 4b1 + 6b2 + 4b3 .......................................  b3 = 0

0 = 1 + 5b1 + 10b2 + 10b3 + 5b4 ...................... b4 = - 1/30

... and so on.

```
bernoulli_number(0) # return 1
bernoulli_number(1) # return Fraction(-1,2) or Rational(-1,2) or "1/2"
bernoulli_number(6) # return Fraction(1,42) or ...
bernoulli_number(42) # return Fraction(1520097643918070802691,1806) or ...
bernoulli_number(22) # return Fraction(854513,138) or ... "854513/138"
```

## Note

See "Sample Tests" to see the return type for each language.

Good luck and happy coding! 

PS: be careful some numbers might exceed `1000`.
If this kata is too hard for you try to solve pascal triangle and something similar to this and then come back :).

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'from fractions import Fraction\n\ndef GetBinominal(Row, Column):\n    Solve = Fraction(1,1)\n    if (Column > Row - Column):\n        Column = Row - Column;\n\n    for i in range(Column):\n        Solve *= (Row - i)\n        Solve /= (i + 1)\n\n    return Solve;\n\ndef bernoulli_number(n):\n    if n == 0:\n        return 1\n    if n == 1:\n        return -0.5\n    if n % 2 != 0:\n        return 0   # all odds after n=1 are 0.\n\n    # Built list using this same function, to avoid crazy timeout issue with server ...\n    CachedList = [1, -0.5, Fraction(1, 6), 0, Fraction(-1, 30), 0, Fraction(1, 42), 0, Fraction(-1, 30), 0, Fraction(5, 66), 0,\n     Fraction(-691, 2730), 0, Fraction(7, 6), 0, Fraction(-3617, 510), 0, Fraction(43867, 798), 0,\n     Fraction(-174611, 330), 0, Fraction(854513, 138), 0, Fraction(-236364091, 2730), 0, Fraction(8553103, 6), 0,\n     Fraction(-23749461029, 870), 0, Fraction(8615841276005, 14322), 0, Fraction(-7709321041217, 510), 0,\n     Fraction(2577687858367, 6), 0, Fraction(-26315271553053477373, 1919190), 0, Fraction(2929993913841559, 6), 0,\n     Fraction(-261082718496449122051, 13530), 0, Fraction(1520097643918070802691, 1806), 0,\n     Fraction(-27833269579301024235023, 690), 0, Fraction(596451111593912163277961, 282), 0,\n     Fraction(-5609403368997817686249127547, 46410), 0, Fraction(495057205241079648212477525, 66), 0,\n     Fraction(-801165718135489957347924991853, 1590), 0, Fraction(29149963634884862421418123812691, 798), 0,\n     Fraction(-2479392929313226753685415739663229, 870), 0, Fraction(84483613348880041862046775994036021, 354), 0,\n     Fraction(-1215233140483755572040304994079820246041491, 56786730), 0,\n     Fraction(12300585434086858541953039857403386151, 6), 0, Fraction(-106783830147866529886385444979142647942017, 510),\n     0, Fraction(1472600022126335654051619428551932342241899101, 64722), 0,\n     Fraction(-78773130858718728141909149208474606244347001, 30), 0,\n     Fraction(1505381347333367003803076567377857208511438160235, 4686), 0,\n     Fraction(-5827954961669944110438277244641067365282488301844260429, 140100870), 0,\n     Fraction(34152417289221168014330073731472635186688307783087, 6), 0,\n     Fraction(-24655088825935372707687196040585199904365267828865801, 30), 0,\n     Fraction(414846365575400828295179035549542073492199375372400483487, 3318), 0,\n     Fraction(-4603784299479457646935574969019046849794257872751288919656867, 230010), 0,\n     Fraction(1677014149185145836823154509786269900207736027570253414881613, 498), 0,\n     Fraction(-2024576195935290360231131160111731009989917391198090877281083932477, 3404310), 0,\n     Fraction(660714619417678653573847847426261496277830686653388931761996983, 6), 0,\n     Fraction(-1311426488674017507995511424019311843345750275572028644296919890574047, 61410), 0,\n     Fraction(1179057279021082799884123351249215083775254949669647116231545215727922535, 272118), 0,\n     Fraction(-1295585948207537527989427828538576749659341483719435143023316326829946247, 1410), 0,\n     Fraction(1220813806579744469607301679413201203958508415202696621436215105284649447, 6), 0,\n     Fraction(-211600449597266513097597728109824233673043954389060234150638733420050668349987259, 4501770), 0,\n     Fraction(67908260672905495624051117546403605607342195728504487509073961249992947058239, 6), 0,\n     Fraction(-94598037819122125295227433069493721872702841533066936133385696204311395415197247711, 33330), 0,\n     Fraction(3204019410860907078243020782116241775491817197152717450679002501086861530836678158791, 4326), 0,\n     Fraction(-319533631363830011287103352796174274671189606078272738327103470162849568365549721224053, 1590), 0,\n     Fraction(36373903172617414408151820151593427169231298640581690038930816378281879873386202346572901, 642), 0,\n     Fraction(-3469342247847828789552088659323852541399766785760491146870005891371501266319724897592306597338057,\n              209191710), 0,\n     Fraction(7645992940484742892248134246724347500528752413412307906683593870759797606269585779977930217515, 1518), 0,\n     Fraction(-2650879602155099713352597214685162014443151499192509896451788427680966756514875515366781203552600109,\n              1671270), 0,\n     Fraction(21737832319369163333310761086652991475721156679090831360806110114933605484234593650904188618562649, 42),\n     0,\n     Fraction(-309553916571842976912513458033841416869004128064329844245504045721008957524571968271388199595754752259,\n              1770), 0,\n     Fraction(366963119969713111534947151585585006684606361080699204301059440676414485045806461889371776354517095799,\n              6), 0, Fraction(\n        -51507486535079109061843996857849983274095170353262675213092869167199297474922985358811329367077682677803282070131,\n        2328255930), 0, Fraction(\n        49633666079262581912532637475990757438722790311060139770309311793150683214100431329033113678098037968564431, 6),\n     0, Fraction(\n        -95876775334247128750774903107542444620578830013297336819553512729358593354435944413631943610268472689094609001,\n        30), 0, Fraction(\n        5556330281949274850616324408918951380525567307126747246796782304333594286400508981287241419934529638692081513802696639,\n        4357878), 0, Fraction(\n        -267754707742548082886954405585282394779291459592551740629978686063357792734863530145362663093519862048495908453718017,\n        510), 0, Fraction(\n        1928215175136130915645299522271596435307611010164728458783733020528548622403504078595174411693893882739334735142562418015,\n        8646), 0, Fraction(\n        -410951945846993378209020486523571938123258077870477502433469747962650070754704863812646392801863686694106805747335370312946831,\n        4206930), 0, Fraction(\n        264590171870717725633635737248879015151254525593168688411918554840667765591690540727987316391252434348664694639349484190167,\n        6), 0, Fraction(\n        -84290226343367405131287578060366193649336612397547435767189206912230442242628212786558235455817749737691517685781164837036649737,\n        4110), 0, Fraction(\n        2694866548990880936043851683724113040849078494664282483862150893060478501559546243423633375693325757795709438325907154973590288136429,\n        274386), 0, Fraction(\n        -3289490986435898803930699548851884006880537476931130981307467085162504802973618096693859598125274741604181467826651144393874696601946049,\n        679470), 0, Fraction(\n        14731853280888589565870080442453214239804217023990642676194878997407546061581643106569966189211748270209483494554402556608073385149191,\n        6), 0, Fraction(\n        -3050244698373607565035155836901726357405007104256566761884191852434851033744761276392695669329626855965183503295793517411526056244431024612640493,\n        2381714790), 0, Fraction(\n        4120570026280114871526113315907864026165545608808541153973817680034790262683524284855810008621905238290240143481403022987037271683989824863,\n        6), 0, Fraction(\n        -1691737145614018979865561095112166189607682852147301400816480675916957871178648433284821493606361235973346584667336181793937950344828557898347149,\n        4470), 0, Fraction(\n        463365579389162741443284425811806264982233725425295799852299807325379315501572305760030594769688296308375193913787703707693010224101613904227979066275,\n        2162622), 0, Fraction(\n        -3737018141155108502105892888491282165837489531488932951768507127182409731328472084456653639812530140212355374618917309552824925858430886313795805601,\n        30), 0, Fraction(\n        10259718682038021051027794238379184461025738652460569233992776489750881337506863808448685054322627708245455888249006715516690124228801409697850408284121,\n        138), 0, Fraction(\n        -81718086083262628510756459753673452313595710396116467582152090596092548699138346942995509488284650803976836337164670494733866559829768848363506624334818961419869,\n        1794590070), 0, Fraction(\n        171672676901153210072183083506103395137513922274029564150500135265308148197358551999205867870374013289728260984269623579880772408522396975250682773558018919,\n        6), 0, Fraction(\n        -4240860794203310376065563492361156949989398087086373214710625778458441940477839981850928830420029285687066701804645453159767402961229305942765784122421197736180867,\n        230010), 0, Fraction(\n        1584451495144416428390934243279426140836596476080786316960222380784239380974799880364363647978168634590418215854419793716549388865905348534375629928732008786233507729,\n        130074), 0, Fraction(\n        -20538064609143216265571979586692646837805331023148645068133372383930344948316600591203926388540940814833173322793804325084945094828524860626092013547281335356200073083,\n        2490), 0, Fraction(\n        5734032969370860921631095311392645731505222358555208498573088911303001784652122964703205752709194193095246308611264121678834250704468082648313788124754168671815815821441,\n        1002), 0, Fraction(\n        -13844828515176396081238346585063517228531109156984345249260453934317772754836791258987516540324983611569758649525983347408589045734176589270143058509026392246407576578281097477,\n        3404310), 0, Fraction(\n        195334207626637530414976779238462234481410337350988427215139995707346979124686918267688171536352650572535330369818176979951931477427594872783018749894699157917782460035894085,\n        66), 0, Fraction(\n        -11443702211333328447187179942991846613008046506032421731755258148665287832264931024781365962633301701773088470841621804328201008020129996955549467573217659587609679405537739509973,\n        5190), 0, Fraction(\n        4166161554662042831884959593250717297395614318182561412048180684077407803317591270831194619293832107482426945655143357909807251852859279483176373435697607639883085093246499347128331,\n        2478), 0, Fraction(\n        -1369347910486705707645621362512824332220360774476594348356938715366608044588614657557436131706543948464159947970464346070253278291989696390096800799614617317655510118710460076077638883999,\n        1043970), 0, Fraction(\n        1124251816617941290026484851206299982774720467712867275292043701618829826708395745459654170718363182143418314514085426692857018428614935412736063946853033094328968069656979232446257101741,\n        1074), 0, Fraction(\n        -6173136454016248924640522272263470960199559328290655337530202055853397791747341312347030141906500993752700612233695954532816018207721731818225290076670213481102834647254685911917265818955932383093313,\n        7225713885390), 0, Fraction(\n        4277269279349192541137304400628629348327468135828402291661683018622451659989595510712915810436238721139546963558655260384328988773219688091443529626531335687951612545946030357929306651006711,\n        6), 0, Fraction(\n        -857321333523056180131194437347933216431403305730705359015465649285681432317514010686029079324479659634642384809061711319481020030715989009140595170556956196762318625529645723516532076273012244047,\n        1410), 0, Fraction(\n        22258646098436968050639602221816385181596567918515338169946670500599612225742487595012775838387331550474751212260636163500086787417640903770807353228157478339547041472679880890292167353534100797481,\n        42), 0, Fraction(\n        -14158277750623758793309386870401397333112823632717478051426522029712001260747920789473711562165031101665618225654329210473605281619696918061316240634857984019071572591940586875558943580878119388321001,\n        30), 0, Fraction(\n        5411555842544259796131885546196787277987837486638756184149141588783989774511509608733429067517383750706299486822702171672522203106730993581242777825864203487238429479957280273093904025319950569633979493395,\n        12606), 0, Fraction(\n        -346465752997582699690191405750952366871923192340955593486485715370392154894102000406980162521728492501917598012711402163530166516991115122131398542029056286959857727373568402417020319761912636411646719477318166587,\n        868841610), 0, Fraction(\n        2269186825161532962833665086968359967389321429297588337232986752409765414223476696863199759981611817660735753831323900456495253961837175924312108872915089534970310604331636484174526399721365966337809334021247,\n        6), 0, Fraction(\n        -62753135110461193672553106699893713603153054153311895305590639107017824640241378480484625554578576142115835788960865534532214560982925549798683762705231316611716668749347221458005671217067357943416524984438771831113,\n        171390), 0, Fraction(\n        88527914861348004968400581010530565220544526400339548429439843908721196349579494069282285662653465989920237253162555666526385826449862863083834096823053048072002986184254693991336699593468906111158296442729034119206322233,\n        244713882), 0]\n\n    if n<len(CachedList):\n        return CachedList[n]\n    #if n > 2:  #to debug daft timeout\n    #    print(n)\n    #    return 1\n\n    BernoulliNumbers = [Fraction(1,1), Fraction(1,2)]\n    Solution = Fraction(1,1)\n\n    for i in range(2,n+1):\n        for j in range(i):\n            if j < 3 or j % 2 == 0:\n                Solution -= GetBinominal(i,j)*(Fraction(BernoulliNumbers[j],(i-j+1)))\n\n        BernoulliNumbers.append(Solution)\n        Solution=Fraction(1,1)\n\n    return BernoulliNumbers[n]'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'bernoulli_number'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 9338