#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
inline int read() {
  int sum = 0, p = 1;
  char ch = getchar();
  while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
  if (ch == '-') p = -1, ch = getchar();
  while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
  return sum * p;
}
const int maxn = 5020;
const int Zero = 4000;
const int One = 4010;
int d, mod;
int cell[maxn];
int X, Y;
int C[100][100];
int tot;
inline int power(int a, int b) {
  int ans = 1;
  while (b)
    (b & 1 ? ans = (long long)ans * a % mod : 0), b >>= 1,
        a = (long long)a * a % mod;
  return ans;
}
inline void add(int a, int b, int c) {
  printf("+ %d %d %d\n", a, b, c);
  cell[c] = (cell[a] + cell[b]) % mod;
}
int tmp = 3000;
inline void mul(int a, int c, int b) {
  add(Zero, Zero, b);
  add(Zero, a, ++tmp);
  while (c) (c & 1 ? add(b, tmp, b), 0 : 0), c >>= 1, add(tmp, tmp, tmp);
}
int x[100];
int g[100][100];
inline int square(int a) {
  if (d == 2)
    return printf("^ %d %d\n", a, ++tot), cell[tot] = power(cell[a], d), tot;
  add(a, Zero, x[0] = ++tot);
  for (int i = (1), _end_ = (d); i <= _end_; i++) {
    add(tot, One, tot + 1);
    x[i] = ++tot;
  }
  for (int i = (0), _end_ = (d); i <= _end_; i++)
    printf("^ %d %d\n", x[i], x[i]), cell[x[i]] = power(cell[x[i]], d);
  memset(g, 0, sizeof(g));
  for (int i = (0), _end_ = (d); i <= _end_; i++)
    for (int j = (0), _end_ = (d); j <= _end_; j++)
      g[i][j] = (long long)power(i, d - j) * C[d][j] % mod;
  for (int i = (0), _end_ = (d); i <= _end_; i++) g[i][d + 1 + i] = 1;
  for (int i = (0), _end_ = (d); i <= _end_; i++) {
    if (!g[i][i]) {
      for (int j = (i + 1), _end_ = (d); j <= _end_; j++)
        if (g[j][i]) {
          for (int l = (i), _end_ = (2 * d + 1); l <= _end_; l++)
            swap(g[i][l], g[j][l]);
          break;
        }
    }
    for (int j = (0), _end_ = (d); j <= _end_; j++)
      if (i != j) {
        int tmp = (long long)g[j][i] * power(g[i][i], mod - 2) % mod;
        for (int l = (i), _end_ = (2 * d + 1); l <= _end_; l++)
          g[j][l] = (g[j][l] - (long long)tmp * g[i][l] % mod + mod) % mod;
      }
    for (int j = (i + 1), _end_ = (2 * d + 1); j <= _end_; j++)
      g[i][j] = (long long)g[i][j] * power(g[i][i], mod - 2) % mod;
    g[i][i] = 1;
  }
  int now = ++tot;
  add(Zero, Zero, now);
  for (int i = (0), _end_ = (d); i <= _end_; i++)
    mul(x[i], g[2][d + 1 + i], ++tot), add(now, tot, now);
  return now;
}
inline void init() {
  d = read();
  mod = read();
  X = 1, Y = 2;
  for (int i = (1), _end_ = (5000); i <= _end_; i++) cell[i] = 1;
  cell[1] = X;
  cell[2] = Y;
  int t = mod - 1;
  while (t)
    (t & 1 ? add(Zero, Zero - 1, Zero), 0 : 0), t >>= 1,
        add(Zero - 1, Zero - 1, Zero - 1);
  C[0][0] = 1;
  for (int i = (1), _end_ = (d); i <= _end_; i++)
    for (int j = (0), _end_ = (i); j <= _end_; j++)
      C[i][j] = ((j ? C[i - 1][j - 1] : 0) + C[i - 1][j]) % mod;
  tot = 2000;
}
inline void doing() {
  add(1, 2, 3);
  int x2 = square(1), y2 = square(2), xy2 = square(3);
  add(x2, y2, 4);
  mul(4, mod - 1, 5);
  add(5, xy2, 5);
  int inv2 = (mod + 1) >> 1;
  mul(5, inv2, 6);
  printf("f 6\n");
}
int main() {
  init();
  doing();
  return 0;
}
