#include<bits/stdc++.h> #define int long long #define piii pair<int,pair<int,int> > #define sum first #define first_num second.first #define last_num second.second #define out(s,f,l) make_pair(s,make_pair(f,l)) usingnamespace std;
queue<int> in; char S[100006];
piii get_dis(){ int dis=0, last = in.front(), _first = in.front(); while(in.front()!=-1){ int cur = in.front(); in.pop(); if(cur >= 10) dis+=abs(cur-last), last=cur; else{ int time=cur; piii inside=get_dis(); dis+=time*inside.sum+(time-1)*abs(inside.first_num-inside.last_num); if(_first<10) _first=inside.first_num; else dis+=abs(last-inside.first_num); last = inside.last_num; } }in.pop(); returnout(dis, _first, last); }