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 <bits/stdc++.h>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

ll dp[101][4][3];
ll info[101];
const int MOD = 10000;

int main()
{
    int N, K;
    cin >> N >> K;

    rep(i, K)
    {
        ll day, kind;
        cin >> day >> kind;
        info[day] = kind;
    }

    if (info[1])
        dp[1][info[1]][1] = 1;
    else
    {
        rep(i, 3) dp[1][i + 1][1] = 1;
    }

    repd(i, 2, N + 1)
    {
        if (info[i])
        {
            repd(j, 1, 4)
            {
                if (info[i] == j)
                    dp[i][info[i]][2] += dp[i - 1][j][1] % MOD;
                else
                {
                    repd(k, 1, 3)
                    {
                        dp[i][info[i]][1] += dp[i - 1][j][k] % MOD;
                    }
                }
            }
        }
        else
        {
            repd(j, 1, 4)
            {
                repd(k, 1, 4)
                {
                    if (j == k)
                    {
                        dp[i][j][2] += dp[i - 1][k][1] % MOD;
                    }
                    else
                    {
                        repd(l, 1, 3)
                        {
                            dp[i][j][1] += dp[i - 1][k][l] % MOD;
                        }
                    }
                }
            }
        }
    }

    ll ans = 0;
    repd(i, 1, 4)
    {
        ans += dp[N][i][1] + dp[N][i][2];
    }

    cout << ans % MOD << endl;

    return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


int main() {
	int N, K; cin >> N >> K;
	vector<int>dis(N);
	for (int i = 0; i < K; ++i) {
		int a, b; cin >> a >> b; a--;
		dis[a] = b;

	}
	int dp[200][4][4];
	memset(dp, 0, sizeof(dp));
	dp[0][0][0] = 1;
	for (int day = 0; day <N; ++day) {
		for (int prepre = 0; prepre <= 3; ++prepre) {
			for (int pre = 0; pre <= 3; ++pre) {
				for (int now = 1; now <= 3; now++)
				{
					if (dis[day] && dis[day] != now)continue;
					else {
						if (prepre == pre&&pre == now)continue;
						dp[day + 1][pre][now] += dp[day][prepre][pre];
						dp[day + 1][pre][now] %= 10000;
					}
			
	long long int ans = 0;
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			ans += dp[N][i][j];
		}
	}
	cout << ans%10000 << endl;
	return 0;
}

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

int dp[110][4][4];
int N,M;

int pas[110];

int main(){
		 
	
  cin >> N >> M;
  memset(pas,0,sizeof(pas));	 
  memset(dp,0,sizeof(dp));

  for(int i = 0; i < M; i++){
    int x,y;
    cin >> x >> y;
    pas[x] = y;
  }

  if(pas[1] == 0){
    for(int j = 0; j <= 3; j++){
      dp[1][j][1] = 1;
    }
  }
  else{
    dp[1][pas[1]][1] = 1;
  }


  for(int i = 2; i <= N; i++){
 
    if(pas[i] == 0){ //テ」ツ?敕」ツ?ョテヲツ猟・テ」ツ?古ヲツアツコテ」ツ?セテ」ツ?」テ」ツ?ヲテ」ツ?ェテ」ツ??」ツ?ェテ」ツつ?
      for(int j = 1; j <= 3; j++){
	// k = 2
	if(pas[i+1] == j) //テヲツャツ。テ」ツ?ョテヲツ猟・テ」ツ?古ヲツアツコテ」ツ?セテ」ツ?」テ」ツ?ヲテ」ツ?ヲテ」ツつ「テ」ツつヲテ」ツδ?
	  dp[i][j][2] = 0;
	else{
	  dp[i][j][2] += dp[i-1][j][1];
	  dp[i][j][2] %= 10000;
	}
	// k = 1
	for(int t = 1; t <= 3; t++){
	  if(j != t){
	    dp[i][j][1] += dp[i-1][t][1] + dp[i-1][t][2];
	    dp[i][j][1] %= 10000;
	  }
	}
 
	if( j == pas[i+1] && j == pas[i+2]) dp[i][j][1] = 0;	
      }
    }
    
    if(pas[i] != 0){ //テヲツアツコテ」ツ?セテ」ツ?」テ」ツ?ヲテ」ツつ?
      for(int j = 1; j <= 3; j++){
	if(pas[i] != j){
	  dp[i][pas[i]][1] += dp[i-1][j][1] + dp[i-1][j][2];
	  dp[i][pas[i]][1] %= 10000;
	}
      }

      dp[i][pas[i]][2] += dp[i-1][pas[i]][1];
      dp[i][pas[i]][2] %= 10000;	   
	
    }
    for(int j = 1; j <=3 ;j++){
      for(int k = 1; k <= 2; k++){
	//	cout << dp[i][j][k] << " ";
      }
      //      cout << endl;
    }
    //    cout << endl;
  }



  int ans=0;
  for(int j =1; j <= 3;j++){
    for(int k = 1; k <=2 ;k++){
      ans += dp[N][j][k];
      ans %= 10000;
    }
  }
  cout << ans << endl;

  
  return 0;
}

C++: #include <iostream>
using namespace std;
int N, K, a, b, x[109], dp[109][3][2];
int main() {
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		cin >> a >> b; a--;
		x[a] = b;
	}
	if (x[0] == 0) {
		dp[0][0][0] = 1;
		dp[0][1][0] = 1;
		dp[0][2][0] = 1;
	}
	else dp[0][x[0] - 1][0] = 1;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			if (x[i] != 0 && x[i] != j + 1) continue;
			for (int k = 0; k < 3; k++) {
				for (int l = 0; l < 2; l++) {
					if (j == k && l == 1) continue;
					if (j == k) dp[i][j][1] += dp[i - 1][k][l];
					else dp[i][j][0] += dp[i - 1][k][l];
				}
			}
			dp[i][j][0] %= 100000;
			dp[i][j][1] %= 100000;
		}
	}
	int ret = 0;
	for (int i = 0; i < 3; i++) ret += dp[N - 1][i][0] + dp[N - 1][i][1];
	cout << ret % 100000 << endl;
	return 0;
}