#include <stdio.h>
#include <malloc.h>
void read_from_file(int** V, int** M, int** P, int* n, char* file){
FILE *in = fopen(file, "r");
int i;
fscanf(in, "%d", n);
*V = (int *) malloc (*n * sizeof(int));
*M = (int *) malloc (*n * sizeof(int));
*P = (int *) malloc (*n * sizeof(int));
for(i = 0; i < *n; i++){
fscanf(in, "%d", (*V) + i);
}
}
int binary_search(int S, int E, int x, int V[]){
int m;
m = (S + E) / 2;
if(S <= E){
if(x == V[m]){
return m;
}else if(x > V[m]){
return binary_search(m + 1, E, x, V);
}else{
return binary_search(S, m - 1, x, V);
}
}
return S;
}
void construct_LIS(int M[], int P[], int V[], int n, int *smax){
int i;
int index_smax;
for (i = 0; i < n; i++){
index_smax = binary_search(0, *smax - 1, V[i], M);
M[index_smax] = V[i];
P[i] = index_smax;
if(index_smax >= *smax){
(*smax)++;
}
}
}
void print(int V[], int n, int smax){
FILE *out = fopen("scmax.out", "w");
fprintf(out, "%d\n", smax + 1);
int i ;
int lmax = smax;
int *sol = (int *) malloc ((smax + 1) * sizeof(int));
for(i = n - 1; i >= 0 && smax >= 0; i--){
if(V[i] == smax){
sol[smax] = i + 1;
smax--;
}
}
for(i = 0; i <= lmax; i++){
fprintf(out, "%d ", sol[i]);
}
}
int main(int argc, char* argv[]){
int *M, *P, *V;
int n;
int smax;
//read_from_file(&V, &M, &P, &n, argv[1]);
read_from_file(&V, &M, &P, &n, "scmax.in");
smax = 0;
M[0] = 0;
construct_LIS(M, P, V, n, &smax);
print(P, n, smax - 1);
return 0;
}