题目地址:http://vjudge.net/problem/UVA-11054
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=(int)(b);++i)
#define REPD(i,a,b) for(int i=a;i>=(int)(b);--i)
typedef long long LL;
int main(int argc, char const *argv[])
{LL n;while(scanf("%lld",&n)==1&&n){LL x,ans=0,now=0;REP(i,1,n){scanf("%lld",&x);ans+=abs(now);now+=x;}printf("%lld\n", ans);}return 0;
}