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>
using namespace std;
int main(){
	long ans=0;
	int n,k,a,b,i,i2,i3,kk[101][4],dp[101][4];//dp[??\][?????????]
	cin>>n>>k;
	for(i=0;i<=100;i++){
		for(i2=0;i2<=3;i2++){
			dp[i][i2]=0;
			kk[i][i2]=0;
		}
	}
	for(i=1;i<=k;i++){
		cin>>a>>b;
		kk[a][b]=1;
		if(b==1){
			dp[a][2]=-1;
			dp[a][3]=-1;
		}
		else if(b==2){
			dp[a][1]=-1;
			dp[a][3]=-1;
		}
		else if(b==3){
			dp[a][1]=-1;
			dp[a][2]=-1;
		}
	}
	for(i=1;i<=n;i++)for(i2=1;i2<=3;i2++)if(kk[i][i2]==1&&kk[i+2][i2]==1)dp[i+1][i2]=-1;
	for(i=1;i<=3;i++){
		if(dp[1][i]!=-1){
			dp[1][i]=1;
		}
	}
	for(i=1;i<n;i++){
		for(i2=1;i2<=3;i2++){
			if(dp[i][i2]>0){
				for(i3=1;i3<=3;i3++){
					if(i2==i3){
						if(dp[i-1][i2]<=0){
							if(dp[i+1][i3]!=-1){
								dp[i+1][i3]+=dp[i][i2];
							}
						}
					}
					else if(dp[i+1][i3]!=-1){
							dp[i+1][i3]+=dp[i][i2];
					}
				}
			}
		}
	}
	for(i=1;i<=3;i++){
		if(dp[n][i]!=-1){
			ans+=dp[n][i];
		}
	}
	cout<<ans%10000<<endl;

	for(i=1;i<=n;i++){
		for(i2=1;i2<=3;i2++){
			cout<<dp[i][i2]<<' ';
			if(dp[i][i2]!=-1){
				cout<<' ';
			}
		}
		cout<<endl;
	}
}

C++: # include <iostream>
# include <algorithm>

# 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);
	}

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

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

int mod=10000;

int main(){
	int n, k;
	cin >> n >> k;
    vector<int> c(n+1, -1);
	for(int i=0; i<k; i++){
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        c[tmp1]=tmp2-1;
    }

    vector<vector<vector<long long>>> dp(n+1, vector<vector<long long>>(3, vector<long long>(3, 0)));
    if(c[1]==-1){
        dp[1][0][1]=1;
        dp[1][1][1]=1;
        dp[1][2][1]=1;
    }else{
        dp[1][c[1]][1]=1;
    }
    for(int i=2; i<=n; i++){
        if(c[i]==-1){
            dp[i][0][1]=(dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][2][1]+dp[i-1][2][2])%mod;
            dp[i][1][1]=(dp[i-1][0][1]+dp[i-1][0][2]+dp[i-1][2][1]+dp[i-1][2][2])%mod;
            dp[i][2][1]=(dp[i-1][0][1]+dp[i-1][0][2]+dp[i-1][1][1]+dp[i-1][1][2])%mod;
            dp[i][0][2]=dp[i-1][0][1]%mod;
            dp[i][1][2]=dp[i-1][1][1]%mod;
            dp[i][2][2]=dp[i-1][2][1]%mod;
        }else{
            dp[i][c[i]][1]=(dp[i-1][(c[i]+1)%3][1]+dp[i-1][(c[i]+1)%3][2]+dp[i-1][(c[i]+2)%3][1]+dp[i-1][(c[i]+2)%3][2])%mod;
            dp[i][c[i]][2]=dp[i-1][c[i]][1]%mod;
        }
    }
    long long ans=0;
    ans=(dp[n][0][1]+dp[n][0][2]+dp[n][1][1]+dp[n][1][2]+dp[n][2][1]+dp[n][2][2])%mod;
    cout << ans << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

const int MOD = 10000;

int N, K;
int plan[128];
int dp[128][4];

void pasta();

int main()
{
	scanf("%d %d", &N, &K);
	for (int i = 0; i < K; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		plan[a] = b;
	}
	
	if (plan[1] == 0) dp[0][1] = 1;
	else dp[0][plan[1]] = 1;
	pasta();
	/*
	for (int i = 1; i <= N; i++){
		for (int j = 1; j < 4; j++){
			printf("%d ", dp[i][j]);
		}
		puts("");
	}
	*/
	int sum = 0;
	for (int i = 1; i < 4; i++){
		sum = (sum + dp[N][i]) % MOD;
	}
	printf("%d\n", sum);
	
	return 0;
}

void pasta()
{
	for (int i = 1; i <= N; i++){
		for (int j = 1; j < 4; j++){
			if (plan[i] != 0 && j != plan[i]) continue;
			for (int k = 1; k < 4; k++){
				dp[i][j] += dp[i - 1][k];
				if (i >= 3 && j == k && dp[i - 1][j] > 0){
					dp[i][j] -= dp[i - 2][k];
				}
			}
			dp[i][j] %= MOD;
		}
	}
}