Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

// 文字列を1行取得
func StrStdin() (stringReturned string) {
//	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput := scanner.Text()

	stringReturned = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func IntStdin() (int, error) {
	stringInput := StrStdin()
	return strconv.Atoi(strings.TrimSpace(stringInput))
}

// 空白や空文字だけの値を除去したSplit()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}

	return
}

// デリミタで分割して文字列スライスを取得
func SplitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := StrStdin()

	// 空白で分割
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func SplitIntStdin(delim string) (intSlices []int, err error) {
	// 文字列スライスを取得
	stringSplited := SplitStrStdin(" ")

	// 整数スライスに保存
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

func main() {
	nk, _ := SplitIntStdin(" ")
	n, k := nk[0], nk[1]
	kind := make([]int, n)
	for i := 0; i < k; i++ {
		var tmp []int
		var err error
		if tmp, err = SplitIntStdin(" "); err != nil {
			panic(err)
		}
		kind[tmp[0]-1] = tmp[1]
	}
	dp := make([][3][3]int, n)
	if kind[0] > 0 {
		dp[0][0][kind[0]-1] = 1
	} else {
		for i := 0; i < 3; i++ {
			dp[0][0][i] = 1
		}
	}
	if kind[1] > 0 {
		for i := 0; i < 3; i++ {
			dp[1][i][kind[1]-1] = dp[0][0][i]
		}
	} else {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				dp[1][i][j] = dp[0][0][i]
			}
		}
	}
	for i := 1; i < n-1; i++ {
		if kind[i+1] > 0 {
			for j := 0; j < 3; j++ {
				if j == kind[i+1]-1 {
					for k := 0; k < 3; k++ {
						if j != k {
							dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
							dp[i+1][j][kind[i+1]-1] %= 10000
						}
					}
				} else {
					for k := 0; k < 3; k++ {
						dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
						dp[i+1][j][kind[i+1]-1] %= 10000
					}
				}
			}
		} else {
			for j := 0; j < 3; j++ {
				for k := 0; k < 3; k++ {
					for l := 0; l < 3; l++ {
						if j != k || k != l {
							dp[i+1][k][j] += dp[i][l][k]
							dp[i+1][k][j] %= 10000
						}
					}
				}
			}
		}
	}
	result := 0
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			result += dp[n-1][i][j]
		}
	}
	// fmt.Println(dp)
	// fmt.Println(kind)
	fmt.Println(result % 10000)
}

C++: #inlcude<cstdio>
using namespace std;

int d[100], n, k, dp[100][6];
// 0:aa, 1:bb, 2:cc, 3:a, 4:b, 5:c

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 0; i < n; i++) d[i] = 0;
  for (int i = 0; i < k; i++) scanf("%d%d", &a, &b), d[a-1] = b;
  dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = dp[0][4] = dp[0][5] = 0;
  if (d[0] == 0) dp[0][3] = dp[0][4] = dp[0][5] = 1;
  if (d[0] == 1) dp[0][3] = 1;
  if (d[0] == 2) dp[0][4] = 1;
  if (d[0] == 3) dp[0][5] = 1;
  for (int i = 1; i < n; i++) {
    dp[i][0] = dp[i-1][3];
    dp[i][1] = dp[i-1][4];
    dp[i][2] = dp[i-1][5];
    dp[i][3] = dp[i-1][1] + dp[i-1][2];
    dp[i][4] = dp[i-1][0] + dp[i-1][2];
    dp[i][5] = dp[i-1][0] + dp[i-1][1];
    for (int j = 0; j < 6; j++) dp[i][j] = dp[i][j] % 10000;
    if (d[i] == 0) continue;
    if (d[i] == 1) dp[i][1] = dp[i][2] = dp[i][4] = dp[i][5] = 0;
    if (d[i] == 2) dp[i][0] = dp[i][2] = dp[i][3] = dp[i][5] = 0;
    if (d[i] == 3) dp[i][0] = dp[i][1] = dp[i][3] = dp[i][4] = 0;
  }
  int ans = 0;
  for (int j = 0; j < 6; j++) ans += dp[n-1][j];
  printf("%d\n", ans % 10000);
}

C++: #include<iostream>
#include<string>
using namespace std;
int dp[3][101];
bool map[3][101];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<3;i++){
		for(int j=0;j<=n;j++){
			dp[i][j]=0;
			map[i][j]=true;
		}
	}
	int q,w;
	for(int i=0;i<k;i++){
		cin>>q>>w;
		for(int j=0;j<3;j++){
			if(j!=w-1)
				map[j][q]=false;
		}
	}
	for(int i=0;i<3;i++){
		if(map[i][1]==true)
			dp[i][1]=1;
	}
	for(int i=2;i<=n;i++){
		for(int j=0;j<3;j++){
			if(map[j][i]==true){
				for(int g=0;g<3;g++)
					dp[j][i]+=dp[g][i-1];
				if(dp[j][i-1]>dp[j][i-2])
				    dp[j][i]-=dp[j][i-2];
				//dp[j][i]%=10000;
			}
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<3;j++)
			cout<<dp[j][i]<<" ";
		cout<<endl;
	}
	int ans=0;
	for(int i=0;i<3;i++)
		ans+=dp[i][n];
	cout<<ans<<endl;
	return 0;
}

C++: #include<iostream>
using namespace std ;

int n,k;
int d[110] = {} ;
int dp[110][4][4] = {} ;

int f( int day , int p , int pp ){
	if( day == n ) return 1 ;
	if( dp[day][p][pp] != 0 ) return dp[day][p][pp] ;
	
	int ans = 0 ;
	for( int i=1 ; i<=3 ; i++ ){
		if( p == pp && p == i ){}
		else {
			if( d[day+1] == 0 || d[day+1] == i ){
				ans += f( day+1 , i , p ) ;
				ans %= 10000 ;
			}
		}
	}
	
	return dp[day][p][pp] = ans ;
}

int main(){
	
	cin >> n >> k ;
	
	int a,b ;
	for( int i=0 ; i<k ; i++ ){
		cin >> a >> b ;
		d[a] = b ;
	}
	
	
	int ans2 = 0 ;
	for( int i=1 ; i<=3 ; i++ ){
		if( d[1] == 0 || d[1] == i ){
			ans2 += f( 1 , i , 0 ) ;
			ans2 %= 10000 ;
		}
	}
	
	cout << ans2 << endl ;
	
return 0;
}

C++: #include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 10000;
LL N, K, A[112], B[112];
std::map<LL, LL>list;

LL dp(LL d, LL b2, LL b1)
{
	if (d == N + 1) { return 1; }
	if (list[d] > 0)
	{
		if (!(b2 == b1 && b1 == list[d])) { return dp(d + 1, b1, list[d]) % mod; }
		else { return 0; }
	}
	else
	{
		LL res = 0;
		for (int i = 1; i <= 3; ++i)
		{
			if (!(b2 == b1 && b1 == i)) { res += dp(d + 1, b1, i) % mod; }
			res %= mod;
		}
		return res;
	}
}

int main()
{
	in >> N >> K;
	rep(i, N) { in >> A[i] >> B[i]; }
	rep(i, N) { list[A[i]] = B[i]; }
	out << dp(1, 0, 0) << std::endl;
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()


const int MAXN = 100, MAXS = 6;
const int T = 1, C = 2, B = 3, TT = 4, CC = 5, BB = 6;
const int DS = 3;
const int res[6][4] = {{0,0}, {C,B,CC,BB},{B,T,BB,TT},{T,C,TT,CC}};
const int MOD = 10000;

int main()
{
    int n, k; cin >> n >> k;
    long long dp[MAXS + 1][MAXN + 1] = {};
    int s[MAXN + 1] = {};
    int a, b;
    REP(k) {cin >> a; a--; cin >> s[a];}

    if(s[0] > 0) dp[s[0]][0] = 1;
    else dp[T][0] = dp[C][0] = dp[B][0] = 1;

    for(int i = 1; i< n; i++)
        if(s[i] > 0)
        {
            rep(j, 4){dp[s[i]][i] = dp[res[s[i]][j]][i - 1]; dp[s[i]][i] %= MOD;}
            dp[s[i] + DS][i] = dp[s[i]][i - 1]; dp[s[i] + DS][i] %= MOD;
        }
        else
        {
            for(int t = 1; t <= 3;t++)
                rep(j, 4)dp[t][i] = (dp[t][i] + dp[res[t][j]][i - 1]) % MOD;
            for(int t = 4; t <= 6; t++)
                dp[t][i] = dp[t - DS][i - 1];
        }
    long long ans  = 0;
    REP(6) ans += dp[i + 1][n - 1];
    cout << ans% 10000 << endl;
    return 0;
}