//Write funciton which takes in string and returns counts of each char. in the string
// 1 문제 분석
// get string return count of string char
// 2 간단한 예제
charCount("aaaa") // --> 4
charCount("ttttt") // --> 5 
//좀 더 복잡한 예제
charCount("Take new letter 123")
/*
count chars
1: 1,
2: 1,
3: 1,
a: 1,
e: 3,
k: 1
...
*/
//Psudocode 구현
function charCount(str){
// make object to return at end
// loop string for each char.
    // if char is a number/letter AND is a key in object, add one to count
    // if char is a number/letter AND not in object, add it and set value to 1
    // if char is sth else (space, period, etc...) X execute
// return object at end
}
// 3 문제 해결 / 아직 어려우면 문제를 나눠서 좀 더 쉽고 단순한 부분을 해결하기 
function charCount(str){
// make object to return at end
  var result = {};
// loop string for each char.
  for(var i = 0; i < str.length; i++){
    var char = str[i].toLowerCase(); // toLowerCase()는 나중에 추가함. 
    if(result[char] > 0){
    // if char is a number/letter AND is a key in object, add one to count
      result[char]++;
    }else{
    // if char is a number/letter AND not in object, add it and set value to 1
      result[char] = 1;
    }
  }
  return result;
}
    // if char is sth else (space, period, etc... non-alphanumeric) X execute
// return object at end
}
// 4 리펙토링
function charCount(str){
  var obj = {};
  for(var i=0; str.length; i++){
    var char = str[i].toLowerCase();
    if( /[a-z0-9/.test(char) ){
      if(obj[char] > 0){
        obj[char]++;
      }else{
        obj[char] = 1;
      }
    };
  };
  return obj;
}
/*
추가적인 리펙터
직관성을 위해서 코드 수정. 
*/
  for(var i=0; str.length; i++)
   -->
  for(var char of str){
     char = char.toLowerCase()
     if( /[a-z0-9/.test(char) ){
       obj[char] = ++obj[char] || 1;
     }
  }
// regex -> must check performance issue depending on browser.
// 최종 결과물
function isAlphaNumeric(char){
	var code = char.charCodeAt(0);
  if(!(code > 47 && code < 58) && //0-9
     !(code > 64 && code < 91) && //A-Z
     !(code > 96 && code < 123)) { //a-z
    return false;
  }
  return true;
}
function charCount(str){
  var obj = {};
  for(var char of str){
    if( isAlphaNumeric(char)){
      char = char.toLowerCase();
      obj[char] = ++obj[char] || 1;
    };
  };
  return obj;
};

//3,6,9 게임 
import java.io.*;
class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Integer input = Integer.parseInt(br.readLine());
		// 유효성
		if(input < 1){
			return;
		}
		//1 N 횟수 입력을 받으면 횟수만큼 루프를 돌기
		int count = 0;
		int result = 0;
		String chkNum = "";
		for(int i=1; i<input; i++){
			chkNum = String.valueOf(i);
			for( int j=0; j<chkNum.length() ; j++ ){
				//*** 방법 1 
				/*
				result = Character.getNumericValue(chkNum.charAt(j));
				if( result%3==0 || result%6==0 || result%9==0 ){
				  count++;
				}
				if( result==0 ){ // 10,20,30 등에서 
					System.out.println("result "+result);
					count--;
				}
				*/
				// *** 방법 2	
				result = chkNum.charAt(j);
				if( result == '3' || result == '6' || result == '9' ){
					count++;
			  }			
			}
		}//end
		//4 count한 만큼 출력- 짝 횟수
		System.out.println(count);
  }//end
}
/*
//1 
369 게임 규칙
- 3, 6, 9 짝
&&
- 3, 6, 9 가 들어가면 들어간 횟수 만큼 짝
예)
1
2
3 짝 
33 짝짝 
36 짝짝
//2
N = 게임 횟수 
result  = 값 체크 변수  
count = 짝 횟수 담기 
//
1 N 횟수 입력을 받으면 횟수만큼 루프를 돌기
2 각 횟수를 세고 3,6,9의 배수면 짝을 clap에 담고 
3 3,6,9가 포함되도 clap에 담기 
4 clap에 담긴만큼 print 짝 횟수 
*/
https://www.indeed.com/career-advice/career-development/inductive-vs-deductive-reasoning