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++: template<typename T, T MOD>
struct ModInt {
  T number;
  ModInt(T n = 0) : number(n % MOD) {while(number < 0) number += MOD;}
  // ??£??\??????
  ModInt& operator+=(const ModInt& m) {return *this = *this + m;}
  ModInt& operator-=(const ModInt& m) {return *this = *this - m;}
  ModInt& operator*=(const ModInt& m) {return *this = *this * m;}
  ModInt& operator/=(const ModInt& m) {return *this = *this / m;}
  ModInt& operator%=(const ModInt& m) {return *this = *this % m;}
  // ????????????
  friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs) {return lhs.number + rhs.number;}
  friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs) {return lhs.number - rhs.number;}
  friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs) {return lhs.number * rhs.number;}
  friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs) {return lhs.number / rhs.number;}
  friend const ModInt operator%(const ModInt& lhs, const ModInt& rhs) {return lhs.number % rhs.number;}
  // ??¢?????????
  friend bool operator==(const ModInt& lhs, const ModInt& rhs) {return lhs.number == rhs.number;}
  friend bool operator!=(const ModInt& lhs, const ModInt& rhs) {return lhs.number != rhs.number;}
  friend bool operator<=(const ModInt& lhs, const ModInt& rhs) {return lhs.number <= rhs.number;}
  friend bool operator>=(const ModInt& lhs, const ModInt& rhs) {return lhs.number >= rhs.number;}
  friend bool operator<(const ModInt& lhs, const ModInt& rhs) {return lhs.number < rhs.number;}
  friend bool operator>(const ModInt& lhs, const ModInt& rhs) {return lhs.number > rhs.number;}
};
// ??\?????????????????????
#include<iostream>
template<typename T, T MOD> inline std::istream& operator>>(std::istream& is, ModInt<T, MOD>& m) {return is >> m.number;}
template<typename T, T MOD> inline std::ostream& operator<<(std::ostream& os, const ModInt<T, MOD>& m) {return os << m.number;}

#include<bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> plan(N + 1 + 1);
  for(int i = 1; i <= K; ++i) {
    int A, B;
    cin >> A >> B;
    plan[A] = B;
  }

  ModInt<int, 10000> dp[102][4][2];
  if(plan[1]) dp[1][plan[1]][0] = 1;
  else        dp[1][1][0] = dp[1][2][0] = dp[1][3][0] = 1;

  for(int i = 1; i < N; ++i) for(auto j: {1, 2, 3}) for(auto k: {0, 1}) if(dp[i][j][k] != 0) {
    if(plan[i + 1]) {
      if(plan[i + 1] == j) dp[i + 1][plan[i + 1]][k + 1] += dp[i][j][k];
      else                 dp[i + 1][plan[i + 1]][0] += dp[i][j][k];
    } else {
      auto nnj = plan[i + 2];
      for(auto nj: {1, 2, 3}) {
        if(j == nj && nj == nnj) continue;
        if(j == nj && k == 1) continue;
        if(j == nj) dp[i + 1][nj][1] += dp[i][j][k];
        else        dp[i + 1][nj][0] += dp[i][j][k];
      }
    }
  }

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

C++: #include<iostream>

using namespace std;

int n,m;
const int mod=10000;
int yotei[101];
int dp[101][3][3]={};	

int pasta(int day,int tdby,int y){//日日　おととい　昨日
	if(dp[day][tdby][y]!=0)return dp[day][tdby][y];
	if(day==n+1)return 1;
	if(yotei[day]!=-1){
		if(tdby==y&&y==yotei[day]){
			return 0;
		}else {
			return dp[day][tdby][y]=pasta(day+1,y,yotei[day])%mod;
		}
	}else {
		int ans=0;
		for(int k=1;k<=3;k++){
			if(tdby!=k||y!=k){
				ans+=pasta(day+1,y,k)%mod;
			}
		}
		return dp[day][tdby][y]=ans%mod;
	}
}
//dayは１から　便宜上
int main(){
	for(int i=0;i<101;i++)yotei[i]=-1;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int a;
		cin>>a;
		cin>>yotei[a];
	}
	cout<<pasta(1,0,0)<<endl;
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
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 <vector>
#include <algorithm>
#include <map>
#include <climits>
using namespace std;
typedef long long int ll;

ll mod=10000;

ll dp[111][5][5];
int a[111];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k; cin >> n >> k;
	for(int i=0;i<k;i++){
		int x,y; cin >> x >> y;
		a[x]=y;
	}
	dp[0][3][3]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<4;j++){
			for(int p=0;p<4;p++){
				if(dp[i][j][p]==0)continue;
				if(a[i+1]!=0){
					if(a[i+1]==j+1&&a[i+1]==p+1)continue;
					if(1){
						(dp[i+1][a[i+1]-1][j]+=dp[i][j][p])%=mod;
					}
				}
				else{
					if(j==p){
						for(int h=0;h<3;h++){
							if(p==h)continue;
							(dp[i+1][h][j]+=dp[i][j][p])%=mod;
						}
					}
					else{
						for(int h=0;h<3;h++){
							(dp[i+1][h][j]+=dp[i][j][p])%=mod;
						}
					}
				}
			}
		}
	}
	ll ans=0;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			//cout << i << " " << j << " " << dp[n-1][i][j] << endl;
			ans+=dp[n][i][j];
		}
	}
	cout << ans%mod << endl;
}