Warning: session_start(): open(/tmp/sess_1a9912b2e339fbfa0beaa36a74728140, O_RDWR) failed: No space left on device (28) in /data/wiki/inc/init.php on line 239
Warning: session_start(): Failed to read session data: files (path: ) in /data/wiki/inc/init.php on line 239
Warning: Cannot modify header information - headers already sent by (output started at /data/wiki/inc/init.php:239) in /data/wiki/inc/auth.php on line 430
Writing /data/wiki/data/cache/4/43994124a9168f34c03db2ff7cd35d94.captchaip failed
Warning: Cannot modify header information - headers already sent by (output started at /data/wiki/inc/init.php:239) in /data/wiki/inc/Action/Export.php on line 103
Warning: Cannot modify header information - headers already sent by (output started at /data/wiki/inc/init.php:239) in /data/wiki/inc/Action/Export.php on line 103
Warning: Cannot modify header information - headers already sent by (output started at /data/wiki/inc/init.php:239) in /data/wiki/inc/Action/Export.php on line 103
#include
#include
#include
#include
#define N 1000005
using namespace std;
typedef long long LL;
char s[N];
int dp[N][2];
int main()
{
scanf("%s",s+1);
dp[0][1]=1;
for(int i=1;s[i];i++)
{
int d=s[i]-'0';
dp[i][0]=min(dp[i-1][0]+d,dp[i-1][1]+10-d);
dp[i][1]=min(dp[i-1][0]+d+1,dp[i-1][1]+9-d);
if(d==9)dp[i][1]=dp[i-1][1];
}
printf("%d\n",dp[strlen(s+1)][0]);
return 0;
}