#include<complex>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <limits>
#include <climits>
#include <time.h>
#include <cstdio>
#include <numeric>
#define LL long long
#define rei(x) scanf("%d",&x)
#define reii(x,y) scanf("%d%d",&x,&y)
#define reiii(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define rel(x) scanf("%I64d",&x);

#define ref(x) scanf("%lf",&x)
#define rec(x) scanf("%c",&x)
#define res(x) scanf("%s",x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define f(i, a, b) for(int i = a; i <= b; i++)
#define ms(Arr) memset(Arr,0,sizeof(Arr));
#define CLR(arr,val)  memset(arr,val,sizeof(arr))
#define bit(a , b) (((a)>>(b))&1)
#define fin freopen("in.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
#define fout1 freopen("out1.txt","w",stdout)
#define ftest freopen("in.txt","w",stdout)
#define lson (id << 1)
#define rson (id << 1 | 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
using namespace std;
const int INF = 0x3f3f3f3f;
const LL mod = 1000000007;
const double e = 2.718281828459;
typedef pair<int, int> Pii;
typedef pair<LL, LL> Pll;

LL gcd(LL a, LL b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL gcd1(int a, int b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL pow_mod(LL a, LL b, LL c)
{
	LL ans = 1;
	a = a % c;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = (ans * a) % c;
		b = b / 2;
		a = (a * a) % c;
	}
	return ans;
}

int pow_int(int a, int b)
{
	int ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

LL pow_llong(LL a, LL b)
{
	LL ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

const int dx[9] = { 0, 1, 1, 1, 0,-1,-1,-1, 0 };
const int dy[9] = { 0, 1, 0,-1,-1,-1, 0, 1, 1 };

int Scan()
{
	int res = 0, flag = 0;
	char ch;
	if ((ch = getchar()) == '-')
	{
		flag = 1;
	}
	else if (ch >= '0' && ch <= '9')
	{
		res = ch - '0';
	}
	while ((ch = getchar()) >= '0' && ch <= '9')
	{
		res = res * 10 + (ch - '0');
	}
	return flag ? -res : res;
}

void Out(int a)
{
	if (a < 0)
	{
		putchar('-');
		a = -a;
	}
	if (a >= 10)
	{
		Out(a / 10);
	}
	putchar(a % 10 + '0');
}

LL jc_mod(LL a, LL b, LL mod)
{
	LL ans = 1;
	b = max(b, a - b);
	for (LL i = a; i > b; i--)
	{
		ans *= i;
		ans %= mod;
	}
	return ans;
}

double lg(double a)
{
	return (log(a) / log(10.0));
}

int lowbit(int x)
{
	return x & -x;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//long long：-9223372036854775808~9223372036854775807
//int：-2147483648~2147483647
//double：-1.7*10^-308~1.7*10^308，15~16位有效数字
//long double：-1.2*10^-4932~1.2*10^4932，18~19位有效数字
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline int read()
{
	int f = 1, x = 0; 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 Struct_Name
{
int variable;
bool operator <(const Struct_Name &other)const   //升序排序
{
return variable > other.variable;
}
};
*******************************************************/

//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define MAXNN 100010
void lisan(int *x, int n) {
	//首先c++调用一个数组直接打这个数组的类型就好了。
	int data[MAXNN];
	f(i, 1, n)data[i] = x[i];
	sort(data + 1, data + 1 + n);//排序是肯定要的。
	int o = unique(data + 1, data + 1 + n) - data - 1;//给data数组[1..n]去重，黑科技
	f(i, 1, n)x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data;//找到x[i]在data中的位置再赋值为这个位置，如果不-data就是返回这个值。
}
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int calc(int M)
{
	return 1;
}
int sanfen(int L, int R)
{
	int M, RM;
	while (L + 1 < R)
	{
		M = (L + R) / 2;
		RM = (M + R) / 2;
		if (calc(M) < calc(RM)) //计算最小值,若为最大值则>
			R = RM;
		else
			L = M;
	}
	return L;
}

int CaculateWeekDay(int y, int m, int d)
{
	if (m == 1 || m == 2) {
		m += 12;
		y--;
	}
	int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
	return iWeek;
}

////////////////////////////////////////////////////e nd/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

priority_queue<LL,vector<LL>,greater<LL>> q;
map<LL,int> mm;
vector<vector<LL>> v;
LL a[160000];
int main()
{
	int n;
	rei(n);
	int j = 0;
	f(i, 1, n)
	{
		rel(a[i]);
		if (i == 1 ||	!mm[a[i]] && a[i] != a[1])
		{
			mm[a[i]] = j++;
			vector<LL> b;
			b.push_back(i);
			v.push_back(b);
		}
		else
		{
			v[mm[a[i]]].push_back(i);
			if(v[mm[a[i]]].size() == 2)
				q.push(a[i]);
		}
	}
	while (q.size())
	{
		int tt = mm[q.top()];
		a[v[tt][0]] = -1;
		v[tt].erase(v[tt].begin());
		a[v[tt][0]] <<= 1;
		int flag = 0;
		if (v[tt].size() <= 2)
			flag = 1;
		if (!mm[a[v[tt][0]]])
		{
			mm[a[v[tt][0]]] = j++;
			vector<LL> b;
			b.push_back(v[tt][0]);
			v.push_back(b);
		}
		else
		{
			int l = 0, r = v[mm[a[v[tt][0]]]].size() - 1;
			while (r > l)
			{
				int mid = (l + r) >> 1;
				if (v[mm[a[v[tt][0]]]][mid] > v[tt][0])
					r = mid;
				else
					l = mid + 1;
			}

			v[mm[a[v[tt][0]]]].insert(v[mm[a[v[tt][0]]]].begin() + l+1, v[tt][0]);
			if (v[mm[a[v[tt][0]]]].size() == 2)
			{
				q.push(a[v[tt][0]]);
				sort(v[mm[a[v[tt][0]]]].begin(), v[mm[a[v[tt][0]]]].end());
			}
		}
		v[tt].erase(v[tt].begin());
		if (v[tt].size() == 0)
			v.erase(v.begin() + tt);
		if (flag)
			q.pop();
	}
	int co = 0;
	for (int i = 0; i < v.size(); i++)
		if (v[i].size())
			co++;
	printf("%d\n", co);
	f(i, 1, n)
	{
		if (a[i] > 0)
			printf("%I64d ", a[i]);
	}
	printf("\n");
	return 0;
}


#include<complex>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <limits>
#include <climits>
#include <time.h>
#include <cstdio>
#include <numeric>
#define LL long long
#define rei(x) scanf("%d",&x)
#define reii(x,y) scanf("%d%d",&x,&y)
#define reiii(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define rel(x) scanf("%I64d",&x);

#define ref(x) scanf("%lf",&x)
#define rec(x) scanf("%c",&x)
#define res(x) scanf("%s",x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define f(i, a, b) for(int i = a; i <= b; i++)
#define ms(Arr) memset(Arr,0,sizeof(Arr));
#define CLR(arr,val)  memset(arr,val,sizeof(arr))
#define bit(a , b) (((a)>>(b))&1)
#define fin freopen("in.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
#define fout1 freopen("out1.txt","w",stdout)
#define ftest freopen("in.txt","w",stdout)
#define lson (id << 1)
#define rson (id << 1 | 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
using namespace std;
const int INF = 0x3f3f3f3f;
const LL mod = 1000000007;
const double e = 2.718281828459;
typedef pair<int, int> Pii;
typedef pair<LL, LL> Pll;

LL gcd(LL a, LL b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL gcd1(int a, int b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL pow_mod(LL a, LL b, LL c)
{
	LL ans = 1;
	a = a % c;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = (ans * a) % c;
		b = b / 2;
		a = (a * a) % c;
	}
	return ans;
}

int pow_int(int a, int b)
{
	int ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

LL pow_llong(LL a, LL b)
{
	LL ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

const int dx[9] = { 0, 1, 1, 1, 0,-1,-1,-1, 0 };
const int dy[9] = { 0, 1, 0,-1,-1,-1, 0, 1, 1 };

int Scan()
{
	int res = 0, flag = 0;
	char ch;
	if ((ch = getchar()) == '-')
	{
		flag = 1;
	}
	else if (ch >= '0' && ch <= '9')
	{
		res = ch - '0';
	}
	while ((ch = getchar()) >= '0' && ch <= '9')
	{
		res = res * 10 + (ch - '0');
	}
	return flag ? -res : res;
}

void Out(int a)
{
	if (a < 0)
	{
		putchar('-');
		a = -a;
	}
	if (a >= 10)
	{
		Out(a / 10);
	}
	putchar(a % 10 + '0');
}

LL jc_mod(LL a, LL b, LL mod)
{
	LL ans = 1;
	b = max(b, a - b);
	for (LL i = a; i > b; i--)
	{
		ans *= i;
		ans %= mod;
	}
	return ans;
}

double lg(double a)
{
	return (log(a) / log(10.0));
}

int lowbit(int x)
{
	return x & -x;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//long long：-9223372036854775808~9223372036854775807
//int：-2147483648~2147483647
//double：-1.7*10^-308~1.7*10^308，15~16位有效数字
//long double：-1.2*10^-4932~1.2*10^4932，18~19位有效数字
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline int read()
{
	int f = 1, x = 0; 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 Struct_Name
{
int variable;
bool operator <(const Struct_Name &other)const   //升序排序
{
return variable > other.variable;
}
};
*******************************************************/

//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define MAXNN 100010
void lisan(int *x, int n) {
	//首先c++调用一个数组直接打这个数组的类型就好了。
	int data[MAXNN];
	f(i, 1, n)data[i] = x[i];
	sort(data + 1, data + 1 + n);//排序是肯定要的。
	int o = unique(data + 1, data + 1 + n) - data - 1;//给data数组[1..n]去重，黑科技
	f(i, 1, n)x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data;//找到x[i]在data中的位置再赋值为这个位置，如果不-data就是返回这个值。
}
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int calc(int M)
{
	return 1;
}
int sanfen(int L, int R)
{
	int M, RM;
	while (L + 1 < R)
	{
		M = (L + R) / 2;
		RM = (M + R) / 2;
		if (calc(M) < calc(RM)) //计算最小值,若为最大值则>
			R = RM;
		else
			L = M;
	}
	return L;
}

int CaculateWeekDay(int y, int m, int d)
{
	if (m == 1 || m == 2) {
		m += 12;
		y--;
	}
	int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
	return iWeek;
}

////////////////////////////////////////////////////e nd/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

priority_queue<LL,vector<LL>,greater<LL>> q;
map<LL,int> mm;
vector<vector<LL>> v;
LL a[160000];
int main()
{
	int n;
	rei(n);
	int j = 0;
	f(i, 1, n)
	{
		rel(a[i]);
		if (i == 1 ||	!mm[a[i]] && a[i] != a[1])
		{
			mm[a[i]] = j++;
			vector<LL> b;
			b.push_back(i);
			v.push_back(b);
		}
		else
		{
			v[mm[a[i]]].push_back(i);
			if(v[mm[a[i]]].size() == 2)
				q.push(a[i]);
		}
	}
	while (q.size())
	{
		int tt = mm[q.top()];
		a[v[tt][0]] = -1;
		v[tt].erase(v[tt].begin());
		a[v[tt][0]] <<= 1;
		int flag = 0;
		if (v[tt].size() <= 2)
			flag = 1;
		if (!mm[a[v[tt][0]]])
		{
			mm[a[v[tt][0]]] = j++;
			vector<LL> b;
			b.push_back(v[tt][0]);
			v.push_back(b);
		}
		else
		{
			int l = 0, r = v[mm[a[v[tt][0]]]].size() - 1;
			while (r > l)
			{
				int mid = (l + r) >> 1;
				if (v[mm[a[v[tt][0]]]][mid] > v[tt][0])
					r = mid;
				else
					l = mid + 1;
			}

			v[mm[a[v[tt][0]]]].insert(v[mm[a[v[tt][0]]]].begin() + l+1, v[tt][0]);
			if (v[mm[a[v[tt][0]]]].size() == 2)
			{
				q.push(a[v[tt][0]]);
				sort(v[mm[a[v[tt][0]]]].begin(), v[mm[a[v[tt][0]]]].end());
			}
		}
		v[tt].erase(v[tt].begin());
		if (flag)
			q.pop();
	}
	int co = 0;
	for (int i = 0; i < v.size(); i++)
		if (v[i].size())
			co++;
	printf("%d\n", co);
	f(i, 1, n)
	{
		if (a[i] > 0)
			printf("%I64d ", a[i]);
	}
	printf("\n");
	return 0;
}


#include<complex>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <limits>
#include <climits>
#include <time.h>
#include <cstdio>
#include <numeric>
#define LL long long
#define rei(x) scanf("%d",&x)
#define reii(x,y) scanf("%d%d",&x,&y)
#define reiii(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define rel(x) scanf("%I64d",&x);

#define ref(x) scanf("%lf",&x)
#define rec(x) scanf("%c",&x)
#define res(x) scanf("%s",x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define f(i, a, b) for(int i = a; i <= b; i++)
#define ms(Arr) memset(Arr,0,sizeof(Arr));
#define CLR(arr,val)  memset(arr,val,sizeof(arr))
#define bit(a , b) (((a)>>(b))&1)
#define fin freopen("in.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
#define fout1 freopen("out1.txt","w",stdout)
#define ftest freopen("in.txt","w",stdout)
#define lson (id << 1)
#define rson (id << 1 | 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
using namespace std;
const int INF = 0x3f3f3f3f;
const LL mod = 1000000007;
const double e = 2.718281828459;
typedef pair<int, int> Pii;
typedef pair<LL, LL> Pll;

LL gcd(LL a, LL b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL gcd1(int a, int b)
{
	if (!b)return a;
	return gcd(b, a%b);
}

LL pow_mod(LL a, LL b, LL c)
{
	LL ans = 1;
	a = a % c;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = (ans * a) % c;
		b = b / 2;
		a = (a * a) % c;
	}
	return ans;
}

int pow_int(int a, int b)
{
	int ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

LL pow_llong(LL a, LL b)
{
	LL ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

const int dx[9] = { 0, 1, 1, 1, 0,-1,-1,-1, 0 };
const int dy[9] = { 0, 1, 0,-1,-1,-1, 0, 1, 1 };

int Scan()
{
	int res = 0, flag = 0;
	char ch;
	if ((ch = getchar()) == '-')
	{
		flag = 1;
	}
	else if (ch >= '0' && ch <= '9')
	{
		res = ch - '0';
	}
	while ((ch = getchar()) >= '0' && ch <= '9')
	{
		res = res * 10 + (ch - '0');
	}
	return flag ? -res : res;
}

void Out(int a)
{
	if (a < 0)
	{
		putchar('-');
		a = -a;
	}
	if (a >= 10)
	{
		Out(a / 10);
	}
	putchar(a % 10 + '0');
}

LL jc_mod(LL a, LL b, LL mod)
{
	LL ans = 1;
	b = max(b, a - b);
	for (LL i = a; i > b; i--)
	{
		ans *= i;
		ans %= mod;
	}
	return ans;
}

double lg(double a)
{
	return (log(a) / log(10.0));
}

int lowbit(int x)
{
	return x & -x;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//long long：-9223372036854775808~9223372036854775807
//int：-2147483648~2147483647
//double：-1.7*10^-308~1.7*10^308，15~16位有效数字
//long double：-1.2*10^-4932~1.2*10^4932，18~19位有效数字
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

inline int read()
{
	int f = 1, x = 0; 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 Struct_Name
{
int variable;
bool operator <(const Struct_Name &other)const   //升序排序
{
return variable > other.variable;
}
};
*******************************************************/

//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//离散化///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define MAXNN 100010
void lisan(int *x, int n) {
	//首先c++调用一个数组直接打这个数组的类型就好了。
	int data[MAXNN];
	f(i, 1, n)data[i] = x[i];
	sort(data + 1, data + 1 + n);//排序是肯定要的。
	int o = unique(data + 1, data + 1 + n) - data - 1;//给data数组[1..n]去重，黑科技
	f(i, 1, n)x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data;//找到x[i]在data中的位置再赋值为这个位置，如果不-data就是返回这个值。
}
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////三分框架 左闭右开////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int calc(int M)
{
	return 1;
}
int sanfen(int L, int R)
{
	int M, RM;
	while (L + 1 < R)
	{
		M = (L + R) / 2;
		RM = (M + R) / 2;
		if (calc(M) < calc(RM)) //计算最小值,若为最大值则>
			R = RM;
		else
			L = M;
	}
	return L;
}

int CaculateWeekDay(int y, int m, int d)
{
	if (m == 1 || m == 2) {
		m += 12;
		y--;
	}
	int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
	return iWeek;
}

////////////////////////////////////////////////////e nd/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////end/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int tmain()
{
	//fout;
	printf("150000\n");
	f(i, 1, 150000)
	{
		printf("1000000000\n");
	}
	return 0;
}
priority_queue<LL,vector<LL>,greater<LL>> q;
map<LL,int> mm;
vector<vector<LL>> v;
LL a[160000];
int main()
{
	int n;
	rei(n);
	int j = 0;
	f(i, 1, n)
	{
		rel(a[i]);
		if (i == 1 ||	!mm[a[i]] && a[i] != a[1])
		{
			mm[a[i]] = j++;
			vector<LL> b;
			b.push_back(i);
			v.push_back(b);
		}
		else
		{
			v[mm[a[i]]].push_back(i);
			if(v[mm[a[i]]].size() == 2)
				q.push(a[i]);
		}
	}
	while (q.size())
	{
		int tt = mm[q.top()];
		for (int i = 0; i + 1 < v[tt].size(); i+=2)
		{
			a[v[tt][i]] = -1;
			a[v[tt][i+1]] <<= 1;
			if (mm[q.top() << 1] || q.top() << 1 == a[1])
			{
				v[mm[q.top()<<1]].push_back(v[tt][i + 1]);
				if (v[mm[q.top() << 1]].size() == 2)
					q.push(q.top() << 1);
			}
			else
			{
				mm[q.top() << 1] = j++;
				vector<LL> b;
				b.push_back(v[tt][i + 1]);
				v.push_back(b);
			}
		}
		q.pop();
	}
	int co = 0;
	for (int i = 0; i < v.size(); i++)
		if (v[i].size())
			co++;
	printf("%d\n", co);
	f(i, 1, n)
	{
		if (a[i] > 0)
			printf("%I64d ", a[i]);
	}
	printf("\n");
	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int INF = 2.1e9;
const int ROOT = 1;
const int MAX = 5000;

int dp[MAX + 1][MAX + 1];
int p[MAX + 1][MAX + 1];
int in[MAX + 1];

vi g[MAX + 1];
vi c[MAX + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	for(int i = 0; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			dp[i][j] = INF;
	}

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) q.push(i);
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == ROOT) p[ROOT][ROOT] = ROOT;
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= n; j++) {
				if(u == ROOT) {
					dp[v][j] = w;
					p[v][j] = ROOT;
					break;
				}

				if(dp[u][j - 1] == INF) continue;

				if(dp[u][j - 1] + w < dp[v][j] and dp[u][j - 1] + w <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = n; i >= 1 and !ans; i--) {
		if(dp[n][i] < INF) ans = i;
	}

	vi path;
	int cnt = ans, now = n;
	while(cnt) {
		path.pb(now);
		now = p[now][cnt--];
	}

	cout << ans << '\n';
	for(int i = path.size() - 1; i >= 0; i--) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int INF = 2.1e9;
const int ROOT = 1;
const int MAX = 5000;

ll dp[MAX + 1][MAX + 1];
int p[MAX + 1][MAX + 1];
int in[MAX + 1];

vi g[MAX + 1];
vi c[MAX + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= n; j++)
			dp[i][j] = INF;
	}

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) {
			q.push(i);
			dp[i][ROOT] = 0;
		}
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == ROOT) {
			dp[u][ROOT] = 0;
			p[ROOT][ROOT] = ROOT;
		}
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= n; j++) {
				if(u == ROOT) {
					dp[v][j] = w;
					p[v][j] = ROOT;
					break;
				}

				if(dp[u][j - 1] == INF) continue;

				if(dp[u][j - 1] + w < dp[v][j] and dp[u][j - 1] + w <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(cnt) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt--];
	}

	cout << ans << '\n';
	while(!path.empty()) {
		cout << path.back() << ' ';
		path.pop_back();
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const ll INF = 1e17;
const int MAX = 5000;

ll dp[MAX + 1][MAX + 1];
int cost[MAX + 1][MAX + 1];
int p[MAX + 1][MAX + 1];
int in[MAX + 1];

vi g[MAX + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			dp[i][j] = INF;
	}

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		cost[u][v] = w;
		g[u].pb(v);
		in[v]++;
	}

	queue<int> q;
	q.push(1);
	dp[1][1] = 0;
	p[1][1] = 1;

	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i];
			for(int j = 1; j <= n; j++) {
				if(dp[u][j - 1] + cost[u][v] <= T and dp[u][j - 1] + cost[u][v] < dp[v][j]) {
					dp[v][j] = dp[u][j - 1] + cost[u][v];
					p[v][j] = u;
					in[v]--;
					if(!in[v]) q.push(v);
				}
			}
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(true) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt];
		cnt--;
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int INF = 1.2e9;
const int ROOT = 1;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	vvi dp(n + 1, vi(n + 1, INF));
	vvi p(n + 1, vi(n + 1));
	vvi g(n + 1), c(n + 1);
	vi in(n + 1);

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) {
			q.push(i);
			dp[i][1] = 0;
		}
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == ROOT) {
			dp[u][ROOT] = 0;
			p[ROOT][ROOT] = 1;
		}
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= n; j++) {
				if(u == ROOT) {
					dp[v][j] = w;
					p[v][j] = ROOT;
					break;
				}
				ll tmp = w + dp[u][j - 1];
				if(tmp < dp[v][j] and tmp <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(cnt) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt--];
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int INF = 2.1e9;
const int ROOT = 1;
const int MAX = 5000;

int dp[MAX + 1][MAX + 1];
int p[MAX + 1][MAX + 1];
int in[MAX + 1];

vi g[MAX + 1];
vi c[MAX + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= n; j++)
			dp[i][j] = INF;
	}

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) {
			q.push(i);
			dp[i][ROOT] = 0;
		}
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == ROOT) {
			dp[u][ROOT] = 0;
			p[ROOT][ROOT] = ROOT;
		}
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= n; j++) {
				if(u == ROOT) {
					dp[v][j] = w;
					p[v][j] = ROOT;
					break;
				}

				if(dp[u][j - 1] == INF) continue;

				if(dp[u][j - 1] + w < dp[v][j] and dp[u][j - 1] + w <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(cnt) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt--];
	}

	cout << ans << '\n';
	while(!path.empty()) {
		cout << path.back() << ' ';
		path.pop_back();
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int INF = 2.1e9;
const int ROOT = 1;
const int MAX = 5000;

int dp[MAX + 1][MAX + 1];
int p[MAX + 1][MAX + 1];
int in[MAX + 1];

vi g[MAX + 1];
vi c[MAX + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	for(int i = 0; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			dp[i][j] = INF;
	}

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) q.push(i);
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == ROOT) p[ROOT][ROOT] = ROOT;
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= n; j++) {
				if(u == ROOT) {
					dp[v][j] = w;
					p[v][j] = ROOT;
					break;
				}

				if(dp[u][j - 1] == INF) continue;

				if(dp[u][j - 1] + w < dp[v][j] and dp[u][j - 1] + w <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = n; i >= 0 and !ans; i--) {
		if(dp[n][i] < INF) ans = i;
	}

	vi path;
	int cnt = ans, now = n;
	while(cnt) {
		path.pb(now);
		now = p[now][cnt--];
	}

	cout << ans << '\n';
	for(int i = path.size() - 1; i >= 0; i--) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int INF = 1.9e9;
const int ROOT = 1;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	vvi dp(n + 1, vi(n + 1, INF));
	vvi p(n + 1, vi(n + 1));
	vvi g(n + 1), c(n + 1);
	vi in(n + 1);

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) {
			q.push(i);
			dp[i][1] = 0;
		}
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == ROOT) {
			dp[u][ROOT] = 0;
			p[ROOT][ROOT] = 1;
		}
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= n; j++) {
				if(u == ROOT) {
					dp[v][j] = w;
					p[v][j] = ROOT;
					break;
				}
				if(dp[u][j - 1] == INF) continue;
				if(dp[u][j - 1] + w < dp[v][j] and dp[u][j - 1] + w <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(cnt) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt--];
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const ll INF = 1.2e9;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	vvi dp(n + 1, vi(n + 1, INF));
	vvi p(n + 1, vi(n + 1));
	vvi g(n + 1), c(n + 1);
	vi in(n + 1);

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	p[1][1] = 1;
	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) {
			q.push(i);
			dp[i][1] = 0;
		}
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == 1) dp[u][1] = 0;
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= (u == 1 ? 2 : n); j++) {
				if(w + dp[u][j - 1] < dp[v][j] and w + dp[u][j - 1] <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(true) {
		path.pb(now);
		if(now == 1) break;
		now = p[now][cnt];
		cnt--;
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int INF = 1.9e9;
const int ROOT = 1;
const int MAX = 5000;

int dp[MAX + 1][MAX + 1];
int p[MAX + 1][MAX + 1];
int in[MAX + 1];

vi g[MAX + 1];
vi c[MAX + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= n; j++)
			dp[i][j] = INF;
	}

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) {
			q.push(i);
			dp[i][1] = 0;
		}
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == ROOT) {
			dp[u][ROOT] = 0;
			p[ROOT][ROOT] = 1;
		}
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= n; j++) {
				if(u == ROOT) {
					dp[v][j] = w;
					p[v][j] = ROOT;
					break;
				}
				if(dp[u][j - 1] == INF) continue;
				if(dp[u][j - 1] + w < dp[v][j] and dp[u][j - 1] + w <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(cnt) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt--];
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const ll INF = 1e17;
const int MAX = 5000;

ll dp[MAX + 1][MAX + 1];
int cost[MAX + 1][MAX + 1];
int p[MAX + 1][MAX + 1];
int in[MAX + 1];

vi g[MAX + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			dp[i][j] = INF;
	}

	int u, v, w;
	for(int i = 1; i <= n; i++) {
		cin >> u >> v >> w;
		cost[u][v] = w;
		g[u].pb(v);
		in[v]++;
	}

	queue<int> q;
	q.push(1);
	dp[1][1] = 0;
	p[1][1] = 1;

	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i];
			for(int j = 1; j <= n; j++) {
				if(dp[u][j - 1] + cost[u][v] <= T and dp[u][j - 1] + cost[u][v] < dp[v][j]) {
					dp[v][j] = dp[u][j - 1] + cost[u][v];
					p[v][j] = u;
					in[v]--;
					if(!in[v]) q.push(v);
				}
			}
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(true) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt];
		cnt--;
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const ll INF = 1e17;
const int MAX = 5000;

ll dp[MAX + 1][MAX + 1];
int p[MAX + 1][MAX + 1];
int in[MAX + 1];

vi g[MAX + 1];
vi c[MAX + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			dp[i][j] = INF;
	}

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	p[1][1] = 1;
	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) {
			q.push(i);
			dp[i][1] = 0;
		}
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == 1) dp[u][1] = 0;
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= (u == 1 ? 2 : n); j++) {
				if(w + dp[u][j - 1] < dp[v][j] and w + dp[u][j - 1] <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(true) {
		path.pb(now);
		if(now == 1) break;
		now = p[now][cnt];
		cnt--;
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const ll INF = 1e17;
const int MAX = 5000;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	vvll dp(n + 1, vll(n + 1, INF));
	vvi p(n + 1, vi(n + 1));
	vvi g(n + 1), c(n + 1);
	vi in(n + 1);

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	p[1][1] = 1;
	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) {
			q.push(i);
			dp[i][1] = 0;
		}
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == 1) dp[u][1] = 0;
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= (u == 1 ? 2 : n); j++) {
				if(w + dp[u][j - 1] < dp[v][j] and w + dp[u][j - 1] <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(true) {
		path.pb(now);
		if(now == 1) break;
		now = p[now][cnt];
		cnt--;
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const ll INF = 1e17;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	vvll dp(n + 1, vll(n + 1, INF));
	vvi cost(n + 1, vi(n + 1, 0));
	vvi p(n + 1, vi(n + 1, 0));
	vi in(n + 1, 0);
	vvi g(n + 1);

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		cost[u][v] = w;
		g[u].pb(v);
		in[v]++;
	}

	queue<int> q;
	q.push(1);
	dp[1][1] = 0;
	p[1][1] = 1;

	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i];
			for(int j = 1; j <= n; j++) {
				if(dp[u][j - 1] + cost[u][v] <= T and dp[u][j - 1] + cost[u][v] < dp[v][j]) {
					dp[v][j] = dp[u][j - 1] + cost[u][v];
					p[v][j] = u;
					in[v]--;
					if(!in[v]) q.push(v);
				}
			}
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(true) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt];
		cnt--;
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int INF = 2.1e9;
const int ROOT = 1;
const int MAX = 5000;

int dp[MAX + 1][MAX + 1];
int p[MAX + 1][MAX + 1];
int in[MAX + 1];

vi g[MAX + 1];
vi c[MAX + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	for(int i = 0; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			dp[i][j] = INF;
	}

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) q.push(i);
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == ROOT) p[ROOT][ROOT] = ROOT;
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= n; j++) {
				if(u == ROOT) {
					dp[v][j] = w;
					p[v][j] = ROOT;
					break;
				}

				if(dp[u][j - 1] == INF) continue;

				if(dp[u][j - 1] + w < dp[v][j] and dp[u][j - 1] + w <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(cnt) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt--];
	}

	cout << ans << '\n';
	for(int i = path.size() - 1; i >= 0; i--) {
		cout << path[i] << ' ';
	}

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;

typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;

typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int INF = 1.2e9;
const int ROOT = 1;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	fast_io();
//	freopen("input/721C.txt", "r", stdin);

	int n, m, T;
	cin >> n >> m >> T;

	vvi dp(n + 1, vi(n + 1, INF));
	vvi p(n + 1, vi(n + 1));
	vvi g(n + 1), c(n + 1);
	vi in(n + 1);

	int u, v, w;
	for(int i = 1; i <= m; i++) {
		cin >> u >> v >> w;
		g[u].pb(v);
		c[u].pb(w);
		in[v]++;
	}

	queue<int> q;
	for(int i = 1; i <= n; i++) {
		if(!in[i]) {
			q.push(i);
			dp[i][1] = 0;
		}
	}

	while(!q.empty()) {
		int u = q.front(); q.pop();
		if(u == ROOT) {
			dp[u][ROOT] = 0;
			p[ROOT][ROOT] = 1;
		}
		for(int i = 0; i < g[u].size(); i++) {
			int v = g[u][i], w = c[u][i];
			for(int j = 2; j <= n; j++) {
				if(u == ROOT) {
					dp[v][j] = w;
					p[v][j] = ROOT;
					break;
				}
				if(w + dp[u][j - 1] < dp[v][j] and w + dp[u][j - 1] <= T) {
					dp[v][j] = w + dp[u][j - 1];
					p[v][j] = u;
				}
			}
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(dp[n][i] < INF) {
			ans = i;
		}
	}

	vi path;
	int cnt = ans, now = n;
	while(cnt) {
		path.pb(now);
		if(p[now][now] == now) break;
		now = p[now][cnt--];
	}
	reverse(all(path));

	cout << ans << '\n';
	for(int i = 0 ; i < path.size(); i++) {
		cout << path[i] << ' ';
	}

	return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];
pair<int, int>aa;
map<pair<int, int>, int>mm;
map<pair<int, int>, int>::iterator ii;

void dfs(int id, int step)
{
    //vis[id] = 1;
    if(id==n) return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        else if(dp[u][step+1] > d+dp[id][step])
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        //if(vis[u]) continue;
        dfs(u, step+1);
    }
}
int ans[MAX], cnt;

void solve()
{

    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &aa.first, &aa.second, &q);
        if(mm[aa]!=0)
        {
            int tt = mm[aa];
            mm[aa] = min(tt, q);
            //cout << aa.x<<" "<<aa.y<<' ' << mm[aa] << endl;
        }
        else mm[aa] = q;
    }
    for(ii=mm.begin(); ii!=mm.end(); ii++)
    {
        v = ii->first.first;
        u = ii->first.second;
        q = ii->second;
        if(v==n)continue;
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;
    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
int p[MAX][MAX];
int dp[MAX][MAX];
int pre[MAX][MAX];

void dfs(int id, int step)
{
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = p[id][u]+dp[id][step];
            pre[u][step+1] = id;
        }
        else if(dp[u][step+1] > p[id][u]+dp[id][step])
        {
            dp[u][step+1] = p[id][u]+dp[id][step];
            pre[u][step+1] = id;
        }
        if(u==n) continue;
        dfs(u, step+1);
    }
}
int ans[MAX], cnt;

void solve()
{
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        mp[v].push_back(u);
        p[v][u] = q;
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;

    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
ll dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];
pair<int, int>aa;
map<pair<int, int>, int>mm;
map<pair<int, int>, int>::iterator ii;

void dfs(int id, int step)
{
    vis[id] = 1;
    if(id==n || step>n) return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
            dfs(u, step+1);
        }
        else if(dp[u][step+1] > d+dp[id][step])
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
            dfs(u, step+1);
        }
        //if(vis[u]) continue;
    }
}
int ans[MAX], cnt;

void solve()
{

    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &aa.first, &aa.second, &q);
        if(mm[aa]!=0)
        {
            int tt = mm[aa];
            mm[aa] = min(tt, q);
            //cout << aa.x<<" "<<aa.y<<' ' << mm[aa] << endl;
        }
        else mm[aa] = q;
    }
    for(ii=mm.begin(); ii!=mm.end(); ii++)
    {
        v = ii->first.first;
        u = ii->first.second;
        q = ii->second;
        if(v==n)continue;
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;
    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];

void dfs(int id, int step)
{
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        else if(dp[u][step+1] > d+dp[id][step])
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        if(u==n) continue;
        dfs(u, step+1);
    }
}
int ans[MAX], cnt;

void solve()
{
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;
    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];
pair<int, int>aa;
map<pair<int, int>, int>mm;
map<pair<int, int>, int>::iterator ii;

void dfs(int id, int step)
{
    vis[id] = 1;
    if(id==n) return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        else if(dp[u][step+1] > d+dp[id][step])
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
                       if(vis[u]) continue;
        dfs(u, step+1);
    }
}
int ans[MAX], cnt;

void solve()
{

    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &aa.first, &aa.second, &q);
        if(mm[aa]!=0)
        {
            int tt = mm[aa];
            mm[aa] = min(tt, q);
            //cout << aa.x<<" "<<aa.y<<' ' << mm[aa] << endl;
        }
        else mm[aa] = q;
    }
    for(ii=mm.begin(); ii!=mm.end(); ii++)
    {
        v = ii->first.first;
        u = ii->first.second;
        q = ii->second;
        if(v==n)continue;
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;
    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];

void dfs(int id, int step)
{
    //vis[id] = 1;
    if(id==n) return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        else if(dp[u][step+1] > d+dp[id][step])
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        //if(!vis[u])
            dfs(u, step+1);
    }
}
int ans[MAX], cnt;

void solve()
{
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;
    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+5;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];

void dfs(int id)
{
    vis[id] = 1;
    if(id==n)return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(!vis[u]);
            dfs(u);
        for(int j=2; j<=n; j++)
        {
            if(dp[u][j-1]+d < dp[id][j])
            {
                dp[id][j] = d+dp[u][j-1];
                pre[id][j] = u;
            }
        }
    }
}
int ans[MAX], cnt;

void solve()
{
    memset(pre,0,sizeof(pre));
    memset(vis,0,sizeof(vis));
    memset(dp,0x3f,sizeof(dp));
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dp[n][1] = 0;
    dfs(1);
    int flag = 0, id = 1;
    for(int i=n; i>=1; i--)
    {
        if(dp[1][i] <= t)
        {
            flag = i;
            break;
        }
    }
    printf("%d\n1 ", flag);
    while(flag > 1)
    {
        if(flag!=1) printf("%d ", pre[id][flag]);
        else printf("%d\n", pre[id][flag]);
        id = pre[id][flag--];
        //id = pre[id][flag--];
        //printf("%d%c", id, flag==1?'\n':' ');
    }
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
bool vis[MAX][MAX];

void dfs(int id, int step)
{
    if(vis[id])return;
    vis[id] = 1;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        else if(dp[u][step+1] > d+dp[id][step])
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        if(u==n) continue;
        dfs(u, step+1);
    }
}
int ans[MAX], cnt;

void solve()
{
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;
    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+5;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];

void dfs(int id)
{
    vis[id] = 1;
    if(id==n)return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(!vis[u])
            dfs(u);
        for(int j=2; j<=n; j++)
        {
            if(dp[u][j-1]+d < dp[id][j])
            {
                dp[id][j] = d+dp[u][j-1];
                pre[id][j] = u;
            }
        }
    }
}
int ans[MAX], cnt;

void solve()
{
    memset(pre,0,sizeof(pre));
    memset(vis,0,sizeof(vis));
    memset(dp,0x3f,sizeof(dp));
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dp[n][1] = 0;
    dfs(1);
    int flag = 0, id = 1;
    for(int i=n; i>=1; i--)
    {
        if(dp[1][i] <= t)
        {
            flag = i;
            break;
        }
    }
    printf("%d\n1 ", flag);
    while(flag > 1)
    {
        id = pre[id][flag--];
        printf("%d%c", id, flag==1?'\n':' ');
    }
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];
pair<int, int>aa;
map<pair<int, int>, int>mm;
map<pair<int, int>, int>::iterator ii;

void dfs(int id, int step)
{
    vis[id] = 1;
    if(id==n || step>n) return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        else if(dp[u][step+1] > d+dp[id][step])
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        //if(vis[u]) continue;
        dfs(u, step+1);
    }
}
int ans[MAX], cnt;

void solve()
{

    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &aa.first, &aa.second, &q);
        if(mm[aa]!=0)
        {
            int tt = mm[aa];
            mm[aa] = min(tt, q);
            //cout << aa.x<<" "<<aa.y<<' ' << mm[aa] << endl;
        }
        else mm[aa] = q;
    }
    for(ii=mm.begin(); ii!=mm.end(); ii++)
    {
        v = ii->first.first;
        u = ii->first.second;
        q = ii->second;
        if(v==n)continue;
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;
    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> g[5005];
vector<int> dist[5005];
short to[5005][5005];
int dp[5005][5005];
bool vis[5005];
int n,m,t;
void dfs(int c) { // depth-first search from node c
    vis[c]=true;
    if(c==n)
        return;
    for(int i=0;i<g[c].size();i++) {
        int k=g[c][i],d=dist[c][i];
        if(!vis[k])
            dfs(k);
        for(int j=2;j<=n;j++) {
            if(dp[k][j-1]+d<dp[c][j]) {
                dp[c][j]=dp[k][j-1]+d;
                to[c][j]=k;
            }
        }
    }
}
int main() {
    memset(vis,0,sizeof(vis));
    memset(dist,0,sizeof(dist));
    memset(to,0,sizeof(to));
    memset(dp,0x3f,sizeof(dp));

    scanf("%d %d %d",&n,&m,&t);
    int u,v,d;
    for(int i=0;i<m;i++) {
        scanf("%d %d %d",&u,&v,&d);
        g[u].push_back(v);
        dist[u].push_back(d);
    }
    dp[n][1]=0;
    dfs(1);

    int a=0;
    for(int i=n;i>=1;i--) {
        if(dp[1][i] <= t) {
            printf("%d\n", i);
            printf("1 ");
            a=i;
            break;
        }
    }
    int j=1;
    while(a>1) {
        if(a!=1)
            printf("%d ", to[j][a]);
        else
            printf("%d", to[j][a]);
        j=to[j][a--];
    }
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];

void dfs(int id)
{
    vis[id] = 1;
    if(id==n)return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(!vis[u]);
            dfs(u);
        for(int j=2; j<=n; j++)
        {
            if(dp[u][j-1]+d < dp[id][j])
            {
                dp[id][j] = d+dp[u][j-1];
                pre[id][j] = u;
            }
        }
    }
}
int ans[MAX], cnt;

void solve()
{
    memset(dp,0x3f,sizeof(dp));
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dp[n][1] = 0;
    dfs(1);
    int flag = 0, id = 1;
    for(int i=n; i>0; i--)
    {
        if(dp[1][i] <= t)
        {
            flag = i;
            break;
        }
    }
    printf("%d\n1 ", flag);
    while(flag > 1)
    {
        id = pre[id][flag--];
        printf("%d%c", id, flag==1?'\n':' ');
    }
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int  MAX = 5005;

int n, m;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];

void dfs(int id)
{
    vis[id] = 1;
    if(id==n)return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(!vis[u]);
            dfs(u);
        for(int j=2; j<=n; j++)
        {
            if(dp[u][j-1]+d < dp[id][j])
            {
                dp[id][j] = d+dp[u][j-1];
                pre[id][j] = u;
            }
        }
    }
}

void solve()
{
    int t, v, u, q;
    memset(pre,0,sizeof(pre));
    memset(vis,0,sizeof(vis));
    memset(dp,0x3f,sizeof(dp));
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dp[n][1] = 0;
    dfs(1);
    int flag = 0, id = 1;
    for(int i=n; i>=1; i--)
    {
        if(dp[1][i] <= t)
        {
            flag = i;
            break;
        }
    }
    printf("%d\n1 ", flag);
    while(flag > 1)
    {
        if(flag!=1) printf("%d ", pre[id][flag]);
        else printf("%d\n", pre[id][flag]);
        id = pre[id][flag--];
        //id = pre[id][flag--];
        //printf("%d%c", id, flag==1?'\n':' ');
    }
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];

void dfs(int id, int step)
{
    vis[id] = 1;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        else if(dp[u][step+1] > d+dp[id][step])
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        if(u==n || vis[u]) continue;
        dfs(u, step+1);
    }
}
int ans[MAX], cnt;

void solve()
{
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;
    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define db double
#define PI acos(-1.0)
#define EI 2.718281828
#define inf ((1ll<<63)-1)
#define INF ((1<<31)-1)
#define T while(1);
#define Frei freopen("input.txt", "r", stdin);
#define Freo freopen("output.txt", "w", stdout);
#define mem(x, y) memset(x, y, sizeof(x));
#define dbg(x) cout << #x << " = " << x << endl
const int MAXN = 100;
const int  MAXM = 100010;
const int  MAXP = 666666;
const int  MAX = 5e3+7;
const int maxn = 1e2+5;
const int mod = 100000007;
const db eps = 1e-7;
const int N = 107;
int ca = 1;

int n, m, t, v, u, q;
vector<int>mp[MAX];
vector<int>p[MAX];
int dp[MAX][MAX];
short pre[MAX][MAX];
int vis[MAX];
pair<int, int>aa;
map<pair<int, int>, int>mm;
map<pair<int, int>, int>::iterator ii;

void dfs(int id, int step)
{
    //vis[id] = 1;
    //if(id==n) return;
    for(int i=0; i<mp[id].size(); i++)
    {
        int u = mp[id][i];
        int d = p[id][i];
        if(dp[u][step+1]==0)
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        else if(dp[u][step+1] > d+dp[id][step])
        {
            dp[u][step+1] = d+dp[id][step];
            pre[u][step+1] = id;
        }
        //if(vis[u]) continue;
        dfs(u, step+1);
    }
}
int ans[MAX], cnt;

void solve()
{

    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &aa.first, &aa.second, &q);
        if(mm[aa]!=0)
        {
            int tt = mm[aa];
            mm[aa] = min(tt, q);
            //cout << aa.x<<" "<<aa.y<<' ' << mm[aa] << endl;
        }
        else mm[aa] = q;
    }
    for(ii=mm.begin(); ii!=mm.end(); ii++)
    {
        v = ii->first.first;
        u = ii->first.second;
        q = ii->second;
        mp[v].push_back(u);
        p[v].push_back(q);
    }
    dfs(1, 0);
    int flag, id = n;
    ans[cnt++] = n;
    for(int i=n; i>0; i--)
    {
        if(dp[n][i] <= t && dp[n][i])
        {
            flag = i;
            break;
        }
    }
    //cout << '*'<<flag <<endl;
    while(1)
    {
        id = pre[id][flag--];
        ans[cnt++] = id;
        if(id==1) break;
    }
    cout << cnt << endl;
    for(int i=cnt-1; i>=0; i--)
        printf("%d%c", ans[i], i==0?'\n':' ');
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}


/*                                       ----.
     @'      @@@@  `@`    +@         _.'__    `.
    `#@     @'     `##    @@     .--(#)(##)---/#\
    #`#`   :#      `#@   ,.@   .' @          /###\
    @ .#   @`      `#.'  @ @   :         ,   #####
   ,+  @   @`      `# @ `+ @    `-..__.-' _.-\###/
   @@@@@,  #,      `# '.#  @          `;_:    `"'
   @   `@  `@      `#  @@  @        .'"""""`.
   @    @   '@@@@  `#      @       /,  ACM  ,\

    我只是一只每天吃着狗粮，默默刷题的单身狗
*/
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int  MAX = 5005;

int n, m;
vector<int>g[MAX];
vector<int>dist[MAX];
int dp[MAX][MAX];
short to[MAX][MAX];
int vis[MAX];

void dfs(int c) { // depth-first search from node c
    vis[c]=true;
    if(c==n)
        return;
    for(int i=0;i<g[c].size();i++) {
        int k=g[c][i],d=dist[c][i];
        if(!vis[k])
            dfs(k);
        for(int j=2;j<=n;j++) {
            if(dp[k][j-1]+d<dp[c][j]) {
                dp[c][j]=dp[k][j-1]+d;
                to[c][j]=k;
            }
        }
    }
}

void solve()
{
    int t, v, u, q;
    memset(to,0,sizeof(to));
    memset(vis,0,sizeof(vis));
    memset(dp,0x3f,sizeof(dp));
    scanf("%d%d%d", &n, &m, &t);
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%d", &v, &u, &q);
        g[v].push_back(u);
        dist[v].push_back(q);
    }
    dp[n][1] = 0;
    dfs(1);
    int a = 0, j = 1;
    for(int i=n;i>=1;i--) {
        if(dp[1][i] <= t) {
            printf("%d\n", i);
            printf("1 ");
            a=i;
            break;
        }
    }
    while(a>1) {
        if(a!=1)
            printf("%d ", to[j][a]);
        else
            printf("%d", to[j][a]);
        j=to[j][a--];
    }
}
int main()
{
    //Frei;
    int t = 1;
    //scanf("%d", &t);
    while(t--) solve();
    return 0;
}