//process.stdin.resume(); //process.stdin.setEncoding('utf8'); 💩 = function(val){ this.obj = new Array(40); this.head = 0; for(var i=0; i<40; i++){ this.obj[i] = val%10; if(this.obj[i]>0){ this.head = i; } val = Math.floor(val/10); } }; 💩.prototype.add = function(y) { var carry = 0; this.head = 0; for(var i=0; i<40; i++){ var tmp = this.obj[i] + y.obj[i] + carry; carry = Math.floor(tmp/10); this.obj[i] = tmp%10; if(this.obj[i]>0){ this.head = i; } } }; 💩.prototype.sub = function(y) { var carry = 0; this.head = 0; for(var i=0; i<40; i++){ var tmp = this.obj[i] - y.obj[i] + carry; carry = 0; if(tmp<0){ tmp += 10; carry = -1; } this.obj[i] = tmp; if(this.obj[i]>0){ this.head = i; } } }; 💩.prototype.toString = function() { var ret = ""; for(var i=this.head; i>=0; i--){ ret += this.obj[i].toString(); } return ret; }; function calc(x){ var dp = new Array(2); for(var i=0; i<2; i++){ dp[i] = new Array(2); for( var j=0; j<2; j++){ dp[i][j] = new Array(3); for(var k=0; k<3; k++){ //dp[i][j][k] = 0; dp[i][j][k] = new 💩(0); } } } dp[0][0][0] = new 💩(2); var ret = new 💩(0); var u = 0; var v = 1; var sz = x.length; for(var i=0; id){ j_ = 1; } var k_ = (k+d)%3; //dp[v][j_][k_] += dp[u][j][k]; dp[v][j_][k_].add(dp[u][j][k]); if(i===sz-1 && d%5===0){ //ret += dp[u][j][k]; ret.add(dp[u][j][k]); } if(i===sz-1 && k_===0){ //ret += dp[u][j][k]; ret.add(dp[u][j][k]); } } } } var tmp = u; u = v; v = tmp; } ret.sub(new 💩(4)); return ret; } function Main(input) { // inputにはすべての入力の文字列が与えられるので必要に応じて input.split("\n") などで分割する。 var data = input.split("\n"); var ans = calc(data[0]); console.log(ans.toString()); } // Don't edit this line! Main(require("fs").readFileSync("/dev/stdin", "utf8")); //Main("98765432123456789\n");