def factorial(n):
"""
Calculate the factorial of a non-negative integer n.
Parameters:
n (int): A non-negative integer whose factorial is to be calculated
Returns:
int: Factorial of the given number n
"""
if n < 0:
raise ValueError("Factorial is not defined for negative numbers")
elif n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
# Example usage:
# print(factorial(5)) # Output: 120
ZGVmIGZhY3RvcmlhbChuKToKICAgICIiIgogICAgQ2FsY3VsYXRlIHRoZSBmYWN0b3JpYWwgb2YgYSBub24tbmVnYXRpdmUgaW50ZWdlciBuLgoKICAgIFBhcmFtZXRlcnM6CiAgICBuIChpbnQpOiBBIG5vbi1uZWdhdGl2ZSBpbnRlZ2VyIHdob3NlIGZhY3RvcmlhbCBpcyB0byBiZSBjYWxjdWxhdGVkCgogICAgUmV0dXJuczoKICAgIGludDogRmFjdG9yaWFsIG9mIHRoZSBnaXZlbiBudW1iZXIgbgogICAgIiIiCiAgICBpZiBuIDwgMDoKICAgICAgICByYWlzZSBWYWx1ZUVycm9yKCJGYWN0b3JpYWwgaXMgbm90IGRlZmluZWQgZm9yIG5lZ2F0aXZlIG51bWJlcnMiKQogICAgZWxpZiBuID09IDAgb3IgbiA9PSAxOgogICAgICAgIHJldHVybiAxCiAgICBlbHNlOgogICAgICAgIHJldHVybiBuICogZmFjdG9yaWFsKG4gLSAxKQoKIyBFeGFtcGxlIHVzYWdlOgojIHByaW50KGZhY3RvcmlhbCg1KSkgICMgT3V0cHV0OiAxMjA=