import sys
import re
def exgcd(a, b):
if b == 0:
return (a, 1, 0)
else:
g, x1, y1 = exgcd(b, a % b)
g, x, y = g, y1, x1 - (a // b) * y1
return (g, x, y)
def inv(a, m):
g, x, y = exgcd(a, m)
if g != 1:
return Noneelse:
return x % m
def tdiv(a, b):
if a * b >= 0:
return a // b
else:
return -(-a // b)
def tmod(a, b):
return a - tdiv(a, b) * b
def cpow(base, exp, mod):
mabs = abs(mod)
if mabs == 1:
return 0if exp < 0:
base = base % mabs
if base < 0:
base += mabs
if base == 0:
return 0
inv = inv(base, mabs)
if inv is None:
return 0
base = inv
exp = -exp
base = base % mabs
res = 1while exp:
if exp & 1:
res = (res * base) % mabs
base = (base * base) % mabs
exp //= 2if base < 0:
res = -res
if res < 0:
res += mabs
if mod < 0 and base < 0:
res = -res
return res
def calc(s: str) -> int:
s = s[:-2]
if '!' in s:
if s == '0!':
n = 0elif s == '0!+1!':
n = 1else:
m = re.fullmatch(r'0!\+\.\.\. \.\.\.\+?(\d+)!', s)
if m:
n = int(m.group(1))
else:
return 0
total = 0
fact = 1
total += fact
for i in range(1, n + 1):
fact *= i
total += fact
return total
if '^' in s and '%' in s:
a, b, c = map(int, re.fullmatch(r'([+-]?\d+)\^([+-]?\d+)%([+-]?\d+)', s).groups())
return cpow(a, b, c)
if '<<' in s or '>>' in s:
a, op, b = re.fullmatch(r'([+-]?\d+)(<<|>>)([+-]?\d+)', s).groups()
a, b = int(a), int(b)
return a << b if op == '<<' else a >> b
m = re.fullmatch(r'([+-]?\d+)([+\-*/%&|^])([+-]?\d+)', s)
a, op, b = m.groups()
a, b = int(a), int(b)
if op == '+': return a + b
if op == '-': return a - b
if op == '*': return a * b
if op == '/': return tdiv(a, b)
if op == '%': return tmod(a, b)
if op == '&': return a & b
if op == '|': return a | b
if op == '^': return a ^ b
for i in range(12):
line = sys.stdin.readline().strip()
result = str(calc(line))
if i < 11:
sys.stdout.write(result + ',\n')
else:
sys.stdout.write(result + '.')