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 <cstring>

using namespace std;
#define mod 10000
#define MAX_N (100+1)
int n, k;
int sche[MAX_N];

int dp[MAX_N][4][4];
int cnt(int day, int one, int two) {
    if (day == n) return 1;
    if (dp[day][one][two] >= 0) return dp[day][one][two];
    if (sche[day] > 0) {
        if (one == two && two == sche[day]) return dp[day][one][two] = 0;
        return dp[day][one][two] = cnt(day+1, sche[day], one);
    }
    int ret = 0;
    for (int i = 1; i <= 3; i++) {
        if (one == two && two == i) continue;
        ret += cnt(day+1, i, one);
        ret %= mod;
    }
    return dp[day][one][two] = ret % mod;
}

int main() {
    cin >> n >> k;
    memset(sche, -1, sizeof(sche));
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < k; i++) {
        int d, p; cin >> d >> p;
        d--;
        sche[d] = p;
    }
//    for (int i = 0; i < n; i++) cout << sche[i] << ' ';cout << endl;
    cout << cnt(0, 0, 0) << 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, 0, 0) << std::endl;

	return 0;
}

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

int main(){
  int n,k;
  int a[100],dp[100][9];
  scanf("%d %d",&n,&k);
  fill(a,a+n,4);
  for(int i=0;i<k;i++){
    int x,y;
    scanf("%d %d",&x,&y);
    x--;
    y--;
    a[x] = y;
  }
  for(int i=0;i<9;i++){
    dp[1][i] = 1;
    if((a[0]!=4&&a[0]!=i%3)||(a[1]!=4&&a[1]!=i/3)) dp[1][i] = 0;
  }
  for(int i=2;i<n;i++){
    for(int j=0;j<9;j++){
      dp[i][j] = 0;
      for(int k=0;k<3;k++){
        if((j%3!=j/3||j/3!=k)&&(a[i]==j/3||a[i]==4)) dp[i][j] += dp[i-1][(j%3)*3+k];
      }
      dp[i][j] %= 10000;
    }
  }
  int ans = 0;
  for(int i=0;i<9;i++) ans += dp[n-1][i];
  printf("%d\n",ans%10000);
  return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;



int main(void){
	int dp[102][5][5],f[102];
	int n,k;
	int a,b;
	int x,y;
	for(a=0;a<102;a++)f[a]=0;
	cin >> n >> k;
	for(a=0;a<k;a++){
		cin >> x >> y;
		f[x]=y;
	}
	if(f[1]!=0)dp[1][f[1]][1]=1;
	else dp[1][1][1]=dp[1][2][1]=dp[1][3][1]=1; 
	for(a=2;a<=n;a++){
		if(f[a]==0){
			dp[a][1][1]=(dp[a-1][2][1]+dp[a-1][2][2]+dp[a-1][3][1]+dp[a-1][3][2])%10000;
			dp[a][1][2]=dp[a-1][1][1]%10000;

			dp[a][2][1]=(dp[a-1][1][1]+dp[a-1][1][2]+dp[a-1][3][1]+dp[a-1][3][2])%10000;
			dp[a][2][2]=dp[a-1][2][1]%10000;

			dp[a][3][1]=(dp[a-1][1][1]+dp[a-1][1][2]+dp[a-1][2][1]+dp[a-1][2][2])%10000;
			dp[a][3][2]=dp[a-1][3][1]%10000;
		}else{
			dp[a][f[a]][2]=dp[a-1][f[a]][1]%10000;
			for(b=1;b<=3;b++){
				if(b!=f[a])dp[b][f[a]][1]+=(dp[a-1][b][1]+dp[a-1][b][2])%10000;

			}
		}
	}
	printf("%d\n",(dp[n][1][1]+dp[n][1][2]+dp[n][2][1]+dp[n][2][2]+dp[n][3][1]+dp[n][3][2])%10000);
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,p[110]={},dp[102][4][4]={};
  cin>>n>>t;
  for(int i=0;i<t;i++){
    int a,b;
    cin>>a>>b;
    p[a]=b;
  }
  
  if(p[1]&&p[2])dp[3][p[2]][p[1]]=1;
  else if(p[2])for(int i=1;i<4;i++)dp[3][p[2]][i]=1;
  else if(p[1])for(int i=1;i<4;i++)dp[3][i][p[1]]=1;
  else 
    for(int i=1;i<4;i++)
      for(int j=1;j<4;j++)dp[3][i][j]=1;

  for(int i=3;i<=n;i++)
    for(int j=1;j<4;j++) //1
      for(int k=1;k<4;k++){//2
	if(p[i]==j&&j==k)continue;
	if(p[i])dp[i+1][p[i]][j]=(dp[i+1][p[i]][j]+dp[i][j][k])%10000;
	else 
	  for(int l=1;l<4;l++){
	    if(j==k&&k==l)continue;
	    dp[i+1][l][j]=(dp[i+1][l][j]+dp[i][j][k])%10000;
	  }
      }
  int ans=0;
  for(int i=1;i<4;i++)
    for(int j=1;j<4;j++)ans+=dp[n+1][i][j];
  cout<<ans%10000<<endl;
  return 0;
}