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>
using namespace std;
int memo[105][5][5],day[105],n,k,ans;

int solve(int dp,int s1,int s2){
    int sum=0;

    if(dp>k){
            return 1;
    }
    if(memo[dp][s1][s2]>0)return memo[dp][s1][s2];

    if(day[dp]==0){

        for(int i=1;i<=3;i++){
        if(s1!=i||s2!=i){
        sum+=solve(dp+1,s2,i);
        sum%=10000;
            }
        }

    }else {

        if(s1!=day[dp]||s2!=day[dp]){
                sum+=solve(dp+1,s2,day[dp]);
                sum%=10000;
            }
    }

    return memo[dp][s1][s2]=sum%10000;
}


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

    cout << solve(1 ,0 , 0)  << endl;
 return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
//K[1-]
	int n,k;
	int K[101] ={};
	int dob=0,ans=0;

	void sol(int now,int yest){

		if(dob == 2){
			return;
		}

		if(now == n+1){
			ans++;
			ans%=10000;
			return;
		}

		if(K[now] != -1){
			if(yest == K[now]){
				dob++;
				return sol(now+1,K[now]);
			}
			else{
				dob=0;
				return sol(now+1,K[now]);
			}
		}

		else{
			if(now!=1){
				dob++;
			}
			sol(now+1,yest%3);
			dob=0;
			sol(now+1,(yest+1)%3);
			sol(now+1,(yest+2)%3);
			return;
		}
	}

int main(){

	cin >> n >> k;

	for(int i=0; i<n+1; i++){
		K[i] = -1;
	}


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

	sol(1,-1);

	cout << ans%10000 << endl;

	return 0;

}

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, 4)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 != 1 && kin == 0)continue;
			/*if (cnt1 == 2 && k[day] == 1)continue;
			if (cnt2 == 2 && k[day] == 2)continue;
			if (cnt3 == 2 && k[day] == 3)continue;*/
			if (kin == 1)cnt1++;
			if (kin == 2)cnt2++;
			if (kin == 3)cnt3++;
			if (k[day] == k[day + 1] && k[day] == k[day + 2]&&k[day]!=0)continue;
			cout << "[" << dp[day][kin] << "]" << endl;
			if (day >= 1){
				cout << k[day - 1] << " " << kin << " " << k[day + 1] << endl;
			}
			if ((k[day - 1] == 1 && k[day + 1] == 1 && kin == 1) || k[day - 2] == k[day] && k[day] == kin&&kin == 1) {
				dp[day + 1][kin] += dp[day][2] + dp[day][3];
				continue;
			}
			if ((k[day - 1] == 2 && k[day + 1] == 2 && kin == 2) || k[day - 2] == k[day] && k[day] == kin&&kin == 2) {
				dp[day + 1][kin] += dp[day][1] + dp[day][3];
				continue;
			}
			if ((k[day - 1] == 3 && k[day + 1] == 3 && kin == 3) || k[day - 2] == k[day] && k[day] == kin&&kin == 3) {
				dp[day + 1][kin] += dp[day][1] + dp[day][2];
				continue;
			}
				if (!k[day]) {
				if (cnt1 == 2 || (cnt1 == 2 && k[day + 1] == 1)) {
					dp[day + 1][kin] += dp[day][2] + dp[day][3];
					cnt1 = 0;
					continue;
				}
				else if (cnt2 == 2 || (cnt2 == 2 && k[day + 1] == 2)) {
					dp[day + 1][kin] += dp[day][1] + dp[day][3];
					cnt2 = 0;
					continue;
				}
				else if (cnt3 == 2 || (cnt3 == 2 && k[day + 1] == 3)) {
					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;
}