Exact rings and semirings