Language: C++

ll power(int k, int n){
  if (n==0){
    return 1;
  }
  else{
    return power(k, n-1)*n;
  }
}

ll num_layers(int n){
  return power(2, n+2)-3;
}

ll num_patties(int n){
  return power(2, n+1)-1;
}

int position(int n, int x){
  if(x<=num_layers(n-1)+1){
    return x-1;
  }
  else if(x<=num_layers(n)-1){
    return x-num_layers(n-1)-2;
  }
  else{
    return -1;
  }
}

int main(){
  int N;cin >>N;
  ll X;cin>>X;
  ll x[N+1];
  x[N]=X;
  for (int n=N;n>0;n--){
    if(x[n]>=0){
      x[n-1]=position(n, x[n]);
    }
    else{
      x[n-1]=-1;
    }
  }
  
  ll dp[N+1];
  if (x[0]<=0){
    dp[0]=0;
  }
  else{
    dp[0]=1;
  }
  
  for (int n=1;n<=N;n++){
    if(x[n]<=num_layers(n-1)+1){
      dp[n]=dp[n-1];
    }
    else if(x[n]==num_layers(n-1)+2){
      dp[n]=num_patties(n-1)+1;
    }
    else if(x[n]<=num_layers(n)-1){
      dp[n]=num_patties(n-1)+1+dp[n-1];
      }
    else if (x[n]==num_layers(n)){
      dp[n]=num_patties(n);
    }
    else{
      dp[n]=-1;
    }
    
  }
  cout << dp[N];
  return 0;
}


Compiler output:
a.cc:1:1: error: 'll' does not name a type
    1 | ll power(int k, int n){
      | ^~
a.cc:10:1: error: 'll' does not name a type
   10 | ll num_layers(int n){
      | ^~
a.cc:14:1: error: 'll' does not name a type
   14 | ll num_patties(int n){
      | ^~
a.cc: In function 'int position(int, int)':
a.cc:19:9: error: 'num_layers' was not declared in this scope
   19 |   if(x<=num_layers(n-1)+1){
      |         ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:31:9: error: 'cin' was not declared in this scope
   31 |   int N;cin >>N;
      |         ^~~
a.cc:32:3: error: 'll' was not declared in this scope
   32 |   ll X;cin>>X;
      |   ^~
a.cc:32:13: error: 'X' was not declared in this scope
   32 |   ll X;cin>>X;
      |             ^
a.cc:33:5: error: expected ';' before 'x'
   33 |   ll x[N+1];
      |     ^~
      |     ;
a.cc:34:3: error: 'x' was not declared in this scope
   34 |   x[N]=X;
      |   ^
a.cc:44:5: error: expected ';' before 'dp'
   44 |   ll dp[N+1];
      |     ^~~
      |     ;
a.cc:46:5: error: 'dp' was not declared in this scope
   46 |     dp[0]=0;
      |     ^~
a.cc:49:5: error: 'dp' was not declared in this scope
   49 |     dp[0]=1;
      |     ^~
a.cc:53:14: error: 'num_layers' was not declared in this scope
   53 |     if(x[n]<=num_layers(n-1)+1){
      |              ^~~~~~~~~~
a.cc:54:7: error: 'dp' was not declared in this scope
   54 |       dp[n]=dp[n-1];
      |       ^~
a.cc:57:7: error: 'dp' was not declared in this scope
   57 |       dp[n]=num_patties(n-1)+1;
      |       ^~
a.cc:57:13: error: 'num_patties' was not declared in this scope
   57 |       dp[n]=num_patties(n-1)+1;
      |             ^~~~~~~~~~~
a.cc:60:7: error: 'dp' was not declared in this scope
   60 |       dp[n]=num_patties(n-1)+1+dp[n-1];
      |       ^~
a.cc:60:13: error: 'num_patties' was not declared in this scope
   60 |       dp[n]=num_patties(n-1)+1+dp[n-1];
      |             ^~~~~~~~~~~
a.cc:63:7: error: 'dp' was not declared in this scope
   63 |       dp[n]=num_patties(n);
      |       ^~
a.cc:63:13: error: 'num_patties' was not declared in this scope
   63 |       dp[n]=num_patties(n);
      |             ^~~~~~~~~~~
a.cc:66:7: error: 'dp' was not declared in this scope
   66 |       dp[n]=-1;
      |       ^~
a.cc:70:3: error: 'cout' was not declared in this scope
   70 |   cout << dp[N];
      |   ^~~~
a.cc:70:11: error: 'dp' was not declared in this scope
   70 |   cout << dp[N];
      |           ^~