#include <bits/stdc++.h>
int d, p, f[11][11], C[11][11], x = 1, y = 2, one = 3, tot = 3, z, I, w[11];
int add(int a, int b) {
  printf("+ %d %d %d\n", a, b, ++tot);
  return tot;
}
int pw(int a) {
  printf("^ %d %d\n", a, ++tot);
  return tot;
}
int mul(int a, int n) {
  int b = -1;
  for (; n; n >>= 1) {
    if (n & 1) b = b < 0 ? a : add(b, a);
    a = add(a, a);
  }
  return b;
}
long long inv(int a, int p) {
  return a == 1 ? 1 : (1 + p * (a - inv(p % a, a))) / a % p;
}
int sqr(int a) {
  for (int i = 0; i <= d - 2; i++) w[i] = i ? add(w[i - 1], one) : a;
  for (int i = 0; i <= d - 2; i++)
    w[i] = pw(w[i]), (d - 2 - i) % 2 ? w[i] = mul(w[i], p - 1) : 1;
  for (int i = d - 1; i >= 2; i--)
    for (int j = 0; j <= i - 2; j++) w[j] = add(w[j], w[j + 1]);
  int s = mul(add(*w, add(mul(a, p - f[d - 2][1] % p), z)), I);
  return s;
}
int main() {
  scanf("%d%d", &d, &p);
  for (int i = 0; i <= d; i++)
    for (int j = *C[i] = 1; j <= i; j++)
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  f[0][d] = 1;
  for (int i = 1; i <= d - 2; i++)
    for (int j = 0; j <= d - i + 1; j++)
      for (int k = 0; k < j; k++) f[i][k] += C[j][k] * f[i - 1][j];
  z = mul(one, p - f[d - 2][0] % p);
  I = inv(f[d - 2][2], p);
  printf("f %d\n",
         mul(add(sqr(add(x, y)), mul(add(sqr(x), sqr(y)), p - 1)), p + 1 >> 1));
}
