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 <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <cstring>
#include <queue>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e4;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

vector<int> meal;
int dp[110][4][2];
int N, K;

int dfs(int i, int j, bool k)
{
    if (dp[i][j][k] != -1)
        return dp[i][j][k];

    if (i == N + 1)
        return 1;

    int res = 0;

    if (meal[i] != 0)
    {
        if (j && k == meal[i])
            return 0;

        res = dfs(i + 1, meal[i], meal[i] == j);

        return dp[i][j][k] = res % MOD;
    }

    FOR(n, 1, 4)
    {
        if (k && j == n)
            return 0;

        res += dfs(i + 1, n, n == j);
    }

    return dp[i][j][k] = res % MOD;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> K;

    meal.resize(N + 1, 0);

    REP(i, K)
    {
        int a, b;
        cin >> a >> b;
        meal[a] = b;
    }

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

    Cout(dfs(1, 0, 0));

    return 0;
}

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[1][i]=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]%10000;
			}
		}
	}
	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 <iostream>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

#define int long long
#define LL long long
#define ULL unsigned long long

const LL LL_INF = ~(ULL)0 >> 1;

int day[105] = {0}, n, k, mem[101][4][4][4];

int f(int d, int src, int presrc, int num) {
    if (d == n) {
        return (num + 1) % 10000;
    }

    if (day[d + 1] != 0) {
        return f(d + 1, day[d + 1], src, num);
    }

    int result = num;
    for (int i = 1; i <= 3; ++i) {
        if (((presrc == src) && (presrc == i)) ||
                ((day[d + 2] != 0) && (src == i) && (i == day[d + 2]))) continue;

        //int temp = (mem[d + 1][i][src][presrc] == LL_INF) ? f(d + 1, i, src, 0) : mem[d + 1][i][src][presrc];
        int temp = f(d + 1, i, src, 0);
        mem[d + 1][i][src][presrc] = temp;
        result = (result + temp) % 10000;
    }

    return result;
}

signed main() {
    for (int i = 0; i < 101; ++i) {
        for (int j = 0; j < 4; ++j) {
            for (int k = 0; k < 4; ++k) {
                fill(mem[i][j][k], mem[i][j][k] + 4, LL_INF);
            }
        }
    }
    cin >> n >> k;

    for (int i = 0; i < k; ++i) {
        int a, b;
        cin >> a >> b;
        day[a] = b;
    }

    int result = 0;

    if (day[1] == 0) {
        for (int i = 1; i <= 3; ++i) {
            result = (result + f(1, i, 0, 0)) % 10000;
        }
    } else {
        result = (result + f(1, day[1], 0, 0)) % 10000;
    }

    cout << result << endl;

    return 0;
}

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

int n,k,m[101];
int dp[4][4][4][101];

int rec(int a,int b,int c,int idx){
  if(m[idx] != -1 && m[idx] != c) return 0;
  if(a == b && b == c) return 0;
  if(idx == n) return 1;
  if(dp[a][b][c][idx] != 0) return dp[a][b][c][idx];
  return dp[a][b][c][idx] = (rec(b,c,1,idx+1) + rec(b,c,2,idx+1) + rec(b,c,3,idx+1))%MOD;
}

int main(){
  cin >> n >> k;
  memset(m,-1,sizeof(m));
  while(k--){
    int d,s; cin >> d >> s; 
    m[d] = s;
  }
  cout << (rec(0,0,1,1) + rec(0,0,2,1) + rec(0,0,3,1))%MOD << endl;
}