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>
#define MOD 10000
using namespace std;

int main(){
	int n,k,p[100],dp[100][4][4] = {};
	cin >> n >> k;
	for(int i = 0;i < n;i++) p[i] = -1;
	for(int i = 0;i < k;i++){
		int a,b;
		cin >> a >> b;
		p[a - 1] = b;
	}
	for(int i = 0;i < n;i++){
		if(i == 0){
			if(p[0] != -1) dp[i][p[0]][0] = 1;
			else{
				dp[i][1][0] = 1;
				dp[i][2][0] = 1;
				dp[i][3][0] = 1;
			}
		}
		else if(i == 1){
			if(p[1] != -1){
				for(int j = 1;j <= 3;j++){
					dp[i][p[1]][j] += dp[i - 1][j][0];
				}
			}else{
				for(int j = 1;j <= 3;j++){
					for(int k = 1;k <= 3;k++) dp[i][j][k] += dp[i - 1][k][0];
				}
			}
		}
		else{
			if(p[i] != -1){
				for(int j = 1;j <= 3;j++){
					for(int k = 1;k <= 3;k++){
						if(p[i] == j && j == k) continue;
						dp[i][p[i]][j] = (dp[i][p[i]][j] + dp[i - 1][j][k]) % MOD;
					}
				}
			}else{
				for(int j = 1;j <= 3;j++){
					for(int k = 1;k <= 3;k++){
						for(int l = 1;l <= 3;l++){
							if(j == k && k == l) continue;
							dp[i][j][k] = (dp[i][j][k] + dp[i - 1][k][l]) % MOD;
						}
					}
				}
			}
		}
	}
	int res = 0;
	for(int i = 1;i <= 3;i++){
		for(int j = 1;j <= 3;j++){
			res = (res + dp[n - 1][i][j]) % MOD;
		}
	}
	cout << res << endl;
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

int a[110],b[110];
int dp[3][3][110];

int main() {
	int n,k;
	cin>>n>>k;
	rep(i,k){
		cin>>a[i]>>b[i];
		--a[i];
		--b[i];
	}
	memset(dp,0,sizeof(dp));
	rep(i,n)rep(p,3)rep(j,3){
		int t;
		rep0(t,k)if(a[t]==i&&b[t]!=j)break;
		if(t<k)continue;
		if(i==0)dp[0][j][i]=1;
		else if(i==1){
			rep(s,3){
				dp[p][j][i]+=dp[s][p][i-1];
				dp[p][j][i]%=10000;
			}
		}else{
			rep(s,3)if(p!=j||s!=p){
				dp[p][j][i]+=dp[s][p][i-1];
				dp[p][j][i]%=10000;
			}
		}
	}
//rep(i,n)rep(j,3)rep(t,3)cout<<i<<" "<<j<<" "<<t<<" "<<dp[j][t][i]<<endl;
	int res=0;
	rep(i,3)rep(j,3)res+=dp[i][j][n-1];
	cout<<res%10000<<endl;
	return 0;
}

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

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);
    }
  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%10000<<endl;


}

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) % 10000 << "\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;
}