import java.util.Stack;
class Solution {
public int solution(int n) {
int answer = 0;
Stack<Integer> stack = new Stack<>();
while(n!=0){
stack.push(n % 3);
n /= 3;
}
int pow = 0;
while(!stack.empty()){
answer += stack.pop() * Math.pow(3,pow);
pow++;
}
return answer;
}
}