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

void input(int& rnMaxNum)
{
  cin >> rnMaxNum;
}

bool is7NotIncluded(int nNum, int nBase)
{
  while (nNum != 0)
  {
    if (nNum % nBase == 7)
      return false;

    nNum /= nBase;
  }
  return true;
}

int calc7NotIncluded(int nMaxNum)
{
  int n7NotIncluded = 0;

  for (int nx = 1; nx <= nMaxNum; ++nx)
    if ( is7NotIncluded(nx, 10) &&
         is7NotIncluded(nx,  8)    )
      ++n7NotIncluded;

  return n7NotIncluded;
}
  
int main()
{
  int nMaxNum;
  input(nMaxNum);
  cout << calc7NotIncluded(nMaxNum) << endl;

  return 0;
}
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

ll MOD=998244353;

int main(){FIN;
	ll n; cin>>n;
	vector<ll> a(n);
	fore(i,0,n)cin>>a[i];
	sort(ALL(a));
	ll res=0;
	ll sum=0;
	fore(i,0,n){
		res=(res+sum*a[i])%MOD;
		sum=(2*sum+a[i])%MOD;
	}
	fore(i,0,n)res=(res+a[i]*a[i])%MOD;
	cout<<res<<"\n";
	
	return 0;
}