func_code_string: #include <bits/stdc++.h>   template <typename Tp>   void in(Tp &x) {     char ch = getchar(), f = 1;     x = 0;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) f = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   template <typename Tp>   bool chkmax(Tp &x, Tp y) {     return x >= y ? 0 : (x = y, 1);   }   template <typename Tp>   bool chkmin(Tp &x, Tp y) {     return x <= y ? 0 : (x = y, 1);   }   template <typename Tp>   Tp Max(const Tp &x, const Tp &y) {     return x > y ? x : y;   }   template <typename Tp>   Tp Min(const Tp &x, const Tp &y) {     return x < y ? x : y;   }   const int MAXN = 400010;   int n;   int s[MAXN], g[MAXN];   int head[MAXN], nxt[MAXN << 1], data[MAXN << 1], flow[MAXN << 1], cnt;   void add(int x, int y, int z) {     nxt[cnt] = head[x];     data[cnt] = y;     flow[cnt] = z;     head[x] = cnt++;   }   using std::queue;   queue<int> q;   bool instack[MAXN];   long long dis[MAXN];   void spfa() {     memset(dis, 0x3f, sizeof dis);     dis[0] = 0;     instack[0] = true;     q.push(0);     while (!q.empty()) {       int now = q.front();       q.pop();       instack[now] = false;       for (int i = head[now]; i != -1; i = nxt[i]) {         if (dis[data[i]] > dis[now] + flow[i]) {           dis[data[i]] = dis[now] + flow[i];           if (!instack[data[i]]) {             q.push(data[i]);             instack[data[i]] = true;           }         }       }     }     long long ans1 = 0;     for (int i = (1), i_END_ = (n); i <= i_END_; ++i) {       ans1 += dis[i];       if (dis[i] < 0) {         puts( -1 );         return;       }     }     printf( %I64d n , ans1);     for (int i = (1), i_END_ = (n); i <= i_END_; ++i)       printf( %I64d  , dis[i] + s[i]);     putchar(10);   }   int main() {     in(n);     for (int i = (1), i_END_ = (n); i <= i_END_; ++i) in(s[i]), in(g[i]);     memset(head, -1, sizeof head);     for (int i = (1), i_END_ = (n); i <= i_END_; ++i) add(0, i, g[i]);     for (int i = (1), i_END_ = (n - 1); i <= i_END_; ++i) {       int t = s[i] - s[i + 1];       add(i, i + 1, 1 + t);       add(i + 1, i, 1 - t);     }     spfa();     return 0;   }   