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;

#define llong long long 

int N, K;
int det[101];
int score[101][4][3];

int solve(int day, int kind, int d){
	if(score[day][kind][d] != -1) return score[day][kind][d];
	if(d == 3) return 0;

	if(day == N) return score[day][kind][d] = 1;

	int ret = 0;
	if(det[day + 1] != 0){
		if(det[day + 1] == kind) ret = solve(day + 1, det[day + 1], d + 1) % 10000;
		else ret = solve(day + 1, det[day + 1], 1) %  10000;
	}else{
		for(int i = 1; i <= 3; i++){
			if(kind == i) ret += solve(day + 1, i, d + 1) % 10000;
			else ret += solve(day + 1, i, 1) % 10000;
		}
	}

	return score[day][kind][d] = ret % 10000;
}

int main(){
	fill_n(det, 101, 0);
	fill_n(**score, 101 * 4 * 3, -1);
	cin >> N >> K;
	int day;
	for(int i = 0; i < K; i++){
		cin >> day;
		cin >> det[day];
	}

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

C++: 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<bits/stdc++.h>
#define LL long long
#define FOR(i,a,b) for(int i=a;i<=b;++i)
 
using namespace std;
 
static const LL MAX_N = 1e+5;
static const LL INF = 1 << 25;
 
struct clothes{
    LL A[MAX_N],B[MAX_N],C[MAX_N];
};
 
int N,D;
LL res=-INF;
LL Day[MAX_N];
clothes T;
 
int cal(LL day,LL p,LL pp,LL sum){
    //cout<<sum+abs(pp-p)<<" "<<day<<" "<<p<<" "<<pp<<endl;
    if(res<sum+abs(pp-p))res=sum+abs(pp-p);
    if(day==N+1)return 0;
    if(day==0){
        FOR(i,1,D)
        if(Day[1]>=T.A[i]&&Day[1]<=T.B[i])cal(day+1,T.C[i],p,sum);
    }
    FOR(i,1,D){
        if(Day[day]>=T.A[i]&&Day[day]<=T.B[i]){
            if(day>2)cal(day+1,T.C[i],p,sum+abs(pp-p));
            else cal(day+1,T.C[i],p,sum);
        }
    }
    return res;
}
 
 
int main(){
    cin>>N>>D;
    FOR(i,1,N)cin>>Day[i];
    FOR(i,1,D)
        cin>>T.A[i]>>T.B[i]>>T.C[i];
        cal(0,0,0,0);
        cout<<res<<endl;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

const int MOD = 10000;

const int MAX_N = 100;
int plan[MAX_N + 1];
int memo[MAX_N + 1][4][4];
int N, K;

int search(int n, int b1, int b2)
{
    if(n == N + 1) return 1;
    if(memo[n][b1][b2] != -1) return memo[n][b1][b2];
    if(plan[n] != 0)
    {
        if(b1 == b2 && b1 == plan[n])
        {
            return 0;
        }
        else
            return search(n + 1, plan[n], b1) % MOD;
    }
    int t = 0;

    for(int i = 1; i <= 3; i++)
    {
        if(b1 == b2 && b1 == i) continue;
        t += search(n + 1, i, b1) % MOD;
    }

    return memo[n][b1][b2] = t % MOD;
    

}

int main()
{
    cin >> N >> K;
    for(int i = 0;i < K; i++)
    {
        int d, k;
        cin >> d >> k;
        plan[d] = k;
    }

    for(int i = 0; i <= N; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            for(int k = 0; k < 4; k++)
            {
                memo[i][j][k] = -1;
            }
        }
    }

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

C++: #include<bits/stdc++.h>
#define rep(a,b) for(int a=0;a<b;a++)
#define int long long int

using namespace std;

const int INF = 1000000009;

int day,al;
int almost[200];
int ans=1;
int used[200];

int pasu(int p){
    if(p==3)return 1;
    else if(p==2)return 3;
    else if(p==1)return 2;
}

int pasu2(int p){
    if(p==3)return 2;
    else if(p==2)return 1;
    else if(p==1)return 3;
}

int kaburi1(int date){
    if(almost[date+1]!=0){
        return almost[date+1];
    }else return 0;
}

int kaburi2(int date){
    if(almost[date+2]!=0){
        return almost[date+2];
    }else return 0;
}

int memo[200][200][200];

int pasuta(int d2, int d1, int dd1, int dd2,int date){
    if(date>day)return 1;
    else if(memo[d2][d1][date]>0&&dd2!=dd1)return memo[d2][d1][date];
    else if(almost[date]>0){
            ///?±??????£?????????
        return memo[d2][d1][date]=pasuta(d1,almost[date],almost[date+2],almost[date+3],date+1)%10000;
    }else if(d2==d1&&d1!=0){
        ///?????\??¨?????????????????¨???
       return memo[d2][d1][date]=(pasuta(d1,pasu(d1),almost[date+2],almost[date+3],date+1)+pasuta(d1,pasu2(d1),almost[date+2],almost[date+3],date+1))%10000;
    }else if(d1==dd1&&d1!=0){
        ///?????\??¨?????????????????¨???
       return memo[d2][d1][date]=(pasuta(d1,pasu(d1),almost[date+2],almost[date+3],date+1)+pasuta(d1,pasu2(d1),almost[date+2],almost[date+3],date+1))%10000;
    }else if(dd1==dd2&&dd1!=0){
        ///?????¨?????¨?????????
       return memo[d2][d1][date]=(pasuta(dd1,dd2,almost[date+5],almost[date+6],date+3)+pasuta(dd1,dd2,almost[date+5],almost[date+6],date+3))%10000;
    }else{
        return memo[d2][d1][date]=(pasuta(d1,1,almost[date+2],almost[date+3],date+1)+
        pasuta(d1,2,almost[date+2],almost[date+3],date+1)+
        pasuta(d1,3,almost[date+2],almost[date+3],date+1))%10000;
    }
}

signed main(){
    fill(almost,almost+200,0);
    fill(used,used+200,0);
    cin >> day >> al;
    rep(a,al){
        int da,pa;
        cin >> da >> pa;
        almost[da]=pa;
    }
    ans = pasuta(0,0,almost[2],almost[3],1);
    cout << ans%10000 << endl;
return 0;
}