const MOD = 1_0000_0000_7 type ModInt = object v:int # 0~MODに収まる proc toModInt*(a:int) : ModInt = if a < -MOD : result.v = ((a mod MOD) + MOD) mod MOD elif a < 0 : result.v = a + MOD elif a >= MOD: result.v = a mod MOD else: result.v = a proc `+`*(a,b:ModInt) : ModInt = result.v = a.v + b.v if result.v >= MOD : result.v = result.v mod MOD proc `*`*(a,b:ModInt) : ModInt = result.v = a.v * b.v if result.v >= MOD : result.v = result.v mod MOD proc `^`*(a:ModInt,b:int) : ModInt = if a.v == 0 : return 0.toModInt() if b == 0 : return 1.toModInt() if b == 1 : return a if b > MOD: return a^(b mod (MOD-1)) # フェルマーの小定理 let pow = a^(b div 2) if b mod 2 == 0 : return pow * pow return pow * pow * a proc `+`*(a:int,b:ModInt) : ModInt = a.toModInt() + b proc `+`*(a:ModInt,b:int) : ModInt = a + b.toModInt() proc `-`*(a:ModInt,b:int) : ModInt = a + (-b) proc `-`*(a,b:ModInt) : ModInt = a + (-b.v) proc `-`*(a:int,b:ModInt) : ModInt = a.toModInt() + (-b.v) proc `*`*(a:int,b:ModInt) : ModInt = a.toModInt() * b proc `*`*(a:ModInt,b:int) : ModInt = a * b.toModInt() proc `/`*(a,b:ModInt) : ModInt = a * b^(MOD-2) proc `$`*(a:ModInt) : string = $a.v proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': return result = 10 * result + k.ord - '0'.ord let n = scan() if n >= MOD : quit "0" ,0 var ans = 1.toModInt() for i in 1..n: ans = ans * i echo ans