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>

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;

  map<int, int> mp;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    mp[a] = b;
  }

  int dp[110][10] = {};
  for (int i = 1; i <= 3; i++) {
    if (mp[1] > 0 && i != mp[1]) continue;
    dp[1][i] = 1;
  }
  for (int i = 1; i <= 3; i++) {
    if (mp[2] > 0 && i != mp[2]) continue;
    for (int j = 1; j <= 3; j++) {
      dp[2][i] += dp[1][j];
    }
  }

  const int mod = 10000;
  for (int i = 3; i <= n; i++) {
    for (int j = 1; j <= 3; j++) {
      if (mp[i] > 0 && j != mp[i]) continue;
      for (int k = 1; k <= 3; k++) {
        if (k == j) continue;
        dp[i][j] += dp[i - 1][k];
        dp[i][j] %= mod;
        if (!dp[i - 1][j]) continue;
        dp[i][j] += dp[i - 2][k];
        dp[i][j] %= mod;
      }
    }
  }

  int ans = 0;
  for (int i = 1; i <= 3; i++) {
    ans += dp[n][i];
    ans %= mod;
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
	int N,K,A,B[101];
	int dp[101][7]={},ans=0;
	memset(B,-1,sizeof(B));
	cin>>N>>K;
	for(int i=0;i<K;i++){
		cin>>A;
		cin>>B[A];
	}

	dp[0][0]=1;
	for(int i=0;i<N;i++){
		for(int j=0;j<=6;j++){
			//printf("%d ",dp[i][j]);
			if(B[i]!=-1 && (j!=B[i] && j!=B[i]+3)) continue;
			else{
				for(int k=1;k<=3;k++){
					if(j-3==k) continue;
					else if(j==k) dp[i+1][j+3] += dp[i][j];
					else dp[i+1][k] += dp[i][j];
				}
			}
		}//puts("");
	}
	for(int i=0;i<=6;i++){
		//printf("%d ",dp[N][i]);
		ans += dp[N][i];
	}//puts("");
	printf("%d\n",ans);
	return 0;
}

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

#define MOD 10000

int n, m;
int dp[102][3][3];
int t[102];

void init(){
  memset(dp, 0, sizeof(dp));

  if(t[0] != -1){
    if(t[1] != -1){
      dp[2][t[1]][t[0]]++;
    }
    else{
      for(int i = 0; i < 3; i++){
        dp[2][i][t[0]]++;
      }
    }
  }
  else{
    if(t[1] != -1){
      for(int i = 0; i < 3; i++){
        dp[2][t[1]][i]++;
      }
    }
    else{
      for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
          dp[2][i][j]++;
        }
      }
    }
  }
}

int main(){
  while(cin >> n >> m){
    memset(t, -1, sizeof(t));

    for(int i = 0; i < m; i++){
      int a, b;
      cin >> a >> b;
      a--; b--;
      t[a] = b;
    }

    init();

    for(int i = 2; i < n; i++){
      for(int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
          if(t[i] != -1){
            if(j != k || t[i] != j){
              dp[i + 1][t[i]][j] += dp[i][j][k];
              dp[i + 1][t[i]][j] %= MOD;
            }
          }
          else{
            for(int l = 0; l < 3; l++){
              if(j != k || l != j){
                dp[i + 1][l][j] += dp[i][j][k];
                dp[i + 1][l][j] %= MOD;
              }
            }
          }
        }
      }
    }

    int ans = 0;

    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        ans += dp[n][j][k];
        ans %= MOD;
      }
    }

    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>

#include <vector>
#include <cmath>

using namespace std;

#define int long long

int dp[101][3][2]={};

inline int che(int ret)
{
    return ret >= 0 ? ret : 0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int ans = 0;
    int day=0,dec=0;
    cin >> day>>dec;
    
    int ind,ink;
    
    for(int i=0;i<3;++i)
        dp[0][i][0] = 1;
    
    for(int i=0;i<dec;++i)
    {
        cin >> ind >> ink;
        ink--;
        ind--;
        for(int k=0;k<3;++k)
        {
            if(k!=ink)
            {
                dp[ind][k][0] = dp[ind][k][1] = -1;
            }
        }
    }
    //dp
    for(int i=0;i<day;++i)
    {
        for(int k = 0;k<3;++k)
        {
//            cout << i <<":" <<k << " "<<dp[i][k][0] << " " << dp[i][k][1] <<endl;
            if(dp[i][k][0]!=-1)
            {
                if(dp[i+1][(k+1)%3][0] >= 0) dp[i+1][(k+1)%3][0] += dp[i][k][0];
                if(dp[i+1][(k+2)%3][0] >= 0) dp[i+1][(k+2)%3][0] += dp[i][k][0];
                
                if(dp[i+1][k][1] >= 0) dp[i+1][k][1] += dp[i][k][0];
                
                if(dp[i+1][(k+1)%3][0] >= 0) dp[i+1][(k+1)%3][0] += dp[i][k][1];
                if(dp[i+1][(k+2)%3][0] >= 0) dp[i+1][(k+2)%3][0] += dp[i][k][1];
            }
        }
    }
    for(int i = 0;i< 3;++i)
    {
        for(int k = 0;k < 2;++k)
        {
            ans = (ans+che(dp[day-1][i][k]))%10000;
        }
    }
    cout << ans << endl;
    return 0;
}