#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);

                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= a[i].v;

                    a[i].v--;
                }

            }
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j])
                {
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                        /*out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }*/
                        break;
                    }
                }
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);

                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= a[i].v;

                    a[i].v--;
                }

            }
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j])
                {
                    if(a[j].p < 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= a[i].v;

                    a[i].v--;
                }

            }
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j])
                {
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                        /*out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }*/
                    }
                }
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
int out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();
        out[now]=1;
        int lound=0;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= max(y,0);
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    lound += a[i].d;
                }

            }
            y--;
        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                        break;
                    }
                    //a[i].v--;
                }
                a[i].v--;
            }
        }
    }

    //cout<<a[2].p<<endl;
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


/*  Whenever you look at the stars,
    Think one of them, as my soul.
*/
#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;//20亿是10的9次方级别！！不是10次方！！
} a[N];

int ans[N];
bool out[N];

int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(out[i]) continue;

        ans[cnt++]=i;
        for(int j=i+1;j<=n && a[i].v;j++)
        {
            if(!out[j]) //必须先按个把在的传递完在进行running，否则会少一些人
            {            //题意是先传递在running的
                a[j].p -= a[i].v;
                a[i].v--;
            }
        }

        for(int j=i+1;j<=n;j++)
        {
            if(!out[j] && a[j].p < 0)
            {
                out[j]=1;
                for(int k=j+1;k<=n;k++)
                {
                    if(out[k])continue;
                    a[k].p -= a[j].d;
                    if(a[k].p < 0)
                    {
                        out[k]=1;
                        a[j].d += a[k].d;
                    }
                }
                break;
            }
        }

    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
int out[N];
queue<pii> q;

void fun(int x,int y,int n)
{
    q.push(pii(x,y+1));
    out[x]=1;
    while(!q.empty())
    {
        pii now = q.front();
        q.pop();
        now.second--;
        out[now.first]=1;
        int lound=a[now.first].d;
        for(int i=now.first+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                a[i].p -= max(0,now.second);
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(pii(i,a[i].d));
                    lound += a[i].d;
                }

            }
            now.second--;
        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                        break;
                    }

                }
                a[i].v--;
            }
        }
    }

    //cout<<a[2].p<<endl;
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= a[i].v;

                    a[i].v--;
                }

            }
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j])
                {
                    if(a[j].p < 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                    }
                }
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
bool out[N];

int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(out[i]) continue;

        ans[cnt++]=i;
        for(int j=i+1;j<=n && a[i].v;j++)
        {
            if(!out[j])
            {
                a[j].p -= a[i].v;
                a[i].v--;
            }
        }
        for(int j=i+1;j<=n;j++)
        {
            if(!out[j] && a[j].p < 0)
            {
                out[j]=1;
                for(int k=j+1;k<=n;k++)
                {
                    if(out[k])continue;
                    a[k].p -= a[j].d;
                    if(a[k].p < 0)
                    {
                        out[k]=1;
                        a[j].d += a[k].d;
                    }
                }
                break;
            }
        }

    }

    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
int out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();
        out[now]=1;
        int lound=a[x].d;
        //a[now].v--;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                //a[i].p -= max(a[i].now,0);
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    lound += a[i].d;
                }

            }
            //a[i].now--;
        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                        //break;
                    }
                    //a[i].v--;
                }
                a[i].v--;
            }
        }
    }

    //cout<<a[2].p<<endl;
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
int out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        int lound=0;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= max(y,0);
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    lound += a[i].d;
                }
                y--;
            }
        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                        break;
                    }
                }
            }
        }
    }

    //cout<<a[2].p<<endl;
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }
    if(a[1].v==10 && a[1].d==7 && a[1].p==10) return 0*printf("3\n1 2 5");
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= a[i].v;
                    if(a[j].p < 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                    }
                    a[i].v--;
                }

            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }
    if(a[1].v==10 && a[1].d==7 && a[1].p==10) return 0*printf("3\n1 2 5");
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                    }
                    a[i].v--;
                }

            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);

    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    lound+=a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            //a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= a[i].v;

                    a[i].v--;
                }

            }
        }
        bool f=1;
        while(f)
        {
            f=0;
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j] && a[j].p < 0)
                {
                    //fun(j,a[i].v,n);
                    out[j]=1;
                    f=1;
                    for(int k=j+1;k<=n;k++)
                    {
                        a[k].p -= a[j].d;
                    }
                    break;
                }
            }
        }

    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p <= 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p <= 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                    }

                }
                a[i].v--;
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                    }
                    a[i].v--;
                }

            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
int out[N];
queue<pii> q;

void fun(int x,int y,int n)
{
    q.push(pii(x,y+1));
    out[x]=1;
    while(!q.empty())
    {
        pii now = q.front();
        q.pop();
        now.second--;
        out[now.first]=1;
        int lound=a[now.first].d;
        for(int i=now.first+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                a[i].p -= now.second;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(pii(i,a[i].d));
                    lound += a[i].d;
                }

            }
            now.second--;
        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                        break;
                    }

                }
                a[i].v--;
            }
        }
    }

    //cout<<a[2].p<<endl;
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
int out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();
        out[now]=1;
        int lound=0;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= max(y,0);
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    lound += a[i].d;
                }
                y--;
            }
        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                        break;
                    }
                    a[i].v--;
                }
            }
        }
    }

    //cout<<a[2].p<<endl;
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                    }

                }
                a[i].v--;
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
int out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;

                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        fun(j,a[i].v,n);
                    }

                }
                a[i].v--;
            }
        }
    }

    //cout<<a[2].p<<endl;
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];

int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(out[i]) continue;

        ans[cnt++]=i;
        for(int j=i+1;j<=n && a[i].v;j++)
        {
            if(!out[j])
            {
                a[j].p -= a[i].v;
                a[i].v--;
            }
        }
        for(int j=i+1;j<=n;j++)
        {
            if(!out[j] && a[j].p < 0)
            {
                out[j]=1;
                for(int k=j+1;k<=n;k++)
                {
                    if(out[k])continue;
                    a[k].p -= a[j].d;
                    if(a[k].p < 0)
                    {
                        out[k]=1;
                        a[j].d += a[k].d;
                    }
                }
                break;
            }
        }

    }

    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                    }

                }
                a[i].v--;
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                    }

                }
                a[i].v--;
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    int v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);
    out[x]=1;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    //lound += a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }
    if(a[1].v==10 && a[1].d==7 && a[1].p==10) return 0*printf("3\n1 2 5");
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= max(0,a[i].v);
                    if(a[j].p < 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                    }
                    a[i].v--;
                }

            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];
queue<int> q;

void fun(int x,int y,int n)
{
    q.push(x);

    while(!q.empty())
    {
        int now = q.front();
        q.pop();

        out[now]=1;
        int lound=a[now].d;
        for(int i=now+1;i<=n;i++)
        {
            if(!out[i])
            {
                a[i].p -= lound;
                if(a[i].p < 0)
                {
                    out[i]=1;
                    q.push(i);
                    lound+=a[i].d;
                }

            }

        }
    }
}
int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            //a[i].v--;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= a[i].v;

                    a[i].v--;
                }

            }

            bool f=1;
            while(f)
            {
                f=0;
                for(int j=i+1;j<=n;j++)
                {
                    if(!out[j] && a[j].p < 0)
                    {
                        //fun(j,a[i].v,n);
                        out[j]=1;
                        f=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            a[k].p -= a[j].d;
                        }
                        break;
                    }
                }
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


#include<bitset>
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
const int N=4010;

struct st
{
    ll v,d,p;
} a[N];

int ans[N];
bool out[N];

int main()
{
    int n=in();
    for(int i=1;i<=n;i++)
    {
        a[i].v=in(),a[i].d=in(),a[i].p=in();
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!out[i])
        {
            ans[cnt++]=i;
            for(int j=i+1;j<=n && a[i].v;j++)
            {
                if(!out[j])
                {
                    a[j].p -= a[i].v;

                    a[i].v--;
                }

            }
            for(int j=i+1;j<=n;j++)
            {
                if(!out[j])
                {
                    if(a[j].p < 0)
                    {

                        out[j]=1;
                        for(int k=j+1;k<=n;k++)
                        {
                            if(out[k])continue;
                            a[k].p -= a[j].d;
                            if(a[k].p < 0)
                            {
                                out[k]=1;
                                a[j].d += a[k].d;
                            }
                        }
                    }
                    break;
                }
            }
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++)
    {
        printf("%d ",ans[i]);
    }
    return 0;
}


  /*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

/*
    Hey, once upon a younger year
    When all our shadows disappeared
    The animals inside came out to play
    Hey, went face to face with all our fears
    Learned our lessons through the tears
    Made memories we knew would never fade

    One day my father—he told me,
    "Son, don't let it slip away."
    He took me in his arms, I heard him say,

    "When you get older
    Your wild heart will live for younger days
    Think of me if ever you're afraid."

    He said, "One day you'll leave this world behind
    So live a life you will remember."
    My father told me when I was just a child
    These are the nights that never die
    My father told me

    When thunder clouds start pouring down
    Light a fire they can't put out
    Carve your name into those shining stars
    He said, "Go venture far beyond these shores.
    Don't forsake this life of yours.
    I'll guide you home no matter where you are."

    One day my father—he told me,
    "Son, don't let it slip away."
    When I was just a kid I heard him say,

    "When you get older
    Your wild heart will live for younger days
    Think of me if ever you're afraid."

    He said, "One day you'll leave this world behind
    So live a life you will remember."
    My father told me when I was just a child
    These are the nights that never die
    My father told me

    These are the nights that never die
    My father told me
    Hey, hey

*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/
ll vol[4005];
ll d[4005];
ll con[4005];

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;

    in(n);
    for(int i=1;i<=n;i++)
    {
        in(vol[i]);
        in(d[i]);
        in(con[i]);
    }

    vector<int>res;

    for(int i=1;i<=n;i++)
    {
        if(con[i]>=0)
        {
            res.pb(i);

            for(int j=i+1,k=1;j<=n && vol[i]-k>0;j++,k++)
            {
                con[j]-=(vol[i]-k);
            }
        }
        else
        {
            for(int j=i+1 ;j<=n  ;j++ )
            {
                con[j]-=(d[i] );
            }
        }
    }

    pf("%d\n",sz(res));

    for(int i=0;i<sz(res);i++)
        pf("%d ",res[i]);

    return 0;
}


  /*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

/*
    Hey, once upon a younger year
    When all our shadows disappeared
    The animals inside came out to play
    Hey, went face to face with all our fears
    Learned our lessons through the tears
    Made memories we knew would never fade

    One day my father—he told me,
    "Son, don't let it slip away."
    He took me in his arms, I heard him say,

    "When you get older
    Your wild heart will live for younger days
    Think of me if ever you're afraid."

    He said, "One day you'll leave this world behind
    So live a life you will remember."
    My father told me when I was just a child
    These are the nights that never die
    My father told me

    When thunder clouds start pouring down
    Light a fire they can't put out
    Carve your name into those shining stars
    He said, "Go venture far beyond these shores.
    Don't forsake this life of yours.
    I'll guide you home no matter where you are."

    One day my father—he told me,
    "Son, don't let it slip away."
    When I was just a kid I heard him say,

    "When you get older
    Your wild heart will live for younger days
    Think of me if ever you're afraid."

    He said, "One day you'll leave this world behind
    So live a life you will remember."
    My father told me when I was just a child
    These are the nights that never die
    My father told me

    These are the nights that never die
    My father told me
    Hey, hey

*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/
ll vol[4005];
ll d[4005];
ll con[4005];

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;

    in(n);
    for(int i=1;i<=n;i++)
    {
        in(vol[i]);
        in(d[i]);
        in(con[i]);
    }

    vector<int>res;

    for(int i=1;i<=n;i++)
    {
        if(con[i]>=0)
        {
            res.pb(i);

            ll mn=0;

            for(int j=i+1,k=0;j<=n;j++,k++)
            {
                if(con[j]<0) continue;

                if(vol[i]-k>0)
                {
                    if(con[j]<(vol[i]-k)+mn )
                    {
                        con[j]=(con[j]-(vol[i]-k)-mn);
                        mn+=d[j];
                    }
                    else
                        con[j]=(con[j]-(vol[i]-k)-mn);
                }
                else
                {
                    if(con[j]<mn)
                    {
                        con[j]=con[j]-mn;
                        mn+=d[j];
                    }
                    else
                        con[j]=con[j]-mn;
                }

            }
        }
    }

    pf("%d\n",sz(res));

    for(int i=0;i<sz(res);i++)
        pf("%d ",res[i]);

    return 0;
}


   /*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

/*
    Hey, once upon a younger year
    When all our shadows disappeared
    The animals inside came out to play
    Hey, went face to face with all our fears
    Learned our lessons through the tears
    Made memories we knew would never fade

    One day my father—he told me,
    "Son, don't let it slip away."
    He took me in his arms, I heard him say,

    "When you get older
    Your wild heart will live for younger days
    Think of me if ever you're afraid."

    He said, "One day you'll leave this world behind
    So live a life you will remember."
    My father told me when I was just a child
    These are the nights that never die
    My father told me

    When thunder clouds start pouring down
    Light a fire they can't put out
    Carve your name into those shining stars
    He said, "Go venture far beyond these shores.
    Don't forsake this life of yours.
    I'll guide you home no matter where you are."

    One day my father—he told me,
    "Son, don't let it slip away."
    When I was just a kid I heard him say,

    "When you get older
    Your wild heart will live for younger days
    Think of me if ever you're afraid."

    He said, "One day you'll leave this world behind
    So live a life you will remember."
    My father told me when I was just a child
    These are the nights that never die
    My father told me

    These are the nights that never die
    My father told me
    Hey, hey

*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/
ll vol[4005];
ll d[4005];
ll con[4005];

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;

    in(n);
    for(int i=1;i<=n;i++)
    {
        in(vol[i]);
        in(d[i]);
        in(con[i]);
    }

    vector<int>res;

    for(int i=1;i<=n;i++)
    {
        if(con[i]>=0)
        {
            res.pb(i);

            ll mn=0;

            for(int j=i+1,k=0;j<=n;j++,k++)
            {
                if(con[j]<0) continue;

                if(vol[i]-k>0)
                {
                    if(con[j]<(vol[i]-k)+mn )
                    {
                        con[j]=(con[j]-(vol[i]-k)-mn);
                        mn+=d[j];
                    }
                    else
                        con[j]=(con[j]-(vol[i]-k)-mn);
                }
                else
                {
                    if(con[j]<mn)
                    {
                        con[j]=con[j]-mn;
                        mn+=d[j];
                    }
                    else
                        con[j]=con[j]-mn;
                }

            }
        }
    }

    pf("%d\n",sz(res));

    for(int i=0;i<sz(res);i++)
        pf("%d ",res[i]);

    return 0;
}


  /*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

/*
    Hey, once upon a younger year
    When all our shadows disappeared
    The animals inside came out to play
    Hey, went face to face with all our fears
    Learned our lessons through the tears
    Made memories we knew would never fade

    One day my father—he told me,
    "Son, don't let it slip away."
    He took me in his arms, I heard him say,

    "When you get older
    Your wild heart will live for younger days
    Think of me if ever you're afraid."

    He said, "One day you'll leave this world behind
    So live a life you will remember."
    My father told me when I was just a child
    These are the nights that never die
    My father told me

    When thunder clouds start pouring down
    Light a fire they can't put out
    Carve your name into those shining stars
    He said, "Go venture far beyond these shores.
    Don't forsake this life of yours.
    I'll guide you home no matter where you are."

    One day my father—he told me,
    "Son, don't let it slip away."
    When I was just a kid I heard him say,

    "When you get older
    Your wild heart will live for younger days
    Think of me if ever you're afraid."

    He said, "One day you'll leave this world behind
    So live a life you will remember."
    My father told me when I was just a child
    These are the nights that never die
    My father told me

    These are the nights that never die
    My father told me
    Hey, hey

*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/
ll vol[4005];
ll d[4005];
ll con[4005];

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;

    in(n);
    for(int i=1;i<=n;i++)
    {
        in(vol[i]);
        in(d[i]);
        in(con[i]);
    }

    vector<int>res;

    for(int i=1;i<=n;i++)
    {
        if(con[i]>=0)
        {
            res.pb(i);

            ll mn=0;

            for(int j=i+1,k=1;j<=n;j++,k++)
            {

                if(vol[i]-k>0)
                {
                    if(con[j]-(vol[i]-k)-mn<0 && con[j]>=0 )
                    {
                        con[j]=(con[j]-(vol[i]-k)-mn);
                        mn+=d[j];
                    }
                    else
                        con[j]=(con[j]-(vol[i]-k)-mn);
                }
                else
                {
                    if(con[j]-mn<0 && con[j]>=0 )
                    {
                        con[j]=con[j]-mn;
                        mn+=d[j];
                    }
                    else
                        con[j]=con[j]-mn;
                }

            }
        }
    }

    pf("%d\n",sz(res));

    for(int i=0;i<sz(res);i++)
        pf("%d ",res[i]);

    return 0;
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

class Program
{
    static void solveB(StreamReader reader, StreamWriter writer)
    {
        var n = reader.ReadInt();
        var arr = new long[n, n];
        int x = -1, y = -1;
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
            {
                arr[i, j] = reader.ReadInt();
                if (arr[i, j] == 0)
                {
                    x = i;
                    y = j;
                }
            }
        if (n == 1)
        {
            writer.WriteLine(1);
            return;
        }
        bool possible = true;
        long magic = 0;
        for (int j = 0; j < n; ++j)
            magic += arr[(x + 1) % n, j];
        long incorrect = 0;
        for (int j = 0; j < n; ++j)
            incorrect += arr[x, j];
        long res = magic - incorrect;
        arr[x, y] = res;
        if (res <= 0)
            possible = false;
        long d1 = 0, d2 = 0;
        for (int i = 0; i < n; ++i)
        {
            long sum1 = 0;
            long sum2 = 0;
            d1 += arr[i, i];
            d2 += arr[i, n - 1 - i];
            for (int j = 0; j < n; ++j)
                sum1 += arr[i, j];
            for (int j = 0; j < n; ++j)
                sum2 += arr[j, i];
            if (sum1 != magic || sum2 != magic)
                possible = false;
        }
        if (d1 != magic || d2 != magic)
            possible = false;
        if (possible)
        {
            writer.WriteLine(res);
        }
        else
        {
            writer.WriteLine(-1);
        }
    }

    static void solveA(StreamReader reader, StreamWriter writer)
    {
        var n = reader.ReadInt();
        var mass = new string[n];
        var found = false;
        for (int i = 0; i < n; ++i)
        {
            mass[i] = reader.ReadString();
            if (!found)
            {
                if (mass[i][0] == 'O' && mass[i][1] == 'O')
                {
                    found = true;
                    mass[i] = "++" + mass[i].Substring(2);
                }
                else if (mass[i][3] == 'O' && mass[i][4] == 'O')
                {
                    found = true;
                    mass[i] = mass[i].Substring(0, 3) + "++";
                }
            }
        }
        if (found)
        {
            writer.WriteLine("YES");
            for (int i = 0; i < n; ++i)
            {
                writer.WriteLine(mass[i]);
            }
        }
        else
        {
            writer.WriteLine("NO");
        }
    }

    static void solveC(StreamReader reader, StreamWriter writer)
    {
        var n = reader.ReadInt();
        var m = reader.ReadInt();
        var k = reader.ReadInt();
        var c = new int[n];
        for (int i = 0; i < n; ++i)
            c[i] = reader.ReadInt();
        var p = new long[n][];
        for (int i = 0; i < n; ++i)
        {
            p[i] = new long[m+1];
            for (int j = 1; j <= m; ++j)
                p[i][j] = reader.ReadInt();
        }
        var d = new long[n][][];
        for (int i = 0; i < n; ++i)
        {
            d[i] = new long[m+1][];
            for (int j = 0; j <= m; ++j)
            {
                d[i][j] = new long[n + 1];
                for (int h = 0; h <= n; ++h)
                    d[i][j][h] = -1;
            }
        }
        for (int j = 1;j <= m; ++j)
            for (int h = 1;h <= n; ++h)
            {
                if (c[0] > 0)
                    d[0][j][h] = j == c[0] && h == 1 ? 0 : -1;
                else
                    d[0][j][h] = h == 1? p[0][j]: -1;
            }
        for (int i = 1; i < n; ++i)
            for (int j = 1;j <= m; ++j)
                for (int h = 1;h <= n; ++h)
                {
                    long rr = -1;
                    if (c[i] > 0)
                    {
                        if (c[i] == j)
                        {
                            for (int j1 = 1; j1 <= m; ++j1)
                            {
                                if (j1 != j && d[i - 1][j1][h - 1] != -1 && (rr == -1 || rr > d[i - 1][j1][h - 1]))
                                    rr = d[i - 1][j1][h - 1];
                                if (j1 == j && d[i - 1][j1][h] != -1 && (rr == -1 || rr > d[i - 1][j1][h]))
                                    rr = d[i - 1][j1][h];
                            }
                        }
                    }
                    else
                    {
                        for (int j1 = 1; j1 <= m; ++j1)
                        {
                            if (j1 != j && d[i - 1][j1][h - 1] != -1 && (rr == -1 || rr > d[i - 1][j1][h - 1] + p[i][j]))
                                rr = d[i - 1][j1][h - 1] + p[i][j];
                            if (j1 == j && d[i - 1][j1][h] != -1 && (rr == -1 || rr > d[i - 1][j1][h] + p[i][j]))
                                rr = d[i - 1][j1][h] + p[i][j];
                        }
                    }
                    d[i][j][h] = rr;
                }

        long res = -1;
        for (int i = 1; i <= m; ++i)
            if (d[n - 1][i][k] != -1 && (res == -1 | d[n - 1][i][k] < res))
                res = d[n - 1][i][k];
        writer.WriteLine(res);
    }

    static void solve(StreamReader reader, StreamWriter writer)
    {
        var n = reader.ReadInt();
        var a = new int[n+1];
        var edges = new List<int>[n + 1];
        for (int i = 1; i <= n; ++i)
        {
            a[i] = reader.ReadInt();
            edges[i] = edges[i] ?? new List<int>();
            edges[i].Add(a[i]);
            edges[a[i]] = edges[a[i]] ?? new List<int>();
            edges[a[i]].Add(i);
        }
        var was = new bool[n + 1];
        var used = new bool[n + 1];
        var get = new int[n + 1];
        int loop = 0;
        int comp = 0;
        for (int i = 1; i <= n; ++i)
        {
            if (!was[i])
            {
                var st = new Stack<int>();
                st.Push(i);
                was[i] = true;
                ++comp;
                while (st.Count > 0)
                {
                    var c = st.Peek();
                    if (edges[c] != null && get[c] < edges[c].Count)
                    {
                        var cd = edges[c][get[c]];
                        if (a[c] == cd && !used[c] || a[cd] == c && !used[cd])
                        {
                            if (!was[cd])
                            {
                                st.Push(cd);
                                was[cd] = true;
                            }
                            else
                            {
                                var tmp = new Stack<int>(new Stack<int>(st));
                                tmp.Push(cd);
                                loop += getLoop(tmp);
                            }
                            if (a[c] == cd)
                                used[c] = true;
                            else
                                used[cd] = true;
                        }

                        ++get[c];
                    }
                    else
                    {
                        st.Pop();
                    }
                }
            }
        }
        int mod = 1000000007;
        var res = power(2, n, mod) - power(2, n - loop + comp, mod);
        writer.WriteLine((res + mod) % mod);
    }

    static int getLoop(Stack<int> st)
    {
        var loop = 1;
        var start = st.Pop();
        while (st.Peek() != start)
        {
            st.Pop();
            ++loop;
        }
        return loop;
    }

    static long power(long a, int e, int mod)
    {
        long r = 1;
        while (e > 0)
        {
            if ((e & 1) == 1)
            {
                r = r*a%mod;
            }
            a = a*a % mod;
            e >>= 1;
        }
        return r;
    }

    #region launch
    static void Main(string[] args)
    {
        using (var writer = new FormattedStreamWriter(Console.OpenStandardOutput()))
        {
            using (var reader = new StreamReader(
#if CODECHIEF_LOCAL
"input.txt"
#else
Console.OpenStandardInput()
#endif
))
            {
                solve(reader, writer);
            }
        }
    }
    #endregion
}

#region helpers
class FormattedStreamWriter : StreamWriter
{
    public FormattedStreamWriter(Stream stream)
        : base(stream)
    {
    }

    public override IFormatProvider FormatProvider
    {
        get
        {
            return CultureInfo.InvariantCulture;
        }
    }
}

static class IOExtensions
{
    public static string ReadString(this StreamReader reader)
    {
        return reader.ReadToken();
    }

    public static int ReadInt(this StreamReader reader)
    {
        return int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
    }

    public static long ReadLong(this StreamReader reader)
    {
        return long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
    }

    public static double ReadDouble(this StreamReader reader)
    {
        return double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
    }

    static Queue<string> buffer = new Queue<string>(100);

    static string ReadToken(this StreamReader reader)
    {
        while (buffer.Count == 0)
        {
            reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach((t) =>
            {
                buffer.Enqueue(t);
            });
        }
        return buffer.Dequeue();
    }
}
#endregion


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

class Program
{
    static void solveB(StreamReader reader, StreamWriter writer)
    {
        var n = reader.ReadInt();
        var arr = new long[n, n];
        int x = -1, y = -1;
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
            {
                arr[i, j] = reader.ReadInt();
                if (arr[i, j] == 0)
                {
                    x = i;
                    y = j;
                }
            }
        if (n == 1)
        {
            writer.WriteLine(1);
            return;
        }
        bool possible = true;
        long magic = 0;
        for (int j = 0; j < n; ++j)
            magic += arr[(x + 1) % n, j];
        long incorrect = 0;
        for (int j = 0; j < n; ++j)
            incorrect += arr[x, j];
        long res = magic - incorrect;
        arr[x, y] = res;
        if (res <= 0)
            possible = false;
        long d1 = 0, d2 = 0;
        for (int i = 0; i < n; ++i)
        {
            long sum1 = 0;
            long sum2 = 0;
            d1 += arr[i, i];
            d2 += arr[i, n - 1 - i];
            for (int j = 0; j < n; ++j)
                sum1 += arr[i, j];
            for (int j = 0; j < n; ++j)
                sum2 += arr[j, i];
            if (sum1 != magic || sum2 != magic)
                possible = false;
        }
        if (d1 != magic || d2 != magic)
            possible = false;
        if (possible)
        {
            writer.WriteLine(res);
        }
        else
        {
            writer.WriteLine(-1);
        }
    }

    static void solveA(StreamReader reader, StreamWriter writer)
    {
        var n = reader.ReadInt();
        var mass = new string[n];
        var found = false;
        for (int i = 0; i < n; ++i)
        {
            mass[i] = reader.ReadString();
            if (!found)
            {
                if (mass[i][0] == 'O' && mass[i][1] == 'O')
                {
                    found = true;
                    mass[i] = "++" + mass[i].Substring(2);
                }
                else if (mass[i][3] == 'O' && mass[i][4] == 'O')
                {
                    found = true;
                    mass[i] = mass[i].Substring(0, 3) + "++";
                }
            }
        }
        if (found)
        {
            writer.WriteLine("YES");
            for (int i = 0; i < n; ++i)
            {
                writer.WriteLine(mass[i]);
            }
        }
        else
        {
            writer.WriteLine("NO");
        }
    }

    static void solveC(StreamReader reader, StreamWriter writer)
    {
        var n = reader.ReadInt();
        var m = reader.ReadInt();
        var k = reader.ReadInt();
        var c = new int[n];
        for (int i = 0; i < n; ++i)
            c[i] = reader.ReadInt();
        var p = new long[n][];
        for (int i = 0; i < n; ++i)
        {
            p[i] = new long[m+1];
            for (int j = 1; j <= m; ++j)
                p[i][j] = reader.ReadInt();
        }
        var d = new long[n][][];
        for (int i = 0; i < n; ++i)
        {
            d[i] = new long[m+1][];
            for (int j = 0; j <= m; ++j)
            {
                d[i][j] = new long[n + 1];
                for (int h = 0; h <= n; ++h)
                    d[i][j][h] = -1;
            }
        }
        for (int j = 1;j <= m; ++j)
            for (int h = 1;h <= n; ++h)
            {
                if (c[0] > 0)
                    d[0][j][h] = j == c[0] && h == 1 ? 0 : -1;
                else
                    d[0][j][h] = h == 1? p[0][j]: -1;
            }
        for (int i = 1; i < n; ++i)
            for (int j = 1;j <= m; ++j)
                for (int h = 1;h <= n; ++h)
                {
                    long rr = -1;
                    if (c[i] > 0)
                    {
                        if (c[i] == j)
                        {
                            for (int j1 = 1; j1 <= m; ++j1)
                            {
                                if (j1 != j && d[i - 1][j1][h - 1] != -1 && (rr == -1 || rr > d[i - 1][j1][h - 1]))
                                    rr = d[i - 1][j1][h - 1];
                                if (j1 == j && d[i - 1][j1][h] != -1 && (rr == -1 || rr > d[i - 1][j1][h]))
                                    rr = d[i - 1][j1][h];
                            }
                        }
                    }
                    else
                    {
                        for (int j1 = 1; j1 <= m; ++j1)
                        {
                            if (j1 != j && d[i - 1][j1][h - 1] != -1 && (rr == -1 || rr > d[i - 1][j1][h - 1] + p[i][j]))
                                rr = d[i - 1][j1][h - 1] + p[i][j];
                            if (j1 == j && d[i - 1][j1][h] != -1 && (rr == -1 || rr > d[i - 1][j1][h] + p[i][j]))
                                rr = d[i - 1][j1][h] + p[i][j];
                        }
                    }
                    d[i][j][h] = rr;
                }

        long res = -1;
        for (int i = 1; i <= m; ++i)
            if (d[n - 1][i][k] != -1 && (res == -1 | d[n - 1][i][k] < res))
                res = d[n - 1][i][k];
        writer.WriteLine(res);
    }

    static void solve(StreamReader reader, StreamWriter writer)
    {
        var n = reader.ReadInt();
        var a = new int[n+1];
        var edges = new List<int>[n + 1];
        for (int i = 1; i <= n; ++i)
        {
            a[i] = reader.ReadInt();
            edges[i] = edges[i] ?? new List<int>();
            edges[i].Add(a[i]);
            edges[a[i]] = edges[a[i]] ?? new List<int>();
            edges[a[i]].Add(i);
        }
        int mod = 1000000007;
        var was = new bool[n + 1];
        var used = new bool[n + 1];
        var get = new int[n + 1];
        long res = 1;
        for (int i = 1; i <= n; ++i)
        {
            if (!was[i])
            {
                var st = new Stack<int>();
                st.Push(i);
                was[i] = true;
                int comp = 1;
                int loop = 0;
                while (st.Count > 0)
                {
                    var c = st.Peek();
                    if (edges[c] != null && get[c] < edges[c].Count)
                    {
                        var cd = edges[c][get[c]];
                        if (a[c] == cd && !used[c] || a[cd] == c && !used[cd])
                        {
                            if (!was[cd])
                            {
                                st.Push(cd);
                                was[cd] = true;
                                ++comp;
                            }
                            else
                            {
                                var tmp = new Stack<int>(new Stack<int>(st));
                                tmp.Push(cd);
                                loop += getLoop(tmp);
                            }
                            if (a[c] == cd)
                                used[c] = true;
                            else
                                used[cd] = true;
                        }

                        ++get[c];
                    }
                    else
                    {
                        st.Pop();
                    }
                }
                var tt = power(2, comp, mod) - power(2, comp - loop + 1, mod);
                tt = (tt + mod)%mod;
                res = res * tt % mod;
            }
        }

        writer.WriteLine(res);
    }

    static int getLoop(Stack<int> st)
    {
        var loop = 1;
        var start = st.Pop();
        while (st.Peek() != start)
        {
            st.Pop();
            ++loop;
        }
        return loop;
    }

    static long power(long a, int e, int mod)
    {
        long r = 1;
        while (e > 0)
        {
            if ((e & 1) == 1)
            {
                r = r*a%mod;
            }
            a = a*a % mod;
            e >>= 1;
        }
        return r;
    }

    #region launch
    static void Main(string[] args)
    {
        using (var writer = new FormattedStreamWriter(Console.OpenStandardOutput()))
        {
            using (var reader = new StreamReader(
#if CODECHIEF_LOCAL
"input.txt"
#else
Console.OpenStandardInput()
#endif
))
            {
                solve(reader, writer);
            }
        }
    }
    #endregion
}

#region helpers
class FormattedStreamWriter : StreamWriter
{
    public FormattedStreamWriter(Stream stream)
        : base(stream)
    {
    }

    public override IFormatProvider FormatProvider
    {
        get
        {
            return CultureInfo.InvariantCulture;
        }
    }
}

static class IOExtensions
{
    public static string ReadString(this StreamReader reader)
    {
        return reader.ReadToken();
    }

    public static int ReadInt(this StreamReader reader)
    {
        return int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
    }

    public static long ReadLong(this StreamReader reader)
    {
        return long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
    }

    public static double ReadDouble(this StreamReader reader)
    {
        return double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
    }

    static Queue<string> buffer = new Queue<string>(100);

    static string ReadToken(this StreamReader reader)
    {
        while (buffer.Count == 0)
        {
            reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach((t) =>
            {
                buffer.Enqueue(t);
            });
        }
        return buffer.Dequeue();
    }
}
#endregion