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++: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#define int long long
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

int n, m;
int k[110];
int d, t;
int sum;
int kid;
int memo[101][101];
/*int solve(int day,int p,int q,int r) {
	sum = 0;
	cout << day << " " << " " << p << endl;
	if (day == n)return 1;
	//if (q == k[day - 1] && r == k[day - 1]) return 0;
	if (memo[day][p]!=-1)return memo[day][p];
	if (!k[day+1]) {
		//if (q == r == p)return memo[day][p] = 0;
		if (q == 1 && r == 1)return memo[day][p] = +solve(day + 1, 2, p, q) + solve(day + 1, 3, p, q);
		else if (q == 2 && r == 2)return memo[day][p] = +solve(day + 1, 1, p, q) + solve(day + 1, 3, p, q);
		else if (q == 3 && r == 3)return memo[day][p] = +solve(day + 1, 1, p, q) + solve(day + 1, 2, p, q);
		else return memo[day][p]=solve(day + 1, 1, p, q)
			+ solve(day + 1, 2, p, q)
			+ solve(day + 1, 3, p, q);
	}
	else if (k[day+1]) {
		//if (q == r == p)return memo[day][p] = 0;
		return memo[day][p]=solve(day + 1, k[day], p, q);
	}
}*/

int dp[101][4];

signed main() {
	cin >> n >> m;
	REP(i, 101)REP(j, 101)dp[i][j] = 0;
	REP(i, m) {
		cin >> d >> t;
		k[d] = t;
	}
	dp[0][1] = 1;
	dp[0][2] = 1;
	dp[0][3] = 1;
	int cnt1 = 0;
	int cnt2 = 0;
	int cnt3 = 0;
	for (int day = 0; day< n; day++) {
		for (int kin = 0; kin <= 3; kin++) {
			if (day != 0 && kin == 0)continue;
			if (kin == 1)cnt1++;
			if (kin == 2)cnt2++;
			if (kin == 3)cnt3++;
			/*if (cnt1 == 2 && k[day + 1] == 1)continue;
			if (cnt2 == 2 && k[day + 1] == 2)continue;
			if (cnt3 == 2 && k[day + 1] == 3)continue;*/
			if (!k[day]) {
				if (cnt1 == 2) {
					dp[day + 1][kin] += dp[day][2] + dp[day][3];
					cnt1 = 0;
					continue;
				}
				else if (cnt2 ==2) {
					dp[day + 1][kin] += dp[day][1] + dp[day][3];
					cnt2 = 0;
					continue;
				}
				else if (cnt3 == 2) {
					dp[day + 1][kin] += dp[day][1] + dp[day][2];
					cnt3 = 0;
					continue;
				}
				cnt1 = 0;
				cnt2 = 0;
				cnt3 = 0;
				dp[day + 1][kin] += dp[day][1] + dp[day][2] + dp[day][3];
			}
			else if (k[day]) {
				//cout << day << " " << kin << endl;
				dp[day + 1][kin] += dp[day][k[day]];
			}
		}
	}
	cout << dp[n][1]%10000<< endl;
	return 0;
}

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

int n, k, next;
int day[101];
int dp[101][4][4];
int solve(int i, int j, int k);

int main(void){
	fill_n(**dp,101*4*4,-1);
	fill_n(day, 101, 0);
	cin >> n >> k;
	for(int i = 0, a; i < k; i++){
		cin >> a;
		cin >> day[a];
	}
	cout << solve(1, 0, 0) << endl;
}

int solve(int i, int b1, int b2){
	if(i == n+1) return 1;
	if(dp[i][b1][b2] != -1) return dp[i][b1][b2];
	if(day[i] != 0){
		if(b1 == b2 && b1 == day[i]){return 0;}
		else return solve(i+1, day[i], b1)%10000;
	}
	int sum = 0;
	for(int next = 1; next <= 3; next++){
		if(b1 == b2 && b1 == next)continue;
		sum += solve(i+1, next, b1)%10000;
	}
	return dp[i][b1][b2] = sum%10000;
}

C++: #include <stdio.h>
#include <algorithm>
#include <string.h>
#define DAY_MAX	123
#define PASTA_MAX	5
#define ONAZI_MAX	123

int max;


int set_pasta[DAY_MAX];
int memo[DAY_MAX][PASTA_MAX][ONAZI_MAX];

int dp(int day, int pasta, int onazi){
	int numbuf = 0;
	int ans = 0;
	if (memo[day][pasta][onazi] >= 0) return memo[day][pasta][onazi];
	if (onazi == 3) return 0;
	if (day == max - 1) return 1;
	if (set_pasta[day + 1] >= 1){
		if (set_pasta[day + 1] == pasta) return memo[day][pasta][onazi] = dp(day + 1, pasta, onazi + 1);
		else return memo[day][pasta][onazi] = dp(day + 1, set_pasta[day + 1], 1);
	}
	else{
		for (int a = 0; a < 3; a++){
			if (a + 1 == pasta) ans += dp(day + 1, pasta, onazi + 1);
			else ans += dp(day + 1, a + 1, 1);
			ans %= 10000;
		}
		return ans;
	}
}

int main(){
	int num;
	int buf;
	int answer = 0;
	memset(memo, 255, sizeof(memo));
	scanf("%d%d", &max, &num);
	for (int a = 0; a < num; a++){
		scanf("%d", &buf);
		scanf("%d", &set_pasta[buf - 1]);
	}
	if (set_pasta[0] >= 1) printf("%d\n", dp(0, set_pasta[0], 1));
	else printf("%d\n", (dp(0, 1, 1) + dp(0, 2, 1) + dp(0, 3, 1)) % 10000);
	return 0;
}