#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long

int n,m,q;
int dist[100001];
bool vist[100001],chavist[100001];

struct id{
    int v,nxt;
}num[100001],antinum[100001];

struct node{
    int v,d;
    node(){}
    node(int vv,int dd){v=vv;d=dd;}
    bool operator < (const node &a) const{
        return a.d<d;
    }
};

vector<node> v[100001],antiv[100001];

void dij()
{
    int i;
    priority_queue<node> q;
    q.push(node(1,0));
    while(!q.empty())
    {
        node a=q.top();
        q.pop();
        for(i=0;i<v[a.v].size();i++)
        {
            node b=v[a.v][i];
            vist[b.v]=true;
            if(a.d+b.d<dist[b.v])
            {
                dist[b.v]=a.d+b.d;
                q.push(node(b.v,dist[b.v]));
            }
        }
    }
}

void dfs(int x)
{
	int i;
    chavist[x]=true;
    for(i=0;i<v[x].size();i++)
    {
        node a=v[x][i];
        if(dist[x]+a.d==dist[a.v]&&!chavist[a.v]) dfs(a.v);
    }
    dist[x]++;
}

void change(int x)
{
    int i;
    for(i=0;i<v[x].size();i++)
    {
        node a=v[x][i];
        if(chavist[a.v]) change(a.v);
    }
    for(i=0;i<antiv[x].size();i++)
    {
        node a=antiv[x][i];
		dist[x]=min(dist[a.v]+a.d,dist[x]);
    }
}

signed main()
{
    int i,x,y,l;
    int add=0;
    cin>>n>>m>>q;
    memset(dist,127,sizeof(dist));
    memset(vist,false,sizeof(vist));
    memset(chavist,false,sizeof(chavist));
    for(i=1;i<=m;i++)
    {
        scanf("%lld %lld %lld",&x,&y,&l);
        v[x].push_back(node(y,l));
        antiv[y].push_back(node(x,l));
        num[i].v=x;
        num[i].nxt=v[x].size()-1;
        antinum[i].v=y;
        antinum[i].nxt=antiv[y].size()-1;
    }
    dist[1]=0;
    dij();
    for(i=1;i<=q;i++)
    {
        int typ;
        scanf("%lld",&typ);
        if(typ==1)
        {
            int to;
            scanf("%lld",&to);
            if(to==1) cout<<0<<endl;
            if(!vist[to]) cout<<-1<<endl;
            else cout<<dist[to]+add<<endl;
        }
        else
        {
            int k,a;
            scanf("%lld",&k);
            for(int j=1;j<=k;j++)
            {
                scanf("%lld",&a);
                node b=v[num[a].v][num[a].nxt];
                antiv[antinum[a].v][antinum[a].nxt].d++;
                if(num[a].v==1&&v[1].size()==1)
                {
                    add++;
                    v[num[a].v][num[a].nxt].d++;
                    continue;
                }
                if(dist[b.v]==dist[num[a].v]+b.d)
                {
                	memset(chavist,false,sizeof(chavist));
                	dfs(b.v);
                    change(b.v);
                }
                v[num[a].v][num[a].nxt].d++;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const
#define fr first
#define se second
//#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e17 + 1;
cs int M = 1e9 + 7;
cs double eps = 1e-7;
inline int read() { int x; scanf("%lld", &x); return x; }

struct DSU
{
	int fa[ff];
	void pre(int N) { rep(i, 1, N) fa[i] = i; }
	int find(int x) { return fa[x] == x? x : fa[x] = find(fa[x]); }
	void merge(int x, int y)
	{
		x = find(x); y = find(y);
		if(x != y) fa[x] = y;
		//x==y?0:fa[x]=y;
	}
}dsu;

int fir[ff], nex[ff], to[ff], tot, va[ff];
void clean() { tot = 0; cn(fir); }
void add(int x, int y, int z)
{
	nex[++tot] = fir[x];
	fir[x] = tot;
	to[tot] = y;
	va[tot] = z;
}
void ade(int x, int y, int z) { add(x, y, z); add(y, x, z); }

int n, m, q, vis[ff], dis[ff];
void dij1()
{
	rep(i, 1, n) dis[i] = inf, vis[i] = 0;
	priority_queue<pair<ll, ll> > q;
	q.push(mp(0, 1)); dis[1] = 0;
	while(!q.empty())
	{
		int u = q.top().se; q.pop();
		if(vis[u]) continue;
		vis[u] = 1;
		fore(i, u)
			if(dis[to[i]] > dis[u] + va[i])
				dis[to[i]] = dis[u] + va[i], q.push(mp(-dis[to[i]], to[i]));
	}
}

pair<ll, ll> id[ff];
int dis2[ff], vis2[ff];
vector<int> tong[ff];
void dij2()
{
	int hd = 0, hd2 = 0;
	rep(i, 1, n) dis2[i] = inf, vis2[i] = 0;
	tong[0].push_back(1); dis2[1] = 0;
	while(hd <= 100000)
	{
		int sz = tong[hd].size(); sz --;
		while(sz < hd2 && hd <= 100000)
			hd ++, hd2 = 0, sz = tong[hd].size(), sz --;

		if(hd > 100000) break;

		int u = tong[hd][hd2]; hd2 ++;
		if(vis2[u]) continue; vis2[u] = 1;
		fore(i, u)
		{
			if(dis2[to[i]] > dis2[u] + va[i])
				dis2[to[i]] = dis2[u] + va[i], tong[dis2[to[i]]].push_back(to[i]);
		}
	}
}

int u[ff], v[ff], w[ff];
void init()
{
	cin >> n >> m >> q;
	rep(i, 1, m)
	{
		scanf("%lld %lld %lld", &u[i], &v[i], &w[i]);
		ade(u[i], v[i], w[i]);
	}
	dij1(); clean();
	rep(i, 1, m)
	{
		ade(u[i], v[i], dis[u[i]] - dis[v[i]] + w[i]);
		id[i] = mp(tot - 1, tot);
	//	cout << "  " << u[i] << " " << v[i] << "\n";
	}
	rep(i, 1, q)
	{
		int x, y, opt; scanf("%lld", &opt);
	//	cout << " " << opt << "\n";
		if(opt == 1)
		{
			dij2(), scanf("%lld", &x);
			if(dis[x] == inf) puts("-1");
			else cout << dis[x] + dis2[x] << "\n";
		}
		else
		{
			scanf("%lld", &y);
			int z;
			rep(j, 1, y) scanf("%lld", &z), va[id[z].fr] ++, va[id[z].se] ++;
		}
	}
}
signed main()
{
//	freopen("xor.in", "r", stdin);
//	freopen("xor.out", "w", stdout);
	int Ts = 1;
	while(Ts--)
		init();
}


//please do not consider it as resubmission
#include<cstdio>
#include<queue>

using namespace std;

struct pri
{
	int id;long long val;pri(int i=0,long long v=0):id(i),val(v){}
};bool operator<(pri a,pri b){return a.val>b.val;}

struct e
{
	int to;long long val;e(int t=0,long long v=0):to(t),val(v){}
};vector<e> ed[200000];

bool vis[200000];
const long long INF=1e15;
void Dijsktra(int n,int s,long long *dis)
{
	for(int i=1;i<=n;i++)dis[i]=INF;dis[s]=0;priority_queue<pri> pq;pq.push(pri(s,0));
	for(int i=1;i<=n;i++)vis[i]=0;
	while(!pq.empty())
	{
		pri x=pq.top();pq.pop();
		if(vis[x.id])continue;vis[x.id]=1;int u=x.id;//printf("%d\n",x.id);
		for(int i=0;i<ed[u].size();i++)
		{
			int v=ed[u][i].to;//printf("%d\n",v);
			if(dis[u]+ed[u][i].val<dis[v])
			{
				dis[v]=dis[u]+ed[u][i].val;
				pq.push(pri(v,dis[v]));
			}
		}
	}
}

int u[200000],id[200000];
long long dis[200000];

int n=0,m=0,q=0;
void subtract(long long *dis)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<ed[i].size();j++)
		{
			int u=ed[i][j].to;ed[i][j].val=dis[i]+ed[i][j].val-dis[u];
		}
	}
}

vector<int> v[2000000];
void another(int n,int s,long long *dis)
{
	for(int i=1;i<=n;i++)dis[i]=INF;dis[s]=0;v[0].push_back(s);
	for(int i=1;i<=n;i++)vis[i]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<v[i].size();j++)
		{
			int u=v[i][j];if(dis[u]!=i||vis[u])continue;vis[u]=1;
			for(int k=0;k<ed[u].size();k++)
			{
				int w=ed[u][k].to;
				if(dis[u]+ed[u][k].val<n&&dis[u]+ed[u][k].val<dis[w])
				{
					dis[w]=dis[u]+ed[u][k].val;
					if(dis[w]<n)v[dis[w]].push_back(w);
					//puts("???");
				}
			}
		}
	}
	for(int i=0;i<n;i++)v[i].clear();
}

long long dis2[200000];
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&u[i]);id[i]=ed[u[i]].size();
		int v=0,w=0;scanf("%d%d",&v,&w);
		ed[u[i]].push_back(e(v,w));
	}

	Dijsktra(n,1,dis);subtract(dis);

	while(q--)
	{
		/*for(int i=1;i<=n;i++)
		{
			for(int j=0;j<ed[i].size();j++)printf("%d %d: %d\n",i,ed[i][j].to,ed[i][j].val);
		}*/
		int op=0;scanf("%d",&op);
		if(op==1)
		{
			int x=0;scanf("%d",&x);
			printf("%lld\n",dis[x]>=INF?-1:dis[x]);
		}
		else
		{
			int c=0;scanf("%d",&c);
			while(c--)
			{
				int i=0;scanf("%d",&i);ed[u[i]][id[i]].val++;
			}
			another(n,1,dis2);subtract(dis2);for(int i=1;i<=n;i++)dis[i]+=dis2[i];
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const
#define fr first
#define se second
//#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e17 + 1;
cs int M = 1e9 + 7;
cs double eps = 1e-7;
inline int read() { int x; scanf("%lld", &x); return x; }

struct DSU
{
	int fa[ff];
	void pre(int N) { rep(i, 1, N) fa[i] = i; }
	int find(int x) { return fa[x] == x? x : fa[x] = find(fa[x]); }
	void merge(int x, int y)
	{
		x = find(x); y = find(y);
		if(x != y) fa[x] = y;
		//x==y?0:fa[x]=y;
	}
}dsu;

int fir[ff], nex[ff], to[ff], tot, va[ff];
void clean() { tot = 0; cn(fir); }
void add(int x, int y, int z)
{
	nex[++tot] = fir[x];
	fir[x] = tot;
	to[tot] = y;
	va[tot] = z;
}
void ade(int x, int y, int z) { add(x, y, z); add(y, x, z); }

int n, m, q, vis[ff], dis[ff];
void dij1()
{
	rep(i, 1, n) dis[i] = inf, vis[i] = 0;
	priority_queue<pair<ll, ll> > q;
	q.push(mp(0, 1)); dis[1] = 0;
	while(!q.empty())
	{
		int u = q.top().se; q.pop();
		if(vis[u]) continue;
		vis[u] = 1;
		fore(i, u)
			if(dis[to[i]] > dis[u] + va[i])
				dis[to[i]] = dis[u] + va[i], q.push(mp(-dis[to[i]], to[i]));
	}
}

pair<ll, ll> id[ff];
int dis2[ff], vis2[ff];
vector<int> tong[ff];
void dij2()
{
	int hd = 0, hd2 = 0;
	rep(i, 0, 100000) dis2[i] = inf, vis2[i] = 0;
	tong[0].push_back(1); dis2[1] = 0;
	while(hd <= 100000)
	{
		int sz = tong[hd].size(); sz --;
		while(sz < hd2 && hd <= 100000)
			hd ++, hd2 = 0, sz = tong[hd].size(), sz --;

		if(hd > 100000) break;

		int u = tong[hd][hd2]; hd2 ++;
		if(vis2[u]) continue; vis2[u] = 1;
		fore(i, u)
		{
			if(dis2[to[i]] > dis2[u] + va[i])
				dis2[to[i]] = dis2[u] + va[i], tong[dis2[to[i]]].push_back(to[i]);
		}
	}
	rep(i, 0, 100000) tong[i].clear();
}

int u[ff], v[ff], w[ff];
void init()
{
	cin >> n >> m >> q;
	rep(i, 1, m)
	{
		scanf("%lld %lld %lld", &u[i], &v[i], &w[i]);
		ade(u[i], v[i], w[i]);
	}
	dij1(); clean();
	rep(i, 1, m)
	{
		ade(u[i], v[i], min(dis[u[i]] - dis[v[i]], dis[v[i]] - dis[u[i]]) + w[i]);
		id[i] = mp(tot - 1, tot);
	//	cout << "  " << u[i] << " " << v[i] << "\n";
	}
	rep(i, 1, q)
	{
		int x, y, opt; scanf("%lld", &opt);
	//	cout << " " << opt << "\n";
		if(opt == 1)
		{
			dij2(), scanf("%lld", &x);
			if(dis[x] == inf) puts("-1");
			else cout << dis[x] + dis2[x] << "\n";
		}
		else
		{
			scanf("%lld", &y);
			int z;
			rep(j, 1, y) scanf("%lld", &z), va[id[z].fr] ++, va[id[z].se] ++, w[z] ++;
			dij2();
			rep(j, 1, n) dis[j] = dis[j] + dis2[j], dis2[j] = 0;
			rep(j, 1, m) va[id[j].fr] = va[id[j].se] = min(dis[u[j]] - dis[v[j]], dis[v[j]] - dis[u[j]]) + w[j];
		}
	}
}
signed main()
{
//	freopen("xor.in", "r", stdin);
//	freopen("xor.out", "w", stdout);
	int Ts = 1;
	while(Ts--)
		init();
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

inline int read() {
    int res=0,fh=1;
    char ch=getchar();
    while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
    if(ch=='-')fh=-1,ch=getchar();
    while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar();
    return fh*res;
}

typedef long long ll;
const int maxn=100010;
const ll INF=1e15;
ll n,m,k;
ll dis[maxn];

struct graph{
	ll to,w,nxt;
}G[maxn];ll head[maxn],tot=0;

struct node{
	ll x;
	inline bool operator <(const node rhs)const{
		return dis[x]>dis[rhs.x];
	}
};
priority_queue<node> que;
queue<int> q[maxn];

bool vis[maxn];
inline void dijkstra(){
	memset(vis,0,sizeof vis);
	for(int i=2;i<=n;i++) dis[i]=INF;
	que.push((node){1});
	while(!que.empty()){
		int u=que.top().x;
		if(vis[u]) continue;
		que.pop();
		for(int i=head[u];i;i=G[i].nxt){
			int to=G[i].to;
			if(dis[to]>dis[u]+G[i].w){
				dis[to]=dis[u]+G[i].w;
				if(!vis[to])
					que.push((node){to});
			}
		}
	}
}

inline int Min(int a,int b){
	return a<b?a:b;
}
ll cnt,f[maxn];

int main()
{
	n=read(),m=read(),k=read();
	for(int i=1;i<=m;i++){
		int x=read(),y=read(),w=read();
		G[++tot]=(graph){y,w,head[x]},head[x]=tot;
	}
	dijkstra();
	while(k--){
		int opt=read(),x=read();
		if(opt==1) printf("%lld\n",dis[x]>=INF?-1:dis[x]);
		else {
			for (int i=1,y; i<=x; ++i) y=read(),++G[y].w;
			for(int i=2;i<=n;i++) f[i]=INF;
			q[cnt=0].push(1); x=Min(x,n-1);
			for(int i=0;i<=cnt;i++){
				while(!q[i].empty()){
					int p=q[i].front();q[i].pop();
					if(i>f[p]) continue;
					for(int i=head[p];i;i=G[i].nxt){
						int to=G[i].to;
						ll tmp=dis[p]+G[i].w-dis[to]+f[p];
						if (f[to]>tmp){
							f[to]=tmp;
							if(tmp<=x)
								q[tmp].push(to),cnt=max(1ll*cnt,tmp);
						}
					}
				}
			}
			for(int i=2; i<=n; ++i)
				dis[i]=min(INF,dis[i]+f[i]);
		}
	}
}


#include <cstdio>
#include <cctype>
#include <queue>
using namespace std;

typedef long long ll;
const int N=1e5+10;
const ll INF=1e15;
struct side{
	int to,w,nt;
}s[N];
int n,m,q,x,y,w,num,h[N],o,cnt;
ll d[N],f[N];
struct note{
	ll x;
	inline bool operator < (const note lyf) const {return d[x]>d[lyf.x];}
};
priority_queue <note> que;
queue <int> g[N];

inline char nc(void){
	static char ch[100010],*p1=ch,*p2=ch;
	return p1==p2&&(p2=(p1=ch)+fread(ch,1,100010,stdin),p1==p2)?EOF:*p1++;
}

inline void read(int &a){
	char c=nc();int f=1;
	for (;!isdigit(c);c=nc()) if (c=='-') f=-1;
	for (a=0;isdigit(c);a=(a<<3)+(a<<1)+c-'0',c=nc());
	return (void)(a*=f);
}

inline void dij(void){
	bool b[N]={0};
	for (int i=2; i<=n; ++i) d[i]=INF;
	que.push((note){1});
	while (!que.empty()){
		note p=que.top();
		if (b[p.x]) continue; que.pop();
		for (int i=h[p.x]; i; i=s[i].nt)
			if (d[s[i].to]>d[p.x]+s[i].w){
				d[s[i].to]=d[p.x]+s[i].w;
				if (!b[s[i].to]) que.push((note){s[i].to});
			}
	}
	return;
}

int main(void){
	read(n),read(m),read(q);
	for (int i=1; i<=m; ++i) read(x),read(y),read(w),s[++num]=(side){y,w,h[x]},h[x]=num;
	dij();
	while (q--){
		read(o),read(x);
		if (o==1) printf("%I64d\n",d[x]>=INF?-1:d[x]);
		else {
			for (int i=1; i<=x; ++i) read(y),++s[y].w;
			for (int i=2; i<=n; ++i) f[i]=INF;
			g[cnt=0].push(1); if (x>=n) x=n-1;
			for (int i=0; i<=cnt; ++i)
				while (!g[i].empty()){
					int p=g[i].front();g[i].pop();
					if (i>f[p]) continue;
					for (int i=h[p]; i; i=s[i].nt){
						ll tmp=d[p]+s[i].w-d[s[i].to]+f[p];
						if (f[s[i].to]>tmp){
							f[s[i].to]=tmp;
							if (tmp<=x) g[tmp].push(s[i].to),cnt=max(1ll*cnt,tmp);
						}
					}
				}
			for (int i=2; i<=n; ++i) d[i]=min(INF,d[i]+f[i]);
		}
	}
	return 0;
}///


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

inline int read() {
    int res=0,fh=1;
    char ch=getchar();
    while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
    if(ch=='-')fh=-1,ch=getchar();
    while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar();
    return fh*res;
}

typedef long long ll;
const int maxn=100010;
const ll INF=1e15;
ll n,m,k;
ll dis[maxn];

struct graph{
	ll to,w,nxt;
}G[maxn];ll head[maxn],tot=0;

struct node{
	ll x;
	inline bool operator <(const node rhs)const{
		return dis[x]>dis[rhs.x];
	}
};
priority_queue<node> que;
queue<int> q[maxn];

bool vis[maxn];
inline void dijkstra(){
	memset(vis,0,sizeof vis);
	for(int i=2;i<=n;i++) dis[i]=INF;
	que.push((node){1});
	while(!que.empty()){
		int u=que.top().x;
		if(vis[u]) continue;
		que.pop();
		for(int i=head[u];u;u=G[i].nxt){
			int to=G[i].to;
			if(dis[to]>dis[u]+G[i].w){
				dis[to]=dis[u]+G[i].w;
				if(!vis[to])
					que.push((node){to});
			}
		}
	}
}

inline int Min(int a,int b){
	return a<b?a:b;
}
ll cnt,f[maxn];

int main()
{
	n=read(),m=read(),k=read();
	for(int i=1;i<=m;i++){
		int x=read(),y=read(),w=read();
		G[++tot]=(graph){y,w,head[x]},head[x]=tot;
	}
	dijkstra();
	while(k--){
		int opt=read(),x=read();
		if(opt==1) printf("%lld\n",dis[x]>=INF?-1:dis[x]);
		else {
			for (int i=1,y; i<=x; ++i) y=read(),++G[y].w;
			for(int i=2;i<=n;i++) f[i]=INF;
			q[cnt=0].push(1); x=Min(x,n-1);
			for(int i=0;i<=cnt;i++){
				while(!q[i].empty()){
					int p=q[i].front();q[i].pop();
					if(i>f[p]) continue;
					for(int i=head[p];i;i=G[i].nxt){
						int to=G[i].to;
						ll tmp=dis[p]+G[i].w-dis[to]+f[p];
						if (f[to]>tmp){
							f[to]=tmp;
							if(tmp<=x)
								q[tmp].push(to),cnt=max(1ll*cnt,tmp);
						}
					}
				}
			}
			for(int i=2; i<=n; ++i)
				dis[i]=min(INF,dis[i]+f[i]);
		}
	}
}


#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define Rint register int
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N = 100003, mod = 998244353;
const LL inf = 0x3f3f3f3f3f3f3f3fll;
int ksm(int a, int b){
	int res = 1;
	for(;b;b >>= 1, a = (LL) a * a % mod) if(b & 1) res = (LL) res * a % mod;
	return res;
}
template<typename T>
inline void read(T &x){
	int ch = getchar(); x = 0;
	bool f = false;
	for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
	for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n, m, q, add[N], head[N], to[N], nxt[N], w[N];
LL dis[N];
bool vis[N];
void adde(int a, int b, int c){static int cnt = 0; to[++ cnt] = b; nxt[cnt] = head[a]; head[a] = cnt; w[cnt] = c;}
priority_queue<pii, vector<pii>, greater<pii> > pq;
queue<int> vec[N];
void dijkstra(){
	memset(dis, 0x3f, sizeof dis);
	pq.push(MP(dis[1] = 0, 1));
	while(!pq.empty()){
		pii u = pq.top(); pq.pop();
		if(vis[u.se]) continue; vis[u.se] = true;
		for(Rint i = head[u.se];i;i = nxt[i])
			if(chmin(dis[to[i]], dis[u.se] + w[i]))
				pq.push(MP(dis[to[i]], to[i]));
	}
}
int main(){
	read(n); read(m); read(q);
	for(Rint i = 1, u, v, c;i <= m;++ i){read(u); read(v); read(c); adde(u, v, c);}
	dijkstra();
	for(Rint i = 1, op, c;i <= q;++ i){
		read(op); read(c);
		if(op == 1) printf("%lld\n", dis[c] >= inf ? -1 : dis[c]);
		else {
			for(Rint i = 1, u;i <= c;++ i){read(u); ++ w[u];}
			for(Rint i = 2;i <= n;++ i) add[i] = c + 1;
			vec[add[1] = 0].push(1);
			for(Rint i = 0;i <= c;++ i)
				while(!vec[i].empty()){
					int x = vec[i].front(); vec[i].pop();
					if(add[x] != i) continue;
					for(Rint j = head[x];j;j = nxt[j]){
						LL tmp = dis[x] + add[x] + w[j] - dis[to[j]];
						if(chmin(add[to[j]], tmp)) vec[tmp].push(to[j]);
					}
				}
			for(Rint i = 1;i <= n;++ i) if(add[i] <= c) dis[i] += add[i];
		}
	}
}


#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define Rint register int
using namespace std;
typedef long long LL;
typedef pair<LL, int> pii;
const int N = 100003, mod = 998244353;
const LL inf = 0x3f3f3f3f3f3f3f3fll;
int ksm(int a, int b){
	int res = 1;
	for(;b;b >>= 1, a = (LL) a * a % mod) if(b & 1) res = (LL) res * a % mod;
	return res;
}
template<typename T>
inline void read(T &x){
	int ch = getchar(); x = 0;
	bool f = false;
	for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
	for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n, m, q, add[N], head[N], to[N], nxt[N], w[N];
LL dis[N];
bool vis[N];
void adde(int a, int b, int c){static int cnt = 0; to[++ cnt] = b; nxt[cnt] = head[a]; head[a] = cnt; w[cnt] = c;}
priority_queue<pii, vector<pii>, greater<pii> > pq;
queue<int> vec[N];
void dijkstra(){
	memset(dis, 0x3f, sizeof dis);
	pq.push(MP(dis[1] = 0, 1));
	while(!pq.empty()){
		pii u = pq.top(); pq.pop();
		if(vis[u.se]) continue; vis[u.se] = true;
		for(Rint i = head[u.se];i;i = nxt[i])
			if(chmin(dis[to[i]], dis[u.se] + w[i]))
				pq.push(MP(dis[to[i]], to[i]));
	}
}
int main(){
	read(n); read(m); read(q);
	for(Rint i = 1, u, v, c;i <= m;++ i){read(u); read(v); read(c); adde(u, v, c);}
	dijkstra();
	for(Rint i = 1, op, c;i <= q;++ i){
		read(op); read(c);
		if(op == 1) printf("%lld\n", dis[c] >= inf ? -1 : dis[c]);
		else {
			for(Rint i = 1, u;i <= c;++ i){read(u); ++ w[u];}
			for(Rint i = 2;i <= n;++ i) add[i] = c + 1;
			vec[add[1] = 0].push(1);
			for(Rint i = 0;i <= c;++ i)
				while(!vec[i].empty()){
					int x = vec[i].front(); vec[i].pop();
					if(add[x] != i) continue;
					for(Rint j = head[x];j;j = nxt[j]){
						int tmp = dis[x] + add[x] + w[j] - dis[to[j]];
						if(chmin(add[to[j]], tmp)) vec[tmp].push(to[j]);
					}
				}
			for(Rint i = 1;i <= n;++ i) if(add[i] <= c) dis[i] += add[i];
		}
	}
}


#include<bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
#define EB emplace_back
#define PB push_back
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
typedef long long LL;
const int N=100005;
const LL INF=0X3F3F3F3F3F3F3F3FLL;
int n,m,Q,dis[N];
LL d[N];
int pp,lnk[N],nxt[N],to[N],we[N];
void ae(int k1,int k2,int k3){
	to[++pp]=k2,we[pp]=k3,nxt[pp]=lnk[k1],lnk[k1]=pp;
}
void dij(){
	priority_queue<pair<LL,int> >q;
	auto push=[&](int x){q.emplace(-d[x],x);};
	vector<bool>vis(n+1);
	memset(d,63,sizeof(d)),d[1]=0;
	push(1);
	while(!q.empty()){
		int k1=q.top().se;q.pop();
		if(vis[k1])continue;
		vis[k1]=1;
		for(int i=lnk[k1];i;i=nxt[i])if(d[k1]+we[i]<d[to[i]]){
			d[to[i]]=d[k1]+we[i];
			push(to[i]);
		}
	}
	rep(k1,1,n)for(int i=lnk[k1];i;i=nxt[i]){
		we[i]-=d[to[i]]-d[k1];
	}
}
vector<int>A[N];
void redij(){
	rep(i,0,n)A[i].clear();
	memset(dis,63,sizeof(dis));
	dis[1]=0,A[0].EB(1);
	rep(cur,0,n){
		rep(_,0,SZ(A[cur])-1){
			int k1=A[cur][_];
			if(dis[k1]!=cur)continue;
			for(int i=lnk[k1];i;i=nxt[i]){
				if(dis[k1]+we[i]<dis[to[i]]){
					if((dis[to[i]]=dis[k1]+we[i])<=n){
						A[dis[to[i]]].EB(to[i]);
					}
				}
			}
		}
	}
	rep(k1,1,n)d[k1]+=dis[k1];
	rep(k1,1,n)for(int i=lnk[k1];i;i=nxt[i])we[i]-=dis[to[i]]-dis[k1];
}
int main(){
	scanf("%d%d%d",&n,&m,&Q);
	rep(i,1,m){
		int k1,k2,k3;scanf("%d%d%d",&k1,&k2,&k3);
		ae(k1,k2,k3);
	}
	dij();
	rep(_,1,Q){
		int o,k1;scanf("%d%d",&o,&k1);
		if(o==1){
			printf("%lld\n",d[k1]>1e18?-1LL:d[k1]);
		}else{
			rep(i,1,k1){
				int k2;scanf("%d",&k2);
				++we[k2];
			}
			redij();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
#define EB emplace_back
#define PB push_back
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
typedef long long LL;
const int N=100005;
const LL INF=0X3F3F3F3F3F3F3F3FLL;
int n,m,Q,dis[N];
LL d[N];
int pp,lnk[N],nxt[N],to[N],we[N];
void ae(int k1,int k2,int k3){
	to[++pp]=k2,we[pp]=k3,nxt[pp]=lnk[k1],lnk[k1]=pp;
}
void dij(){
	priority_queue<pair<LL,int> >q;
	auto push=[&](int x){q.emplace(-d[x],x);};
	vector<bool>vis(n+1);
	memset(d,63,sizeof(d)),d[1]=0;
	push(1);
	while(!q.empty()){
		int k1=q.top().se;q.pop();
		if(vis[k1])continue;
		vis[k1]=1;
		for(int i=lnk[k1];i;i=nxt[i])if(d[k1]+we[i]<d[to[i]]){
			d[to[i]]=d[k1]+we[i];
			push(to[i]);
		}
	}
	rep(k1,1,n)for(int i=lnk[k1];i;i=nxt[i]){
		we[i]-=d[to[i]]-d[k1];
	}
}
vector<int>A[N];
void redij(){
	rep(i,1,n)A[i].clear();
	memset(dis,63,sizeof(dis));
	dis[1]=0,A[0].EB(1);
	rep(cur,0,n){
		rep(_,0,SZ(A[cur])-1){
			int k1=A[cur][_];
			if(dis[k1]!=cur)continue;
			for(int i=lnk[k1];i;i=nxt[i]){
				if(dis[k1]+we[i]<dis[to[i]]){
					if((dis[to[i]]=dis[k1]+we[i])<=n){
						A[dis[to[i]]].EB(to[i]);
					}
				}
			}
		}
	}
	rep(k1,1,n)d[k1]+=dis[k1];
	rep(k1,1,n)for(int i=lnk[k1];i;i=nxt[i])we[i]-=dis[to[i]]-dis[k1];
}
int main(){
	scanf("%d%d%d",&n,&m,&Q);
	rep(i,1,m){
		int k1,k2,k3;scanf("%d%d%d",&k1,&k2,&k3);
		ae(k1,k2,k3);
	}
	dij();
	rep(_,1,Q){
		int o,k1;scanf("%d%d",&o,&k1);
		if(o==1){
			printf("%lld\n",d[k1]>1e18?-1LL:d[k1]);
		}else{
			rep(i,1,k1){
				int k2;scanf("%d",&k2);
				++we[k2];
			}
			redij();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define cs const
#define fr first
#define se second
//#define ls (now<<1)
//#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define Mid ((l + r) / 2)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 1e6 + 1;
cs ll inf = 1e17 + 1;
cs int M = 1e9 + 7;
cs double eps = 1e-7;
cs int mod = 998244353;
inline int read() { int x; scanf("%lld", &x); return x; }

int fir[ff], nex[ff], to[ff], tot;
ll va[ff], va2[ff];
void add(int x, int y, ll z) { nex[++tot] = fir[x]; fir[x] = tot; to[tot] = y; va[tot] = z; }
void ade(int x, int y, ll z) { add(x, y, z); add(y, x, z); }

int id[ff];
queue<int> Q[100006];

int N;
int n, m, q;
struct Node
{
	int vis[ff];
	ll dis[ff], f[ff];
	void solve2()
	{
		rep(i, 1, n) f[i] = inf, vis[i] = 0;
		Q[0].push(1); f[1] = 0;
		rep(i, 0, N)
			while(!Q[i].empty())
			{
				int u = Q[i].front(); Q[i].pop();
				if(vis[u]) continue;
				vis[u] = 1;
				fore(j, u)
				{
					int v = to[j];
					ll w = dis[u] - dis[v] + va[j] + va2[j];
					if(f[u] + w < f[v] && f[u] + w <= N)
						f[v] = f[u] + w, Q[f[v]].push(v);
				}
			}
		rep(i, 1, n) dis[i] = min(inf, f[i] + dis[i]), f[i] = inf;
	}
	void solve()
	{
		priority_queue<pair<int, int> > qs;
		rep(i, 1, n) dis[i] = inf, vis[i] = 0;
		dis[1] = 0; qs.push(mp(0, 1));
		while(!qs.empty())
		{
			int u = qs.top().se; qs.pop();
			if(vis[u]) continue;
			vis[u] = 1;
			fore(i, u)
				if(dis[to[i]] > dis[u] + va[i])
					dis[to[i]] = dis[u] + va[i], qs.push(mp(-dis[to[i]], to[i]));
		}
	}
}dij;

void init()
{
	cin >> n >> m >> q;
	N = n; int u, v; ll w;
	rep(i, 1, m) scanf("%d %d %lld", &u, &v, &w), add(u, v, w), id[i] = tot;
	dij.solve();
	rep(i, 1, q)
	{
		int x, y; scanf("%d %d", &x, &y);
		if(x == 1)
		{
			if(dij.dis[y] >= inf) { puts("-1"); }
			else printf("%lld\n", dij.dis[y]);
			continue;
		}
		rep(j, 1, y)
		{
			int xx; scanf("%d", &xx);
			va2[id[xx]] ++;
		}
		dij.solve2();
	}
}
signed main()
{
	int Ts = 1;
//	cin >> Ts;
	while(Ts--)
		init();
}
/*
3 2 9
1 2 0
2 3 0
2 1 2
1 3
1 2
2 1 1
1 3
1 2
2 2 1 2
1 3
1 2
*/


#include<bits/stdc++.h>
#define ll long long
#define inf 10000000000000000ll
using namespace std;
struct node {
	ll v,next,w;
} g[200005];
int head[200005],cnt;
void add(int u,int v,int w) {
	g[++cnt]=(node) {
		v,head[u],w
	};
	head[u]=cnt;
}
int read() {
	char c=getchar();
	int x=0;
	while(!isdigit(c))	c=getchar();
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x;
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
bool vis[100005];
int n,m,Q;
ll dis[100005];
void dijkstra() {
	for(int i=1;i<=n;i++)	dis[i]=inf;
	q.push(make_pair(0,1));
	dis[1]=0;
	while(!q.empty()) {
		int u=q.top().second;
		q.pop();
		if(vis[u])	continue;
		vis[u]=1;
		for(int i=head[u]; i; i=g[i].next) {
			int v=g[i].v,w=g[i].w;
			if(dis[v]>dis[u]+w) {
				dis[v]=dis[u]+w;
				q.push(make_pair(dis[v],v));
			}
		}
	}
}
queue<int>p[100005];
ll ad[100005];
int x,y,z,k,cmd;
void new_dijkstra() {
	for(int i=1;i<=n;i++)	ad[i]=inf;
	int maxv=0;
	ad[1]=0;
	p[0].push(1);
	for(int i=0; i<=maxv; i++) {
		while(!p[i].empty()) {
			int u=p[i].front();
			p[i].pop();
			if(ad[u]<i)    continue;
			for(int j=head[u]; j; j=g[j].next) {
				int v=g[j].v,w=g[j].w;
				int t=ad[u]+dis[u]-dis[v]+w;
				if(ad[v]>t) {
					ad[v]=t;
					if(t>min(k,n-1))	continue;
					p[t].push(v);
					maxv=max(maxv,t);
				}
			}
		}
	}
	for(int i=1; i<=n; i++)	dis[i]=min(inf,dis[i]+ad[i]);
}
int main() {
	n=read(),m=read(),Q=read();
	for(int i=1; i<=m; i++) {
		x=read(),y=read(),z=read();
		add(x,y,z);
	}
	dijkstra();
	while(Q--) {
		cmd=read();
		if(cmd==1) {
			x=read();
			if(dis[x]>inf)	printf("%d\n",-1);
			else printf("%d\n",dis[x]);
			continue;
		}
		k=read();
		for(int i=1; i<=k; i++) {
			x=read();
			g[x].w++;
		}
		new_dijkstra();
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define INF 10000000000000000ll
#define maxn 100005
using namespace std;
int n,m,q;
long long dis[maxn];
long long delta[maxn];
struct edge {
	int from;
	int to;
	int next;
	int len;
} E[maxn<<1];
int head[maxn];
int size=0;
void add_edge(int u,int v,int w) {
	size++;
	E[size].from=u;
	E[size].to=v;
	E[size].len=w;
	E[size].next=head[u];
	head[u]=size;
}

struct node {
	int x;
	long long d;
	node() {}
	node(int u,long long v) {
		x=u;
		d=v;
	}
	friend bool operator <(node u,node v) {
		return u.d>v.d;
	}
};
void dijkstra() {
	priority_queue<node>heap;
	for(int i=1; i<=n; i++) dis[i]=INF;
	dis[1]=0;
	heap.push(node(1,0));
	while(!heap.empty()) {
		int x=heap.top().x;
		heap.pop();
		for(int i=head[x]; i; i=E[i].next) {
			int y=E[i].to;
			if(dis[x]+E[i].len<dis[y]) {
				dis[y]=dis[x]+E[i].len;
				heap.push(node(y,dis[y]));
			}
		}
	}
}

queue<int>Q[maxn];
void new_dijkstra(int k) {
	int maxv=0;
	for(int i=1; i<=n; i++) {
		delta[i]=INF;
	}
	delta[1]=0;
	Q[0].push(1);
	for(int i=0; i<=maxv; i++) {
		while(!Q[i].empty()) {
			int x=Q[i].front();
			Q[i].pop();
			if(delta[x]<i) continue;
			for(int j=head[x]; j; j=E[j].next) {
				int t=delta[x]+(dis[x]-dis[E[j].to]+E[j].len);
				if(t<delta[E[j].to]) {
					delta[E[j].to]=t;
					if(t<=min(k,n-1)) {
						Q[t].push(E[j].to);
						maxv=max(maxv,t);
					}
				}
			}
		}
	}

	for(int i=1; i<=n; i++) dis[i]=min(INF,dis[i]+delta[i]);
}

int main() {

	int u,v,w;
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1; i<=m; i++) {
		scanf("%d %d %d",&u,&v,&w);
		add_edge(u,v,w);
	}
	dijkstra();
	int cmd,k,x;
	for(int i=1; i<=q; i++) {
		scanf("%d",&cmd);
		if(cmd==1) {
			scanf("%d",&x);
			if(dis[x]<INF) printf("%lld\n",dis[x]);
			else printf("-1\n");
		} else {
			scanf("%d",&k);
			for(int i=1; i<=k; i++) {
				scanf("%d",&x);
				E[x].len++;
			}
			new_dijkstra(k);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const
#define fr first
#define se second
//#define ls (now<<1)
//#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define Mid ((l + r) / 2)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 1e6 + 1;
cs int inf = 1e17 + 1;
cs int M = 1e9 + 7;
cs double eps = 1e-7;
cs int mod = 998244353;
inline int read() { int x; scanf("%lld", &x); return x; }

int fir[ff], nex[ff], to[ff], tot, va[ff], va2[100001];
void add(int x, int y, int z) { nex[++tot] = fir[x]; fir[x] = tot; to[tot] = y; va[tot] = z; }
void ade(int x, int y, int z) { add(x, y, z); add(y, x, z); }

int id[ff];
queue<int> Q[200006];

int N;
int n, m, q;
struct Node
{
	int vis[ff], dis[ff], f[ff];
	void solve2()
	{
		rep(i, 1, n) f[i] = inf, vis[i] = 0;
		Q[0].push(1); f[1] = 0;
		rep(i, 0, N)
			while(!Q[i].empty())
			{
				int u = Q[i].front(); Q[i].pop();
				if(vis[u]) continue;
				vis[u] = 1;
				fore(i, u)
				{
					int v = to[i];
					int w = dis[u] - dis[v] + va[i] + va2[i];
					if(f[u] + w < f[v] && f[u] + w <= N)
						f[v] = f[u] + w, Q[f[v]].push(v);
				}
			}
		rep(i, 1, n) dis[i] = min(inf, f[i] + dis[i]), f[i] = inf;
	}
	void solve()
	{
		priority_queue<pair<int, int> > qs;
		rep(i, 1, n) dis[i] = inf, vis[i] = 0;
		dis[1] = 0; qs.push(mp(0, 1));
		while(!qs.empty())
		{
			int u = qs.top().se; qs.pop();
			if(vis[u]) continue;
			vis[u] = 1;
			fore(i, u)
				if(dis[to[i]] > dis[u] + va[i])
					dis[to[i]] = dis[u] + va[i], qs.push(mp(-dis[to[i]], to[i]));
		}
	}
}dij;

void init()
{
	cin >> n >> m >> q;
	N = n + n; int u, v, w;
	rep(i, 1, m) scanf("%lld %lld %lld", &u, &v, &w), add(u, v, w), id[i] = tot;
	dij.solve();
	rep(i, 1, q)
	{
		int x, y; scanf("%lld %lld", &x, &y);
		if(x == 1)
		{
			if(dij.dis[y] >= inf) { puts("-1"); }
			else printf("%lld\n", dij.dis[y] /*+ dij.f[y]*/ );
			continue;
		}
		rep(j, 1, y)
		{
			int xx; scanf("%lld", &xx);
			va2[id[xx]] ++;
		}
		dij.solve2();
	//	cn(va2);
	}
}
signed main()
{
	int Ts = 1;
//	cin >> Ts;
	while(Ts--)
		init();
}
/*
3 2 9
1 2 0
2 3 0
2 1 2
1 3
1 2
2 1 1
1 3
1 2
2 2 1 2
1 3
1 2
*/


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define int long long
using namespace std;
const int maxn=1e5+10;
const int INF=0x3f3f3f3f3f3f3f3f;
int n,m,Q;
int tot,head[maxn],val[maxn],nxt[maxn],to[maxn];
priority_queue<pair<int,int> >q;
int v[maxn],dist[maxn];
queue<int> t[maxn];
int f[maxn],maxx;
void add(int x,int y,int z)
{
    to[++tot]=y;
    nxt[tot]=head[x];
    val[tot]=z;
    head[x]=tot;
}
void dijkstra()
{
    memset(dist,0x3f,sizeof(dist));
    memset(v,0,sizeof(v));
    q.push(make_pair(0,1));
    dist[1]=0;
    while(!q.empty())
    {
        int x=q.top().second;
        if(v[x])
        {
            q.pop();
            continue;
        }
        x=q.top().second;q.pop();v[x]=1;
        for(int i=head[x];i;i=nxt[i])
        {
            int y=to[i];
            if(dist[y]>dist[x]+val[i])
                dist[y]=dist[x]+val[i],q.push(make_pair(-dist[y],y));
        }
    }
}
void bfs(int v)
{
    maxx=0;
    for(int i=0;i<=maxx;i++)
        while(!t[i].empty())
        {
            int x=t[i].front();
            t[i].pop();
            if(f[x]<i)
                continue;
            for(int i=head[x];i;i=nxt[i])
            {
                int y=to[i];
                int z=dist[x]+val[i]-dist[y];
                if(f[y]>f[x]+z)
                {
                    f[y]=f[x]+z;
                    if(f[y]<=min(v,n-1))
                    {
                        t[f[y]].push(y);
                        maxx=max(maxx,f[y]);
                    }
                }
            }
        }
}
signed main()
{
    scanf("%I64d%I64d%I64d",&n,&m,&Q);
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        scanf("%I64d%I64d%I64d",&x,&y,&z);
        add(x,y,z);
    }
    dijkstra();
    while(Q--)
    {
        int opt,v,c;
        scanf("%I64d%I64d",&opt,&v);
        if(opt==1)
        {
            if(dist[v]>INF)
            {
                puts("-1");
                continue;
            }
            printf("%I64d\n",dist[v]);
        }
        else
        {
            for(int i=1;i<=v;i++)
            {
                int a;
                scanf("%I64d",&a);
                val[a]++;
            }
            memset(f,0x3f,sizeof(f));
            f[1]=0;
            t[0].push(1);
            bfs(v);
            for(int i=1;i<=n;i++)
                dist[i]=min(INF,f[i]+dist[i]);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
#define ri register int
#define For(i,a,b) for(ri i=(a);i<=(b);++i)
#define DFor(i,a,b) for(ri i=(a);i>=(b);--i)
template<class T>inline T Max(register T a,register T b){return a>b?a:b;}
template<class T>inline T Min(register T a,register T b){return a<b?a:b;}
const int MAXN=100005;const long long INF=0x7ffffffffffffll;
int n,m,Q,tot,h,t,mx;
int head[MAXN];
long long dis[MAXN],f[MAXN];
bool vis[MAXN];
struct edge{int v,w,nxt;}e[MAXN<<1];
struct node{
	int u;long long w;
	friend bool operator <(const node n1,const node n2){return n1.w>n2.w;}
};
template<class T>inline void read(T&x){
 char ch=getchar();x=0;
   while(!isdigit(ch))ch=getchar();
   while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
}
inline void add(int u,int v,int w){++tot;e[tot]=(edge){v,w,head[u]};head[u]=tot;}
priority_queue<node> qn;
inline void dijkstra(){
	For(i,2,n)dis[i]=INF;
	qn.push((node){1,0});dis[1]=0;
	while(!qn.empty()){
		node h=qn.top();qn.pop();
		int u=h.u;if(vis[u])continue;
		vis[u]=1;
		for(ri i=head[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(dis[v]>dis[u]+e[i].w){
				dis[v]=dis[u]+e[i].w;
				qn.push((node){v,dis[v]});
			}
		}
	}
}
queue<int> q[MAXN];
inline void updata(){
	For(i,1,n)vis[i]=0;
	q[0].push(1);
	For(k,0,mx){
		while(!q[k].empty()){
			int u=q[k].front();q[k].pop();vis[u]=1;
			//printf("%d %lld\n",u,f[u]);
			for(ri i=head[u];i;i=e[i].nxt){
				int v=e[i].v,w=e[i].w-dis[v]+dis[u];
				if(!vis[v]){
					f[v]=f[u]+w;
					//printf("#%d->%d %lld\n",u,v,f[v]);
					if(f[v]>mx)continue;
					q[f[v]].push(v);
				}
			}
		}
	}
	//For(i,1,n)printf("%lld ",dis[i]);printf("->");
	For(i,1,n)dis[i]+=f[i];
	//For(i,1,n)printf("%lld ",dis[i]);puts("");
}
int main(){
	read(n),read(m),read(Q);//N=n<<1;
	For(i,1,m){
		int u,v,w;read(u),read(v),read(w);
		add(u,v,w);
	}
	dijkstra();
	//For(i,1,n)printf("%lld ",dis[i]);puts("");
	while(Q--){
		int opt,k;read(opt),read(k);
		if(opt==1)printf("%lld\n",dis[k]>=INF?-1ll:dis[k]);
		else {
			int x;
			For(i,1,k)read(x),++e[x].w;
			mx=Min(k,n-1);
			updata();
		}
	}
 return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 10000000000000000ll
using namespace std;
struct node {
	ll v,next,w;
} g[200005];
int head[200005],cnt;
void add(int u,int v,int w) {
	g[++cnt]=(node) {
		v,head[u],w
	};
	head[u]=cnt;
}
int read() {
	char c=getchar();
	int x=0;
	while(!isdigit(c))	c=getchar();
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x;
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
bool vis[100005];
int n,m,Q;
ll dis[100005];
void dijkstra() {
	for(int i=1;i<=n;i++)	dis[i]=inf;
	q.push(make_pair(0,1));
	dis[1]=0;
	while(!q.empty()) {
		int u=q.top().second;
		q.pop();
		if(vis[u])	continue;
		vis[u]=1;
		for(int i=head[u]; i; i=g[i].next) {
			int v=g[i].v,w=g[i].w;
			if(dis[v]>dis[u]+w) {
				dis[v]=dis[u]+w;
				q.push(make_pair(dis[v],v));
			}
		}
	}
}
queue<int>p[100005];
ll ad[100005];
int x,y,z,k,cmd;
void new_dijkstra(int k) {
	for(int i=1;i<=n;i++)	ad[i]=inf;
	int maxv=0;
	ad[1]=0;
	p[0].push(1);
	for(int i=0; i<=maxv; i++) {
		while(!p[i].empty()) {
			int u=p[i].front();
			p[i].pop();
			if(ad[u]<i)    continue;
			for(int j=head[u]; j; j=g[j].next) {
				int v=g[j].v,w=g[j].w;
				int t=ad[u]+dis[u]-dis[v]+w;
				if(ad[v]>t) {
					ad[v]=t;
					if(t>min(k,n-1))	continue;
					p[t].push(v);
					maxv=max(maxv,t);
				}
			}
		}
	}
	for(int i=1; i<=n; i++)	dis[i]=min(inf,dis[i]+ad[i]);
}
int main() {
	n=read(),m=read(),Q=read();
	for(int i=1; i<=m; i++) {
		x=read(),y=read(),z=read();
		add(x,y,z);
	}
	dijkstra();
	while(Q--) {
		cmd=read();
		if(cmd==1) {
			x=read();
			if(dis[x]>=inf)	printf("%d\n",-1);
			else printf("%lld\n",dis[x]);
			continue;
		}
		k=read();
		for(int i=1; i<=k; i++) {
			x=read();
			g[x].w++;
		}
		new_dijkstra(k);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const
#define fr first
#define se second
//#define ls (now<<1)
//#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define Mid ((l + r) / 2)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 1e6 + 1;
cs int inf = 1e17 + 1;
cs int M = 1e9 + 7;
cs double eps = 1e-7;
cs int mod = 998244353;
inline int read() { int x; scanf("%lld", &x); return x; }

int fir[ff], nex[ff], to[ff], tot, va[ff], va2[ff];
void add(int x, int y, int z) { nex[++tot] = fir[x]; fir[x] = tot; to[tot] = y; va[tot] = z; }
void ade(int x, int y, int z) { add(x, y, z); add(y, x, z); }

int id[ff];
queue<int> Q[200006];

int N;
int n, m, q;
struct Node
{
	int vis[ff], dis[ff], f[ff];
	void solve2()
	{
		rep(i, 1, n) f[i] = inf, vis[i] = 0;
		Q[0].push(1); f[1] = 0;
		rep(i, 0, N)
			while(!Q[i].empty())
			{
				int u = Q[i].front(); Q[i].pop();
				if(vis[u]) continue;
				vis[u] = 1;
				fore(j, u)
				{
					int v = to[j];
					int w = dis[u] - dis[v] + va[j] + va2[j];
					if(f[u] + w < f[v] && f[u] + w <= N)
						f[v] = f[u] + w, Q[f[v]].push(v);
				}
			}
		rep(i, 1, n) dis[i] = min(inf, f[i] + dis[i]), f[i] = inf;
	}
	void solve()
	{
		priority_queue<pair<int, int> > qs;
		rep(i, 1, n) dis[i] = inf, vis[i] = 0;
		dis[1] = 0; qs.push(mp(0, 1));
		while(!qs.empty())
		{
			int u = qs.top().se; qs.pop();
			if(vis[u]) continue;
			vis[u] = 1;
			fore(i, u)
				if(dis[to[i]] > dis[u] + va[i])
					dis[to[i]] = dis[u] + va[i], qs.push(mp(-dis[to[i]], to[i]));
		}
	}
}dij;

void init()
{
	cin >> n >> m >> q;
	N = n + n; int u, v, w;
	rep(i, 1, m) scanf("%lld %lld %lld", &u, &v, &w), add(u, v, w), id[i] = tot;
	dij.solve();
	rep(i, 1, q)
	{
		int x, y; scanf("%lld %lld", &x, &y);
		if(x == 1)
		{
			if(dij.dis[y] >= inf) { puts("-1"); }
			else printf("%lld\n", dij.dis[y]);
			continue;
		}
		rep(j, 1, y)
		{
			int xx; scanf("%lld", &xx);
			va2[id[xx]] ++;
		}
		dij.solve2();
	}
}
signed main()
{
	int Ts = 1;
//	cin >> Ts;
	while(Ts--)
		init();
}
/*
3 2 9
1 2 0
2 3 0
2 1 2
1 3
1 2
2 1 1
1 3
1 2
2 2 1 2
1 3
1 2
*/


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define int unsigned long long

int n,m,q;
int dist[100001];
bool vist[100001],chavist[100001];

inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

struct id{
    int v,nxt;
}num[100001],antinum[100001];

struct node{
    int v,d;
    node(){}
    node(int vv,int dd){v=vv;d=dd;}
    bool operator < (const node &a) const{
        return a.d<d;
    }
};

vector<node> v[100001],antiv[100001];

void dij()
{
    int i;
    priority_queue<node> q;
    q.push(node(1,0));
    while(!q.empty())
    {
        node a=q.top();
        q.pop();
        for(i=0;i<v[a.v].size();i++)
        {
            node b=v[a.v][i];
            vist[b.v]=true;
            if(a.d+b.d<dist[b.v])
            {
                dist[b.v]=a.d+b.d;
                q.push(node(b.v,dist[b.v]));
            }
        }
    }
}

void change(int x)
{
    int i;
    chavist[x]=true;
    for(i=0;i<v[x].size();i++)
    {
        node a=v[x][i];
        if(dist[x]+a.d==dist[a.v]) change(a.v);
    }
    dist[x]++;
    for(i=0;i<antiv[x].size();i++)
    {
        node a=antiv[x][i];
        if(!chavist[a.v]) dist[x]=min(dist[a.v]+a.d,dist[x]);
        else dist[x]=min(dist[x],dist[a.v]+1+a.d);
    }
    chavist[x]=false;
}

signed main()
{
    int i,x,y,l;
    int add=0;
    n=read();
    m=read();
    q=read();
    memset(dist,127,sizeof(dist));
    memset(vist,false,sizeof(vist));
    memset(chavist,false,sizeof(chavist));
    for(i=1;i<=m;i++)
    {
        x=read();
        y=read();
        l=read();
        v[x].push_back(node(y,l));
        antiv[y].push_back(node(x,l));
        num[i].v=x;
        num[i].nxt=v[x].size()-1;
        antinum[i].v=y;
        antinum[i].nxt=antiv[y].size()-1;
    }
    dist[1]=0;
    dij();
    for(i=1;i<=q;i++)
    {
        int typ;
        typ=read();
        if(typ==1)
        {
            int to;
            to=read();
            if(to==1){cout<<0<<endl;continue;}
            if(!vist[to]) cout<<-1<<endl;
            else cout<<dist[to]+add<<endl;
        }
        else
        {
            int k,a;
            k=read();
            for(int j=1;j<=k;j++)
            {
                a=read();
                node b=v[num[a].v][num[a].nxt];
                antiv[antinum[a].v][antinum[a].nxt].d++;
                if(num[a].v==1&&v[1].size()==1)
                {
                    add++;
                    v[num[a].v][num[a].nxt].d++;
                    continue;
                }
                if(dist[b.v]==dist[num[a].v]+b.d)
                {
                    memset(chavist,false,sizeof(chavist));
                    change(b.v);
                }
                v[num[a].v][num[a].nxt].d++;
            }
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define INF 10000000000000000ll
#define maxn 100005
using namespace std;
int n,m,q;
long long dis[maxn];
long long delta[maxn];
struct edge {
	int from;
	int to;
	int next;
	int len;
} E[maxn<<1];
int head[maxn];
int size=0;
void add_edge(int u,int v,int w) {
	size++;
	E[size].from=u;
	E[size].to=v;
	E[size].len=w;
	E[size].next=head[u];
	head[u]=size;
}

struct node {
	int x;
	long long d;
	node() {

	}
	node(int u,long long v) {
		x=u;
		d=v;
	}
	friend bool operator <(node u,node v) {
		return u.d>v.d;
	}
};
void dijkstra() {
	priority_queue<node>heap;
	for(int i=1; i<=n; i++) dis[i]=INF;
	dis[1]=0;
	heap.push(node(1,0));
	while(!heap.empty()) {
		int x=heap.top().x;
		heap.pop();
		for(int i=head[x]; i; i=E[i].next) {
			int y=E[i].to;
			if(dis[x]+E[i].len<dis[y]) {
				dis[y]=dis[x]+E[i].len;
				heap.push(node(y,dis[y]));
			}
		}
	}
}

queue<int>Q[maxn];
void new_dijkstra(int k) {
	int maxv=0;
	for(int i=1; i<=n; i++) {
		delta[i]=INF;
	}
	delta[1]=0;
	Q[0].push(1);
	for(int i=0; i<=maxv; i++) {
		while(!Q[i].empty()) {
			int x=Q[i].front();
			Q[i].pop();
			if(delta[x]<i) continue;
			for(int j=head[x]; j; j=E[j].next) {
				int t=delta[x]+(dis[x]-dis[E[j].to]+E[j].len);
				if(t<delta[E[j].to]) {
					delta[E[j].to]=t;
					if(t<=min(k,n-1)) {
						Q[t].push(E[j].to);
						maxv=max(maxv,t);
					}
				}
			}
		}
	}

	for(int i=1; i<=n; i++) dis[i]=min(INF,dis[i]+delta[i]);
}

int main() {
//	freopen("visit.in","r",stdin);
//	freopen("visit.out","w",stdout);

	int u,v,w;
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1; i<=m; i++) {
		scanf("%d %d %d",&u,&v,&w);
		add_edge(u,v,w);
	}
	dijkstra();
	int cmd,k,x;
	for(int i=1; i<=q; i++) {
		scanf("%d",&cmd);
		if(cmd==1) {
			scanf("%d",&x);
			if(dis[x]<INF) printf("%lld\n",dis[x]);
			else printf("-1\n");
		} else {
			scanf("%d",&k);
			for(int i=1; i<=k; i++) {
				scanf("%d",&x);
				E[x].len++;
			}
			new_dijkstra(k);
		}
	}
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define int long long
using namespace std;
const int maxn=1e5+10;
const int INF=1e9;
int n,m,Q;
int tot,head[maxn],val[maxn],nxt[maxn],to[maxn];
priority_queue<pair<int,int> >q;
int v[maxn],dist[maxn];
queue<int> t[maxn];
int f[maxn],maxx;
void add(int x,int y,int z)
{
    to[++tot]=y;
    nxt[tot]=head[x];
    val[tot]=z;
    head[x]=tot;
}
void dijkstra()
{
    memset(dist,0x3f,sizeof(dist));
    memset(v,0,sizeof(v));
    q.push(make_pair(0,1));
    dist[1]=0;
    while(!q.empty())
    {
        int x=q.top().second;
        if(v[x])
        {
            q.pop();
            continue;
        }
        x=q.top().second;q.pop();v[x]=1;
        for(int i=head[x];i;i=nxt[i])
        {
            int y=to[i];
            if(dist[y]>dist[x]+val[i])
                dist[y]=dist[x]+val[i],q.push(make_pair(-dist[y],y));
        }
    }
}
void bfs(int v)
{
    maxx=0;
    for(int i=0;i<=maxx;i++)
        while(!t[i].empty())
        {
            int x=t[i].front();
            t[i].pop();
            if(f[x]<i)
                continue;
            for(int i=head[x];i;i=nxt[i])
            {
                int y=to[i];
                int z=dist[x]+val[i]-dist[y];
                if(f[y]>f[x]+z)
                {
                    f[y]=f[x]+z;
                    if(f[y]<=min(v,n-1))
                    {
                        t[f[y]].push(y);
                        maxx=max(maxx,f[y]);
                    }
                }
            }
        }
}
signed main()
{
    scanf("%d%d%d",&n,&m,&Q);
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        add(x,y,z);
    }
    dijkstra();
    while(Q--)
    {
        int opt,v,c;
        scanf("%d%d",&opt,&v);
        if(opt==1)
        {
            if(dist[v]>INF)
            {
                puts("-1");
                continue;
            }
            printf("%d\n",dist[v]);
        }
        else
        {
            for(int i=1;i<=v;i++)
            {
                int a;
                scanf("%d",&a);
                val[a]++;
            }
            memset(f,0x3f,sizeof(f));
            f[1]=0;
            t[0].push(1);
            bfs(v);
            for(int i=1;i<=n;i++)
                dist[i]=min(INF,f[i]+dist[i]);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 200007
int read() {
	char ch;
	int sum=0,f=1;
	ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		sum=sum*10+(ch-'0');
		ch=getchar();
	}
	return f*sum;
}
struct xl {
	ll di,id;
} p,o;
priority_queue<xl> que;
bool operator < (xl a,xl b) {
	return a.di>b.di;
}
struct zzst {
	int to,nxt,w;
} edge[maxn];
int head[maxn];
ll dis[maxn];
ll dt[maxn];
const ll INF=999999999999999;
bool book[maxn];
int cnt;
int n,m,s,l;
void init() {
	memset(dis,0x7f,sizeof(dis));
	dis[1]=0;
}
void add(int u,int v,int w) {
	edge[++cnt].to=v;
	edge[cnt].nxt=head[u];
	edge[cnt].w=w;
	head[u]=cnt;
}
void dij() {
	init();
	p.id=1;
	p.di=0;
	que.push(p);
	while(!que.empty()) {
		o=que.top();
		que.pop();
		int u=o.id;
		if(book[u]) continue;
		book[u]=1;
		for(int i=head[u]; i; i=edge[i].nxt) {
			int v=edge[i].to;
			int w=edge[i].w;
			if(dis[v]>dis[u]+w) {
				dis[v]=dis[u]+w;
				p.id=v;
				p.di=dis[v];
				que.push(p);
			}
		}
	}
//	cout<<"dis  ";
//	for(int i=1;i<=n;i++) cout<<dis[i]<<" ";
//	cout<<endl;
}
queue<ll> q[maxn];
void bfs(int k){
	memset(dt,0x7f,sizeof(dt));
	dt[1]=0;
	int madt=0;
	q[0].push(1);
	for(int j=0;j<=madt;j++){
		while(!q[j].empty()){
			int u=q[j].front();
			q[j].pop();
			if(dt[u]<j) continue;
			for(int i=head[u];i;i=edge[i].nxt){
				int v=edge[i].to;
				int d=dt[u]+dis[u]-dis[v]+edge[i].w;
				if(d<dt[v]){
					dt[v]=d;
					if(d<=min(k,n-1)){
						q[d].push(v);
						madt=max(madt,d);
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++) dis[i]=min(INF,dis[i]+dt[i]);
}
int main() {
	n=read();
	m=read();
	l=read();
	int u,v,w,k;
	for(int i=1; i<=m; i++) {
		u=read();
		v=read();
		w=read();
		add(u,v,w);
	}
	dij();
	while(l--) {
		u=read();
		v=read();
		if(u==1) {
			if(dis[v]>INF) puts("-1");
			else printf("%lld\n",dis[v]);
		} else {
			for(int i=1;i<=v;i++) {
				k=read();
				edge[k].w++;
			}
			bfs(v);
		}
	}
	return 0;
}
/*
3 2 9
1 2 0
2 3 0
2 1 2
1 3
1 2
2 1 1
1 3
1 2
2 2 1 2
1 3
1 2
*/


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const
#define fr first
#define se second
//#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])

cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e17 + 1;
cs int M = 1e9 + 7;
cs double eps = 1e-7;
inline int read() { int x; scanf("%lld", &x); return x; }

struct DSU
{
	int fa[ff];
	void pre(int N) { rep(i, 1, N) fa[i] = i; }
	int find(int x) { return fa[x] == x? x : fa[x] = find(fa[x]); }
	void merge(int x, int y)
	{
		x = find(x); y = find(y);
		if(x != y) fa[x] = y;
		//x==y?0:fa[x]=y;
	}
}dsu;

int fir[ff], nex[ff], to[ff], tot, va[ff];
void clean() { tot = 0; cn(fir); }
void add(int x, int y, int z)
{
	nex[++tot] = fir[x];
	fir[x] = tot;
	to[tot] = y;
	va[tot] = z;
}
void ade(int x, int y, int z) { add(x, y, z); add(y, x, z); }

int n, m, q, vis[ff], dis[ff];
void dij1()
{
	rep(i, 1, n) dis[i] = inf, vis[i] = 0;
	priority_queue<pair<ll, ll> > q;
	q.push(mp(0, 1)); dis[1] = 0;
	while(!q.empty())
	{
		int u = q.top().se; q.pop();
		if(vis[u]) continue;
		vis[u] = 1;
		fore(i, u)
			if(dis[to[i]] > dis[u] + va[i])
				dis[to[i]] = dis[u] + va[i], q.push(mp(-dis[to[i]], to[i]));
	}
}

pair<ll, ll> id[ff];
int dis2[ff], vis2[ff];
vector<int> tong[ff];
void dij2()
{
	int hd = 0, hd2 = 0;
	rep(i, 1, n) dis2[i] = inf, vis2[i] = 0;
	tong[0].push_back(1); dis2[1] = 0;
	while(hd <= 100000)
	{
		int sz = tong[hd].size(); sz --;
		while(sz < hd2 && hd <= 100000)
			hd ++, hd2 = 0, sz = tong[hd].size(), sz --;

		if(hd > 100000) break;

		int u = tong[hd][hd2]; hd2 ++;
		if(vis2[u]) continue; vis2[u] = 1;
		fore(i, u)
		{
			if(dis2[to[i]] > dis2[u] + va[i])
				dis2[to[i]] = dis2[u] + va[i], tong[dis2[to[i]]].push_back(to[i]);
		}
	}
	rep(i, 1, 100000) tong[i].clear();
}

int u[ff], v[ff], w[ff];
void init()
{
	cin >> n >> m >> q;
	rep(i, 1, m)
	{
		scanf("%lld %lld %lld", &u[i], &v[i], &w[i]);
		ade(u[i], v[i], w[i]);
	}
	dij1(); clean();
	rep(i, 1, m)
	{
		ade(u[i], v[i], min(dis[u[i]] - dis[v[i]], dis[v[i]] - dis[u[i]]) + w[i]);
		id[i] = mp(tot - 1, tot);
	//	cout << "  " << u[i] << " " << v[i] << "\n";
	}
	rep(i, 1, q)
	{
		int x, y, opt; scanf("%lld", &opt);
	//	cout << " " << opt << "\n";
		if(opt == 1)
		{
			dij2(), scanf("%lld", &x);
			if(dis[x] == inf) puts("-1");
			else cout << dis[x] + dis2[x] << "\n";
		}
		else
		{
			scanf("%lld", &y);
			int z;
			rep(j, 1, y) scanf("%lld", &z), va[id[z].fr] ++, va[id[z].se] ++;
		}
	}
}
signed main()
{
//	freopen("xor.in", "r", stdin);
//	freopen("xor.out", "w", stdout);
	int Ts = 1;
	while(Ts--)
		init();
}


#include<bits/stdc++.h>
#define ri register int
using namespace std;

typedef long long ll;

const int N(1e5+5);
const ll INF(1e17);

inline int read(){
	char ch=getchar(); int x=0;
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return x;
}

int n,m,Q,head[N],tot;

ll d[N];

bool b[N];

struct Edge{
	int v,w,next;
}e[N];

inline void add(int u,int v,int w){
	e[++tot].v=v;
	e[tot].w=w;
	e[tot].next=head[u];
	head[u]=tot;
}

void dijkstra(){
	int u,v,w;
	for(ri i=1;i<=n;i++)d[i]=INF,b[i]=0;
	d[1]=0;
	priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >q;
	q.push(make_pair(0,1));
	while(!q.empty()){
		u=q.top().second;
		q.pop();
		if(b[u])continue;
		b[u]=1;
		for(ri i=head[u];i;i=e[i].next){
			v=e[i].v,w=e[i].w;
			if(d[v]>d[u]+w){
				d[v]=d[u]+w;
				q.push(make_pair(d[v],v));
			}
		}
	}
}

int main(){
	int op,u,v,w;
	n=read(),m=read(),Q=read();
	for(ri i=1;i<=m;i++){
		u=read(),v=read(),w=read();
		add(u,v,w);
	}
	while(Q--){
		op=read();
		if(op==1){
			u=read();
			dijkstra();
			cout<<d[u]<<endl;
		}
		else if(op==2){
			op=read();
			for(ri i=1;i<=op;i++){
				u=read();
				e[u].w++;
			}
		}
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define int long long
using namespace std;
const int maxn=1e5+10;
const int INF=0x3f3f3f3f3f3f3f3f;
int n,m,Q;
int tot,head[maxn],val[maxn],nxt[maxn],to[maxn];
priority_queue<pair<int,int> >q;
int v[maxn],dist[maxn];
queue<int> t[maxn];
int f[maxn],maxx;
void add(int x,int y,int z)
{
    to[++tot]=y;
    nxt[tot]=head[x];
    val[tot]=z;
    head[x]=tot;
}
void dijkstra()
{
    memset(dist,0x3f,sizeof(dist));
    memset(v,0,sizeof(v));
    q.push(make_pair(0,1));
    dist[1]=0;
    while(!q.empty())
    {
        int x=q.top().second;
        if(v[x])
        {
            q.pop();
            continue;
        }
        x=q.top().second;q.pop();v[x]=1;
        for(int i=head[x];i;i=nxt[i])
        {
            int y=to[i];
            if(dist[y]>dist[x]+val[i])
                dist[y]=dist[x]+val[i],q.push(make_pair(-dist[y],y));
        }
    }
}
void bfs(int v)
{
    maxx=0;
    for(int i=0;i<=maxx;i++)
        while(!t[i].empty())
        {
            int x=t[i].front();
            t[i].pop();
            if(f[x]<i)
                continue;
            for(int i=head[x];i;i=nxt[i])
            {
                int y=to[i];
                int z=dist[x]+val[i]-dist[y];
                if(f[y]>f[x]+z)
                {
                    f[y]=f[x]+z;
                    if(f[y]<=min(v,n-1))
                    {
                        t[f[y]].push(y);
                        maxx=max(maxx,f[y]);
                    }
                }
            }
        }
}
signed main()
{
    scanf("%I64d%I64d%I64d",&n,&m,&Q);
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        scanf("%I64d%I64d%I64d",&x,&y,&z);
        add(x,y,z);
    }
    dijkstra();
    while(Q--)
    {
        int opt,v,c;
        scanf("%I64d%I64d",&opt,&v);
        if(opt==1)
        {
            if(dist[v]==INF)
            {
                puts("-1");
                continue;
            }
            printf("%I64d\n",dist[v]);
        }
        else
        {
            for(int i=1;i<=v;i++)
            {
                int a;
                scanf("%I64d",&a);
                val[a]++;
            }
            memset(f,0x3f,sizeof(f));
            f[1]=0;
            t[0].push(1);
            bfs(v);
            for(int i=1;i<=n;i++)
                dist[i]=min(INF,f[i]+dist[i]);
        }
    }
    return 0;
}


#include<cstdio>
#include<queue>

using namespace std;

struct pri
{
	int id;long long val;pri(int i=0,long long v=0):id(i),val(v){}
};bool operator<(pri a,pri b){return a.val>b.val;}

struct e
{
	int to;long long val;e(int t=0,long long v=0):to(t),val(v){}
};vector<e> ed[200000];

bool vis[200000];
const long long INF=1e15;
void Dijsktra(int n,int s,long long *dis)
{
	for(int i=1;i<=n;i++)dis[i]=INF;dis[s]=0;priority_queue<pri> pq;pq.push(pri(s,0));
	for(int i=1;i<=n;i++)vis[i]=0;
	while(!pq.empty())
	{
		pri x=pq.top();pq.pop();
		if(vis[x.id])continue;vis[x.id]=1;int u=x.id;//printf("%d\n",x.id);
		for(int i=0;i<ed[u].size();i++)
		{
			int v=ed[u][i].to;//printf("%d\n",v);
			if(dis[u]+ed[u][i].val<dis[v])
			{
				dis[v]=dis[u]+ed[u][i].val;
				pq.push(pri(v,dis[v]));
			}
		}
	}
}

int u[200000],id[200000];
long long dis[200000];

int n=0,m=0,q=0;
void subtract(long long *dis)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<ed[i].size();j++)
		{
			int u=ed[i][j].to;ed[i][j].val=dis[i]+ed[i][j].val-dis[u];
		}
	}
}

vector<int> v[2000000];
void another(int n,int s,long long *dis)
{
	for(int i=1;i<=n;i++)dis[i]=INF;dis[s]=0;v[0].push_back(s);
	for(int i=1;i<=n;i++)vis[i]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<v[i].size();j++)
		{
			int u=v[i][j];if(dis[u]!=i||vis[u])continue;vis[u]=1;
			for(int k=0;k<ed[u].size();k++)
			{
				int w=ed[u][k].to;
				if(dis[u]+ed[u][k].val<n&&dis[u]+ed[u][k].val<dis[w])
				{
					dis[w]=dis[u]+ed[u][k].val;
					if(dis[w]<n)v[dis[w]].push_back(w);
					//puts("???");
				}
			}
		}
	}
	for(int i=0;i<n;i++)v[i].clear();
}

long long dis2[200000];
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&u[i]);id[i]=ed[u[i]].size();
		int v=0,w=0;scanf("%d%d",&v,&w);
		ed[u[i]].push_back(e(v,w));
	}

	/*for(int i=1;i<=n;i++)printf("%lld ",dis[i]);puts("");
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<ed[i].size();j++)printf("%d %d: %d\n",i,ed[i][j].to,ed[i][j].val);
	}*/
	Dijsktra(n,1,dis);subtract(dis);

	while(q--)
	{
		/*for(int i=1;i<=n;i++)
		{
			for(int j=0;j<ed[i].size();j++)printf("%d %d: %d\n",i,ed[i][j].to,ed[i][j].val);
		}*/
		int op=0;scanf("%d",&op);
		if(op==1)
		{
			int x=0;scanf("%d",&x);
			another(n,1,dis2);printf("%lld\n",dis[x]>=INF?-1:dis[x]+dis2[x]);
			//for(int i=1;i<=n;i++)printf("%lld ",dis2[i]);puts("");
			subtract(dis2);for(int i=1;i<=n;i++)dis[i]+=dis2[i];
		}
		else
		{
			int c=0;scanf("%d",&c);
			while(c--)
			{
				int i=0;scanf("%d",&i);ed[u[i]][id[i]].val++;
			}
		}
	}
	return 0;
}
//


#include <bits/stdc++.h>
#define ff first
#define pb push_back
#define err erase
#define mp make_pair
#define ss second
using namespace std;

int main()
{
    long n;
    cin>>n;
    long a[n];
    long b[n];
    vector <long> as;
    vector <long> bs;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    long parts=0;
    for(int i=0;i<n;i++)
    {
        as.pb(a[i]);
        bs.pb(b[i]);
        sort(as.begin(),as.end());
        if(as==bs)
        parts++;
    }
    cout<<parts;

    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define pb push_back
#define err erase
#define mp make_pair
#define ss second
using namespace std;

int main()
{
    long n;
    cin>>n;
    long a[n];
    long b[n+1];

    for(long i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }

    for(int i=n-1;i>0;i--)
    {
        b[i-1]= min(b[i],b[i-1]);
    }
    b[n]=LONG_MAX;
    for(int j=1;j<n;j++)
    {
       a[j] = (max (a[j] , a[j-1]) );
    }

    long parts=0;
    for(long i=0;i<n;i++)
    {
        if(a[i]<=b[i+1])
        parts++;
    }
    cout<<parts;
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define pb push_back
#define err erase
#define mp make_pair
#define ss second
using namespace std;

int main()
{
    long n;
    cin>>n;
    long a[n];
    long b[n];
    set <long> as;
    set <long> bs;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    long parts=0;
    for(int i=0;i<n;i++)
    {
        as.insert(a[i]);
        bs.insert(b[i]);
        if(as==bs)
        parts++;
    }
    cout<<parts;

    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define pb push_back
#define err erase
#define mp make_pair
#define ss second
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    long n;
    cin>>n;
    long a[n];
    long b[n];

    for(long i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }

    for(int i=n-1;i>0;i--)
    {
        b[i-1]= min(b[i],b[i-1]);
    }

    long parts=0;
    for(long j=1;j<n;j++)
    {
       a[j] = (max (a[j] , a[j-1]) );
    }

    for(long i=0;i<n;i++)
    {
        if(a[i]<=b[i+1])
        parts++;

    }
    cout<<parts;
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define pb push_back
#define err erase
#define mp make_pair
#define ss second
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    long n;
    cin>>n;
    long a[n];
    long b[n];

    for(long i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }

    sort(b,b+n);
    long parts=0;
    for(long j=1;j<n;j++)
    {
       a[j] = (max (a[j] , a[j-1]) );
    }

    for(long i=0;i<n;i++)
    {
        if(a[i]==b[i])
        parts++;
    }
    cout<<parts;
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define pb push_back
#define err erase
#define mp make_pair
#define ss second
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    long n;
    cin>>n;
    long a[n];
    long b[n];
    vector <long> as;
    vector <long> bs;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    long parts=0;
    for(int i=0;i<n;i++)
    {
        as.pb(a[i]);
        bs.pb(b[i]);
        sort(as.begin(),as.end());
        if(as==bs)
        {parts++;
            as.erase(as.begin(),as.end());
            bs.erase(bs.begin(),bs.end());
        }
    }
    cout<<parts;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
int f2(){

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

            int max1 = *max_element(a+i,a+k);
            int min2 = *min_element(a+k,a+j);

            if(max1 <= min2){
                  res++;
                   i = k ;

            }

    }
    return res;

}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",a+i);

    }

    cout<<f2()<<endl;

//    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001],m[100001];
int f2(){
    int res = 1 ;
    int max1 = -1 * (1<<30);
    int min2 = 1<<30;
    for(int k=0;k<n;k++){
         max1 = max(max1,a[k]);
         min2 =  m[k+1] ;
        if(max1 <= min2){
                res++;
                max1 = a[k+1];
            }
    }
    return res;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
    }
    int minx = 1<<30 ;
    for(int i=n-1;i>=0;i--){
        minx = min(a[i],minx);

        m[i] = minx ;
    }
    cout<<f2()<<endl;
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];

int memo[10000][10000];
int f(int i=0,int j=n){

    if( j-i == 1) return 1;
    int &ret = memo[i][j];
    if(ret != -1) return ret;

    //cout<<i<<" "<<j<<endl;
    for(int k=i+1;k<j;k++){

            int max1 = *max_element(a+i,a+k);
            int min2 = *min_element(a+k,a+j);

            if(max1 <= min2){
                    return ret= 1+f(k,j);
            }

    }

    return ret= 1;

}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",a+i);

    }
    memset(memo,-1,sizeof(memo));

    cout<<f()<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    long long a[n] ;
    int x = 0 ;
    scanf("%d",&x);
    int t = x ;
    int res = 1;
    n--;
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        res += x > t ;
        t = x;
    }
    printf("%d\n",res);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
//int memo[10001][10001];
int f(int i=0,int j=n){

    if( j-i == 1) return 1;
  //  int &ret = memo[i][j];
   // if(ret != -1) return ret;

    //cout<<i<<" "<<j<<endl;
    for(int k=i+1;k<j;k++){

            int max1 = *max_element(a+i,a+k);
            int min2 = *min_element(a+k,a+j);

            if(max1 <= min2){
                    return  1+f(k,j);
            }

    }

    return  1;

}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",a+i);

    }
 //   memset(memo,-1,sizeof(memo));

    cout<<f()<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
int f2(){
    int res = 1 ;
    int max1 = a[0] ;
    int r= 1;
    for(int k=0;k<n;k++){
        max1 = max(max1,a[k]);
        int min2 = *min_element(a+k+1,a+n);
        if(max1 <= min2){
                res++;
                max1 = a[k+1];
            }

    }
        return res;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
    }

    cout<<f2()<<endl;

//    return 0;
}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int tree[400010];
void build(int low,int high,int node){

	if(low==high){
		tree[node]=A[low];
		return;
	}
	int mid=(low+high)/2;

	build(low,mid,2*node);

	build(mid+1,high,2*node+1);

	tree[node]=min(tree[2*node],tree[2*node+1]);

}
int query(int low,int high,int begin,int end,int node){

	if(low>end||high<begin)return 2000000000;

	if(low>=begin&&high<=end)return tree[node];

	int mid=(low+high)/2;

	return min(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int blk=0;
	int cur=1,i=0;
	build(0,n-1,1);
	if(n==1){
		cout<<1<<"\n";
		return 0;
	}
	//printf("SDSD\n");
	while(i<n){
		//cout<<"HELLO\n";
		int maxi=A[i];
		while(1){
			if(cur==n)break;
			if(query(0,n-1,cur,n-1,1)>A[i]||(maxi==A[i]&&query(0,n-1,cur,n-1,1)==A[i]&&cur==A[i]))
				break;
			maxi=max(maxi,A[cur]);
			cur++;
		}
		i=cur;
		cur++;
		blk++;
	}
	if(i==n-1)cur++;
	cout<<blk<<"\n";

}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int tree[400010];
void build(int low,int high,int node){

	if(low==high){
		tree[node]=A[low];
		return;
	}
	int mid=(low+high)/2;

	build(low,mid,2*node);

	build(mid+1,high,2*node+1);

	tree[node]=min(tree[2*node],tree[2*node+1]);

}
int query(int low,int high,int begin,int end,int node){

	if(low>end||high<begin)return 2000000000;

	if(low>=begin&&high<=end)return tree[node];

	int mid=(low+high)/2;

	return min(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int blk=0;
	int cur=1,i=0;
	build(0,n-1,1);
	if(n==1){
		cout<<1<<"\n";
		return 0;
	}
	//printf("SDSD\n");
	while(i<n){
		//cout<<"HELLO\n";
		while(query(0,n-1,cur,n-1,1)<=A[i]&&cur<n)
			cur++;
		i=cur;
		cur++;
		blk++;
	}
	if(i==n-1)cur++;
	cout<<blk<<"\n";

}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int tree[400010];
void build(int low,int high,int node){

	if(low==high){
		tree[node]=A[low];
		return;
	}
	int mid=(low+high)/2;

	build(low,mid,2*node);

	build(mid+1,high,2*node+1);

	tree[node]=min(tree[2*node],tree[2*node+1]);

}
int query(int low,int high,int begin,int end,int node){

	if(low>end||high<begin)return 2000000000;

	if(low>=begin&&high<=end)return tree[node];

	int mid=(low+high)/2;

	return min(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int blk=0;
	int cur=1,i=0;
	build(0,n-1,1);
	//printf("SDSD\n");
	while(i<n){
		//cout<<"HELLO\n";
		while(query(0,n-1,cur,n-1,1)<A[i]&&cur<n)
			cur++;
		i=cur;
		cur++;
		blk++;
	}
	if(i==n-1)cur++;
	cout<<blk<<"\n";

}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int tree[400010];
void build(int low,int high,int node){

	if(low==high){
		tree[node]=A[low];
		return;
	}
	int mid=(low+high)/2;

	build(low,mid,2*node);

	build(mid+1,high,2*node+1);

	tree[node]=min(tree[2*node],tree[2*node+1]);

}
int query(int low,int high,int begin,int end,int node){

	if(low>end||high<begin)return 2000000000;

	if(low>=begin&&high<=end)return tree[node];

	int mid=(low+high)/2;

	return min(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int blk=0;
	int cur=1,i=0;
	build(0,n-1,1);
	if(n==1){
		cout<<1<<"\n";
		return 0;
	}
	//printf("SDSD\n");
	while(i<n){
		//cout<<"HELLO\n";
		int maxi=A[i];
		while(1){
			if(cur==n)break;
			if(maxi==A[i]&&query(0,n-1,cur,n-1,1)>A[i])
				break;
			if(maxi!=A[i]&&query(0,n-1,cur,n-1,1)>=A[i])
				break;
			maxi=max(maxi,A[cur]);
			cur++;
		}
		i=cur;
		cur++;
		blk++;
	}
	if(i==n-1)cur++;
	cout<<blk<<"\n";

}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	stack<int> st;
	st.push(0);
	for(int i=1;i<n;i++){
		if(st.size()){
			while(A[st.top()]<=A[i]){
				//cout<<A[st.top()]<<" "<<A[i]<<"\n";
				//cout<<"HELLO\n";
				B[st.top()]=i;
				//cout<<st.top()<<"\n";
				st.pop();
				if(!st.size())break;
			}
		}
		st.push(i);
	}
	while(st.size()){
		//cout<<st.top()<<"\n";
		B[st.top()]=n;
		st.pop();
	}
	int k=0,blks=0;
	while(k<n){
		//cout<<k<<"\n";
		k=B[k];
		blks++;
	}
	//cout<<"HELLO\n";
	cout<<blks<<"\n";

}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int tree[400010];
void build(int low,int high,int node){

	if(low==high){
		tree[node]=A[low];
		return;
	}
	int mid=(low+high)/2;

	build(low,mid,2*node);

	build(mid+1,high,2*node+1);

	tree[node]=min(tree[2*node],tree[2*node+1]);

}
int query(int low,int high,int begin,int end,int node){

	if(low>end||high<begin)return 2000000000;

	if(low>=begin&&high<=end)return tree[node];

	int mid=(low+high)/2;

	return min(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int blk=0;
	int cur=1,i=0;
	build(0,n-1,1);
	if(n==1){
		cout<<1<<"\n";
		return 0;
	}
	//printf("SDSD\n");
	while(cur<n){
		//cout<<"HELLO\n";
		int maxi=A[i];
		while(1){
			if(cur==n)break;
			if(query(0,n-1,cur,n-1,1)>A[i]||(maxi==A[i]&&query(0,n-1,cur,n-1,1)==A[i]&&cur==A[i]))
				break;
			maxi=max(maxi,A[cur]);
			cur++;
		}
		i=cur;
		//cout<<i<<"\n";
		cur++;
		blk++;
	}
	if(i==n-1)blk++;
	cout<<blk<<"\n";
}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int tree[400010];
void build(int low,int high,int node){

	if(low==high){
		tree[node]=A[low];
		return;
	}
	int mid=(low+high)/2;

	build(low,mid,2*node);

	build(mid+1,high,2*node+1);

	tree[node]=min(tree[2*node],tree[2*node+1]);

}
int query(int low,int high,int begin,int end,int node){

	if(low>end||high<begin)return 2000000000;

	if(low>=begin&&high<=end)return tree[node];

	int mid=(low+high)/2;

	return min(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int blk=0;
	int cur=1,i=0;
	build(0,n-1,1);
	if(n==1){
		cout<<1<<"\n";
		return 0;
	}
	//printf("SDSD\n");
	while(i<n){
		//cout<<"HELLO\n";
		int maxi=A[i];
		while(1){
			if(cur==n)break;
			if(maxi!=A[i]&&query(0,n-1,cur,n-1,1)>A[i]||(maxi==A[i]&&query(0,n-1,cur,n-1,1)==A[i]&&cur==A[i]))
				break;
			maxi=max(maxi,A[cur]);
			cur++;
		}
		i=cur;
		cur++;
		blk++;
	}
	if(i==n-1)cur++;
	cout<<blk<<"\n";

}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	stack<int> st;
	st.push(0);
	for(int i=1;i<n;i++){
		if(st.size()){
			while(A[st.top()]<A[i]){
				//cout<<A[st.top()]<<" "<<A[i]<<"\n";
				//cout<<"HELLO\n";
				B[st.top()]=i;
				//cout<<st.top()<<"\n";
				st.pop();
				if(!st.size())break;
			}
		}
		st.push(i);
	}
	while(st.size()){
		//cout<<st.top()<<"\n";
		B[st.top()]=n;
		st.pop();
	}
	int k=0,blks=0;
	while(k<n){
		//cout<<k<<"\n";
		k=B[k];
		blks++;
	}
	//cout<<"HELLO\n";
	cout<<blks<<"\n";

}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	B[n-1]=A[n-1];
	for(int i=n-2;i>=0;i--)B[i]=min(A[i],B[i+1]);
	int i=0,j=0;
	int blk=0;
	while(1){
		j++;
		if(j>=n)break;
		int maxi=A[i];
		while(B[j]<maxi&&j<n){
			maxi=max(A[j],maxi);
			j++;
		}
		blk++;
		i=j;
		if(i==n-1)blk++;
	}
	if(n==1)blk=1;
	cout<<blk<<"\n";
}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int tree[400010];
void build(int low,int high,int node){

	if(low==high){
		tree[node]=A[low];
		return;
	}
	int mid=(low+high)/2;

	build(low,mid,2*node);

	build(mid+1,high,2*node+1);

	tree[node]=min(tree[2*node],tree[2*node+1]);

}
int query(int low,int high,int begin,int end,int node){

	if(low>end||high<begin)return 2000000000;

	if(low>=begin&&high<=end)return tree[node];

	int mid=(low+high)/2;

	return min(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int blk=0;
	int cur=1,i=0;
	build(0,n-1,1);
	if(n==1){
		cout<<1<<"\n";
		return 0;
	}
	//printf("SDSD\n");
	while(i<n){
		//cout<<"HELLO\n";
		while(query(0,n-1,cur,n-1,1)<A[i]&&cur<n)
			cur++;
		i=cur;
		cur++;
		blk++;
	}
	if(i==n-1)cur++;
	cout<<blk<<"\n";

}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	B[n-1]=A[n-1];
	for(int i=n-2;i>=0;i--)B[i]=min(A[i],B[i+1]);
	int i=0,j=0;
	int blk=0;
	while(1){
		j++;
		if(j>=n)break;
		int maxi=A[i];
		while(B[j]<maxi&&j<n){
			maxi=max(A[j],maxi);
			j++;
		}
		blk++;
		i=j;
		if(i==n-1)blk++;
	}
	cout<<blk<<"\n";
}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int tree[400010];
void build(int low,int high,int node){

	if(low==high){
		tree[node]=A[low];
		return;
	}
	int mid=(low+high)/2;

	build(low,mid,2*node);

	build(mid+1,high,2*node+1);

	tree[node]=min(tree[2*node],tree[2*node+1]);

}
int query(int low,int high,int begin,int end,int node){

	if(low>end||high<begin)return 2000000000;

	if(low>=begin&&high<=end)return tree[node];

	int mid=(low+high)/2;

	return min(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int blk=0;
	int cur=1,i=0;
	build(0,n-1,1);
	if(n==1){
		cout<<1<<"\n";
		return 0;
	}
	//printf("SDSD\n");
	while(i<n){
		//cout<<"HELLO\n";
		int maxi=A[i];
		while(1){
			if(cur==n)break;
			if(maxi!=A[i]&&query(0,n-1,cur,n-1,1)>A[i]||(maxi==A[i]&&query(0,n-1,cur,n-1,1)>=A[i]&&cur==A[i]))
				break;
			maxi=max(maxi,A[cur]);
			cur++;
		}
		i=cur;
		cur++;
		blk++;
	}
	if(i==n-1)cur++;
	cout<<blk<<"\n";

}


/*
G.Arshad
Indian Institute of Information Technology, Sricity
arshad2117@gmail.com
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
int A[100010],B[100010];
int tree[400010];
void build(int low,int high,int node){

	if(low==high){
		tree[node]=A[low];
		return;
	}
	int mid=(low+high)/2;

	build(low,mid,2*node);

	build(mid+1,high,2*node+1);

	tree[node]=min(tree[2*node],tree[2*node+1]);

}
int query(int low,int high,int begin,int end,int node){

	if(low>end||high<begin)return 2000000000;

	if(low>=begin&&high<=end)return tree[node];

	int mid=(low+high)/2;

	return min(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	int blk=0;
	int cur=1,i=0;
	build(0,n-1,1);
	if(n==1){
		cout<<1<<"\n";
		return 0;
	}
	//printf("SDSD\n");
	while(cur<n){
		//cout<<"HELLO\n";
		int maxi=A[i];
		while(1){
			if(cur==n)break;
			if(query(0,n-1,cur,n-1,1)>A[i]||(maxi==A[i]&&query(0,n-1,cur,n-1,1)==A[i]&&cur>=A[i]))
				break;
			maxi=max(maxi,A[cur]);
			cur++;
		}
		i=cur;
		//cout<<i<<"\n";
		cur++;
		blk++;
	}
	if(i==n-1)blk++;
	cout<<blk<<"\n";
}


#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n, h, k; in >> n >> h >> k;

		vector<long long> nums;

		for (int i = 0; i < n; i++){
			long long c; in >> c;
			nums.push_back(c);
		}

		int ans = 0;
		long long curh = 0;

		int idx = 0;

		while (idx < n){

			while ( idx < n){
				if (curh <= h || curh - h < k){
					curh += nums[idx];
					idx++;
				}
				else{
					break;
				}
			}

			int dif = curh - h;
			//out << curh << " " << dif << endl;
			if (dif %k == 0){
				ans += dif / k;
			}
			else{

					ans += dif / k;
					ans++;
			}

			curh = h;
		}

		if (curh != 0){
			if (curh % k == 0){
				ans += curh / k;
			}
			else{
				ans += curh / k;
				ans++;
			}
		}

		out << ans;

    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;
    solve(in, out);
    return 0;
}


#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n; in >> n;

		vector<pair<int, int>> ns;

		for (int i = 0; i < n; i++){
			int c; in >> c;
			ns.push_back({ c, i });
		}

		sort(ns.begin(), ns.end());

		int f = -1;
		int ans = 0;

		int r = -1;

		for (int i = 1; i < n; i++){
			if (ns[i].first != ns[i - 1].first){
				if (ns[i - 1].second > f){
					f = max(r, ns[i - 1].second);
					ans++;
				}
				else{
					r = max(ns[i].second, ns[i - 1].second);
				}
			}
		}

		if (ns[n - 1].first == ns[n - 2].first){
			out << ans;
		} else{

			if (ns[n - 1].second > f){
				ans++;
			}

			out << ans;
		}

    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;
    solve(in, out);
    return 0;
}


#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n; in >> n;

		vector<pair<int, int>> ns;

		for (int i = 0; i < n; i++){
			int c; in >> c;
			ns.push_back({ c, i });
		}

		sort(ns.begin(), ns.end());

		int f = -1;
		int ans = 0;
		for (int i = 1; i < n; i++){
			if (ns[i].first != ns[i - 1].first){
				if (ns[i - 1].second > f){
					f = ns[i - 1].second;
					ans++;
				}
			}
		}

		if (ns[n - 1].first == ns[n - 2].first){
			out << ans;
		} else{

			if (ns[n - 1].second > f){
				ans++;
			}

			out << ans;
		}

    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;
    solve(in, out);
    return 0;
}


#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)

const int MAXN = 100001;
const int INF = 1000 * 1000 * 1001;

int a[MAXN];
int  l[MAXN];

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {

		int n;
		in >> n;

		l[0] = 0;

		for (int i = 0; i < n; i++)
		{
			in >> a[i];
			l[i + 1] = max(l[i], a[i]);
		}
		int r = INF, ans = 0;
		for (int i = n - 1; i >= 0; i--)
		{
			r = min(r, a[i]);
			//out << r << " " << l[i] << endl;
			if (r >= l[i]) ans++;
		}
		out << ans << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;
    solve(in, out);
    return 0;
}


#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n; in >> n;

		vector<pair<int, int>> ns;

		for (int i = 0; i < n; i++){
			int c; in >> c;
			ns.push_back({ c, i });
		}

		sort(ns.begin(), ns.end());

		int f = -1;
		int ans = 0;

		int r = -1;

		for (int i = 1; i < n; i++){
			if (ns[i].first != ns[i - 1].first){
				if (ns[i - 1].second > f){
					f = max(r, ns[i - 1].second);
					ans++;
				}

				//out << f << endl;
			}
			else{
					r = max(ns[i].second, ns[i - 1].second);

					//out << f << " " << ns[i].second << " " << ns[i - 1].second << endl;
			}
		}

		if (ns[n - 1].first == ns[n - 2].first){
			out << ans;
		} else{

			if (ns[n - 1].second > f){
				ans++;
			}

			out << ans;
		}

    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;
    solve(in, out);
    return 0;
}


#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n; in >> n;

		vector<pair<int, int>> ns;

		for (int i = 0; i < n; i++){
			int c; in >> c;
			ns.push_back({ c, i });
		}

		sort(ns.begin(), ns.end());

		int f = -1;
		int ans = 0;

		int r = -1;

		for (int i = 1; i < n; i++){
			if (ns[i].first != ns[i - 1].first){
				if (ns[i - 1].second > f){
					f = max(r, ns[i - 1].second);
					ans++;
				}
			}
			else{
					f = max(ns[i].second, ns[i - 1].second);

			}
		}

		if (ns[n - 1].first == ns[n - 2].first){
			out << ans;
		} else{

			if (ns[n - 1].second > f){
				ans++;
			}

			out << ans;
		}

    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;
    solve(in, out);
    return 0;
}


#include <map>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N=100005;
int INF=0x3f3f3f3f;
LL mod=1e9+7;
int a[N];
map<int,int> mp;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int n,wc,t,ok=1,mint,r,sb;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(mp[a[i]]==0)
            mp[a[i]]=i;
        else{
            mp[a[i]]=min(mp[a[i]],i);
        }
    }
    auto it=mp.end();
    it--;
    r=n;
    int ans=0;
    mint=INF;
    for(;;it--){
        t=it->first;
        wc=it->second;
        if(wc<=r){
            if(t>mint){
                r=wc-1;
            }
            else{
                for(;t==a[r]&&r>=wc;r--){
                    ans++;
                }
                for(int i=wc+1;i<=r;i++){
                    mint=min(mint,a[i]);
                }
                if(r>wc){
                    ans++;
                }
                r=wc-1;
            }

        }
       if(it==mp.begin()){
           break;
       }
    }
    if(ok==0){
        puts("1");
    }
    else{
        printf("%d\n",ans);
    }
    return 0;
}


#include <map>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N=100005;
int INF=0x3f3f3f3f;
LL mod=1e9+7;
int a[N];
map<int,int> mp;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int n,wc,t,ok=1,mint,r,sb;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(mp[a[i]]==0)
            mp[a[i]]=i;
        else{
            mp[a[i]]=min(mp[a[i]],i);
        }
    }
    auto it=mp.end();
    it--;
    r=n;
    int ans=0;
    mint=INF;
    for(;;it--){
        t=it->first;
        wc=it->second;
        if(wc<=r){
            if(t>mint){
                r=wc-1;
            }
            else{
                sb=1;
                for(int i=wc+1;i<=r;i++){
                    if(a[i]!=t){
                        sb=0;
                    }
                    mint=min(mint,a[i]);
                }
                if(sb){
                    ans=ans+r-wc;
                }
                ans++;
                r=wc-1;
            }

        }
       if(it==mp.begin()){
           break;
       }
    }
    if(ok==0){
        puts("1");
    }
    else{
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N=100005;
int INF=0x3f3f3f3f;
LL mod=1e9+7;
int a[N],v[N];
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int n,mi;
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        scanf("%d",&a[i]);
        v[i]=max(v[i-1],a[i]);
    }
    int ans=0;
    mi=a[n];
    for(int i=n; i>=1; i--) {
        mi=min(a[i],mi);
        if(v[i-1]<=mi) {
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <map>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N=100005;
int INF=0x3f3f3f3f;
LL mod=1e9+7;
int a[N];
map<int,int> mp;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int n,wc,t,ok=1,mint,r;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(mp[a[i]]==0)
            mp[a[i]]=i;
        else{
            mp[a[i]]=min(mp[a[i]],i);
        }
    }
    auto it=mp.end();
    it--;
    r=n;
    int ans=0;
    mint=INF;
    for(;;it--){
        t=it->first;
        wc=it->second;
        if(wc<=r){
            if(t>mint){
                ok=0;
                break;
            }
            ans++;
             for(int i=wc+1;i<=r;i++){
                mint=min(mint,a[i]);
            }
            r=wc-1;
        }
       if(it==mp.begin()){
           break;
       }
    }
    if(ok==0){
        puts("1");
    }
    else{
        printf("%d\n",ans);
    }
    return 0;
}


#include <map>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N=100005;
int INF=0x3f3f3f3f;
LL mod=1e9+7;
int a[N];
map<int,int> mp;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int n,wc,t,ok=1,mint,r,sb;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(mp[a[i]]==0)
            mp[a[i]]=i;
        else{
            mp[a[i]]=min(mp[a[i]],i);
        }
    }
    auto it=mp.end();
    it--;
    r=n;
    int ans=0;
    mint=INF;
    for(;;it--){
        t=it->first;
        wc=it->second;
        if(wc<=r){
            if(t>mint){
                ok=0;
                break;
            }
            sb=1;
            for(int i=wc+1;i<=r;i++){
                if(a[i]!=t){
                    sb=0;
                }
                mint=min(mint,a[i]);
            }
            if(sb){
                ans=ans+r-wc;
            }
            ans++;
            r=wc-1;
        }
       if(it==mp.begin()){
           break;
       }
    }
    if(ok==0){
        puts("1");
    }
    else{
        printf("%d\n",ans);
    }
    return 0;
}


#include <map>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N=100005;
int INF=0x3f3f3f3f;
LL mod=1e9+7;
int a[N];
map<int,int> mp;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int n,wc,t,ok=1,mint,r,sb;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(mp[a[i]]==0)
            mp[a[i]]=i;
        else{
            mp[a[i]]=min(mp[a[i]],i);
        }
    }
    auto it=mp.end();
    it--;
    r=n;
    int ans=0;
    mint=INF;
    for(;;it--){
        t=it->first;
        wc=it->second;
        if(wc<=r){
            if(t>mint){
                r=wc-1;
            }
            else{
                for(;t==a[r]&&r>=wc;r--){
                    ans++;
                }
                for(int i=wc;i<=r;i++){
                    mint=min(mint,a[i]);
                }
                if(r>wc){
                    ans++;
                }
                r=wc-1;
            }

        }
       if(it==mp.begin()){
           break;
       }
    }
    printf("%d\n",ans);
    return 0;
}


#include <map>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N=100005;
int INF=0x3f3f3f3f;
LL mod=1e9+7;
int a[N];
map<int,int> mp;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int n,wc,t,ok=1,mint,r,sb;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(mp[a[i]]==0)
            mp[a[i]]=i;
        else{
            mp[a[i]]=min(mp[a[i]],i);
        }
    }
    auto it=mp.end();
    it--;
    r=n;
    int ans=0;
    mint=INF;
    for(;;it--){
        t=it->first;
        wc=it->second;
        if(wc<=r){
            if(t>mint){
                r=wc-1;
            }
            else{
                sb=1;
                for(;t==a[r]&&r>wc;r--){
                    ans++;
                }
                for(int i=wc+1;i<=r;i++){
                    mint=min(mint,a[i]);
                }
                ans++;
                r=wc-1;
            }

        }
       if(it==mp.begin()){
           break;
       }
    }
    if(ok==0){
        puts("1");
    }
    else{
        printf("%d\n",ans);
    }
    return 0;
}


#include <map>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N=100005;
int INF=0x3f3f3f3f;
LL mod=1e9+7;
int a[N];
map<int,int> mp;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int n,wc,t,ok=1,mint,r;

    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(mp[a[i]]==0)
            mp[a[i]]=i;
        else{
            mp[a[i]]=min(mp[a[i]],i);
        }
    }
    auto it=mp.end();
    it--;
    r=n;
    int ans=0;
    mint=INF;
    for(;;it--){
        t=it->first;
        wc=it->second;
        if(t>mint){
            ok=0;
            break;
        }
        if(wc<=r){
            ans++;
             for(int i=wc+1;i<=r;i++){
                mint=min(mint,a[i]);
            }
            r=wc-1;
        }
       if(it==mp.begin()){
           break;
       }
    }
    if(ok==0){
        puts("1");
    }
    else{
        printf("%d\n",ans);
    }
    return 0;
}


#include <map>
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N=100005;
int INF=0x3f3f3f3f;
LL mod=1e9+7;
int a[N];
map<int,int> mp;
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int n,wc,t,ok=1,mint,r,sb;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(mp[a[i]]==0)
            mp[a[i]]=i;
        else{
            mp[a[i]]=min(mp[a[i]],i);
        }
    }
    auto it=mp.end();
    it--;
    r=n;
    int ans=0;
    mint=INF;
    for(;;it--){
        t=it->first;
        wc=it->second;
        if(wc<=r){
            if(t>mint){
                r=wc-1;
            }
            else{
                for(;t==a[r]&&r>=wc;r--){
                    ans++;
                }
                for(int i=wc;i<=r;i++){
                    mint=min(mint,a[i]);
                }
                if(r>wc){
                    ans++;
                }
                r=wc-1;
            }

        }
       if(it==mp.begin()){
           break;
       }
    }
    else{
        printf("%d\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int num[100100];
struct node
{
    int l,r;
    long long nsum;
}segtree[300300];

void build(int i,int l,int r)
{
    segtree[i].l=l;
    segtree[i].r=r;
    if(l==r)
    {
        segtree[i].nsum=num[l];
        return;
    }
    int mid=(l+r)>>1;
    build(i<<1,l,mid);
    build(i<<1|1,mid+1,r);
    segtree[i].nsum=max(segtree[i<<1].nsum,segtree[i<<1|1].nsum);
}

long long query(int i,int a,int b)
{
    if(segtree[i].l==a&&segtree[i].r==b)
    {
        return segtree[i].nsum;
    }
    int mid=(segtree[i].l+segtree[i].r)>>1;
    if(b<=mid)
        return  query(i<<1,a,b);
    else if(a>mid)
        return query(i<<1|1,a,b);
    else
        return max(query(i<<1,a,mid),query(i<<1|1,mid+1,b));
}

struct my
{
    int id,x;
}arr[100100];

bool cmp(my n1,my n2)
{
    if(n1.x!=n2.x)
        return n1.x<n2.x;
    else
        return n1.id<n2.id;
}

int main()
{
    int n,i,ans,now;
    while(cin>>n)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&num[i]);
            arr[i].id=i;
            arr[i].x=num[i];
        }
        build(1,1,n);
        sort(arr+1,arr+1+n,cmp);
        ans=0;
        arr[0].x=0;arr[0].id=0;now=0;
        for(i=1;i<=n;i++)
        {
            if(arr[i].x>arr[i-1].x)
            {
                if(arr[i].id>now)
                {
                    ans++;
                    now=arr[i].id;
                }
            }
            else
            {
                if(arr[i].id>now)
                {
                    if((arr[i].id==now+1&&query(1,1,now)==arr[i].x)||(arr[i].id>now+1))
                        ans++;
                    now=arr[i].id;
                }
            }
        }
        cout<<ans<<endl;
    }
}