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

int main(){
	int n,m,d[1000],t[1000],type[4][100],c[4][100];
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>d[i]>>t[i];
	}
	for(int i=0;i<m;i++){
		if(d[i]==1){
			type[i][1]=1;
			goto Exit1;
		}
	}
	type[1][1]=1;
	type[2][1]=1;
	type[3][1]=1;
	
Exit1:
	for(int i=1;i<=3;i++){
		if(type[i][1]!=1){
			type[i][1]=0;
		}
	}
	type[1][2]=0;
	type[2][2]=0;
	type[3][2]=0;
	for(int i=2;i<=n;i++){
		for(int j=0;j<m;j++){

			if(d[j]==i){
				type[t[j]][2]=type[t[j]][1];
				type[t[j]][1]=0;
				for(int k=1;k<=3;k++){
					if(t[j]!=k){
						for(int l=1;l<=2;l++){
						type[t[j]][1] += type[k][l];
						type[k][l]=0;
						}
					}
				}
				goto Exit2;
			}

		}
		memset(c,0,sizeof(c));
		for(int k=1;k<=3;k++){
			for(int l=1;l<=3;l++){
				if(k==l){
					c[l][2] += type[k][1];
				}
				else{
					c[l][1] += type[k][1]+type[k][2];
				}
			}
		}
		for(int k=1;k<=3;k++){
			type[k][1]=c[k][1];
			type[k][2]=c[k][2];
		}
Exit2:
		for(int j=1;j<=3;j++){
			for(int k=1;k<=2;k++){
				type[j][k]=type[j][k]%100000000;
			}
		}
	}
	cout<<(type[1][1]+type[1][2]+type[2][1]+type[2][2]+type[3][1]+type[3][2])%10000<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n, k;

int sche[100];

int dp[100][4][4];

int rec(int day, int a, int b) // a = i - 2 ??\???, b = i - 1 ??\???
{
	if (day == n) return 1;

	if (dp[day][a][b] >= 0) return dp[day][a][b];
	
	int res = 0;
	
	if (sche[day]) {
		if (sche[day] != a || sche[day] != b) {
			res += rec(day + 1, b, sche[day]);
			res %= 10000;
		}
	} else {
		for (int i = 1; i <= 3; ++i) {
			if (a == b && b == i) continue;
			res += rec(day + 1, b, i);
			res %= 10000;
		}
	}

	return dp[day][a][b] = res;
}

int main()
{
	cin >> n >> k;

	for (int i = 0; i < k; ++i) {
		int day; cin >> day; --day;
		cin >> sche[day];
	}

	memset(dp, -1, sizeof(dp));

	printf("%d\n", rec(0, 0, 0));
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 10000;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, k;
bool fix[105];
int pasta[105];
int dp[105][3][3];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    rep(i, k) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        fix[a] = true;
        pasta[a] = b;
    }
    rep(i, n)rep(j, 3) {
        if (fix[i]) {
            if (i == 0) {dp[i + 1][pasta[i]][1] = 1; break;}
            if (pasta[i] == j) (dp[i + 1][pasta[i]][2] += dp[i][j][1]) %= mod;
            else (dp[i + 1][pasta[i]][1] += dp[i][j][1] + dp[i][j][2]) %= mod;
        }
        else {
            if (i == 0)  {
                dp[i + 1][j][1] = 1;
            }
            else {
                (dp[i + 1][j][2] += dp[i][j][1]) %= mod;
                (dp[i + 1][(j + 1) % 3][1] += dp[i][j][1] + dp[i][j][2]) %= mod;
                (dp[i + 1][(j + 2) % 3][1] += dp[i][j][1] + dp[i][j][2]) %= mod;
            }
        }
    }
    int ans = 0;
    rep(j, 3) (ans += dp[n][j][1] + dp[n][j][2]) %= mod;
    cout << ans % mod << endl;
}