import java.util.*; import java.io.*; public class Main { public static Scanner sc = new Scanner(System.in); public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { int t = 1; while( t > 0 ) { solve(); t--; } pw.flush(); } static void solve() { int N = sc.nextInt(); long ans = 1; for( long i = 0, cnt = 0; i < 3*N; i++ ) { int x = sc.nextInt(); if( x%3 != 0 ) cnt++; if( i%N == N-1 ) { ans *= cnt; cnt = 0; } } pw.println(ans); } }