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++: #include <iostream>
#include <algorithm>

using namespace std;



int main() {
	int n, k;
	int dp[101][10] = {0};
	int data[101] = {0};
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int a;
		cin >> a;
		cin >> data[a];

	}
	if (data[1] != 0) {
		if (data[2] != 0) {
			dp[2][data[2] + 3 * (data[1] - 1)] = 1;
		}
		else {
			for (int i = 1; i <= 3; i++) {
				int b = (data[1]-1)*3 + i;
				dp[2][b] = 1;
			}
		}
	}
	else {
		if (data[2] != 0) {
			for (int i = 0; i < 3; i++) {
				int c = i * 3 + data[2];
				dp[2][c] = 1;
			}
		}
		else {
			for (int i = 1; i <= 9; i++) {
				dp[2][i] = 1;
			}
		}
	}
	for (int i = 3; i <= n; i++) {
		if (data[i] != 0) {
			for (int j = 0; j < 3; j++) {
				int k = data[i] + j * 3;
				for (int l = 0; l < 3; l++) {
					int m = j+1+ l * 3;
					int o = 0;
					if (m == 1 || m == 5 || m == 9) {
						if (k == m) {
							o = 1;
						}
						
					}
					if(o==0){
						dp[i][k] += dp[i - 1][m];
					}
					o = 0;
				}
			}
		}
		else {
			for (int j = 1; j <= 9; j++) {
				if (j <= 3) {
					if (j == 1) {
						dp[i][1] += dp[i - 1][4] + dp[i - 1][7];
					}
					else {
						dp[i][j] += dp[i - 1][1] + dp[i - 1][4] + dp[i - 1][7];
					}
				} 
				else if (j >= 4 && j <= 6) {
					if (j == 5) {
						dp[i][5] += dp[i - 1][2] + dp[i - 1][8];
					}
					else {
						dp[i][j] += dp[i - 1][2] + dp[i - 1][5] + dp[i - 1][8];
					}
				}
				else {
					if (j == 9) {
						dp[i][9] += dp[i - 1][3] + dp[i - 1][6];
					}
					else {
						dp[i][j] += dp[i - 1][3] + dp[i - 1][6] + dp[i - 1][9];

					}
				}
			}
		}
		for (int j = 1; j <= 9; j++) {
			if (dp[i][j] >= 10000) {
				dp[i][j] = dp[i][j] % 10000;
			}
		}
	}
	int z = 0;
	for (int i = 1; i <= 9; i++) {
		z += dp[n][i];
		if (z >= 10000) {
			z = z % 10000;
		}
	}
	cout << z << endl;
	return 0;
}

C++: # include <iostream>

# define MAX_N 100
# define MOD 10000

int n, K;

int plan[MAX_N+1];
int memo[MAX_N+1][4][4];

int solve(int day,int t,int y){
	if (day == n + 1)
		return 1;
	if (memo[day][t][y] != -1)
		return memo[day][t][y];
	if (plan[n + 1] != 0){
		if (t == y&&t == plan[n + 1])
			return 0;
		else
			return solve(n + 1, plan[n + 1], t)%MOD;
	}

	int result = 0;
	for (int i = 1; i <= 3; ++i){
		if (t == y&&t == i)
			continue;
		else
			result+=solve(n + 1, i, t)%MOD;
	}
	return memo[n][t][y] = result%MOD;
}

int main(){
	int d, k;
	std::cin >> n >> K;

	for (int i = 0; i < K; ++i){
		std::cin >> d >> k;
		plan[d] = k;
	}

	for (int i = 1; i <= n; ++i){
		for (int j = 1; j < 4; ++j){
			for (int k = 0; k < 4; ++k){
				memo[i][j][k] = -1;
			}
		}
	}

	std::cout << solve(1, 1, 1) << std::endl;

	return 0;
}

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

int N, K, mem[100][3][3], decided[100];

int dp(int n, int b1, int b2)
{
  if(n == N)
    return 1;
  if(mem[n][b1][b2] != -1)
    return mem[n][b1][b2];
  int ans = 0;
  if(decided[n] != 0)
  {
    if(b1 == b2 && decided[n] == b1)
      return 0;
    mem[n][b1][b2] = dp(n + 1, decided[n], b1);
    return mem[n][b1][b2];
  }
  for(int i = 1; i <= 3; i++)
  {
    if(b1 == b2 && b1 == i)
      continue;
    ans += dp(n + 1, i, b1);
  }
  mem[n][b1][b2] = ans % 10000;
  return ans % 10000;
}

int main()
{
  cin >> N >> K;
  for(int i = 0; i < 100; i++)
    for(int j = 0; j < 3; j++)
      for(int k = 0; k < 3; k++)
        mem[i][j][k] = -1;
  for(int i = 0; i < K; i++)
  {
    int a, b;
    cin >> a >> b;
    decided[a - 1] = b;
  }
  cout << dp(0, 0, 0) << endl;
}

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

const int INF = 10000;
int n,k;

int N[110];
int dp[110][4][4];

int f(int i, int a, int b)
{
	if(i==n)return 1;
	if(dp[i][a][b]>=0)return dp[i][a][b];
	if(N[i]!=0){
		return dp[i][a][b] = f(i+1,N[i],a)%INF;
	}
	
	return dp[i][a][b] = ((a==b&&a==1)||(a==N[i+1]&&a==1)||(N[i+1]==N[i+2]&&N[i+1]==1)?0:f(i+1,1,a)) + 
						 ((a==b&&a==2)||(a==N[i+1]&&a==2)||(N[i+1]==N[i+2]&&N[i+1]==2)?0:f(i+1,2,a)) + 
						 ((a==b&&a==3)||(a==N[i+1]&&a==3)||(N[i+1]==N[i+2]&&N[i+1]==3)?0:f(i+1,3,a));
}

int main()
{	
	int a,b;
	cin >> n >> k;
	for (int i = 0; i < k; ++i){
		cin >> a >> b;
		N[a-1] = b;
	}
	fill((int*)dp,(int*)(dp+(sizeof(dp)/sizeof(*(dp)))),-1);
	cout << f(0,0,0)%INF << endl;
	
	return 0;
}