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 <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define pb         push_back
#define mp         make_pair
#define ll         long long
#define PI         acos(-1.0)
#define ALL(A)     ((A).begin(), (A).end())
#define vsort(v)   sort(v.begin(),v.end())
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int N, K;
    cin >> N >> K;
    int pasta[N+1];
    FOR(i, 0, N+1) pasta[i] = 0;
    FOR(i, 1, K+1){
        int hi, pas;
        cin >> hi >> pas;
        pasta[hi] = pas;
    }
    ll int dp[N+1][4][4];
    FOR(i, 0, N+1){
        FOR(j, 0, 4){
            FOR(k, 0, 4){
                dp[i][j][k] = 0;
            }
        }
    }
    FOR(i, 1, 4){
        if(pasta[1]==0){
            dp[1][i][0] = 1;
        }
        else{
            if(i==pasta[1]) dp[1][i][0] = 1;
        }
    }

    FOR(i, 1, N+1){
        FOR(j, 0, 4){
            FOR(k, 0, 4){
                if(dp[i][j][k]==0) continue;
                FOR(m, 1, 4){
                    if(j==k && m==k) continue;
                    if(pasta[i+1]==0){
                        dp[i+1][m][j] = dp[i+1][m][j] + dp[i][j][k];
                        dp[i+1][m][j] %= 10000;
                    }
                    else{
                        if(pasta[i+1]==m){
                            dp[i+1][m][j] = dp[i+1][m][j] + dp[i][j][k];
                            dp[i+1][m][j] %= 10000;
                        }
                        //else dp[i+1][m][j] = 0;
                    }
                }

            }
        }
    }
    ll int ans = 0;
    FOR(i, 1, 4){
        FOR(j, 1, 4){
            ans += dp[N][i][j];
            ans = ans % 10000;
        }
    }
    cout << ans << endl;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int MAX_N = 110;
const int MAX_K = 110;
const int MAX_P = 3;
const int MOD = 10000;

int main(){
    int n, k;
    cin >>n >>k;
    vector<int> pasta(n, -1);
    REP(i, k){
        int day, p;
        cin >>day >>p;
        day--;
        p--;
        pasta[day] = p;
    }

    int dp[MAX_N][MAX_P][2];
    memset(dp, 0, sizeof(dp));
    //init
    if(pasta[0] != -1) dp[0][pasta[0]][0] = 1;
    else REP(i, MAX_P) dp[0][i][0] = 1;

    //dp
    REP(i, n - 1){
        REP(j, MAX_P){
            REP(k, MAX_P){
                if(pasta[i] != -1 && pasta[i] != j) continue;

                if(j == k){
                    dp[i + 1][k][1] += dp[i][j][0];
                    dp[i + 1][k][1] %= MOD;
                } else{
                    dp[i + 1][k][0] += (dp[i][j][0] + dp[i][j][1]);
                    dp[i + 1][k][0] %= MOD;
                }

            }
        }
    }

    int ans = 0;
    REP(i, MAX_P){
        ans += dp[n - 1][i][0];
        ans += dp[n - 1][i][1];
    }
    cout <<ans % MOD <<endl;


    return 0;
}