import sys inputs=[] for line in sys.stdin: if line.strip()=='': break else: inputs.append(line.strip()) A=inputs[0].strip().split(',') #print(A) a=[] for aa in A: a.append(int(aa)) a=sorted(a) add=[] while(len(set(a))!=len(a)): # print(a,set(a)) for i in range(len(a)-1): if a[i]==a[i+1]: for j in range(40000): if a[i]+j not in a: a[i]=a[i]+j add.append(j) break break a=sorted(a) #print(a) print(sum(add))