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>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int n,k;
    int dp[100][3][3];
    int a[101];
    memset(dp,0,sizeof(dp));
    memset(a,-1,sizeof(a));
    cin >> n >> k;
    REP(i,k){
	int d,dd;
	cin >> d >> dd;
	a[d-1] = dd-1;
    }
    if(a[0] == -1){
	REP(i,3) dp[0][i][0] = 1;
    }else{
	dp[0][a[0]][0] = 1;
    }
    if(a[1] == -1){
	REP(i,3)REP(j,3)
		dp[1][i][j] += dp[0][j][0];
    }else{
	REP(i,3)
	    dp[1][a[1]][i] += dp[0][i][0];
    }
    FOR(i,1,n-1){
	if(a[i+1] == -1){
	    REP(j,3){
		REP(k,3)REP(l,3){
		    if( !(j == k && j == l) ){
			dp[i+1][j][l] = (dp[i+1][j][l] + dp[i][l][k]) % 10000;
		    }
		}
	    }
	}else{
	    REP(j,3)REP(k,3){
		if( !(j == a[i+1] && a[i+1] == k) ){
		    dp[i+1][a[i+1]][j] = (dp[i+1][a[i+1]][j] + dp[i][j][k]) % 10000;
		}
	    }
	}
    }
    int ans = 0;
    REP(i,3)REP(j,3){
	ans += dp[n-1][i][j]; 
    }
    ans %= 10000;
    cout << ans << endl;
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()


const int MAXN = 100, MAXS = 6;
const int T = 1, C = 2, B = 3, TT = 4, CC = 5, BB = 6;
const int DS = 3;
const int res[4][4] = {{0,0,0,0}, {C,B,CC,BB},{B,T,BB,TT},{T,C,TT,CC}};
const int MOD = 10000;

int main()
{
    int n, k; cin >> n >> k;
    long long dp[MAXS + 10][MAXN + 10] = {};
    int s[MAXN + 1] = {};
    int a, b;
    REP(k) {cin >> a; a--; cin >> s[a];}

    if(s[0] > 0) dp[s[0]][0] = 1;
    else dp[T][0] = dp[C][0] = dp[B][0] = 1;

    for(int i = 1; i< n; i++)
        if(s[i] > 0)
        {
            rep(j, 4){(dp[s[i]][i] += dp[res[s[i]][j] ][i - 1]) %= MOD;}
            dp[s[i] + DS][i] = dp[s[i]][i - 1];
        }
        else
        {
            for(int t = 1; t <= 3;t++)
                rep(j, 4) (dp[t][i] += dp[res[t][j] ][i - 1]) %= MOD;
            for(int t = 4; t <= 6; t++)
                dp[t][i] = dp[t - DS][i - 1];
        }
    long long ans  = 0;
    REP(6) (ans += dp[i + 1][n - 1]) %= MOD;
    cout << ans << endl;
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[101] = { 0 };
	int n;
	int i;
	cin >> n >> i;
	for (int v = 0; v < i; v++){
		int y, x;
		cin >> y >> x;
		a[y] = { x };

	}
	int f;
	if (a[1] = a[2] != a[3]){
		if (a[1] != 0){
			f = 2;
		}
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[1] = a[3] != a[2]){
		if (a[1] != 0)
			f = 2;
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[3] = a[2] != a[1]){
		if (a[2] != 0)
			f = 2;
		if (a[2] = 0){
			f = 8;
		}
	}
	if (a[1] = a[2] = a[3]){
		if (a[1] = 0){
			f = 24;
		}
		if (a[1] != 0){
			f = 1;
		}

	}

	for (int v = 4; v <= n; v++){
		if (a[v] = 0){
			if (a[v - 2] = a[v - 1] != 0){
				f = f * 2;
			}
			if (a[v - 2] != a[v - 1] != 0){
				f = f * 3;
			}
			if (a[v - 2] = 0 != a[v - 1]){
				f = f * 3;
			}
			if (a[v - 1] = 0 != a[v - 2]){
				f = f * 3;
			}
		
		}
	}
	        cout << f << endl;
        	return 0;
}

C++: #include<iostream>

const int MAX_N = 100;
//memo[i][j][k]: i日目jをk+1日続けた総数
int memo[MAX_N+1][3][2], plan[MAX_N+1];

void pass(int day, int source){
	if(source != -1){
		memo[day][source][1] = memo[day-1][source][0];

		for(int j=0;j<3;j++){
			if(j != source){
				memo[day][source][0] += memo[day-1][j][0];
				memo[day][source][0] += memo[day-1][j][1];
				memo[day][source][0] %= 10000;
			}
		}
	}
}

int main(){
	int n, k;

	std::cin >> n >> k;

	std::fill(plan, plan+MAX_N+1, -1);

	for(int i=0;i<=MAX_N;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<2;k++){
				memo[i][j][k] = 0;
			}
		}
	}

	// a, b; a日目はbですよー
	for(int i=0;i<k;i++){
		int a, b;
		std::cin >> a >> b;
		plan[a] = b-1;
	}
	
	if(plan[1] != -1){
		memo[1][plan[1]][0] = 1;
	}else{
		memo[1][0][0] = 1;
		memo[1][1][0] = 1;
		memo[1][2][0] = 1;
	}

	for(int day=2;day<=n;day++){
		if(plan[day] != -1){//決まっている
			pass(day, plan[day]);
		}else{//決まっていない
			for(int source=0;source<3;source++){
				pass(day, source);
			}
		}
	}

	int res = 0;
	for(int i=0;i<3;i++){
		for(int j=0;j<2;j++){
			res += memo[n][i][j];
			res %= 10000;
		}
	}

	std::cout << res << std::endl;
}