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 <bits/stdc++.h>
using namespace std;

#define int long long

int mod = 10000;
int n, k;
int p[101] = {0};

string debug="00000000000000000000";

int dp[110][2][4];

int dfs(int i = 1, bool ff = false, int f = 0)
{
  int &ans = dp[i][ff][f];

  if (ans != -1) return ans;
  if (i == n + 1) {
    //cout << debug << endl;
    return 1;
  }
  
  if (p[i] != 0){
    if (ff && f == p[i]) return 0;
    debug[i-1] = p[i] + '0';
    ans = dfs(i + 1, f == p[i], p[i]);
    return ans %= mod;
  }

  ans = 0;
  for (int j = 1; j < 4; j++){
    if (ff && f == j) continue;
    debug[i-1] = j + '0';
    ans += dfs(i + 1, f == j, j);
  }

  return ans %= mod;
}

main()
{
  memset(dp, -1, sizeof(dp));

  cin >> n >> k;
  for (int i = 0; i < k; i++){
    int a, b;
    cin >> a >> b;
    p[a] = b;
  }

  cout << dfs() << endl;
}

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

int main(){
	int n,m,d[100],t[100],type[4][4],c;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>d[i]>>t[i];
	}
	for(int i=0;i<m;i++){
		if(d[i]==1){
			type[1][i]=1;
			goto Exit1;
		}
	}
	type[1][1]=1;
	type[2][1]=1;
	type[3][1]=1;
	
Exit1:
	for(int i=1;i<=3;i++){
		if(type[i][1]!=1){
			type[i][1]=0;
		}
	}
	type[1][2]=0;
	type[2][2]=0;
	type[3][2]=0;
	for(int i=2;i<=n;i++){
		for(int j=0;j<m;j++){

			if(d[j]==i){
				type[t[j]][2]=type[t[j]][1];
				type[t[j]][1]=0;
				for(int k=1;k<=3;k++){
					if(t[j]!=k){
						for(int l=1;l<=2;l++){
						type[t[j]][1] += type[k][l];
						type[k][l]=0;
						}
					}
				}
				goto Exit2;
			}

		}
		for(int k=1;k<=3;k++){
			type[k][2] = type[k][2]*2+type[k][1];
			type[k][1]  *= 2;
		}
Exit2:
		for(int j=1;j<=3;j++){
			for(int k=1;k<=2;k++){
				type[j][k]=type[j][k]%10000;
			}
		}
	}
	cout<<(type[1][1]+type[1][2]+type[2][1]+type[2][2]+type[3][1]+type[3][2])%10000<<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[day + 1] != 0){
		if (t == y&&t == plan[n + 1])
			return 0;
		else
			return solve(day + 1, plan[day + 1], t)%MOD;
	}

	int result = 0;
	for (int i = 1; i <= 3; ++i){
		if (t == y&&t == i)
			continue;
		else
			result+=solve(day + 1, i, t)%MOD;
	}
	return memo[day][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, 0, 0) << std::endl;

	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[101] = {0};
	int n;
	int i;
	cin >> n >> i ;
	for (int v = 0; v < i; v++){
		int y, x;
		cin >> y >> x;
		a[y] = { x };
		
	}
	int f;
	if (a[1] = a[2] != a[3]){
		if (a[1] != 0){
			f = 2;
		}
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[1] = a[3] != a[2]){
		if (a[1]!= 0)
		f = 2;
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[3] = a[2] != a[1]){
		if (a[2]!= 0)
		f = 2;
		if (a[2] = 0){
			f = 8;
		}
	}
	if (a[1] = a[2] = a[3]){
		if (a[1] = 0){
			f = 24;
		}
		if (a[1] != 0){
			f = 1;
		}
		
	}

	for (int v = 4; v <= n; v++){
		if (a[v] = 0){
			if (a[v - 2] = a[v - 1]!=0){
				f = f * 2;
			}
			if (a[v - 2] != a[v - 1] != 0){
				f = f * 3;
			}
		}
	
	}
		return 0;
}