#!/usr/bin/env python3 import sys def expand(dense): fs = [] for i in range(len(dense)): if i % 2 == 0: for j in range(int(dense[i])): fs.append(i // 2) else: for j in range(int(dense[i])): fs.append(None) return fs def pprint(fs): for c in fs: if c is not None: print(c, end="") else: print(".", end="") print("") def compact(fs): comp = [c for c in fs] l = 0 r = len(fs) - 1 while l < r: while comp[l] is not None: l += 1 while comp[r] is None: r -= 1 if l < r: comp[l] = comp[r] comp[r] = None l += 1 r -= 1 return comp def chksum(fs): tot = 0 for i in range(len(fs)): if fs[i] is None: break tot += fs[i] * i return tot if __name__ == '__main__': dense = next(sys.stdin).strip() fs = expand(dense) comp = compact(fs) #pprint(fs) #pprint(compact(fs)) print(chksum(comp))