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<map>
#include<cstring>
using namespace std;
#define NUM 10000
int hashs[102];
int N,K;
long long int dp[5][5][102];


long long int check(int i,int j,int k)
{
  //  cerr<<"#"<<i<<" "<<j<<" "<<k<<endl;

  long long int sum=0;
  if(k==N)
    return 1;
  if(dp[i][j][k]!=-1)
    return dp[i][j][k];

  for(int x=1;x<4;x++)
    {
      if(!(i==x && j==x) && (hashs[k+1]==-1 || hashs[k+1]==x))
        sum+=check(j,x,k+1)%NUM;
    }
  dp[i][j][k]=sum;
  return sum;

}



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

  cin>>N>>K;
  for(int i=0;i<K;i++)
    {
      int a,b;
      cin>>a>>b;

      hashs[a]=b;
    }
  long long int ans=check(0,0,0);
  cout<<ans%NUM<<endl;


}

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

int main() {
	int n, k, l, m;
	cin >> n >> k;
	int krsw[101][3] = {};
	int a[100] = {} ;
	for(int i = 0; i < k; i++) {
		cin >> l >> m;
		a[l] = m;
	}
	if(a[1]) krsw[1][a[1]] = 1;
	else { krsw[1][1] = 1; krsw[1][2] = 1; krsw[1][3] = 1; }
	for(int hi = 2; hi <= n; hi++) {
		if(a[hi]) {
			krsw[hi][a[hi]] = krsw[hi - 1][1] + krsw[hi - 1][2] + krsw[hi - 1][3];
			if(krsw[hi - 1][a[hi]] > 0 && krsw[hi - 2][a[hi]] > 0) {
				krsw[hi][a[hi]] -= krsw[hi - 2][a[hi]];
				krsw[hi - 1][a[hi]] -= krsw[hi - 2][a[hi]];	
			if(a[hi - 2]) {
				krsw[hi][a[hi - 2]] = 0;
				krsw[hi - 1][a[hi - 2]] = 0;
			}
			if(krsw[hi][a[hi]]>10000)krsw[hi][a[hi]] %= 10000;
		}
		else
			for(int i = 1; i <= 3; i++) {
				krsw[hi][i] = krsw[hi - 1][1] + krsw[hi - 1][2] + krsw[hi - 1][3];
				if(krsw[hi - 1][i] > 0 && krsw[hi - 2][i] > 0) {
					krsw[hi][i] -= krsw[hi - 2][i];
					krsw[hi - 1][i] -= krsw[hi - 2][i];
				}
				if(a[hi - 2]) {
					krsw[hi][a[hi - 2]] = 0;
					krsw[hi - 1][a[hi - 2]] = 0;
				}
			}
				if(krsw[hi][i]>10000)krsw[hi][i] %= 10000;
			}
	}
	cout << (krsw[n][1] + krsw[n][2] + krsw[n][3]) % 10000 << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int i,j,k,n,m,d[999],t[999],T[4][9],c[4][9],S;
main(){
cin>>n>>m;
for(i=0;i<m;i++){cin>>d[i]>>t[i];}
for(i=0;i<m;i++){if(d[i]==1){T[d[i]][1]=1;break;}}
T[1][1]=1;T[2][1]=1;T[3][1]=1;
for(i=1;i<=3;i++){if(T[i][1]!=1){T[i][1]=0;}}
T[1][2]=0;T[2][2]=0;T[3][2]=0;
for(i=2;i<=n;i++){for(j=0;j<m;j++){
if(d[j]==i){T[t[j]][2]=T[t[j]][1];T[t[j]][1]=0;
for(k=1;k<=3;k++){if(t[j]!=k){for(int l=1;l<=2;l++){T[t[j]][1]+=T[k][l];T[k][l]=0;}}}goto Z;}}
for(int k=1;k<=3;k++){for(int l=1;l<=3;l++){
if(k==l){c[l][2] += T[k][1];}
else{c[l][1] += T[k][1]+T[k][2];}
}}
for(int k=1;k<=3;k++){T[k][1]=c[k][1];T[k][2]=c[k][2];}
Z:
for(int j=1;j<=3;j++){for(int k=1;k<=2;k++){S+=T[j][k];}}
}
cout<<S%10000<<endl;}

C++: #include<iostream>
using namespace std;
int main(){
	int N,K,a,b;
	cin>>N>>K;
	int dp[110][4]={};
	for(int i=0;i<K;i++){
		cin>>a>>b;
		dp[a][b]=1;
	}
	if(dp[1][1]==0 && dp[1][2]==0 && dp[1][3]==0){
		for(int i=1;i<=3;i++){
			dp[1][i]=1;
		}
	}

	for(int i=1;i<=N;i++){
		if(dp[i+1][1]==0 && dp[i+1][2]==0 && dp[i+1][3]==0){
			for(int j=1;j<=3;j++){
				if(dp[i+2][j]>0 && dp[i+3][j]>0){
					dp[i+1][j]=0;


				}

				else	if(dp[i][j]>0 && dp[i+2][j]>0){
					if(j==1){
						dp[i+1][j]=(dp[i][2]+dp[i][3])%10000;
					}
					else if(j==2){
						dp[i+1][j]=(dp[i][1]+dp[i][3])%10000;
					}
					else{
						dp[i+1][j]=(dp[i][1]+dp[i][2])%10000;
					}


				}
				else if(dp[i+2][j]>0 && dp[i+3][j]>0){
					dp[i+1][j]=0;


				}
				else if(dp[i-1][j]>0  && dp[i][j]>0){
					if(j==1){

						dp[i+1][j]=((+dp[i][2]+dp[i][3])%10000+(+dp[i-1][2]+dp[i-1][3])%10000)%10000;
					}
					else if(j==2){
						dp[i+1][j]=((+dp[i][1]+dp[i][3])%10000+(+dp[i-1][1]+dp[i-1][3])%10000)%10000;
					}
					else{
						dp[i+1][j]=((+dp[i][2]+dp[i][1])%10000+(+dp[i-1][2]+dp[i-1][1])%10000)%10000;
					}


				}

				else{
					dp[i+1][j]=((dp[i][1]+dp[i][2])%10000+dp[i][3])%10000;
				}
			}
		}
		else{
			for(int j=1;j<=3;j++){
				if(dp[i+1][j]==1){
					dp[i+1][j]=((dp[i][1]+dp[i][2])%10000+dp[i][3])%10000;
				}
			}
		}
	}
	for(int i=1;i<=N;i++){
		for(int j=0;j<4;j++){
			cout<<dp[i][j];

		}
		cout<<endl;
	}
	
	cout<<(dp[N][1]+dp[N][2]+dp[N][3])%10000<<endl;
	return 0;
	

	}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int MAX_N = 110;
int n, k;
int plan[MAX_N];
int memo[3][3][MAX_N];
int dfs(int a, int b, int depth)
{
    if(memo[a][b][depth]) return memo[a][b][depth];
    if(depth > n) return 1;
    int res = 0;
    if(plan[depth])
    {
        if(not(a == b && b == plan[depth])) res += dfs(b, plan[depth], depth + 1);
    }
    else
    {
        for(int c = 1; c <= 3; c++)
        {
            if(a == b && b == c) continue;
            res += dfs(b, c, depth + 1);
        }
    }
    return memo[a][b][depth] = res % 10000;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    memset(memo, 0, sizeof(memo));
    for(int i = 0; i < k; i++)
    {
        int a, b; cin >> a >> b;
        plan[a] = b;
    }
    cout << dfs(0, 0, 1) % 10000 << endl;
    return 0;
}