console.log((args=>{
  const [N,...s] = args.trim().split`\n`.map(v=>v|0);
  const dp = Array.from({length:N+1},_=>Array(10).fill(-Infinity));
  dp[0][0] = 0;
  for ( let i = 0; i < N; i++ ) {
    for ( let j = 0; j < 10; j++ ) {
      const d = (j+s[i]) % 10;
      dp[i+1][d] = Math.max( dp[i][d], dp[i][j] + s[i] );
    }
  }
  dp[N][0] = 0;
  return `${Math.max(...dp[N])}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
