import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {

    void solve() {
        n=ni(); m=ni();
        f=new int[m+1];
        for(int i=1;i<=n;i++) f[ni()]++;
        int ans=0;
        if(m<=2){

            for(int i=1;i<=m;i++) ans+=f[i]/3;
            pw.println(ans);
            return;
        }
        for(int i=1;i<=m;i++){
            if(f[i]>6){
                ans+=(f[i]-6)/3;
                f[i]=6+f[i]%3;
            }

        }
        dp=new int[m+1][3][3];
        for(int i=1;i<=m;i++) for(int j=0;j<=2;j++) Arrays.fill(dp[i][j],-1);
        ans+=go(3,0,0);
        pw.println(ans);
    }
    int n,m;
    int f[];
    int dp[][][];
    int go(int i,int c1,int c2){

        if(i>m) {

            return (f[i-2]-c1-c2)/3+(f[i-1]-c2)/3;
        }

        if(dp[i][c1][c2]!=-1) return dp[i][c1][c2];
        //  pw.println(i);
        int mx=0;
        int kk=Math.min(2,Math.min(f[i-2]-c1-c2,Math.min(f[i-1]-c2,f[i])));
        for(int k=0;k<=kk;k++){
            int d=k+(f[i-2]-c1-c2-k)/3;
            mx=Math.max(mx,d+go(i+1,c2,k));
        }
        dp[i][c1][c2]=mx;
        return mx;
    }
    long add(long a,long b){
        a+=b;
        if(a>=M) a-=M;
        return a;
    }
    long sub(long a,long b){
        a-=b;
        if(a<0) a+=M;
        return a;
    }
    long mul(long a,long b){
        a*=b;
        if(a>=M) a%=M;
        return a;
    }
    long modpow(long a, long b,long M)
    {
        long r=1;
        while(b>0)
        {
            if((b&1)>0) r=mul(r,a);
            a=mul(a,a);
            b>>=1;
        }
        return r;
    }

    long modInverse(long A, long M)
    {

        return modpow(A,M-2,M);
    }

    long M = (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");

    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  V< VV<> > dp; assign(dp, m + 1, 3, 3, -1e9);
  for (int j = 0; j < 3; ++j) {
    dp[1][0][j] = (c[0] - j) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (c[i - 1] - j < 0) continue;
      for (int k = 0; k < 3; ++k) {
        if (c[i] - k < 0) continue;
        dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][0][j] + (c[i] - k) / 3);
        if (c[i] - k - 1 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][1][(j + 1) % 3] - (j + 1) / 3 + 1 + (c[i] - k - 1) / 3);
        if (c[i] - k - 2 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][2][(j + 2) % 3] - (j + 2) / 3 + 2 + (c[i] - k - 2) / 3);
      }
    }
  }
  cout << dp[m][0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  V< VV<> > dp; assign(dp, m + 1, 3, 3, -1e9);
  for (int j = 0; j < 3; ++j) {
    dp[1][0][j] = (c[0] - j) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (c[i - 1] - j < 0) continue;
      for (int k = 0; k < 3; ++k) {
        if (c[i] - k < 0) continue;
        dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][0][j] + (c[i] - k) / 3);
        if (c[i] - k - 1 >= 0 and c[i - 1] - j - 1 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][1][(j + 1) % 3] - (j + 1) / 3 + 1 + (c[i] - k - 1) / 3);
        if (c[i] - k - 2 >= 0 and c[i - 1] - j - 2 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][2][(j + 2) % 3] - (j + 2) / 3 + 2 + (c[i] - k - 2) / 3);
      }
    }
  }
  cout << dp[m][0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  VV<> dp0; assign(dp0, 3, 3, -1e9);
  dp0[0][0] = 0;
  for (int i = 0; i < m; ++i) {
    VV<> dp1; assign(dp1, 3, 3, -1e9);
    for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) {
      for (int x = 0; x < 3; ++x) {
        if (c[i] - x - j - k >= 0) {
          dp1[j][k] = max(dp1[j][k], dp0[x][j] + x + (c[i] - x - j - k) / 3);
        }
      }
    }
    swap(dp0, dp1);
  }
  cout << dp0[0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  V< VV<> > dp; assign(dp, m + 1, 3, 3, -1e9);
  dp[0][0][0] = 0;
  for (int k = 0; k < 3; ++k) {
    if (c[0] - k >= 0) dp[1][0][k] = (c[0] - k) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (c[i - 1] - j - 0 >= 0 and c[i] - k - 0 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][0][(j + 0) % 3] - (j + 0) / 3 + 0 + (c[i] - k - 0) / 3);
        if (c[i - 1] - j - 1 >= 0 and c[i] - k - 1 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][1][(j + 1) % 3] - (j + 1) / 3 + 1 + (c[i] - k - 1) / 3);
        if (c[i - 1] - j - 2 >= 0 and c[i] - k - 2 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][2][(j + 2) % 3] - (j + 2) / 3 + 2 + (c[i] - k - 2) / 3);
      }
    }
  }
  int res = -1e9;
  for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) {
    res = max(res, dp[m][j][k]);
  }
  cout << res << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  V< VV<> > dp; assign(dp, m + 1, 3, 3, -1e9);
  for (int j = 0; j < 3; ++j) {
    if (c[0] - j >= 0) dp[1][0][j] = (c[0] - j) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (c[i - 1] - j < 0) continue;
      for (int k = 0; k < 3; ++k) {
        if (c[i] - k < 0) continue;
        dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][0][j] + (c[i] - k) / 3);
        if (c[i] - k - 1 >= 0 and c[i - 1] - j - 1 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][1][(j + 1) % 3] - (j + 1) / 3 + 1 + (c[i] - k - 1) / 3);
        if (c[i] - k - 2 >= 0 and c[i - 1] - j - 2 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][2][(j + 2) % 3] - (j + 2) / 3 + 2 + (c[i] - k - 2) / 3);
      }
    }
  }
  cout << dp[m][0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  VV<> dp0; assign(dp0, 6, 6, -1e9);
  VV<> dp1; assign(dp1, 6, 6, -1e9);
  for (int k = 0; k < 6; ++k) {
    if (c[0] - k >= 0) dp0[0][k] = (c[0] - k) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 6; ++j) {
      for (int k = 0; k < 6; ++k) {
        if (c[i - 1] - j - 0 >= 0 and c[i] - k - 0 >= 0) dp1[j][k] = max(dp1[j][k], dp0[0][(j + 0) % 6] + 0 + (c[i] - k - 0) / 3);
        if (c[i - 1] - j - 1 >= 0 and c[i] - k - 1 >= 0) dp1[j][k] = max(dp1[j][k], dp0[1][(j + 1) % 6] - (j + 1 >= 6 ? 2 : 0) + 1 + (c[i] - k - 1) / 3);
        if (c[i - 1] - j - 2 >= 0 and c[i] - k - 2 >= 0) dp1[j][k] = max(dp1[j][k], dp0[2][(j + 2) % 6] - (j + 2 >= 6 ? 2 : 0) + 2 + (c[i] - k - 2) / 3);
      }
    }
    swap(dp0, dp1);
  }
  cout << dp0[0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  V< VV<> > dp; assign(dp, m + 1, 3, 3, -1e9);
  for (int j = 0; j < 3; ++j) {
    dp[1][j][0] = (c[0] - j) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (c[i] - j < 0) continue;
      for (int k = 0; k < 3; ++k) {
        if (c[i - 1] - k < 0) continue;
        dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][k][0] + (c[i] - j) / 3);
        if (k + 1 < 3 and c[i] - j - 1 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][k + 1][1] + 1 + (c[i] - j - 1) / 3);
        if (k + 2 < 3 and c[i] - j - 2 >= 0) dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][k + 2][2] + 2 + (c[i] - j - 2) / 3);
      }
    }
  }
  cout << dp[m][0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  VV<> dp0; assign(dp0, 6, 6, -1e9);
  VV<> dp1; assign(dp1, 6, 6, -1e9);
  for (int k = 0; k < 6; ++k) {
    if (c[0] - k >= 0) dp0[0][k] = (c[0] - k) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 6; ++j) {
      for (int k = 0; k < 6; ++k) {
        // if (c[i - 1] - j - 0 >= 0 and c[i] - k - 0 >= 0) dp1[j][k] = max(dp1[j][k], dp0[0][(j + 0) % 6] + 0 + (c[i] - k - 0) / 3);
        // if (c[i - 1] - j - 1 >= 0 and c[i] - k - 1 >= 0) dp1[j][k] = max(dp1[j][k], dp0[1][(j + 1) % 6] - (j + 1 >= 6 ? 2 : 0) + 1 + (c[i] - k - 1) / 3);
        // if (c[i - 1] - j - 2 >= 0 and c[i] - k - 2 >= 0) dp1[j][k] = max(dp1[j][k], dp0[2][(j + 2) % 6] - (j + 2 >= 6 ? 2 : 0) + 2 + (c[i] - k - 2) / 3);
        for (int x = 0; x < 6; ++x) {
          if (c[i - 1] - j - x >= 0 and c[i] - k - x >= 0) dp1[j][k] = max(dp1[j][k], dp0[x][(j + x) % 6] - (j + x >= 6 ? 2 : 0) + x + (c[i] - k - x) / 3);
        }
      }
    }
    swap(dp0, dp1);
  }
  cout << dp0[0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  VV<> dp0; assign(dp0, 6, 6, -1e9);
  VV<> dp1; assign(dp1, 6, 6, -1e9);
  for (int k = 0; k < 6; ++k) {
    if (c[0] - k >= 0) dp0[0][k] = (c[0] - k) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 6; ++j) {
      for (int k = 0; k < 6; ++k) {
        if (c[i - 1] - j - 0 >= 0 and c[i] - k - 0 >= 0) dp1[j][k] = max(dp1[j][k], dp0[0][(j + 0) % 6] + 0 + (c[i] - k - 0) / 3);
        if (c[i - 1] - j - 1 >= 0 and c[i] - k - 1 >= 0) dp1[j][k] = max(dp1[j][k], dp0[1][(j + 1) % 6] - max((j - 2) / 3, 0) + 1 + (c[i] - k - 1) / 3);
        if (c[i - 1] - j - 2 >= 0 and c[i] - k - 2 >= 0) dp1[j][k] = max(dp1[j][k], dp0[2][(j + 2) % 6] - max((j - 1) / 3, 0) + 2 + (c[i] - k - 2) / 3);
      }
    }
    swap(dp0, dp1);
  }
  cout << dp0[0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  VV<> dp0; assign(dp0, 6, 6, -1e9);
  VV<> dp1; assign(dp1, 6, 6, -1e9);
  for (int k = 0; k < 6; ++k) {
    if (c[0] - k >= 0) dp0[0][k] = (c[0] - k) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 6; ++j) {
      for (int k = 0; k < 6; ++k) {
        if (c[i - 1] - j - 0 >= 0 and c[i] - k - 0 >= 0) dp1[j][k] = max(dp1[j][k], dp0[0][(j + 0) % 6] - (j + 0) / 3 + 0 + (c[i] - k - 0) / 3);
        if (c[i - 1] - j - 1 >= 0 and c[i] - k - 1 >= 0) dp1[j][k] = max(dp1[j][k], dp0[1][(j + 1) % 6] - (j + 1) / 3 + 1 + (c[i] - k - 1) / 3);
        if (c[i - 1] - j - 2 >= 0 and c[i] - k - 2 >= 0) dp1[j][k] = max(dp1[j][k], dp0[2][(j + 2) % 6] - (j + 2) / 3 + 2 + (c[i] - k - 2) / 3);
      }
    }
    swap(dp0, dp1);
  }
  cout << dp0[0][0] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c(m);
  for (int i = 0; i < n; ++i) {
    int a; cin >> a, --a;
    ++c[a];
  }
  VV<> dp0; assign(dp0, 6, 6, -1e9);
  VV<> dp1; assign(dp0, 6, 6, -1e9);
  for (int k = 0; k < 6; ++k) {
    if (c[0] - k >= 0) dp0[0][k] = (c[0] - k) / 3;
  }
  for (int i = 1; i < m; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (c[i - 1] - j - 0 >= 0 and c[i] - k - 0 >= 0) dp1[j][k] = max(dp1[j][k], dp0[0][(j + 0) % 3] - (j + 0) / 3 + 0 + (c[i] - k - 0) / 3);
        if (c[i - 1] - j - 1 >= 0 and c[i] - k - 1 >= 0) dp1[j][k] = max(dp1[j][k], dp0[1][(j + 1) % 3] - (j + 1) / 3 + 1 + (c[i] - k - 1) / 3);
        if (c[i - 1] - j - 2 >= 0 and c[i] - k - 2 >= 0) dp1[j][k] = max(dp1[j][k], dp0[2][(j + 2) % 3] - (j + 2) / 3 + 2 + (c[i] - k - 2) / 3);
      }
    }
    swap(dp0, dp1);
  }
  int res = -1e9;
  for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) {
    res = max(res, dp0[j][k]);
  }
  cout << res << '\n';
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 1000000009
int dp[1000005][3][3];
int n,m;
int a[1000005];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=n;++i){
		int x;cin>>x;++a[x];
	}
	for (int i=1;i<1000005;++i) for (int j=0;j<3;++j) for (int k=0;k<3;++k) dp[i][j][k]=-INF;
	dp[0][0][0]=0;
	for (int i=0;i<n;++i) for (int j=0;j<3;++j) for (int k=0;k<3;++k){
		if (dp[i][j][k]==-INF) continue;
		int cur=dp[i][j][k];
		for (int l=0;l<3;++l){
			if (a[i+2]<l) continue;
			if (a[i+1]<k+l) continue;
			if (a[i]<j+k+l) continue;
			dp[i+1][k][l]=max(dp[i+1][k][l],dp[i][j][k]+l+(a[i]-j-k-l)/3);
		}
	}
	int ans=0;
	for (int j=0;j<3;++j) for (int k=0;k<3;++k) ans=max(ans,dp[n][j][k]);
	cout<<ans;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 1000000009
int dp[1000005][3][3];
int n,m;
int a[1000005];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=n;++i){
		int x;cin>>x;++a[x];
	}
	for (int i=1;i<1000005;++i) for (int j=0;j<3;++j) for (int k=0;k<3;++k) dp[i][j][k]=-INF;
	dp[0][0][0]=0;
	for (int i=0;i<m;++i) for (int j=0;j<3;++j) for (int k=0;k<3;++k){
		if (dp[i][j][k]==-INF) continue;
		int cur=dp[i][j][k];
		for (int l=0;l<3;++l){
			if (a[i+2]<l) continue;
			if (a[i+1]<k+l) continue;
			if (a[i]<j+k+l) continue;
			dp[i+1][k][l]=max(dp[i+1][k][l],dp[i][j][k]+l+(a[i]-j-k-l)/3);
		}
	}
	int ans=0;
	for (int j=0;j<3;++j) for (int k=0;k<3;++k) ans=max(ans,dp[m][j][k]);
	cout<<ans;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 1000000009
int dp[1000005][5][5];
int n,m;
int a[1000005];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	while(n--){
		int x;cin>>x;a[x]++;
	}
	for (int i=0;i<1000005;++i) rep(j,5) rep(k,5) dp[i][j][k]=-INF;
	dp[0][0][0]=0;
	rep(i,m+2) rep(j,5) rep(k,5){
		if (dp[i][j][k]==-INF) continue;
		int minx=min(j,k);minx=min(minx,a[i+1]);
		minx=min(minx,2);
		for (int l=0;l<=minx;++l){
			int lft=a[i+1]-l,triple=lft/3,rem=lft%3;
			dp[i+1][rem][j-l]=max(dp[i+1][rem][j-l],dp[i][j][k]+triple+l);
			if (triple>0) dp[i+1][min(4,rem+3)][j-l]=max(dp[i+1][min(4,rem+3)][j-l],dp[i][j][k]+triple-1+l);
			if (triple>1) dp[i+1][4][j-l]=max(dp[i+1][4][j-l],dp[i][j][k]+triple-2+l);
		}
	}
	int ans=0;
	rep(j,5) rep(k,5){
		ans=max(ans,dp[m][j][k]);
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 1000000009
int dp[1000005][3][3];
int n,m;
int a[1000005];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=n;++i){
		int x;cin>>x;++a[x];
	}
	for (int i=1;i<1000005;++i) for (int j=0;j<3;++j) for (int k=0;k<3;++k) dp[i][j][k]=-INF;
	dp[0][0][0]=0;
	for (int i=0;i<m;++i) for (int j=0;j<3;++j) for (int k=0;k<3;++k){
		if (dp[i][j][k]==-INF) continue;
		int cur=dp[i][j][k];
		for (int l=0;l<3;++l){
			if (a[i+2]<l) continue;
			if (a[i+1]<k+l) continue;
			if (a[i]<j+k+l) continue;
			dp[i+1][k][l]=max(dp[i+1][k][l],dp[i][j][k]+l+(a[i]-j-k-l)/3);
		}
	}
	int ans=0;
	for (int j=0;j<3;++j) for (int k=0;k<3;++k) ans=max(ans,dp[n][j][k]);
	cout<<ans;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 1000000009
int dp[1000005][3][3];
int n,m;
int a[1000005];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=n;++i){
		int x;cin>>x;++a[x];
	}
	for (int i=1;i<1000005;++i) for (int j=0;j<3;++j) for (int k=0;k<3;++k) dp[i][j][k]=-INF;
	dp[0][0][0]=0;
	for (int i=0;i<m;++i) for (int j=0;j<3;++j) for (int k=0;k<3;++k){
		if (dp[i][j][k]==-INF) continue;
		int cur=dp[i][j][k];
		for (int l=0;l<3;++l){
			if (a[i+2]<l) continue;
			if (a[i+1]<k+l) continue;
			if (a[i]<j+k+l) continue;
			dp[i+1][k][l]=max(dp[i+1][k][l],dp[i][j][k]+l+(a[i]-j-k-l)/3);
		}
	}
	int ans=0;
	for (int j=0;j<3;++j) for (int k=0;k<3;++k) ans=max(ans,dp[m][j][k]+(a[m]-j-k)/3);
	cout<<ans;
	return 0;
}


#include <iostream>
using namespace std;
const int N = 1e6 + 1;

static int dp[N][7][7], cnt[N];

int main()
{
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n];
    long long ans = 0;
    for (int i = 0; i < n; ++i)
        cin >> a[i], cnt[a[i]]++;
    for (int i = 0; i < n; ++i)
        ans += (cnt[i] - cnt[i]%6) / 3, cnt[i] %= 6;
    for (int i = 0; i <= m; ++i)
    {
        for (int j = 0; j < 7; ++j)
        {
            for (int k = 0; k < 7; ++k)
            {
                if (j > cnt[i-1] || k > cnt[i])
                    continue;
                if (k >= 3)
                    dp[i][j][k] = dp[i][j][k-3] + 1;
                int r = min(j, k);
                if (i)
                    r = min(r, cnt[i-2]);
                for (int l = 0; l <= r; ++l)
                    dp[i][j][k] = max(dp[i][j][k], l + dp[i-1][cnt[i-2]-l][j-l]);
            }
        }
    }
    cout << ans + dp[m][cnt[m-1]][cnt[m]];
    return 0;
}


#include <iostream>
using namespace std;
const int N = 1e6 + 1;

static int dp[N][7][7], cnt[N];

int main()
{
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n], ans = 0;
    for (int i = 0; i < n; ++i)
        cin >> a[i], cnt[a[i]]++;
    for (int i = 0; i <= m; ++i)
        while (cnt[i] > 6)
            cnt[i] -= 3, ans++;
    for (int i = 0; i <= m; ++i)
    {
        for (int j = 0; j < 7; ++j)
        {
            for (int k = 0; k < 7; ++k)
            {
                if (!i && j || i && j > cnt[i-1] || k > cnt[i])
                    continue;
                if (k >= 3)
                    dp[i][j][k] = dp[i][j][k-3] + 1;
                if (i >= 2)
                {
                    int r = min(min(j,k), cnt[i-2]);
                    for (int l = 0; l <= r; ++l)
                        dp[i][j][k] = max(dp[i][j][k], l + dp[i-1][cnt[i-2]-l][j-l]);
                }
            }
        }
    }
    cout << ans + dp[m][cnt[m-1]][cnt[m]];
    return 0;
}


#include <iostream>
using namespace std;
const int N = 1e6 + 1;

static int dp[N][7][7], cnt[N];

int main()
{
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n], ans = 0;
    for (int i = 0; i < n; ++i)
        cin >> a[i], cnt[a[i]]++;
    for (int i = 0; i < n; ++i)
        ans += (cnt[i] - cnt[i]%9) / 3, cnt[i] %= 9;
    for (int i = 0; i < n; ++i)
        if (cnt[i] > 6)
            cnt[i] -= 3, ans++;
    for (int i = 0; i <= m; ++i)
    {
        for (int j = 0; j < 7; ++j)
        {
            for (int k = 0; k < 7; ++k)
            {
                if (!i && j || i && j > cnt[i-1] || k > cnt[i])
                    continue;
                if (k >= 3)
                    dp[i][j][k] = dp[i][j][k-3] + 1;
                if (i >= 2)
                {
                    int r = min(min(j,k), cnt[i-2]);
                    for (int l = 0; l <= r; ++l)
                        dp[i][j][k] = max(dp[i][j][k], l + dp[i-1][cnt[i-2]-l][j-l]);
                }
            }
        }
    }
    cout << ans + dp[m][cnt[m-1]][cnt[m]];
    return 0;
}


#include <iostream>
using namespace std;
const int N = 1e6 + 1;

static int dp[N][7][7], cnt[N];

int main()
{
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n], ans = 0;
    for (int i = 0; i < n; ++i)
        cin >> a[i], cnt[a[i]]++;
    for (int i = 0; i < n; ++i)
        ans += (cnt[i] - cnt[i]%9) / 3, cnt[i] %= 9;
    for (int i = 0; i < n; ++i)
        if (cnt[i] > 6)
            cnt[i] -= 3, ans++;
    for (int i = 0; i <= m; ++i)
    {
        for (int j = 0; j < 7; ++j)
        {
            for (int k = 0; k < 7; ++k)
            {
                if (j > cnt[i-1] || k > cnt[i])
                    continue;
                if (k >= 3)
                    dp[i][j][k] = dp[i][j][k-3] + 1;
                int r = min(j, k);
                if (i > 1)
                    r = min(r, cnt[i-2]);
                for (int l = 0; l <= r; ++l)
                    dp[i][j][k] = max(dp[i][j][k], l + dp[i-1][cnt[i-2]-l][j-l]);
            }
        }
    }
    cout << ans + dp[m][cnt[m-1]][cnt[m]];
    return 0;
}


#include <iostream>
using namespace std;
const int N = 1e6 + 1;

static int dp[N][7][7], cnt[N];

int main()
{
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n], ans = 0;
    for (int i = 0; i < n; ++i)
        cin >> a[i], cnt[a[i]]++;
    for (int i = 0; i < n; ++i)
        ans += (cnt[i] - cnt[i]%9) / 3, cnt[i] %= 9;
    for (int i = 0; i < n; ++i)
        if (cnt[i] > 6)
            cnt[i] -= 3, ans++;
    for (int i = 0; i <= m; ++i)
    {
        for (int j = 0; j < 7; ++j)
        {
            for (int k = 0; k < 7; ++k)
            {
                if (j > cnt[i-1] || k > cnt[i])
                    continue;
                if (k >= 3)
                    dp[i][j][k] = dp[i][j][k-3] + 1;
                if (i > 1)
                {
                    int r = min(min(j,k), cnt[i-2]);
                    for (int l = 0; l <= r; ++l)
                        dp[i][j][k] = max(dp[i][j][k], l + dp[i-1][cnt[i-2]-l][j-l]);
                }
            }
        }
    }
    cout << ans + dp[m][cnt[m-1]][cnt[m]];
    return 0;
}


#include <iostream>
using namespace std;
const int N = 1e6 + 1;

static int dp[N][7][7], cnt[N];

int main()
{
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n];
    long long ans = 0;
    for (int i = 0; i < n; ++i)
        cin >> a[i], cnt[a[i]]++;
    for (int i = 0; i < n; ++i)
        ans += (cnt[i] - cnt[i]%9) / 3, cnt[i] %= 9;
    for (int i = 0; i < n; ++i)
        if (cnt[i] > 6)
            cnt[i] -= 3, ans++;
    for (int i = 0; i <= m; ++i)
    {
        for (int j = 0; j < 7; ++j)
        {
            for (int k = 0; k < 7; ++k)
            {
                if (j > cnt[i-1] || k > cnt[i])
                    continue;
                if (k >= 3)
                    dp[i][j][k] = dp[i][j][k-3] + 1;
                int r = min(j, k);
                if (i)
                    r = min(r, cnt[i-2]);
                for (int l = 0; l <= r; ++l)
                    dp[i][j][k] = max(dp[i][j][k], l + dp[i-1][cnt[i-2]-l][j-l]);
            }
        }
    }
    cout << ans + dp[m][cnt[m-1]][cnt[m]];
    return 0;
}


#include <iostream>
using namespace std;
const int N = 1e6 + 1;
const int C = 9;

static int dp[N][C][C], cnt[N];

int main()
{
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n], ans = 0;
    for (int i = 0; i < n; ++i)
        cin >> a[i], cnt[a[i]]++;
    for (int i = 0; i <= m; ++i)
        while (cnt[i] > 8)
            cnt[i] -= 3, ans++;
    for (int i = 0; i <= m; ++i)
    {
        for (int j = 0; j < C; ++j)
        {
            for (int k = 0; k < C; ++k)
            {
                if (!i && j || i && j > cnt[i-1] || k > cnt[i])
                    continue;
                if (k >= 3)
                    dp[i][j][k] = dp[i][j][k-3] + 1;
                if (i >= 2)
                {
                    int r = min(min(j,k), cnt[i-2]);
                    for (int l = 0; l <= r; ++l)
                        dp[i][j][k] = max(dp[i][j][k], l + dp[i-1][cnt[i-2]-l][j-l]);
                }
            }
        }
    }
    cout << ans + dp[m][cnt[m-1]][cnt[m]];
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e6 + 1;
const int C = 9;

static int dpi[C][C], dpi1[C][C], cnt[N];

int main()
{
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n], ans = 0;
    for (int i = 0; i < n; ++i)
        cin >> a[i], cnt[a[i]]++;
    for (int i = 0; i <= m; ++i)
        while (cnt[i] > 8)
            cnt[i] -= 3, ans++;
    for (int i = 0; i <= m; ++i)
    {
        for (int j = 0; j < C; ++j)
        {
            for (int k = 0; k < C; ++k)
            {
                if (!i && j || i && j > cnt[i-1] || k > cnt[i])
                    continue;
                if (k >= 3)
                    dpi[j][k] = dpi[j][k-3] + 1;
                if (i >= 2)
                {
                    int r = min(min(j,k), cnt[i-2]);
                    for (int l = 0; l <= r; ++l)
                        dpi[j][k] = max(dpi[j][k], l + dpi1[cnt[i-2]-l][j-l]);
                }
            }
        }
        for (int j = 0; j < C; ++j)
            copy(dpi[j], dpi[j] + C, dpi1[j]);
    }
    cout << ans + dpi[cnt[m-1]][cnt[m]];
    return 0;
}


#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define debug_call() cout << __PRETTY_FUNCTION__ << endl

using namespace std;
typedef long long ll;
typedef long double ld;

const int oo=0x7fffffff;
const ll  OO=0x7fffffffffffffff;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int N;
	cin>>N;
	vector<int> X(N),Y(N);

	for(auto& a: X)cin>>a;
	for(auto& a: Y)cin>>a;

	for(int i=N-1;i>0;--i){
		X[i]-=X[i-1];
		Y[i]-=Y[i-1];
	}

	sort(X.begin()+1,X.end());
	sort(Y.begin()+1,Y.end());

	cout<< (X==Y ? "YES" : "NO") << "\n";
	return 0;
}


#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define debug_call() cout << __PRETTY_FUNCTION__ << endl

using namespace std;
typedef long long ll;
typedef long double ld;

const int  oo=0x7fffffff;
const ll  OO=0x7fffffffffffffff;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int NX=1000'006;
int ct[NX],dp[2][3][3];

int readInt() {
int ans = 0, c, f = 1;
while (!isdigit(c = getchar()))
if (c == '-') f *= -1;
do ans = ans * 10 + c - '0';
while (isdigit(c = getchar()));
return ans * f;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int N,M;
	//cin>>N>>M;
	N=readInt();
	M=readInt();
	for(int i=0,x;i<N;++i){
		//cin>>x;
		x=readInt();
		++ct[x];
	}

	for(int i=0;i<3;++i)
		for(int j=0;j<3;++j)
			dp[0][i][j]=-1;

	dp[0][0][0]=0;

	for(int i=0;i<NX;++i){
		for(int x=0;x<3;++x)
			for(int xx=0;xx<3;++xx)
				dp[i+1&1][x][xx]=-1;

		for(int x=0;x<3;++x)
		for(int xx=0;xx<3;++xx)if(dp[i&1][x][xx]>=0){
			for(int y=0,yy=x;y<3;++y)
			//for(int yy=0;yy<3;++yy)
			if( ct[i+1]>=(y+yy) and x>=yy ){
				int xxx,r;
				xxx=min(ct[i+1]-y-yy,xx);
				r=ct[i+1]-y-yy-xxx;
				dp[i+1&1][y][yy] = max( dp[i+1&1][y][yy],
					xxx+r/3+dp[i&1][x][xx]);
			}

		}}
	cout<<dp[NX&1][0][0]<<endl;

	return 0;
}


/*
Author  : Malisetti Samrat
Date    : 2020-06-09 10:03:06
*/
#include   <bits/stdc++.h>
using      namespace        std;
#define    int              long long int
#define    sz(a)            (int)(a).size()
#define    w(x)              int T; cin>>T; while(T -- > 0)
#define    debug             cout<<"~~~~\n";

void SolveTestCase() {

	// Code goes here

	string home, away;
	cin >> home >> away;

	int n;
	cin >> n;

	unordered_map < int , bool > mp1, mp2;

	vector < string > vec;

	for (int i = 0; i < n; i++)
	{
		int min, player;

		char team_name, card_color;

		cin >> min >> team_name >> player >> card_color;

		if (card_color == 'y' and team_name == 'h' and mp1.count(player) == false) {
			mp1[player] = true;
		}
		else if (card_color == 'y' and team_name == 'a' and mp2.count(player) == false) {
			mp2[player] = true;
		}
		else if (card_color == 'y' and team_name == 'h' and mp1.count(player) == true) {
			string ans;

			ans += home, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min);

			vec.push_back(ans);

		}

		else if (card_color == 'y' and team_name == 'a' and mp2.count(player) == true) {
			string ans;

			ans += home, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min);

			vec.push_back(ans);

		}

		else if (card_color == 'r') {
			string ans;
			if (team_name == 'a')
				ans += away, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min);
			else
				ans += home, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min);

			vec.push_back(ans);

		}
	}

	for (string x : vec)
		cout << x << endl;
}

int32_t main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	SolveTestCase();

	return 0;

}


/*
Author  : Malisetti Samrat
Date    : 2020-06-09 10:03:06
*/
#include   <bits/stdc++.h>
using      namespace        std;
#define    int              long long int
#define    sz(a)            (int)(a).size()
#define    w(x)              int T; cin>>T; while(T -- > 0)
#define    debug             cout<<"~~~~\n";

void SolveTestCase() {

	// Code goes here

	string home, away;
	cin >> home >> away;

	int n;
	cin >> n;

	unordered_map < int , bool > mp1, mp2, res1, res2;

	vector < string > vec;

	for (int i = 0; i < n; i++)
	{
		int min, player;

		char team_name, card_color;

		cin >> min >> team_name >> player >> card_color;

		if (card_color == 'y' and team_name == 'h' and mp1.count(player) == false) {
			mp1[player] = true;
		}
		else if (card_color == 'y' and team_name == 'a' and mp2.count(player) == false) {
			mp2[player] = true;
		}
		else if (card_color == 'y' and team_name == 'h' and mp1.count(player) == true) {

			string ans;

			if (res1.count(player) == false)

				res1[player] = true , ans += home, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min) , vec.push_back(ans);

		}

		else if (card_color == 'y' and team_name == 'a' and mp2.count(player) == true) {
			string ans;

			if (res2.count(player) == false)

				res2[player] = true , ans += away, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min) , vec.push_back(ans);

		}

		else if (card_color == 'r') {

			string ans;

			if (team_name == 'a') {
				if (res2.count(player) == false)
					res2[player] = true , ans += away, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min), vec.push_back(ans);
			}
			else {
				if (res1.count(player) == false)
					res1[player] = true, ans += home, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min), vec.push_back(ans);
			}

		}
	}

	for (string x : vec)
		cout << x << endl;
}

int32_t main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	SolveTestCase();

	return 0;

}


/*
Author  : Malisetti Samrat
Date    : 2020-06-09 10:03:06
*/
#include   <bits/stdc++.h>
using      namespace        std;
#define    int              long long int
#define    sz(a)            (int)(a).size()
#define    w(x)              int T; cin>>T; while(T -- > 0)
#define    debug             cout<<"~~~~\n";

void SolveTestCase() {

	// Code goes here

	string home, away;
	cin >> home >> away;

	int n;
	cin >> n;

	unordered_map < int , bool > mp1, mp2;

	vector < string > vec;

	for (int i = 0; i < n; i++)
	{
		int min, player;

		char team_name, card_color;

		cin >> min >> team_name >> player >> card_color;

		if (card_color == 'y' and team_name == 'h' and mp1.count(player) == false) {
			mp1[player] = true;
		}
		else if (card_color == 'y' and team_name == 'a' and mp2.count(player) == false) {
			mp2[player] = true;
		}
		else if (card_color == 'y' and team_name == 'h' and mp1.count(player) == true) {
			string ans;

			ans += home, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min);

			vec.push_back(ans);

		}

		else if (card_color == 'y' and team_name == 'a' and mp2.count(player) == true) {
			string ans;

			ans += away, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min);

			vec.push_back(ans);

		}

		else if (card_color == 'r') {
			string ans;
			if (team_name == 'a')
				ans += away, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min);
			else
				ans += home, ans += " " , ans += to_string(player), ans += " ", ans += to_string(min);

			vec.push_back(ans);

		}
	}

	for (string x : vec)
		cout << x << endl;
}

int32_t main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	SolveTestCase();

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string kom1,kom2;
    cin>>kom1>>kom2;
    int n,minut, pnum;
    cin>>n;
    char h,card;
    vector<char>v;
    map<char,int>mp;
    map<char,int>home;
    map<char,int>abr;
    for(int i =0 ; i < n; i ++)
    {
        cin>>minut>>h>>pnum>>card;
        if(h=='h'){
            if(card=='r')
            {
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
                continue;
            }
            home[pnum]++;
            if(home[pnum]==2)
            {
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
            }
        }
        else
        {
            if(card=='r')
            {
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
               continue;
            }
            abr[pnum]++;
            if(abr[pnum]==2)
            {
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char h,card;
    pair<string,pair<int,int>>p[101];
    map<char,int>red1;
    map<char,int>red2;
    map<char,int>yellow1;
    map<char,int>yellow2;
    int playernum=0,playernum2=0,n,minut, pnum;
    string kom1,kom2;

    cin>>kom1>>kom2;
    cin>>n;
    for(int i =0; i < n; i++)
    {
        cin>>minut>>h>>pnum>>card;

        if(h=='h')
        {
           if(card=='r' && yellow1[pnum]<2)
           {
               red1[pnum]++;
               if(red1[pnum]==1)
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
           }
           else
           {
               yellow1[pnum]++;
               if(yellow1[pnum]==2)
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
           }

        }
        else
        {       if(card=='r' && yellow2[pnum]<2)
                {
                    red2[pnum]++;
                    if(red2[pnum]==1)
                        cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
                }
                else
                {
                    yellow2[pnum]++;
                    if(yellow2[pnum]==2)
                    cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
                }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string kom1,kom2;
    cin>>kom1>>kom2;
    int n,minut, pnum;
    cin>>n;
    char h,card;
    vector<char>v;
    map<char,int>mp;
    map<char,int>home;
    map<char,int>abr;
    for(int i =0 ; i < n; i ++)
    {
        cin>>minut>>h>>pnum>>card;
        if(h=='h'){
            if(card=='r')
            {
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
            }
            home[pnum]++;
            if(home[pnum]==2)
            {
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
            }
        }
        else
        {
            if(card=='r')
            {
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
            }
            abr[pnum]++;
            if(abr[pnum]==2)
            {
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string kom1,kom2;
    cin>>kom1>>kom2;
    int playernum=0,playernum2=0,n,minut, pnum;
    cin>>n;
    char h,card;
    vector<char>v;
    map<char,int>mp;
    map<char,int>mp2;
    map<char,int>home;
    map<char,int>abr;
    for(int i =0 ; i < n; i ++)
    {
        cin>>minut>>h>>pnum>>card;
        if(h=='h'){
            if(card=='r' && mp[playernum]==0)
            {
                mp[playernum]++;
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
                continue;
            }

            home[pnum]++;

            if(home[pnum]==2 && mp[playernum]==0)
            {
                mp[playernum]++;
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
            }
        }
        else
        {
            if(card=='r' && mp2[playernum2]==0)
            {
                mp2[playernum2]++;
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
               continue;
            }
            abr[pnum]++;
            if(abr[pnum]==2 && mp2[playernum2]==0)
            {
                mp2[playernum2]++;
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string kom1,kom2;
    cin>>kom1>>kom2;
    int playernum=0,playernum2=0,n,minut, pnum;
    cin>>n;
    char h,card;
    vector<char>v;
    map<char,int>mp;
    map<char,int>home;
    map<char,int>abr;
    for(int i =0 ; i < n; i ++)
    {
        cin>>minut>>h>>pnum>>card;
        if(h=='h'){
            if(card=='r' && playernum!=pnum)
            {
                playernum=pnum;
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
                continue;
            }
            home[pnum]++;
            if(home[pnum]==2)
            {
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
            }
        }
        else
        {
            if(card=='r' && playernum2!=pnum)
            {
                playernum2 = pnum;
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
               continue;
            }
            abr[pnum]++;
            if(abr[pnum]==2)
            {
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string kom1,kom2;
    cin>>kom1>>kom2;
    int n,minut, pnum;
    cin>>n;
    char h,card;
    map<char,int>mp;
    for(int i =0 ; i < n; i ++)
    {
        cin>>minut>>h>>pnum>>card;
        if(card=='r')
        {
            if(h=='h')
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
            else
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
        }
        else
        {
            mp[pnum]++;
            if(mp[pnum]==2)
            {
             if(h=='h')
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
             else
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;

            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char h,card;
    pair<string,pair<int,int>>p[101];
    map<char,int>red1;
    map<char,int>red2;
    map<char,int>yellow1;
    map<char,int>yellow2;
    int playernum=0,playernum2=0,n,minut, pnum;
    string kom1,kom2;

    cin>>kom1>>kom2;
    cin>>n;
    for(int i =0; i < n; i++)
    {
        cin>>minut>>h>>pnum>>card;

        if(h=='h')
        {
           if(card=='r' && yellow1[pnum]<2)
           {
               red1[pnum]++;
               if(red1[pnum]==1)
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
           }
           else
           {
               yellow1[pnum]++;
               if(yellow1[pnum]==2 && red1[pnum]<1)
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
           }

        }
        else
        {       if(card=='r' && yellow2[pnum]<2)
                {
                    red2[pnum]++;
                    if(red2[pnum]==1)
                        cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
                }
                else
                {
                    yellow2[pnum]++;
                    if(yellow2[pnum]==2 && red2[pnum]<1)
                    cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
                }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string kom1,kom2;
    cin>>kom1>>kom2;
    int playernum=0,playernum2=0,n,minut, pnum;
    cin>>n;
    char h,card;
    vector<char>v;
    map<char,int>mp;
    map<char,int>home;
    map<char,int>abr;
    for(int i =0 ; i < n; i ++)
    {
        cin>>minut>>h>>pnum>>card;
        if(h=='h'){
            if(card=='r' && playernum!=pnum)
            {
                playernum=pnum;
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
                continue;
            }
            home[pnum]++;
            if(home[pnum]==2 && playernum!=pnum)
            {
                playernum = pnum;
                cout<<kom1<<" "<<pnum<<" "<<minut<<endl;
            }
        }
        else
        {
            if(card=='r' && playernum2!=pnum)
            {
                playernum2 = pnum;
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
               continue;
            }
            abr[pnum]++;
            if(abr[pnum]==2 && playernum2!=pnum)
            {
                playernum2 = pnum;
                cout<<kom2<<" "<<pnum<<" "<<minut<<endl;
            }
        }
    }
}


#include <iostream>
#include <string>

using namespace std;
int main()
{
	bool dble;
	string ht,at;
	cin>>ht>>at;
	int n,i,k;
	cin>>n;
	int min[n];
	char card[n];
	int num [n];
	char team[n];
	for (i=0;i<n;i++)
	{
	cin>>min[i]>>team[i]>>num[i]>>card[i];
	}
	for(i=0;i<n;i++)
	{
		if (card[i]=='r')
			{
				for (k=0;k<i;k++)
				if (num[k]==num[i]) dble=true;
				if (!dble)
				{
				if (team[i]=='h') cout<<ht;
				else cout<<at;
				cout<<' '<<num[i]<<' '<<min[i]<<endl;
				}

			}
		else
			{
				for (k=i-1;k>-1; k--)
				{
					if (team[k]==team[i] && num[i]==num[k] && card[k]=='y')
					{
						if (team[i]=='h') cout<<ht;
						else cout<<at;
						cout<<' '<<num[i]<<' '<<min[i]<<endl;
					}

				}
			}

	}
return 0;
}


#include <iostream>
#include <string>

using namespace std;
int main()
{
	string ht,at;
	cin>>ht>>at;
	int n,i,k;
	cin>>n;
	int min[n];
	char card[n];
	int num [n];
	char team[n];
	for (i=0;i<n;i++)
	{
	cin>>min[i]>>team[i]>>num[i]>>card[i];
	}
	for(i=0;i<n;i++)
	{
		if (card[i]=='r')
			{
				for (k=0;k<i;k++)
				if (num[k]==num[i]) bool dble=true;
				if (!dble)
				{
				if (team[i]=='h') cout<<ht;
				else cout<<at;
				cout<<' '<<num[i]<<' '<<min[i]<<endl;
				}

			}
		else
			{
				for (k=i-1;k>-1; k--)
				{
					if (team[k]==team[i] && num[i]==num[k] && card[k]=='y')
					{
						if (team[i]=='h') cout<<ht;
						else cout<<at;
						cout<<' '<<num[i]<<' '<<min[i]<<endl;
					}

				}
			}

	}
return 0;
}


#include <iostream>
#include <string>

using namespace std;
int main()
{
	string ht,at;
	cin>>ht>>at;
	int n,i,k;
	cin>>n;
	int min[n];
	char card[n];
	int num [n];
	char team[n];

	for (i=0;i<n;i++)
	{
	cin>>min[i]>>team[i]>>num[i]>>card[i];
	}
	for(i=0;i<n;i++)
		for(k=i+1;k<n;k++)
		{
			if (num[i]==num[k] && team[i]==team[k] && card[i]=='r')
			card[k]=' ';
		}
	for(i=0;i<n;i++)
		{
			int count=0;
			for(k=i+1;k<n;k++)

		{
			if (num[i]==num[k] && team[i]==team[k] && card[i]=='y')
			if (count==0) count++;
			else card [k]=' ';
		}
		}
	for(i=0;i<n;i++)
	{
		if (card[i]=='r')
			{
				if (team[i]=='h') cout<<ht;
				else cout<<at;
				cout<<' '<<num[i]<<' '<<min[i]<<endl;
			}
		else if (card[i]=='y')
			{
				for (k=i-1;k>-1; k--)
				{
					if (team[k]==team[i] && num[i]==num[k])
					{
						if (team[i]=='h') cout<<ht;
						else cout<<at;
						cout<<' '<<num[i]<<' '<<min[i]<<endl;
					}

				}
			}

	}
return 0;
}


#include <iostream>
#include <string>

using namespace std;
int main()
{
	string ht,at;
	cin>>ht>>at;
	int n,i,k;
	cin>>n;
	int min[n];
	char card[n];
	int num [n];
	char team[n];
	for (i=0;i<n;i++)
	{
	cin>>min[i]>>team[i]>>num[i]>>card[i];
	}
	for(i=0;i<n;i++)
	{
		if (card[i]=='r')
			{
				if (team[i]=='h') cout<<ht;
				else cout<<at;
				cout<<' '<<num[i]<<' '<<min[i]<<endl;
			}
		else
			{
				for (k=i-1;k>-1; k--)
				{
					if (team[k]==team[i] && num[i]==num[k])
					{
						if (team[i]=='h') cout<<ht;
						else cout<<at;
						cout<<' '<<num[i]<<' '<<min[i]<<endl;
					}

				}
			}

	}
return 0;
}


#include <iostream>
#include <string>

using namespace std;
int main()
{
	string ht,at;
	cin>>ht>>at;
	int n,i,k;
	cin>>n;
	int min[n];
	char card[n];
	int num [n];
	char team[n];

	for (i=0;i<n;i++)
	{
	cin>>min[i]>>team[i]>>num[i]>>card[i];
	}
	for(i=0;i<n;i++)
		for(k=i+1;k<n;k++)
		{
			if (num[i]==num[k] && team[i]==team[k] && card[i]=='r')
			card[k]=' ';
		}
	for(i=0;i<n;i++)
	{
		if (card[i]=='r')
			{
				if (team[i]=='h') cout<<ht;
				else cout<<at;
				cout<<' '<<num[i]<<' '<<min[i]<<endl;
			}
		else if (card[i]=='y')
			{
				for (k=i-1;k>-1; k--)
				{
					if (team[k]==team[i] && num[i]==num[k])
					{
						if (team[i]=='h') cout<<ht;
						else cout<<at;
						cout<<' '<<num[i]<<' '<<min[i]<<endl;
					}

				}
			}

	}
return 0;
}


#include <iostream>
#include <string>

using namespace std;
int main()
{
	string ht,at;
	cin>>ht>>at;
	int n,i,k;
	cin>>n;
	int min[n];
	char card[n];
	int num [n];
	char team[n];
	for(i=0;i<n;i++)
		for(k=0;k<n;k++)
		{
			if (num[i]==num[k] && team[i]==team[k])
			card[k]='y';
		}
	for (i=0;i<n;i++)
	{
	cin>>min[i]>>team[i]>>num[i]>>card[i];
	}
	for(i=0;i<n;i++)
	{
		if (card[i]=='r')
			{
				if (team[i]=='h') cout<<ht;
				else cout<<at;
				cout<<' '<<num[i]<<' '<<min[i]<<endl;
			}
		else
			{
				for (k=i-1;k>-1; k--)
				{
					if (team[k]==team[i] && num[i]==num[k])
					{
						if (team[i]=='h') cout<<ht;
						else cout<<at;
						cout<<' '<<num[i]<<' '<<min[i]<<endl;
					}

				}
			}

	}
return 0;
}


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

int main(){
string a,h;
 ll q;
 cin>>h>>a>>q;
 map<pair<char,int>,int>mp;
 vector<int>visited1(100,0);
 vector<int>visited2(100,0);
 while(q--){
   ll t,n;
   char p,card;
   cin>>t>>p>>n>>card;
   if(card=='r'){
     if(p=='a' && visited2[n]==0){
       cout<<a<<" "<<n<<" "<<t<<" "<<endl;
       visited2[n]=1;
     }
     else if(p=='h' && visited1[n]==0){
       cout<<h<<" "<<n<<" "<<t<<" "<<endl;
       visited1[n]=1;
      }
   }
   else if(mp[make_pair(p,n)]==1){
     if(p=='a' && visited2[n]==0){
       cout<<a<<" "<<n<<" "<<t<<" "<<endl;
       visited2[n]=1;
      }
     else if(p=='h' && visited1[n]==0){
       cout<<h<<" "<<n<<" "<<t<<" "<<endl;
       visited1[n]=1;
      }

    }
    else mp[make_pair(p,n)]=1;
 }
 return 0;
}


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

int main(){
  string a,h;
 ll q;
 cin>>h>>a>>q;
 map<pair<char,int>,int>mp;
 while(q--){
   ll t,n;
   char p,card;
   cin>>t>>p>>n>>card;
   if(card=='r'){
     if(p=='a')cout<<a<<" ";
     else cout<<h<<" ";
     cout<<n<<" "<<t<<" "<<endl;
   }
   else{
     if(mp[make_pair(p,n)]==1){
        if(p=='a')cout<<a<<" ";
        else cout<<h<<" ";
        cout<<n<<" "<<t<<" "<<endl;
     }
     else mp[make_pair(p,n)]=1;
    }
 }
 return 0;
}


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

int main(){
  string a,h;
 ll q;
 cin>>h>>a>>q;
 map<pair<char,int>,int>mp;
 vector<int>visited(100,0);
 while(q--){
   ll t,n;
   char p,card;
   cin>>t>>p>>n>>card;
   if(card=='r' && visited[n]==0){
     if(p=='a')cout<<a<<" ";
     else cout<<h<<" ";
     cout<<n<<" "<<t<<" "<<endl;
     visited[n]=1;
   }
   else{
     if(mp[make_pair(p,n)]==1 && visited[n]==0){
        if(p=='a')cout<<a<<" ";
        else cout<<h<<" ";
        cout<<n<<" "<<t<<" "<<endl;
        visited[n]=1;
     }
     else mp[make_pair(p,n)]=1;
    }
 }
 return 0;
}


 #include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long double ld;

#define sync                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int base = 1e9;
const int MAX = 1e5;
const double EPS = 1e-9;
const double PI = acos(-1.);

map<string,int> cnt;

int main() {
    int n,t,num;
    char e,team;
    string home, an;

    cin>>home>>an;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>t>>team>>num>>e;
        string s=team+to_string(num);
        if(e=='r') {
            if(team == 'h') cout<<home<<' ';
            else cout<<an<<' ';
            cout<<num<<' '<<t<<endl;
        }
        else cnt[s]++;
        if(cnt[s]==2) {
            if(team == 'h') cout<<home<<' ';
            else cout<<an<<' ';
            cout<<num<<' '<<t<<endl;
        }
    }
    return 0;

}


 #include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long double ld;

#define sync                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int base = 1e9;
const int MAX = 1e5;
const double EPS = 1e-9;
const double PI = acos(-1.);

map<string,int> cnt;

int main() {
    int n,t,num;
    char e,team;
    string home, an;

    cin>>home>>an;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>t>>team>>num>>e;
        string s=team+to_string(num);
        if(e=='r') {
            if(team == 'h') cout<<home<<' ';
            else cout<<an<<' ';
            cout<<num<<' '<<t<<endl<<endl;
        }
        else cnt[s]++;
        if(cnt[s]==2) {
            if(team == 'h') cout<<home<<' ';
            else cout<<an<<' ';
            cout<<num<<' '<<t<<endl<<endl;
        }
    }
    return 0;

}


 #include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long double ld;

#define sync                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int base = 1e9;
const int MAX = 1e5;
const double EPS = 1e-9;
const double PI = acos(-1.);

map<string,int> cnt;
map<string,bool> was;

int main() {
    int n,t,num;
    char e,team;
    string home, an;
    cin>>home>>an;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>t>>team>>num>>e;
        string s=team+to_string(num);
        if(was[s]) continue;
        if(e=='r') {
            if(team == 'h') cout<<home<<' ';
            else cout<<an<<' ';
            cout<<num<<' '<<t<<endl;
            was[s] = true;
        }
        else cnt[s]++;
        if(cnt[s]==2) {
            if(team == 'h') cout<<home<<' ';
            else cout<<an<<' ';
            cout<<num<<' '<<t<<endl;
        }
    }
    return 0;

}


 #include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long double ld;

#define sync                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int base = 1e9;
const int MAX = 1e5;
const double EPS = 1e-9;
const double PI = acos(-1.);

map<string,int> cnt;
map<string,bool> was;

int main() {
    int n,t,num;
    char e,team;
    string home, an;
    cin>>home>>an;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>t>>team>>num>>e;
        string s=team+to_string(num);
        if(was[s]) continue;
        if(e=='r') {
            if(team == 'h') cout<<home<<' ';
            else cout<<an<<' ';
            cout<<num<<' '<<t<<endl;
            was[s] = true;
        }
        else cnt[s]++;
        if(cnt[s]==2) {
            if(team == 'h') cout<<home<<' ';
            else cout<<an<<' ';
            cout<<num<<' '<<t<<endl;
            was[s]=true;
        }
    }
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define sz(a) a.size()
typedef long long ll;

char h[21], a[21];
map <pair<char, int>, int> m;
int n;
vector <pair<char*, pair<int, int>>> res;

int main() {
      scanf("%s%s%d", h, a, &n);
      for (int i = 0; i < n; i++) {
            int time, num;
            char team, card;
            scanf("%d %c%d %c", &time, &team, &num, &card);
            if (m[{team, num}] == 1 || (card == 'r'&&m[{team, num}] < 2)) {
                  res.push_back({team == 'h' ? h : a,{num, time}});
                  m[{team, num}] = 2;
            }
            else
                  m[{team, num}]++;
      }
      int size = res.size();
      for (int i = 0; i < size; i++)
            printf("%s %d %d\n", res[i].first, res[i].second.first, res[i].second.second);
      return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sz(a) a.size()
typedef long long ll;

int main() {
      string nameh, hamea;
      cin >> nameh >> hamea;
      int n,i; scanf("%d", &n);
      map <int, int> gh;
      while (n--) {
            int minute, value;
            char typeTeam, typeCard;
            scanf("%d %c %d %c", &minute, &typeTeam, &value, &typeCard);
            gh[value]++;
            if (typeCard == 'r' || gh[value] == 2) {
                  if (typeTeam == 'h')
                        cout << nameh << ' ';
                  else
                        cout << hamea << ' ';
                  cout << value << ' ' << minute << endl;
            }
      }
      return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sz(a) a.size()
typedef long long ll;

int main() {
      string nameh, hamea;
      cin >> nameh >> hamea;
      int n,i; scanf("%d", &n);
      map<int ,map <int, int>> gh;
      map<int, map<int, int>> be;
      while (n--) {
            int minute, value;
            char typeTeam, typeCard;
            scanf("%d %c %d %c", &minute, &typeTeam, &value, &typeCard);
            gh[(typeTeam=='h')][value]++;
            if (typeCard == 'r' || gh[(typeTeam == 'h')][value] == 2 && !be[typeTeam == 'h'][value]) {
                  if (typeTeam == 'h')
                        cout << nameh << ' ';
                  else
                        cout << hamea << ' ';
                  cout << value << ' ' << minute << endl;
                  be[typeTeam == 'h'][value] = 1;
            }
      }
      return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define test int t;cin>>t;while(t--)
#define input(a,n) for(i=0;i<n;i++)cin>>a[i];
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define forn1(i,n) for(int i = 1; i <= int(n); i++)
#define dwn(i,n) for(int i=(n); --i>=0; )
#define fora(i,a,b) for(int i=a;i<b;i++)
#define line(n) getline(cin,n)
using namespace std ;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector< vector<int> > adjl;
void TIME() {
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
}
int s = 1 ;
void gcd(int a ,int b){
    forn(i,100)if(a%i==0&&b%i==0){s=i; break;}
    return;
}
bool prime (int n ,int i){
    if (i == n)
        return true ;
    if (n%i == 0)
        return false ;
    prime (n , i+1);
}
void nice (int n){
    if(n==0) return;
    cout << "3aaaaaaa4 AlMarwa 3aaaaaaaaaa4\n";
    nice(n-1);
}
struct team {
    string s ;
    int n , m ;
};
int main ()
{
    map < pair<char,int>,int > m ;
    team arr[1000];
    string s , s1 ;
    cin >> s >> s1 ;
    char a , b ;
    int t , n , r , k = 0;
    cin >> r ;
    forn(i,r){
        cin >> t >> a >> n >> b;
        m[mp(a,n)]++;
        if (b == 'r'){
            if(a == 'h')
                arr[k].s=s,arr[k].n=n,arr[k].m=t,k++;
            else arr[k].s=s1,arr[k].n=n,arr[k].m=t,k++;
        }
        else if (m[{a,n}] == 2){
            if(a == 'h')
                arr[k].s=s,arr[k].n=n,arr[k].m=t,k++;
            else arr[k].s=s1,arr[k].n=n,arr[k].m=t,k++;
        }
    }
    forn(i,k)cout<<arr[i].s<<' '<<arr[i].n<<' '<<arr[i].m<<'\n';
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define test int t;cin>>t;while(t--)
#define input(a,n) for(i=0;i<n;i++)cin>>a[i];
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define forn1(i,n) for(int i = 1; i <= int(n); i++)
#define dwn(i,n) for(int i=(n); --i>=0; )
#define fora(i,a,b) for(int i=a;i<b;i++)
#define line(n) getline(cin,n)
using namespace std ;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector< vector<int> > adjl;
void TIME() {
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
}
int s = 1 ;
void gcd(int a ,int b){
    forn(i,100)if(a%i==0&&b%i==0){s=i; break;}
    return;
}
bool prime (int n ,int i){
    if (i == n)
        return true ;
    if (n%i == 0)
        return false ;
    prime (n , i+1);
}
void nice (int n){
    if(n==0) return;
    cout << "3aaaaaaa4 AlMarwa 3aaaaaaaaaa4\n";
    nice(n-1);
}
struct team {
    string s ;
    int n , m ;
};
int main ()
{
    map < pair<char,int>,int > m ;
    team arr[1000];
    string s , s1 ;
    cin >> s >> s1 ;
    char a , b ;
    int t , n , r , k = 0;
    cin >> r ;
    forn(i,r){
        cin >> t >> a >> n >> b;
        m[mp(a,n)]++;
        if (b == 'r' && m[{a,n}] <= 2){
            if(a == 'h')
                arr[k].s=s,arr[k].n=n,arr[k].m=t,k++,m[{a,n}]=100;
            else arr[k].s=s1,arr[k].n=n,arr[k].m=t,k++,m[{a,n}]=100;
        }
        else if (m[{a,n}] == 2 && b == 'y'){
            if(a == 'h')
                arr[k].s=s,arr[k].n=n,arr[k].m=t,k++;
            else arr[k].s=s1,arr[k].n=n,arr[k].m=t,k++;
        }
    }
    forn(i,k)cout<<arr[i].s<<' '<<arr[i].n<<' '<<arr[i].m<<'\n';
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define test int t;cin>>t;while(t--)
#define input(a,n) for(i=0;i<n;i++)cin>>a[i];
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define forn1(i,n) for(int i = 1; i <= int(n); i++)
#define dwn(i,n) for(int i=(n); --i>=0; )
#define fora(i,a,b) for(int i=a;i<b;i++)
#define line(n) getline(cin,n)
using namespace std ;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector< vector<int> > adjl;
void TIME() {
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
}
int s = 1 ;
void gcd(int a ,int b){
    forn(i,100)if(a%i==0&&b%i==0){s=i; break;}
    return;
}
bool prime (int n ,int i){
    if (i == n)
        return true ;
    if (n%i == 0)
        return false ;
    prime (n , i+1);
}
void nice (int n){
    if(n==0) return;
    cout << "3aaaaaaa4 AlMarwa 3aaaaaaaaaa4\n";
    nice(n-1);
}
struct team {
    string s ;
    int n , m ;
};
int main ()
{
    map < pair<char,int>,int > m ;
    team arr[1000];
    string s , s1 ;
    cin >> s >> s1 ;
    char a , b ;
    int t , n , r , k = 0;
    cin >> r ;
    forn(i,r){
        cin >> t >> a >> n >> b;
        m[mp(a,n)]++;
        if (b == 'r' && m[{a,n}] == 1){
            if(a == 'h')
                arr[k].s=s,arr[k].n=n,arr[k].m=t,k++;
            else arr[k].s=s1,arr[k].n=n,arr[k].m=t,k++;
        }
        else if (m[{a,n}] == 2 && b == 'y'){
            if(a == 'h')
                arr[k].s=s,arr[k].n=n,arr[k].m=t,k++;
            else arr[k].s=s1,arr[k].n=n,arr[k].m=t,k++;
        }
    }
    forn(i,k)cout<<arr[i].s<<' '<<arr[i].n<<' '<<arr[i].m<<'\n';
}


#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string home, away;
	cin >> home >> away;

	int t;
	cin >> t;

	map<int, int> home_yellow, away_yellow;
	int curr_time, num;
	char team, card;
	while (t--) {
		cin >> curr_time >> team >> num >> card;
		if (team == 'a') {
			if (card == 'y') {
				if (away_yellow.count(num)) {
					cout << away << " " << num << " " << curr_time << "\n";
				} else {
					++away_yellow[num];
				}
			} else {
				cout << away << " " << num << " " << curr_time << "\n";
			}
		} else {
			if (card == 'y') {
				if (home_yellow.count(num)) {
					cout << home << " " << num << " " << curr_time << "\n";
				} else {
					++home_yellow[num];
				}
			} else {
				cout << home << " " << num << " " << curr_time << "\n";
			}
		}
	}

	return 0;

}


#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string home, away;
	cin >> home >> away;

	int t;
	cin >> t;

	map<int, int> home_yellow, away_yellow;
	vector<int> home_ousted(100), away_ousted(100);
	int curr_time, num;
	char team, card;
	while (t--) {
		cin >> curr_time >> team >> num >> card;

		if (team == 'a') {
			if (away_ousted[num]) {
				continue;
			}

			if (card == 'y') {
				if (away_yellow.count(num)) {
					away_ousted[num] = 1;
					cout << away << " " << num << " " << curr_time << "\n";
				} else {
					++away_yellow[num];
				}
			} else {
				away_ousted[num] = 1;
				cout << away << " " << num << " " << curr_time << "\n";
			}
		} else {
			if (home_ousted[num]) {
				continue;
			}

			if (card == 'y') {
				if (home_yellow.count(num)) {
					home_ousted[num] = 1;
					cout << home << " " << num << " " << curr_time << "\n";
				} else {
					++home_yellow[num];
				}
			} else {
				home_ousted[num] = 1;
				cout << home << " " << num << " " << curr_time << "\n";
			}
		}
	}

	return 0;

}


#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string home, away;
	cin >> home >> away;

	int t;
	cin >> t;

	map<int, int> home_yellow, away_yellow;
	vector<int> ousted(100);
	int curr_time, num;
	char team, card;
	while (t--) {
		cin >> curr_time >> team >> num >> card;
		if (ousted[num]) {
			continue;
		}

		if (team == 'a') {
			if (card == 'y') {
				if (away_yellow.count(num)) {
					ousted[num] = 1;
					cout << away << " " << num << " " << curr_time << "\n";
				} else {
					++away_yellow[num];
				}
			} else {
				ousted[num] = 1;
				cout << away << " " << num << " " << curr_time << "\n";
			}
		} else {
			if (card == 'y') {
				if (home_yellow.count(num)) {
					ousted[num] = 1;
					cout << home << " " << num << " " << curr_time << "\n";
				} else {
					++home_yellow[num];
				}
			} else {
				ousted[num] = 1;
				cout << home << " " << num << " " << curr_time << "\n";
			}
		}
	}

	return 0;

}


#include<bits/stdc++.h>
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);

	string home,away;cin>>home>>away;
	ll n;cin>>n;
	ll h[1000],a[1000];For(i,0,1000){
		h[i]=0;a[i]=0;
	}
	pair<pair<ll,char>,pair<ll,char> > input[n];
	ll count=0;
	For(w,0,n){
		ll t,m;cin>>t;
		char x;cin>>x>>m;
		char card;cin>>card;
		input[count].fi.fi=t;input[count].fi.se=x;
		input[count].se.fi=m;input[count].se.se=card;
		count++;
	}

	sort(input,input+n);
	For(w,0,n){
		ll t,m;t=input[w].fi.fi;
		char x;x=input[w].fi.se;
		m=input[w].se.fi;
		char card;card=input[w].se.se;

		if(x=='h' && h[m]==-1) continue;
		else if(x=='a' && a[m]==-1) continue;

		if(card=='r'){
			if(x=='h') {
				cout<<home<<" "<<m<<" "<<t<<endl;
				h[m]=-1;
			}
			else {
				cout<<away<<" "<<m<<" "<<t<<endl;
				a[m]=-1;
			}
		}else{
			if(x=='h') h[m]++;
			else a[m]++;
		}

		if(x=='h') {if(h[m]==2){
			h[m]=-1;
			cout<<home<<" "<<m<<" "<<t<<endl;
		}}
		else {if(a[m]==2){
			a[m]=-1;
			cout<<away<<" "<<m<<" "<<t<<endl;
		}}
	}
}


#include<bits/stdc++.h>
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);

	string home,away;cin>>home>>away;
	ll n;cin>>n;
	ll h[1000],a[1000];For(i,0,1000){
		h[i]=0;a[i]=0;
	}
	while(n--){
		ll t,m;cin>>t;
		char x;cin>>x>>m;
		char card;cin>>card;
		if(card=='r'){
			if(x=='h') cout<<home<<" "<<m<<" "<<t<<endl;
			else cout<<away<<" "<<m<<" "<<t<<endl;
		}else{
			if(x=='h') h[m]++;
			else a[m]++;
		}
		if(x=='h') {if(h[m]==2){
			cout<<home<<" "<<m<<" "<<t<<endl;
		}}
		else {if(a[m]==2){
			cout<<away<<" "<<m<<" "<<t<<endl;
		}}
	}
}


#include<bits/stdc++.h>
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);

	string home,away;cin>>home>>away;
	ll n;cin>>n;
	ll h[1000],a[1000];For(i,0,1000){
		h[i]=0;a[i]=0;
	}
	pair<pair<ll,char>,pair<ll,char> > input[n];
	ll count=0;
	For(w,0,n){
		ll t,m;cin>>t;
		char x;cin>>x>>m;
		char card;cin>>card;
		input[count].fi.fi=t;input[count].fi.se=x;
		input[count].se.fi=m;input[count].se.se=card;
		count++;
		// cout<<t<<" "<<x<<" "<<m<<" "<<card<<endl;
	}
	sort(input,input+n);
	For(w,0,n){
		ll t,m;t=input[w].fi.fi;
		char x;x=input[w].fi.se;
		m=input[w].se.fi;
		char card;card=input[w].se.se;

		if(card=='r'){
			if(x=='h') cout<<home<<" "<<m<<" "<<t<<endl;
			else cout<<away<<" "<<m<<" "<<t<<endl;
		}else{
			if(x=='h') h[m]++;
			else a[m]++;
		}
		if(x=='h') {if(h[m]==2){
			cout<<home<<" "<<m<<" "<<t<<endl;
		}}
		else {if(a[m]==2){
			cout<<away<<" "<<m<<" "<<t<<endl;
		}}
	}
}


#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
char a[25], b[25];
map <int, int> pa1, pa2, paa1, paa2;
int main() {
	int n;
	scanf("%s", a);
	scanf("%s", b);
	scanf("%d", &n);
	while(n--) {
		int t, d;
		char p1, p2;
		scanf("%d %c %d %c", &t, &p1, &d, &p2);
		if(p2 == 'r') {
			if(p1 == 'a') {
				if(paa1[d] == 0) {
					printf("%s %d %d\n", b, d, t); paa1[d]++;
				}
			}
			else {
				if(paa2[d] == 0) {
					printf("%s %d %d\n", a, d, t); paa2[d]++;
				}
			}
		}
		else {
			if(p1 == 'a') {
				pa1[d]++;
				if(pa1[d] == 2) {
					printf("%s %d %d\n", b, d, t);
				}
			}
			else {
				pa2[d]++;
				if(pa2[d] == 2) {
					printf("%s %d %d\n", a, d, t);
				}
			}
		}
	}
	return 0;
}


#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
char a[25], b[25];
map <int, int> pa1, pa2, paa1, paa2;
int main() {
	int n;
	scanf("%s", a);
	scanf("%s", b);
	scanf("%d", &n);
	while(n--) {
		int t, d;
		char p1, p2;
		scanf("%d %c %d %c", &t, &p1, &d, &p2);
		if(p2 == 'r') {
			if(p1 == 'a') {
				paa1[d]++;
				if(paa1[d] == 1 && pa1[d] < 2) printf("%s %d %d\n", b, d, t);
			}
			else {
				paa2[d]++;
				if(paa2[d] == 1 && pa2[d] < 2) printf("%s %d %d\n", a, d, t);
			}
		}
		else {
			if(p1 == 'a') {
				pa1[d]++;
				if(pa1[d] == 2 && paa1[d] == 0) printf("%s %d %d\n", b, d, t);
			}
			else {
				pa2[d]++;
				if(pa2[d] == 2 && paa2[d] == 0) printf("%s %d %d\n", a, d, t);
			}
		}
	}
	return 0;
}


#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
char a[25], b[25];
map <int, int> pa1, pa2, paa1, paa2;
int main() {
	int n;
	scanf("%s", a);
	scanf("%s", b);
	scanf("%d", &n);
	while(n--) {
		int t, d;
		char p1, p2;
		scanf("%d %c %d %c", &t, &p1, &d, &p2);
		if(p2 == 'r') {
			if(p1 == 'a') {
				if(paa1[d] == 0) {
					printf("%s %d %d\n", b, d, t); paa1[d]++;
				}
			}
			else {
				if(paa2[d] == 0) {
					printf("%s %d %d\n", a, d, t); paa2[d]++;
				}
			}
		}
		else {
			if(p1 == 'a') {
				pa1[d]++;
				if(pa1[d] > 1) {
					printf("%s %d %d\n", b, d, t);
				}
			}
			else {
				pa2[d]++;
				if(pa2[d] > 1) {
					printf("%s %d %d\n", a, d, t);
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll N=1e5+5;
const ll INF=1e18;
const ll mod=1e9+7;

#define f first
#define s second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define bits(x) __builtin_popcount(x)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define OPT ios_base::sync_with_stdio(false);cin.tie(NULL);

ll hh[N],aa[N];

int main()
{
  char st,crd;
  ll n,timex,num;
  string home,away;
  cin>>home>>away;
  cin>>n;
  ll pp=n,pos=0;
  pair<ll,pair<string,ll> > p[n];
  while(n--)
  {
    cin>>timex>>st>>num>>crd;
    if(st=='h')
    {
      if(crd=='y')
      {
        hh[num]++;
        if(hh[num]==2){p[pos++]=mp(timex,mp(home,num));}
      }
      else
      {
        if(hh[num]<=2){p[pos++]=mp(timex,mp(home,num));}
        hh[num]=3;}
    }
    else
    {
      if(crd=='y')
      {
        aa[num]++;
        if(aa[num]==2){p[pos++]=mp(timex,mp(away,num));}
      }
      else
      {
        if(aa[num]<=2){p[pos++]=mp(timex,mp(away,num));}
        aa[num]=3;
      }
    }
  }
  sort(p,p+pos);
  for(ll i=0;i<pos;i++){cout<<p[i].s.f<<" "<<p[i].s.s<<" "<<p[i].f<<endl;}
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll N=1e5+5;
const ll INF=1e18;
const ll mod=1e9+7;

#define f first
#define s second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define bits(x) __builtin_popcount(x)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define OPT ios_base::sync_with_stdio(false);cin.tie(NULL);

ll hh[N],aa[N];

int main()
{
  char st,crd;
  ll n,timex,num;
  string home,away;
  cin>>home>>away;
  cin>>n;
  while(n--)
  {
    cin>>timex>>st>>num>>crd;
    if(st=='h')
    {
      if(crd=='y')
      {
        hh[num]++;
        if(hh[num]==2){cout<<home<<" "<<num<<" "<<timex<<endl;}
      }
      else{cout<<home<<" "<<num<<" "<<timex<<endl;hh[num]=3;}
    }
    else
    {
      if(crd=='y')
      {
        aa[num]++;
        if(aa[num]==2){cout<<away<<" "<<num<<" "<<timex<<endl;}
      }
      else{cout<<away<<" "<<num<<" "<<timex<<endl;aa[num]=3;}
    }
  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll N=1e5+5;
const ll INF=1e18;
const ll mod=1e9+7;

#define f first
#define s second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define bits(x) __builtin_popcount(x)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define OPT ios_base::sync_with_stdio(false);cin.tie(NULL);

ll hh[N],aa[N];

int main()
{
  char st,crd;
  ll n,timex,num;
  string home,away;
  cin>>home>>away;
  cin>>n;
  ll pp=n,pos=0;
  pair<ll,pair<string,ll> > p[n];
  while(n--)
  {
    cin>>timex>>st>>num>>crd;
    if(st=='h')
    {
      if(crd=='y')
      {
        hh[num]++;
        if(hh[num]==2){p[pos++]=mp(timex,mp(home,num));}
      }
      else{p[pos++]=mp(timex,mp(home,num));hh[num]=3;}
    }
    else
    {
      if(crd=='y')
      {
        aa[num]++;
        if(aa[num]==2){p[pos++]=mp(timex,mp(away,num));}
      }
      else{p[pos++]=mp(timex,mp(away,num));aa[num]=3;}
    }
  }
  sort(p,p+pos);
  for(ll i=0;i<pos;i++){cout<<p[i].s.f<<" "<<p[i].s.s<<" "<<p[i].f<<endl;}
}


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll N=1e5+5;
const ll INF=1e18;
const ll mod=1e9+7;

#define f first
#define s second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define bits(x) __builtin_popcount(x)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define OPT ios_base::sync_with_stdio(false);cin.tie(NULL);

ll hh[N],aa[N];

int main()
{
  char st,crd;
  ll n,timex,num;
  string home,away;
  cin>>home>>away;
  cin>>n;
  ll pp=n,pos=0;
  pair<ll,pair<string,ll> > p[n];
  while(n--)
  {
    cin>>timex>>st>>num>>crd;
    if(st=='h')
    {
      if(crd=='y')
      {
        hh[num]++;
        if(hh[num]==2){p[pos++]=mp(timex,mp(home,num));hh[num]=INF;}
      }
      else
      {
        if(hh[num]<=1){p[pos++]=mp(timex,mp(home,num));}
        hh[num]=INF;
      }
    }
    else
    {
      if(crd=='y')
      {
        aa[num]++;
        if(aa[num]==2){p[pos++]=mp(timex,mp(away,num));hh[num]=INF;}
      }
      else
      {
        if(aa[num]<=1){p[pos++]=mp(timex,mp(away,num));}
        aa[num]=INF;
      }
    }
  }
  sort(p,p+pos);
  for(ll i=0;i<pos;i++){cout<<p[i].s.f<<" "<<p[i].s.s<<" "<<p[i].f<<endl;}
}


#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define LL long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define vecprint(vec) for (int i=0;i<vec.size();i++)printf("%d ",vec[i]);
#define queprint(q) while(q.size()){printf("%d ",q.front());q.pop();}
#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define sz(x) ((int)x.size())
#define MEM(v,x) memset(v,x,sizeof v)
#define rep(v,i) for(int i=0;i<v.size();i++)

const double eps=1e-7,PI=3.1415926;
const int N=1e6;

using namespace std;

LL q,n,m,t,k,x,y,sum,mx=-1,mn=1e9;

string s1;
string s2;
char s,p;

vector <string> c;
vector <LL> a,b;
map <LL,LL> Mh;
map <LL,LL> Ma;

int main()
{
    cin>>s1>>s2;
    sc(n);
    while (n--)
    {
        sc(t);
        cin>>s;
        sc(m);
        cin>>p;
        if(s=='a')
        {
            if(p=='y')Ma[m]++;
            else Ma[m]+=2;
            if(Ma[m]==2 ||Ma[m]==3)
            {
                c.pb(s2);
                a.pb(m);
                b.pb(t);
            }
        }
        else
        {
            if(p=='y')Mh[m]++;
            else Mh[m]+=2;
            if(Mh[m]==2 ||Mh[m]==3)
            {
                c.pb(s1);
                a.pb(m);
                b.pb(t);
            }
        }
    }
    for(int i=0;i<c.size();i++)
    {
        cout<<c[i]<<" "<<a[i]<<" "<<b[i]<<endl;
    }

}


#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define LL long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define vecprint(vec) for (int i=0;i<vec.size();i++)printf("%d ",vec[i]);
#define queprint(q) while(q.size()){printf("%d ",q.front());q.pop();}
#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define sz(x) ((int)x.size())
#define MEM(v,x) memset(v,x,sizeof v)
#define rep(v,i) for(int i=0;i<v.size();i++)

const double eps=1e-7,PI=3.1415926;
const int N=1e6;

using namespace std;

LL q,n,m,t,k,x,y,sum,mx=-1,mn=1e9;

string s1;
string s2;
char s,p;

vector <string> c;
vector <LL> a,b;
map <LL,LL> Mh;
map <LL,LL> Ma;

int main()
{
    cin>>s1>>s2;
    sc(n);
    while (n--)
    {
        sc(t);
        cin>>s;
        sc(m);
        cin>>p;
        if(s=='a')
        {
            if(p=='y')Ma[m]++;
            else Ma[m]+=2;
            if(Ma[m]>=2)
            {
                c.pb(s2);
                a.pb(m);
                b.pb(t);
            }
        }
        else
        {
            if(p=='y')Mh[m]++;
            else Mh[m]+=2;
            if(Mh[m]>=2)
            {
                c.pb(s1);
                a.pb(m);
                b.pb(t);
            }
        }
    }
    for(int i=0;i<c.size();i++)
    {
        cout<<c[i]<<" "<<a[i]<<" "<<b[i]<<endl;
    }

}


#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define LL long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define vecprint(vec) for (int i=0;i<vec.size();i++)printf("%d ",vec[i]);
#define queprint(q) while(q.size()){printf("%d ",q.front());q.pop();}
#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define sz(x) ((int)x.size())
#define MEM(v,x) memset(v,x,sizeof v)
#define rep(v,i) for(int i=0;i<v.size();i++)

const double eps=1e-7,PI=3.1415926;
const int N=1e6;

using namespace std;

LL q,n,m,t,k,x,y,sum,mx=-1,mn=1e9;

string s1;
string s2;
char s,p;

vector <string> c;
vector <LL> a,b;
map <LL,LL> Mh;
map <LL,LL> Ma;
map <LL,LL> Mh1;
map <LL,LL> Ma1;

int main()
{
    cin>>s1>>s2;
    sc(n);
    while (n--)
    {
        sc(t);
        cin>>s;
        sc(m);
        cin>>p;
        if(s=='a')
        {
            if(p=='y')Ma[m]++;
            else Ma[m]+=2;
            if(Ma[m]>=2 && Ma1[m]==0)
            {
                c.pb(s2);
                a.pb(m);
                b.pb(t);
                Ma1[m]+=1;
            }
        }
        else
        {
            if(p=='y')Mh[m]++;
            else Mh[m]+=2;
            if(Mh[m]>=2 && Mh1[m]==0)
            {
                c.pb(s1);
                a.pb(m);
                b.pb(t);
                Mh1[m]+=1;
            }
        }
    }
    for(int i=0;i<c.size();i++)
    {
        cout<<c[i]<<" "<<a[i]<<" "<<b[i]<<endl;
    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define double long double
#define mod 1000000007
#define maxN 1000005
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii>
#define fir first
#define sec second
#define beg begin()
#define e end()
//#define len length()
//#define MAX 500005
#define ll long long
#define FASTIO ios::sync_with_stdio(0);cin.tie();cout.tie(0);
#define M 998244353
using namespace std;

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

struct fault
{
    string s;
    int num;
    int Min;
};
fault p[200];
int i;
int a[300];
int b[300];

int main()
{
    string s1,s2;cin >> s1 >> s2;

    int f;cin >> f;

    while(f--)
    {
        int x,y;
        char c1,c2;
        cin >> x >> c1 >> y >> c2;

        if(c2 == 'r')
        {
            p[i].num=y;
            p[i].Min=x;
            if(c1 == 'h')p[i].s=s1;
            else p[i].s=s2;
            i++;
        }
        else
        {
            if(c1 == 'h')a[y]++;
            else b[y]++;

            if(a[y] == 2)
            {
                p[i].num=y;
                p[i].Min=x;
                p[i].s=s1;
                i++;
                a[y]=0;
            }
            else if(b[y] == 2)
            {
                p[i].num=y;
                p[i].Min=x;
                p[i].s=s1;
                i++;
                b[y]=0;
            }

        }

    }

    for(int j=0;j<i;j++)
        cout << p[j].s << " " << p[j].num << " " << p[j].Min << endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define double long double
#define mod 1000000007
#define maxN 1000005
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii>
#define fir first
#define sec second
#define beg begin()
#define e end()
//#define len length()
//#define MAX 500005
#define ll long long
#define FASTIO ios::sync_with_stdio(0);cin.tie();cout.tie(0);
#define M 998244353
using namespace std;

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

struct fault
{
    string s;
    int num;
    int Min;
};
fault p[200];
int i;
int a[300];
int b[300];
int vis1[300];
int vis2[300];

int main()
{
    string s1,s2;
    cin >> s1 >> s2;

    int f;
    cin >> f;

    while(f--)
    {
        int x,y;
        char c1,c2;
        cin >> x >> c1 >> y >> c2;

        if(c2 == 'r')
        {

            if(!vis1[y]&&c1 == 'h')
            {
                p[i].s=s1;
                vis1[y]=1;
                p[i].num=y;
                p[i].Min=x;
                i++;
            }
            else if(!vis2[y] &&c1 == 'a')
            {
                p[i].s=s2;
                vis2[y]=1;
                p[i].num=y;
                p[i].Min=x;
                i++;
            }

        }
        else
        {
            if(c1 == 'h')a[y]++;
            else b[y]++;

            if(a[y] == 2 && !vis1[y])
            {
                p[i].num=y;
                p[i].Min=x;
                p[i].s=s1;
                i++;
                vis1[y]++;
            }
            else if(b[y] == 2 &&!vis2[y])
            {
                p[i].num=y;
                p[i].Min=x;
                p[i].s=s2;
                i++;
                vis2[y]++;
            }

        }

    }

    for(int j=0; j<i; j++)
        cout << p[j].s << " " << p[j].num << " " << p[j].Min << endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define double long double
#define mod 1000000007
#define maxN 1000005
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pii>
#define vi vector<int>
#define vpi vector<pii>
#define fir first
#define sec second
#define beg begin()
#define e end()
//#define len length()
//#define MAX 500005
#define ll long long
#define FASTIO ios::sync_with_stdio(0);cin.tie();cout.tie(0);
#define M 998244353
using namespace std;

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

struct fault
{
    string s;
    int num;
    int Min;
};
fault p[200];
int i;
int a[300];
int b[300];

int main()
{
    string s1,s2;cin >> s1 >> s2;

    int f;cin >> f;

    while(f--)
    {
        int x,y;
        char c1,c2;
        cin >> x >> c1 >> y >> c2;

        if(c2 == 'r')
        {
            p[i].num=y;
            p[i].Min=x;
            if(c1 == 'h')p[i].s=s1;
            else p[i].s=s2;
            i++;
        }
        else
        {
            if(c1 == 'h')a[y]++;
            else b[y]++;

            if(a[y] == 2)
            {
                p[i].num=y;
                p[i].Min=x;
                p[i].s=s1;
                i++;
                a[y]=0;
            }
            else if(b[y] == 2)
            {
                p[i].num=y;
                p[i].Min=x;
                p[i].s=s2;
                i++;
                b[y]=0;
            }

        }

    }

    for(int j=0;j<i;j++)
        cout << p[j].s << " " << p[j].num << " " << p[j].Min << endl;
    return 0;
}