The contestant and the incumbent are responsible for the expenses of the witnesses called by them, respectively. If the results of the election are upheld by the contest, if the statement is dismissed, or if the prosecution fails, the costs of the contest shall be paid by the contestant. If the court or tribunal trying the contest determines that the contestant won the election, or if the election is set aside, the costs of the contest shall be paid by the county.