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>
using namespace std;

int N, K, mem[100][3][3], decided[100];

int dp(int n, int b1, int b2)
{
  if(n == N)
    return 1;
  int ans = 0;
  if(decided[n] != 0)
  {
    if(b1 == b2 && decided[n] == b1)
      return 0;
    mem[n][b1][b2] = dp(n + 1, decided[n], b1);
    return mem[n][b1][b2];
  }
  for(int i = 1; i <= 3; i++)
  {
    if(b1 == b2 && b1 == i)
      continue;
    ans += dp(n + 1, i, b1);
  }
  return ans % 10000;
}

int main()
{
  cin >> N >> K;
  for(int i = 0; i < K; i++)
  {
    int a, b;
    cin >> a >> b;
    decided[a - 1] = b;
  }
  cout << dp(0, 0, 0) << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
int mod = 10000;
int n, k;
int p[111] = {0};
 
int dp[111][2][4];
 
int dfs(int i = 1, bool ff = false, int f = 0)
{
  int &ans = dp[i][ff][f];
 
  if (ans != -1) return ans;
  if (i == n + 1) {
    return 1;
  }
   
  if (p[i] != 0){
    if (ff && f == p[i]) return 0;
    ans = dfs(i + 1, f == p[i], p[i]);
    return ans %= mod;
  }
 
  ans = 0;
  for (int j = 1; j < 4; j++){
    if (ff && f == j) continue;
    ans += dfs(i + 1, f == j, j);
  }
 
  return ans %= mod;
}
 
main()
{
  memset(dp, -1, sizeof(dp));
 
  cin >> n >> k;
  for (int i = 0; i < k; i++){
    int a, b;
    cin >> a >> b;
    p[a] = b;
  }
 
  cout << dfs() << endl;
}

C++: #include<iostream>
#include<map>
using namespace std;
int main(){
  int n,m;
  map<int,int> day;
  cin >>n>>m;
  for(int i=0,a,b; i<m; i++){
    cin >>a>>b;
    day[a-1] = b;
  }
  int dp[101][3][3];
  for(int i=0; i<3; i++) dp[0][i][0] = 1;
  if(day[0]!=0)
    for(int i=0; i<3; i++)
      if(day[0]-1!=i) dp[0][i][0] = 0;
  for(int i=1; i<n; i++){
    if(day[i] == 0){
      for(int kinou=0; kinou<3; kinou++){
	for(int kyou=0; kyou<3; kyou++){
	  for(int len=0; len<2; len++){
	    if(kyou == kinou){
	      dp[i][kyou][len+1]+=dp[i-1][kinou][len];
	      dp[i][kyou][len+1]%=10000;
	    }
	    else{
	      dp[i][kyou][0]+=dp[i-1][kinou][len];
	      dp[i][kyou][0]%=10000;
	    }
	  }
	}
      }
    }
    else{
      for(int kinou=0; kinou<3; kinou++){
	for(int len=0; len<2; len++){
	  if(day[i]-1 == kinou){
	    dp[i][day[i]-1][len+1]+=dp[i-1][kinou][len];
	    dp[i][day[i]-1][len+1]%=10000;
	  }
	  else{
	    dp[i][day[i]-1][0]+=dp[i-1][kinou][len];
	    dp[i][day[i]-1][0]%=10000;
	  }
	}
      }
    }
  }
  int ans = 0;
  for(int i=0; i<3; i++){
    for(int j=0; j<2; j++){
      ans+=dp[n-1][i][j];
    }
  }
  cout <<ans%10000<<endl;
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <array>
#include <numeric>

int f(int, int, int);
int N;
int yotei[100];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int k, date;
    std::cin >> N >> k;
    for (int i = 0; i < k; i++) {
        std::cin >> date;
        std::cin >> yotei[date];
    }

    std::cout << f(0, 0, 0) << "\n";
    return 0;
}

int f(int day, int kinou, int ototui) {
    if (day == N) return 1;
    int ans = 0;

    for (int i = 1; i <= 3; i++) {
        if ((i == kinou && i == ototui) || (yotei[day] != 0 && i != yotei[day])) continue;

        ans += f(day + 1, i, kinou);
    }

    return ans % 10000;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

int n, k;
int a, b;

int daypasta[110];
int dp[10][110][10];

int main(){
	cin >> n >> k;
	REP(i, k){
		cin >> a >> b;
		daypasta[a] = b;
	}
	if (daypasta[1] == 0){
		dp[1][1][1] = 1;
		dp[2][1][1] = 1;
		dp[3][1][1] = 1;
	}
	else{
		dp[daypasta[1]][1][1] = 1;
	}
	FOR(i, 1, n){
		if (daypasta[i + 1] == 0){
			dp[1][i + 1][1] = dp[2][i][1] + dp[2][i][2] + dp[3][i][1] + dp[3][i][2];
			dp[1][i + 1][2] = dp[1][i][1];

			dp[2][i + 1][1] = dp[1][i][1] + dp[1][i][2] + dp[3][i][1] + dp[3][i][2];
			dp[2][i + 1][2] = dp[2][i][1];

			dp[3][i + 1][1] = dp[1][i][1] + dp[1][i][2] + dp[2][i][1] + dp[2][i][2];
			dp[3][i + 1][2] = dp[3][i][1];
		}
		else{
			if (daypasta[i + 1] == 1){
				dp[1][i + 1][1]
					= dp[2][i][1] + dp[2][i][2] + dp[3][i][1] + dp[3][i][2];
			}
			else if (daypasta[i + 1] == 2){
				dp[2][i + 1][1]
					= dp[1][i][1] + dp[1][i][2] + dp[3][i][1] + dp[3][i][2];
			}
			else{
				dp[3][i + 1][1]
					= dp[1][i][1] + dp[1][i][2] + dp[2][i][1] + dp[2][i][2];
			}
			dp[daypasta[i + 1]][i + 1][2] = dp[daypasta[i + 1]][i][1];
		}
		FOR(j, 1, 4){
			FOR(k, 1, 3){
				dp[j][i + 1][k] %= 10000;
			}
		}
	}
	int ans = 0;
	FOR(j, 1, 4){
		FOR(k, 1, 3){
			ans += dp[j][n][k];
			ans %= 10000;
		}
	}
	cout << ans << endl;
}