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 <cstdio>
#include <algorithm>
using namespace std;
#define mod 10000
int day[100];
long long dp[100][3][3];
int main() {
    int n, k; scanf("%d%d",&n,&k);
    for (int i=0; i<k; i++) {
        int a,b; scanf("%d%d",&a,&b);
        day[a-1]=b;
    }
    if (day[0]) {
        dp[0][day[0]-1][0]=dp[0][day[0]-1][2]=1;
    } else {
        dp[0][0][0]=dp[0][1][0]=dp[0][2][0]=1;
        dp[0][0][2]=dp[0][1][2]=dp[0][2][2]=1;
    }
    for (int i=1; i<n; i++) {
        if (day[i]==1) {
            dp[i][0][0]=(dp[i-1][1][2]+dp[i-1][2][2])%mod;
            dp[i][0][1]=dp[i-1][0][0];
            dp[i][0][2]=(dp[i][0][1]+dp[i][0][0])%mod;
        } else if (day[i]==2) {
            dp[i][1][0]=(dp[i-1][0][2]+dp[i-1][2][2])%mod;
            dp[i][1][1]=dp[i-1][1][0];
            dp[i][1][2]=(dp[i][1][1]+dp[i][1][0])%mod;
        } else if (day[i]==3) {
            dp[i][2][0]=(dp[i-1][0][2]+dp[i-1][1][2])%mod;
            dp[i][2][1]=dp[i-1][2][0];
            dp[i][2][2]=(dp[i][2][1]+dp[i][2][0])%mod;
        } else {
            dp[i][0][0]=(dp[i-1][1][2]+dp[i-1][2][2])%mod;
            dp[i][0][1]=dp[i-1][0][0];
            dp[i][0][2]=(dp[i][0][1]+dp[i][0][0])%mod;
            dp[i][1][0]=(dp[i-1][0][2]+dp[i-1][2][2])%mod;
            dp[i][1][1]=dp[i-1][1][0];
            dp[i][1][2]=(dp[i][1][1]+dp[i][1][0])%mod;
            dp[i][2][0]=(dp[i-1][0][2]+dp[i-1][1][2])%mod;
            dp[i][2][1]=dp[i-1][2][0];
            dp[i][2][2]=(dp[i][2][1]+dp[i][2][0])%mod;
        }
    }
    printf("%lld\n",(dp[n-1][0][2]+dp[n-1][1][2]+dp[n-1][2][2])%mod);
}

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 <string>
#include <algorithm>

#include <vector>
#include <cmath>

using namespace std;

#define int long long

int dp[101][3][2]={};

inline int che(int ret)
{
    return ret >= 0 ? ret : 0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int ans = 0;
    int day=0,dec=0;
    cin >> day>>dec;
    
    int ind,ink;
    
    for(int i=0;i<3;++i)
        dp[0][i][0] = 1;
    
    for(int i=0;i<dec;++i)
    {
        cin >> ind >> ink;
        ink--;
        ind--;
        for(int k=0;k<3;++k)
        {
            if(k!=ink)
            {
                dp[ind][k][0] = dp[ind][k][1] = -1;
            }
        }
    }
    //dp
    for(int i=0;i<day;++i)
    {
        for(int k = 0;k<3;++k)
        {
            cout << i <<":" <<k << " "<<dp[i][k][0] << " " << dp[i][k][1] <<endl;
            if(dp[i][k][0]!=-1)
            {
                dp[i][k][0] %= 10000;
                dp[i][k][1] %= 10000;
                
                if(dp[i+1][(k+1)%3][0] >= 0) dp[i+1][(k+1)%3][0] += dp[i][k][0];
                if(dp[i+1][(k+2)%3][0] >= 0) dp[i+1][(k+2)%3][0] += dp[i][k][0];
                
                if(dp[i+1][k][1] >= 0) dp[i+1][k][1] += dp[i][k][0];
                
                if(dp[i+1][(k+1)%3][0] >= 0) dp[i+1][(k+1)%3][0] += dp[i][k][1];
                if(dp[i+1][(k+2)%3][0] >= 0) dp[i+1][(k+2)%3][0] += dp[i][k][1];

            }
        }
    }
    for(int i = 0;i< 3;++i)
    {
        for(int k = 0;k < 2;++k)
        {
            ans = (ans+che(dp[day-1][i][k]));
        }
    }
    cout << ans%10000 << endl;
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n, k;

int sche[100];

int dp[100][4][4];

int rec(int day, int a, int b) // a = i - 2 ??\???, b = i - 1 ??\???
{
	if (day == n) return 1;

	if (dp[day][a][b] >= 0) return dp[day][a][b];
	
	int res = 0;
	
	if (sche[day]) {
		if (sche[day] != a || sche[day] != b) {
			res += rec(day + 1, b, sche[day]);
			res %= 10000;
		}
	} else {
		for (int i = 1; i <= 3; ++i) {
			if (a == b && b == i) continue;
			res += rec(day + 1, b, i);
			res %= 10000;
		}
	}

	return dp[day][a][b] = res;
}

int main()
{
	cin >> n >> k;

	for (int i = 0; i < k; ++i) {
		int day; cin >> day; --day;
		cin >> sche[day];
	}

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

    int ans = 0;

    for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j) {
            ans += rec(2, i, j);
            ans %= 10000;
        }
    }

	printf("%d\n", ans);
}