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<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#define int long long
#define INF 1000000
using namespace std;
int dp[101][3][2],p[101];
int n,k,a,b;
void pst(int day,int tas){
    dp[day][tas][1]=dp[day-1][tas][0];
    for(int i=0;i<3;i++){
        if(i!=tas){
            dp[day][tas][0]+=dp[day-1][i][0];
            dp[day][tas][0]+=dp[day-1][i][1];
            dp[day][tas][0]%=10000;
        }
    }
}
signed main(){
    cin>>n>>k;
    fill(p,p+101,-1);
    for(int i=0;i<k;i++){
        cin>>a>>b;
        p[a]=b-1;
    }
    if(p[1]!=-1)dp[1][p[1]][0]=1;
    else{
        dp[1][0][0]=1;
        dp[1][1][0]=1;
        dp[1][2][0]=1;
    }
    for(int i=2;i<=n;i++){
        if(p[i]!=-1){
            pst(i,p[i]);
        }
        else{
            for(int j=0;j<3;j++){
                pst(i,j);
            }
        }
    }
    int ans=0;
    for(int i=0;i<3;i++){
        for(int j=0;j<2;j++){
            ans+=dp[n][i][j];
            ans%=10000;
        }
    }
    cout<<ans<<endl;
    return 0;
}

C++: #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int dp[100][2][3];

int main(){
	int n,k,a[100],b[100];
	scanf("%d%d",&n,&k);
	dp[0][0][0]=dp[0][0][1]=dp[0][0][2]=1;
	for(int i=0;i<k;i++){
		scanf("%d%d",&a[i],&b[i]);
		for(int j=0;j<3;j++) if(b[i]!=j+1) dp[a[i]-1][0][j]=dp[a[i]-1][1][j]=-1;
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			if(dp[i][0][j]==-1) continue;
			for(int k=0;k<3;k++){
				if(k==j) dp[i][1][j]=(dp[i][1][j]+(dp[i-1][0][k]==-1?0:dp[i-1][0][k]))%10000;
				else dp[i][0][j]=(dp[i][0][j]+(dp[i-1][0][k]==-1?0:dp[i-1][0][k])+(dp[i-1][1][k]==-1?0:dp[i-1][1][k]))%10000;
			}
		}
	}
	int res=0;
	for(int i=0;i<3;i++) res+=(dp[n-1][0][i]==-1?0:dp[n-1][0][i])+(dp[n-1][1][i]==-1?0:dp[n-1][1][i]);
	res%=10000;
	printf("%d\n",res);
}

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

using namespace std;
const int MOD = 10000;

int main()
{
  int N,K;
  while(cin >> N){
    int  preplan[1+N];
    cin >> K;
    for(int i = 0; i < 1+N; ++i)preplan[i]=-1;
    for(int i = 0; i < K; ++i){
      int a,b;
      cin >> a >> b;
      //--a;
      preplan[a] = b;
    }

    int dp[N+1][4][4][4];

    for(int i = 0; i < N+1; ++i){
      for(int j = 0; j < 4; ++j){
        for(int k = 0; k < 4; ++k){
          for(int l = 0; l < 4; ++l){
            dp[i][j][k][l] = 0;
          }
        }
      }
    }

    if(preplan[1]!=-1){
      dp[1][preplan[1]][0][0] = 1;
    }else{
      dp[1][1][0][0] = 1;
      dp[1][2][0][0] = 1;
      dp[1][3][0][0] = 1;
    }
    for(int i = 1; i < N; ++i){
      for(int j = 1; j < 4; ++j){
        for(int k = i==1?0:1; k < 4; ++k){
          for(int l = i<=2?0:1; l < 4; ++l){
            for(int m = 1; m < 4; ++m){
              if( (m == j && j == k ) || (j == k && k == l) ) continue;
              if( preplan[i+1] != -1 && m != preplan[i+1] ) continue;
              //printf("dp[%d][%d][%d][%d] = dp[%d][%d][%d][%d] : %d <- %d+1\n",
              //i+1,m,j,k,i,j,k,l,dp[i+1][m][j][k],dp[i][j][k][l]);
              dp[i+1][m][j][k] += dp[i][j][k][l];
              dp[i+1][m][j][k] %= MOD;
            }
          }
        }
      }
    }

    int res = 0;
    for(int i = 1; i < 4; ++i){
      for(int j = 1; j < 4; ++j){
        for(int k = 1; k < 4; ++k){
          if( i==j&&j==k ) continue;
          res += dp[N][i][j][k];
          res %= MOD;
        }
      }
    }

    cout << res << endl;
    
  }
  return 0;
}