#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:36777216")
template <class T>
inline T &RD(T &);
template <class T>
inline void OT(const T &);
inline long long RD() {
  long long x;
  return RD(x);
}
inline char &RC(char &c) {
  scanf(" %c", &c);
  return c;
}
inline char RC() {
  char c;
  return RC(c);
}
inline double &RF(double &x) {
  scanf("%lf", &x);
  return x;
}
inline double RF() {
  double x;
  return RF(x);
}
inline char *RS(char *s) {
  scanf("%s", s);
  return s;
}
template <class T0, class T1>
inline T0 &RD(T0 &x0, T1 &x1) {
  RD(x0), RD(x1);
  return x0;
}
template <class T0, class T1, class T2>
inline T0 &RD(T0 &x0, T1 &x1, T2 &x2) {
  RD(x0), RD(x1), RD(x2);
  return x0;
}
template <class T0, class T1, class T2, class T3>
inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {
  RD(x0), RD(x1), RD(x2), RD(x3);
  return x0;
}
template <class T0, class T1, class T2, class T3, class T4>
inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {
  RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);
  return x0;
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {
  RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);
  return x0;
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) {
  RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);
  return x0;
}
template <class T0, class T1>
inline void OT(const T0 &x0, const T1 &x1) {
  OT(x0), OT(x1);
}
template <class T0, class T1, class T2>
inline void OT(const T0 &x0, const T1 &x1, const T2 &x2) {
  OT(x0), OT(x1), OT(x2);
}
template <class T0, class T1, class T2, class T3>
inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3) {
  OT(x0), OT(x1), OT(x2), OT(x3);
}
template <class T0, class T1, class T2, class T3, class T4>
inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3,
               const T4 &x4) {
  OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3,
               const T4 &x4, const T5 &x5) {
  OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3,
               const T4 &x4, const T5 &x5, const T6 &x6) {
  OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);
}
inline char &RC(char &a, char &b) {
  RC(a), RC(b);
  return a;
}
inline char &RC(char &a, char &b, char &c) {
  RC(a), RC(b), RC(c);
  return a;
}
inline char &RC(char &a, char &b, char &c, char &d) {
  RC(a), RC(b), RC(c), RC(d);
  return a;
}
inline char &RC(char &a, char &b, char &c, char &d, char &e) {
  RC(a), RC(b), RC(c), RC(d), RC(e);
  return a;
}
inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f) {
  RC(a), RC(b), RC(c), RC(d), RC(e), RC(f);
  return a;
}
inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g) {
  RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g);
  return a;
}
inline double &RF(double &a, double &b) {
  RF(a), RF(b);
  return a;
}
inline double &RF(double &a, double &b, double &c) {
  RF(a), RF(b), RF(c);
  return a;
}
inline double &RF(double &a, double &b, double &c, double &d) {
  RF(a), RF(b), RF(c), RF(d);
  return a;
}
inline double &RF(double &a, double &b, double &c, double &d, double &e) {
  RF(a), RF(b), RF(c), RF(d), RF(e);
  return a;
}
inline double &RF(double &a, double &b, double &c, double &d, double &e,
                  double &f) {
  RF(a), RF(b), RF(c), RF(d), RF(e), RF(f);
  return a;
}
inline double &RF(double &a, double &b, double &c, double &d, double &e,
                  double &f, double &g) {
  RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g);
  return a;
}
inline void RS(char *s1, char *s2) { RS(s1), RS(s2); }
inline void RS(char *s1, char *s2, char *s3) { RS(s1), RS(s2), RS(s3); }
template <class T>
inline void RST(T &A) {
  memset(A, 0, sizeof(A));
}
template <class T0, class T1>
inline void RST(T0 &A0, T1 &A1) {
  RST(A0), RST(A1);
}
template <class T0, class T1, class T2>
inline void RST(T0 &A0, T1 &A1, T2 &A2) {
  RST(A0), RST(A1), RST(A2);
}
template <class T0, class T1, class T2, class T3>
inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {
  RST(A0), RST(A1), RST(A2), RST(A3);
}
template <class T0, class T1, class T2, class T3, class T4>
inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {
  RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {
  RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {
  RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);
}
template <class T>
inline void FLC(T &A, int x) {
  memset(A, x, sizeof(A));
}
template <class T0, class T1>
inline void FLC(T0 &A0, T1 &A1, int x) {
  FLC(A0, x), FLC(A1, x);
}
template <class T0, class T1, class T2>
inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x) {
  FLC(A0, x), FLC(A1, x), FLC(A2, x);
}
template <class T0, class T1, class T2, class T3>
inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x) {
  FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);
}
template <class T0, class T1, class T2, class T3, class T4>
inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x) {
  FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x) {
  FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x) {
  FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x),
      FLC(A6, x);
}
template <class T>
inline void CLR(priority_queue<T, vector<T>, less<T> > &Q) {
  while (!Q.empty()) Q.pop();
}
template <class T>
inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q) {
  while (!Q.empty()) Q.pop();
}
template <class T>
inline void CLR(T &A) {
  A.clear();
}
template <class T0, class T1>
inline void CLR(T0 &A0, T1 &A1) {
  CLR(A0), CLR(A1);
}
template <class T0, class T1, class T2>
inline void CLR(T0 &A0, T1 &A1, T2 &A2) {
  CLR(A0), CLR(A1), CLR(A2);
}
template <class T0, class T1, class T2, class T3>
inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {
  CLR(A0), CLR(A1), CLR(A2), CLR(A3);
}
template <class T0, class T1, class T2, class T3, class T4>
inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {
  CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);
}
template <class T0, class T1, class T2, class T3, class T4, class T5>
inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {
  CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);
}
template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>
inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {
  CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);
}
template <class T>
inline void CLR(T &A, int n) {
  for (int i = 0; i < int(n); ++i) CLR(A[i]);
}
template <class T>
inline T &SRT(T &A) {
  sort(A.begin(), A.end());
  return A;
}
template <class T, class C>
inline T &SRT(T &A, C B) {
  sort(A.begin(), A.end(), B);
  return A;
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int MOD = 777777777;
const int INF = 0x3f3f3f3f;
const long long INFF = 1LL << 60;
const double EPS = 1e-9;
const double OO = 1e15;
const double PI = acos(-1.0);
template <class T>
inline void checkMin(T &a, const T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkMax(T &a, const T b) {
  if (a < b) a = b;
}
template <class T>
inline void checkMin(T &a, T &b, const T x) {
  checkMin(a, x), checkMin(b, x);
}
template <class T>
inline void checkMax(T &a, T &b, const T x) {
  checkMax(a, x), checkMax(b, x);
}
template <class T, class C>
inline void checkMin(T &a, const T b, C c) {
  if (c(b, a)) a = b;
}
template <class T, class C>
inline void checkMax(T &a, const T b, C c) {
  if (c(a, b)) a = b;
}
template <class T>
inline T min(T a, T b, T c) {
  return min(min(a, b), c);
}
template <class T>
inline T max(T a, T b, T c) {
  return max(max(a, b), c);
}
template <class T>
inline T min(T a, T b, T c, T d) {
  return min(min(a, b), min(c, d));
}
template <class T>
inline T max(T a, T b, T c, T d) {
  return max(max(a, b), max(c, d));
}
template <class T>
inline T sqr(T a) {
  return a * a;
}
template <class T>
inline T cub(T a) {
  return a * a * a;
}
inline int Ceil(int x, int y) { return (x - 1) / y + 1; }
namespace BO {
inline bool _1(int x, int i) { return bool(x & 1 << i); }
inline bool _1(long long x, int i) { return bool(x & 1LL << i); }
inline long long _1(int i) { return 1LL << i; }
inline long long _U(int i) { return _1(i) - 1; };
inline int reverse_bits(int x) {
  x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);
  x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);
  x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);
  x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);
  x = ((x >> 16) & 0x0000ffff) | ((x << 16) & 0xffff0000);
  return x;
}
inline long long reverse_bits(long long x) {
  x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);
  x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);
  x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);
  x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);
  x = ((x >> 16) & 0x0000ffff0000ffffLL) | ((x << 16) & 0xffff0000ffff0000LL);
  x = ((x >> 32) & 0x00000000ffffffffLL) | ((x << 32) & 0xffffffff00000000LL);
  return x;
}
template <class T>
inline bool odd(T x) {
  return x & 1;
}
template <class T>
inline bool even(T x) {
  return !odd(x);
}
template <class T>
inline T low_bit(T x) {
  return x & -x;
}
template <class T>
inline T high_bit(T x) {
  T p = low_bit(x);
  while (p != x) x -= p, p = low_bit(x);
  return p;
}
template <class T>
inline T cover_bit(T x) {
  T p = 1;
  while (p < x) p <<= 1;
  return p;
}
inline int low_idx(int x) { return __builtin_ffs(x); }
inline int low_idx(long long x) { return __builtin_ffsll(x); }
inline int high_idx(int x) { return low_idx(reverse_bits(x)); }
inline int high_idx(long long x) { return low_idx(reverse_bits(x)); }
inline int clz(int x) { return __builtin_clz(x); }
inline int clz(long long x) { return __builtin_clzll(x); }
inline int ctz(int x) { return __builtin_ctz(x); }
inline int ctz(long long x) { return __builtin_ctzll(x); }
inline int parity(int x) { return __builtin_parity(x); }
inline int parity(long long x) { return __builtin_parityll(x); }
inline int lg2(int a) { return 31 - clz(a); }
inline int lg2(long long a) { return 63 - clz(a); }
inline int count_bits(int x) { return __builtin_popcount(x); }
inline int count_bits(long long x) { return __builtin_popcountll(x); }
}  // namespace BO
using namespace BO;
namespace NT {
inline void INC(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
inline int sum(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
inline void DEC(int &a, int b) {
  a -= b;
  if (a < 0) a += MOD;
}
inline int dff(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
inline void MUL(int &a, int b) { a = (long long)a * b % MOD; }
inline int pdt(int a, int b) { return (long long)a * b % MOD; }
inline int sum(int a, int b, int c) { return sum(sum(a, b), c); }
inline int sum(int a, int b, int c, int d) { return sum(sum(a, b), sum(c, d)); }
inline int pdt(int a, int b, int c) { return pdt(pdt(a, b), c); }
inline int pdt(int a, int b, int c, int d) { return pdt(pdt(pdt(a, b), c), d); }
inline int pow(int a, int b) {
  int c(1);
  while (b) {
    if (b & 1) MUL(c, a);
    MUL(a, a), b >>= 1;
  }
  return c;
}
inline int pow(int a, long long b) {
  int c(1);
  while (b) {
    if (b & 1) MUL(c, a);
    MUL(a, a), b >>= 1;
  }
  return c;
}
template <class T>
inline T pow(T a, long long b) {
  T c(1);
  while (b) {
    if (b & 1) c *= a;
    a *= a, b >>= 1;
  }
  return c;
}
inline int _I(int b) {
  int a = MOD, x1 = 0, x2 = 1, q;
  while (true) {
    q = a / b, a %= b;
    if (!a) return (x2 + MOD) % MOD;
    DEC(x1, pdt(q, x2));
    q = b / a, b %= a;
    if (!b) return (x1 + MOD) % MOD;
    DEC(x2, pdt(q, x1));
  }
}
inline void DIV(int &a, int b) { MUL(a, _I(b)); }
inline int qtt(int a, int b) { return pdt(a, _I(b)); }
inline int phi(int n) {
  int res = n;
  for (int i = 2; sqr(i) <= n; ++i)
    if (!(n % i)) {
      DEC(res, qtt(res, i));
      do {
        n /= i;
      } while (!(n % i));
    }
  if (n != 1) DEC(res, qtt(res, n));
  return res;
}
}  // namespace NT
using namespace NT;
namespace MT {
const int N = 30;
int n = 10;
struct matrix {
  double d[N][N];
  void init(double e = 0) {
    RST(d);
    if (e)
      for (int i = 0; i < int(n); ++i) d[i][i] = e;
  }
  matrix(double e = 0) { init(e); }
  matrix operator*(const matrix &rhs) const {
    matrix res;
    for (int i = 0; i < int(n); ++i)
      for (int j = 0; j < int(n); ++j)
        for (int k = 0; k < int(n); ++k) res.d[i][j] += d[i][k] * rhs.d[k][j];
    return res;
  }
  matrix &operator*=(const matrix &rhs) { (*this) = (*this) * rhs; }
};
inline matrix pow_sum(const matrix &a, unsigned long long nn) {
  matrix t;
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(n); ++j) t.d[i][j] = t.d[i][j + n] = a.d[i][j];
  for (int b____ = int(n * 2), i = n; i < b____; ++i) t.d[i][i] = 1;
  n <<= 1;
  t = pow(t, nn), n >>= 1;
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(n); ++j) t.d[i][j] = t.d[i][j + n];
  return t;
}
template <class T>
T pow_sum(T a, unsigned long long nn) {
  int _n = n;
  n = 1;
  matrix t;
  t.d[0][0] = a;
  t = pow_sum(t, nn), n = _n;
  return t.d[0][0];
}
}  // namespace MT
namespace SL {
namespace KMP {
void calc_pi(const char *P, int n, int *pi) {
  for (int i = 1, j = pi[0] = -1; i < n; ++i) {
    while (j >= 0 && P[i] != P[j + 1]) j = pi[j];
    if (P[i] == P[j + 1]) ++j;
    pi[i] = j;
  }
}
bool run(const char *T, int n, const char *P, int m, const int *pi) {
  for (int i = 0, j = -1; i < n; ++i) {
    while (j >= 0 && T[i] != P[j + 1]) j = pi[j];
    if (T[i] == P[j + 1]) ++j;
    if (j == m - 1) return true;
  }
  return false;
}
}  // namespace KMP
namespace Z {
void calc_z(const char *P, int n, int *z) {
  z[0] = n;
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i > r) {
      for (l = r = i; r < n && P[r] == P[r - l];) ++r;
      z[i] = r - l, --r;
    } else {
      if (z[i - l] < r - i + 1)
        z[i] = z[i - l];
      else {
        for (l = i; r < n && P[r] == P[r - l];) ++r;
        z[i] = r - l, --r;
      }
    }
  }
}
int run(const char *T, int n, const char *P, int m, const int *z) {
  int ex;
  for (int n____ = (ex = 0, int(min(n, m))); ex < n____; ++ex)
    if (T[ex] != P[ex]) break;
  int res = ex == m;
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i > r) {
      for (l = r = i; r < n && T[r] == P[r - l];) ++r;
      ex = r - l, --r;
    } else {
      if (z[i - l] < r - i + 1)
        ex = z[i - l];
      else {
        for (l = i; r < n && T[r] == P[r - l];) ++r;
        ex = r - l, --r;
      }
    }
    if (ex == m) ++res;
  }
  return res;
}
}  // namespace Z
void Manacher(char s[], int n, int p[]) {
  const int NN = 0;
  static char ss[NN * 2 + 2];
  int nn = 2 * n + 2;
  ss[0] = '$', ss[nn - 1] = '#', ss[nn] = 0;
  for (int i = 0; i < int(n); ++i) ss[i * 2 + 1] = '#', ss[i * 2 + 2] = s[i];
  int mx = 0, id = 0;
  for (int i = int(1); i < int(nn); ++i) {
    p[i] = mx > i ? min(p[2 * id - i], mx - i) : 1;
    while (ss[i + p[i]] == ss[i - p[i]]) ++p[i];
    if (i + p[i] > mx) mx = i + p[i], id = i;
  }
}
}  // namespace SL
using namespace SL;
namespace CG {
struct Po;
struct Line;
struct Seg;
inline int sgn(double x) { return x < -EPS ? -1 : x > EPS; }
inline int sgn(double x, double y) { return sgn(x - y); }
struct Po {
  double x, y;
  Po(double _x = 0, double _y = 0) : x(_x), y(_y) {}
  friend istream &operator>>(istream &in, Po &p) { return in >> p.x >> p.y; }
  friend ostream &operator<<(ostream &out, Po p) {
    return out << "(" << p.x << ", " << p.y << ")";
  }
  friend bool operator==(Po, Po);
  friend bool operator!=(Po, Po);
  friend Po operator+(Po, Po);
  friend Po operator-(Po, Po);
  friend Po operator*(Po, double);
  friend Po operator/(Po, double);
  bool operator<(const Po &rhs) const {
    return sgn(x, rhs.x) < 0 || sgn(x, rhs.x) == 0 && sgn(y, rhs.y) < 0;
  }
  Po operator-() const { return Po(-x, -y); }
  Po &operator+=(Po rhs) {
    x += rhs.x, y += rhs.y;
    return *this;
  }
  Po &operator-=(Po rhs) {
    x -= rhs.x, y -= rhs.y;
    return *this;
  }
  Po &operator*=(double k) {
    x *= k, y *= k;
    return *this;
  }
  Po &operator/=(double k) {
    x /= k, y /= k;
    return *this;
  }
  double length_sqr() const { return sqr(x) + sqr(y); }
  double length() const { return sqrt(length_sqr()); }
  Po unit() const { return (*this) / length(); }
  bool dgt() const { return !sgn(x) && !sgn(y); }
  double atan() const { return atan2(y, x); }
  void input() { scanf("%lf %lf", &x, &y); }
};
bool operator==(Po a, Po b) {
  return sgn(a.x - b.x) == 0 && sgn(a.y - b.y) == 0;
}
bool operator!=(Po a, Po b) {
  return sgn(a.x - b.x) != 0 || sgn(a.y - b.y) != 0;
}
Po operator+(Po a, Po b) { return Po(a.x + b.x, a.y + b.y); }
Po operator-(Po a, Po b) { return Po(a.x - b.x, a.y - b.y); }
Po operator*(Po a, double k) { return Po(a.x * k, a.y * k); }
Po operator*(double k, Po a) { return a * k; }
Po operator/(Po a, double k) { return Po(a.x / k, a.y / k); }
struct Line {
  Po a, b;
  Line(const Po &a = Po(), const Po &b = Po()) : a(a), b(b) {}
  Line(const Line &l) : a(l.a), b(l.b) {}
  Line(double x0, double y0, double x1, double y1)
      : a(Po(x0, y0)), b(Po(x1, y1)) {}
  void getequation(double, double, double) const;
  Line operator+(Po x) const { return Line(a + x, b + x); }
  friend ostream &operator<<(ostream &out, Line p) {
    return out << p.a << "-" << p.b;
  }
  double length() const { return (b - a).length(); }
  bool dgt() const { return (a - b).dgt(); }
  void input() { a.input(), b.input(); }
};
struct Seg : Line {
  Seg(const Po &a = Po(), const Po &b = Po()) : Line(a, b) {}
  Seg(const Line &l) : Line(l) {}
  Seg(double x0, double y0, double x1, double y1) : Line(x0, y0, x1, y1) {}
};
inline double dot(const double &x1, const double &y1, const double &x2,
                  const double &y2) {
  return x1 * x2 + y1 * y2;
}
inline double dot(const Po &a, const Po &b) { return dot(a.x, a.y, b.x, b.y); }
inline double dot(const Po &p0, const Po &p1, const Po &p2) {
  return dot(p1 - p0, p2 - p0);
}
inline double dot(const Po &o, const Line &l) { return dot(o, l.a, l.b); }
inline double dot(const Line &l, const Po &o) { return dot(o, l.a, l.b); }
inline double dot(const Line &l1, const Line &l2) {
  return dot(l1.b - l1.a, l2.b - l2.a);
}
inline double det(const double &x1, const double &y1, const double &x2,
                  const double &y2) {
  return x1 * y2 - x2 * y1;
}
inline double det(const Po &a, const Po &b) { return det(a.x, a.y, b.x, b.y); }
inline double det(const Po &p0, const Po &p1, const Po &p2) {
  return det(p1 - p0, p2 - p0);
}
inline double det(const Po &o, const Line &l) { return det(o, l.a, l.b); }
inline double det(const Line &l, const Po &o) { return det(o, l.a, l.b); }
inline double det(const Line &l1, const Line &l2) {
  return det(l1.b - l1.a, l2.b - l2.a);
}
void Line::getequation(double A, double B, double C) const {
  A = a.y - b.y, B = b.x - a.x, C = det(a, b);
}
template <class T1, class T2>
inline double dist(const T1 &x, const T2 &y) {
  return sqrt(dist_sqr(x, y));
}
template <class T1, class T2, class T3>
inline double dist(const T1 &x, const T2 &y, const T3 &z) {
  return sqrt(dist_sqr(x, y, z));
}
template <class T1, class T2>
inline int dett(const T1 &x, const T2 &y) {
  return sgn(det(x, y));
}
template <class T1, class T2>
inline int dott(const T1 &x, const T2 &y) {
  return sgn(dot(x, y));
}
template <class T1, class T2, class T3>
inline int dett(const T1 &x, const T2 &y, const T3 &z) {
  return sgn(det(x, y, z));
}
template <class T1, class T2, class T3>
inline int dott(const T1 &x, const T2 &y, const T3 &z) {
  return sgn(dot(x, y, z));
}
template <class T1, class T2, class T3, class T4>
inline int dett(const T1 &x, const T2 &y, const T3 &z, const T4 &w) {
  return sgn(det(x, y, z, w));
}
template <class T1, class T2, class T3, class T4>
inline int dott(const T1 &x, const T2 &y, const T3 &z, const T4 &w) {
  return sgn(dot(x, y, z, w));
}
inline double dist_sqr(const double &x, const double &y) {
  return sqr(x) + sqr(y);
}
inline double dist_sqr(const double &x, const double &y, const double &z) {
  return sqr(x) + sqr(y) + sqr(z);
}
inline double dist_sqr(const Po &a, const Po &b) {
  return sqr(a.x - b.x) + sqr(a.y - b.y);
}
inline double dist_sqr(const Po &p, const Line &l) {
  Po v0 = l.b - l.a, v1 = p - l.a;
  return sqr(fabs(det(v0, v1))) / v0.length_sqr();
}
inline double dist_sqr(const Po &p, const Seg &l) {
  Po v0 = l.b - l.a, v1 = p - l.a, v2 = p - l.b;
  if (sgn(dot(v0, v1)) * sgn(dot(v0, v2)) <= 0)
    return dist_sqr(p, Line(l));
  else
    return min(v1.length_sqr(), v2.length_sqr());
}
inline double dist_sqr(Line l, Po p) { return dist_sqr(p, l); }
inline double dist_sqr(Seg l, Po p) { return dist_sqr(p, l); }
inline double dist_sqr(Line l1, Line l2) {
  if (sgn(det(l1, l2)) != 0) return 0;
  return dist_sqr(l1.a, l2);
}
inline double dist_sqr(Line l1, Seg l2) {
  Po v0 = l1.b - l1.a, v1 = l2.a - l1.a, v2 = l2.b - l1.a;
  double c1 = det(v0, v1), c2 = det(v0, v2);
  return sgn(c1) != sgn(c2) ? 0
                            : sqr(min(fabs(c1), fabs(c2))) / v0.length_sqr();
}
bool isIntersect(Seg l1, Seg l2) {
  if (l1.a == l2.a || l1.a == l2.b || l1.b == l2.a || l1.b == l2.b) return true;
  return min(l1.a.x, l1.b.x) <= max(l2.a.x, l2.b.x) &&
         min(l2.a.x, l2.b.x) <= max(l1.a.x, l1.b.x) &&
         min(l1.a.y, l1.b.y) <= max(l2.a.y, l2.b.y) &&
         min(l2.a.y, l2.b.y) <= max(l1.a.y, l1.b.y) &&
         sgn(det(l1.a, l2.a, l2.b)) * sgn(det(l1.b, l2.a, l2.b)) <= 0 &&
         sgn(det(l2.a, l1.a, l1.b)) * sgn(det(l2.b, l1.a, l1.b)) <= 0;
}
inline double dist_sqr(Seg l1, Seg l2) {
  if (isIntersect(l1, l2))
    return 0;
  else
    return min(dist_sqr(l1.a, l2), dist_sqr(l1.b, l2), dist_sqr(l2.a, l1),
               dist_sqr(l2.b, l1));
}
inline bool isOnSide(const Po &p, const Seg &l) { return p == l.a || p == l.b; }
inline bool isOnSeg(const Po &p, const Seg &l) {
  return sgn(det(p, l.a, l.b)) == 0 && sgn(l.a.x, p.x) * sgn(l.b.x, p.x) <= 0 &&
         sgn(l.a.y, p.y) * sgn(l.b.y, p.y) <= 0;
}
inline bool isOnSegg(const Po &p, const Seg &l) {
  return sgn(det(p, l.a, l.b)) == 0 && sgn(l.a.x, p.x) * sgn(l.b.x, p.x) < 0 &&
         sgn(l.a.y, p.y) * sgn(l.b.y, p.y) < 0;
}
inline Po intersect(const Line &l1, const Line &l2) {
  return l1.a + (l1.b - l1.a) * (det(l2.a, l1.a, l2.b) / det(l2, l1));
}
inline Po intersect(const Po &p, const Line &l) {
  return intersect(Line(p, p + Po(l.a.y - l.b.y, l.b.x - l.a.x)), l);
}
inline Po rotate(Po p, double alpha, Po o = Po()) {
  p.x -= o.x, p.y -= o.y;
  return Po(p.x * cos(alpha) - p.y * sin(alpha),
            p.y * cos(alpha) + p.x * sin(alpha)) +
         o;
}
}  // namespace CG
using namespace CG;
namespace RNG {
inline unsigned int rand16() { return (bool(rand() & 1) << 15) | rand(); }
inline unsigned int rand32() { return (rand16() << 16) | rand16(); }
inline unsigned long long rand64() {
  return ((long long)rand32() << 32) | rand32();
}
inline unsigned long long random(long long l, long long r) {
  return rand64() % (r - l) + l;
}
int dice() { return rand() % 6; }
bool coin() { return bool(rand() % 2); }
}  // namespace RNG
using namespace RNG;
namespace CLK {
double s0, s1, rd, k, T;
inline double getTime() { return 1.0 * clock() / CLOCKS_PER_SEC; }
inline void st0(double _T = 0.98) { T = _T, s0 = getTime(); }
inline void st1(double _k = 1.618) { k = _k, s1 = getTime(); }
inline void ed1() { rd = getTime() - s1; }
inline double elapsed() { return getTime() - s0; }
inline bool safe() { return elapsed() + rd * k < T; }
}  // namespace CLK
namespace TMP {
template <class T>
pair<T, T> operator+(const pair<T, T> &p1, const pair<T, T> &p2) {
  return pair<T, T>(p1.first + p2.first, p1.second + p2.second);
}
template <class T>
pair<T, T> operator-(const pair<T, T> &p1, const pair<T, T> &p2) {
  return pair<T, T>(p1.first - p2.first, p1.second - p2.second);
}
template <class T>
pair<T, T> operator*(const pair<T, T> &lhs, T k) {
  return pair<T, T>(lhs.first * k, lhs.second * k);
}
}  // namespace TMP
using namespace TMP;
template <class T>
inline T &RD(T &x) {
  char c;
  for (c = getchar(); c < '0'; c = getchar())
    ;
  x = c - '0';
  for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x;
}
int ____Case;
template <class T>
inline void OT(const T &x) {
  printf("%d\n", x);
}
int a[10][300] = {
    {0},
    {2, 1},
    {32, 30, 80, 109},
    {6824, 59808, 147224, 415870, 1757896, 1897056, 4898872, 7593125},
    {776830421, 290516100, 746623577, 293783147, 33900006, 735127505, 565460332,
     428982705, 472062098, 161873957, 117354594, 515619293, 578944191,
     312106242, 569389279, 391464593},
    {261086313, 584837659, 683961846, 468868529, 211593382, 736955478,
     229471758, 157617135, 398169441, 360252438, 629394768, 264125799,
     647490480, 342079395, 391579767, 225200475, 486011304, 513156108,
     628771752, 132906648, 142138221, 20119449,  444199674, 195188679,
     387329805, 44684703,  651912135, 737154512, 612549793, 519860281,
     186175544, 212568440},
    {240805271, 239509872, 581127897, 6511239,   156126222, 509425833,
     672407328, 366667722, 459185405, 509737025, 554790222, 165216555,
     703150560, 74806569,  398730015, 383350905, 506108358, 51326142,
     298053147, 104256117, 391428765, 374020479, 206607807, 87664059,
     275899176, 56407680,  551553401, 448939463, 582889860, 129676638,
     226078251, 135769095, 61292868,  578972226, 190181628, 390739055,
     184587732, 446575689, 732674124, 232198470, 676760679, 352474101,
     611444862, 575661807, 628905585, 320813094, 522840969, 469781928,
     156006018, 554473341, 239654268, 643714911, 433540170, 199307003,
     496385218, 291740751, 67309914,  370826673, 202356819, 279421821,
     421203111, 63744786,  520987612, 550671827},
    {482164403, 768209115, 462063756, 154906374, 36099042,  341766705,
     678182556, 621882744, 478771358, 231881111, 175889805, 243630450,
     168908523, 671961765, 55761813,  652682670, 773939082, 517628076,
     756201264, 124604900, 750976272, 498253248, 676047609, 137170026,
     705610017, 495032139, 561797418, 703097347, 500815609, 95984586,
     739707108, 265613565, 387099846, 777331779, 594676173, 591219559,
     407997044, 208947235, 93337440,  478908360, 685013007, 487033953,
     671903001, 39521181,  738490312, 33785059,  465470131, 310453920,
     54648783,  346831137, 427694175, 474743430, 705296781, 435828036,
     429824745, 663532359, 261388683, 244690731, 533997135, 596108961,
     506813013, 371892402, 590145264, 104733162, 143420103, 654339672,
     700348950, 685038942, 578826927, 286484229, 501639192, 434962491,
     299270097, 27702486,  335375775, 111746817, 565603164, 294926121,
     676063665, 735862995, 710035809, 437011960, 668528077, 138765186,
     508213986, 615036450, 353784942, 624827616, 343900011, 241289776,
     52410890,  72018835,  352406796, 415705878, 4802637,   376367145,
     65589678,  333633477, 341834527, 303717460, 282387700, 42951006,
     254706039, 423048528, 526429710, 68131467,  669954708, 12787348,
     500636381, 317959019, 479433192, 657133515, 416259390, 610216692,
     340129188, 44594256,  257373347, 138718678, 530767740, 292922628,
     37220268,  605295159, 480722613, 458170419, 30540300,  487159055,
     232966794, 149150650},
    {412133651, 386543325, 139952108, 289303402, 102404925, 317067177,
     396414708, 80515854,  663739304, 317300809, 228877044, 493725043,
     715317967, 490300965, 315527373, 743539734, 488329191, 553627998,
     533025234, 242583957, 706116537, 614109258, 645447222, 523195911,
     492109128, 722623041, 111085128, 766395126, 654378921, 691964847,
     496688157, 399056049, 654363234, 102052314, 191720088, 473910948,
     259736526, 332840025, 388047555, 665791056, 627111387, 139696515,
     441456687, 443032569, 283264821, 771641703, 452641455, 511306362,
     117572859, 127701891, 721298331, 176520078, 357242229, 611296308,
     696994956, 405628839, 429224274, 465336054, 695091546, 689828796,
     574648641, 351220905, 507964023, 675326610, 517248963, 453528621,
     220301928, 494463186, 681789969, 339589656, 44524053,  417125457,
     339589404, 747135963, 341780733, 734158215, 396817281, 21997836,
     5728464,   147611205, 456248898, 714128667, 377654949, 3862068,
     128418948, 589390074, 304947090, 11703825,  228266073, 127304142,
     429215724, 361541124, 521572968, 468358191, 341231688, 65323503,
     613778508, 15985323,  291661029, 410970006, 591638112, 349541550,
     89967528,  224922159, 361094166, 584206074, 640051812, 324264456,
     652625388, 693768537, 11740617,  309238398, 211085469, 194905872,
     639416484, 110110707, 296645895, 748118511, 131177718, 511142751,
     775975599, 421403409, 475528473, 434685258, 1768977,   80301375,
     708023862, 569195676, 56238084,  632887668, 88089750,  631539342,
     396695565, 38780154,  695798271, 469819224, 439587099, 69045921,
     682966116, 112310856, 64943298,  534475872, 40215357,  389728458,
     286368453, 736006257, 501181650, 54829908,  603489402, 338032656,
     512182818, 627500097, 462674016, 3103092,   157324491, 43978329,
     596818971, 259025598, 9088632,   91991781,  577291428, 211245489,
     429471231, 142626330, 172560633, 510907446, 444609585, 758102058,
     375112647, 744786693, 276174402, 19259856,  233672418, 745389414,
     225772848, 23385663,  324290610, 519804558, 120337812, 402578568,
     360676008, 450089262, 551043738, 337388940, 512108856, 28879011,
     690040638, 106017282, 558262341, 99972432,  608226003, 612152037,
     42414435,  776201013, 39580443,  518796945, 494437752, 583194366,
     723936555, 415359657, 309569589, 751104774, 166684527, 249229170,
     353120823, 130668327, 753823584, 580966092, 561963717, 543672234,
     393846327, 586278000, 327398400, 278403867, 156455586, 363920382,
     190245195, 290039148, 547014447, 466218648, 146037150, 585462906,
     666008595, 691786683, 374707494, 622498779, 231158277, 685740951,
     115612245, 681825249, 545555745, 551718468, 277206615, 640171035,
     757727334, 195193908, 658656684, 457760646, 225925875, 505761984,
     18685233,  506832921, 112511021, 396846646, 290147622, 113924623,
     669986155, 336008070, 63611061,  238586775, 119956662, 616557739,
     772784623, 334527774, 410403148, 51933421}};
int n, k;
int main() { RD(n, k), OT(a[lg2(n)][k - 1]); }
