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<stdio.h>
#include<string.h>
 
int n,k;
int dp[105][5][5]={};
//dp[a][b][c] .. a日目に、今日はb、昨日はcのパスタを食べた場合の通り数
int dat[105]={};
 
int main(void){
	scanf("%d%d",&n,&k);
	int d,i,j,p;
	for(i=1;i<=k;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		dat[a] = b;
	}
 
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++){
			if(dat[1]!=0 && dat[1]!=j){
				continue;
			}
			if(dat[2]!=0 && dat[2]!=i){
				continue;
			}
			dp[2][i][j]=1;
		}
	}
	//カレンダーに合わない食べ方なら、0
	//そうでなければ、1
	for(d=3;d<=n;d++){
		for(i=1;i<=3;i++){
			for(j=1;j<=3;j++){
				//dp[d][i][j]について
				if(dat[d-1]!=0 && dat[d-1]!=j){
					dp[d][i][j]=0;
				}
				else if(dat[d]!=0 && dat[d]!=i){
					dp[d][i][j]=0;
				}
				//カレンダーに合わないなら、飛ばす(0)
				else{
					for(p=1;p<=3;p++){
						if(i==j && j==p)continue;
						//三日連続で同じのなら、飛ばす（足さない）
						dp[d][i][j] += dp[d-1][j][p];
					}
					dp[d][i][j]%=10000;
				}
				//printf("%d ",dp[d][i][j]);
			}
		}
		//printf("\n");
	}
 
	int ans=0;
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++){
			//総和
			ans += dp[n][i][j];
		}
	}
	ans %= 10000;
 
	printf("%d\n",ans);
	return 0;
}

C++: #include<bits/stdc++.h>
#define int long long

using namespace std;

int n,k,q[110];
int mem[110][5][5];
static const int mod = 10000;
int dfs(int day,int p,int pp){
    if(day==0)return 1;
    if(mem[day][p][pp]!=-1)mem[day][p][pp];
    int ans=0;
    if(q[day]!=0){
        if(p==pp&&q[day]==p)return 0;
        ans=dfs(day-1,q[day],p);
        return ans;
    }
    for(int i=1;i<=3;i++){
        if(p==pp&&p==i) continue;
        ans+=dfs(day-1,i,p);
    }
    ans=ans%mod;
    mem[day][p][pp]=ans;
    return ans;
}

signed main(){
    cin>>n>>k;
    memset(mem,-1,sizeof(mem));
    int a,b;
    for(int i=1;i<=k;++i){
        cin>>a>>b;
        q[a]=b;
    }
    cout<<dfs(n,0,0)<<endl;
}

C++: #include <iostream>
#include <vector>
#include <array>
#include <numeric>

int f(int, int, int);
int N;
int yotei[100];

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

    int k, date;
    std::cin >> N >> k;
    for (int i = 0; i < k; i++) {
        std::cin >> date;
        std::cin >> yotei[date-1];
    }

    std::cout << f(0, 0, 0) << "\n";
    return 0;
}

int f(int day, int kinou, int ototui) {
    if (day == N) return 1;
    int ans = 0;

    for (int i = 1; i <= 3; i++) {
        if ((i == kinou && i == ototui) || (yotei[day] != 0 && i != yotei[day])) continue;

        ans += f(day + 1, i, kinou);
    }

    return ans % 10000;
}

C++: #include<iostream>
using namespace std;
int N,K,day,sosu;
int plan[101];
int memo[101][4][4];

int solve(int n,int b1,int b2){
  if(plan[n]!=0){
    if(b1==b2&&b1==plan[n])
      return 0;
      else
       return slove(n+1,plan[n],b1)%10000;
    }
    int t=0;
    for(int i=1;i<=3;++i){
      if(b1==b2&&b1==i)continue;
      t+=solve(n+1,i,b1)%10000;
    }
    returm memo[n][b1][b2]=t%10000;
}

int main(){
  cin>>N>>K;

  for(int i=0;i<K;i++){
    cin>>day>>sosu;
    plan[day]=sosu;
  }
  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<<solve(1,0,0)<<endl;
}

C++: #include<iostream>
using namespace std;
int dp[105][3][2],a[105],n,m,p,q;
int main(){
	cin>>n>>m;for(int i=0;i<m;i++){cin>>p>>q;a[p]=q;}
	if(a[1]==0){dp[1][0][0]=1;dp[1][1][0]=1;dp[1][2][0]=1;}
	if(a[1]>=1)dp[1][a[1]-1][0]=1;
	for(int i=2;i<=n;i++){
		if(a[i]==0 || a[i]==1){
			dp[i][0][0]+=(dp[i-1][1][0]+dp[i-1][1][1]+dp[i-1][2][0]+dp[i-1][2][1]);dp[i][0][0]%=10000;
			dp[i][0][1]+=dp[i-1][0][0];dp[i][0][1]%=10000;
		}
		if(a[i]==0 || a[i]==2){
			dp[i][1][0]+=(dp[i-1][0][0]+dp[i-1][0][1]+dp[i-1][2][0]+dp[i-1][2][1]);dp[i][1][0]%=10000;
			dp[i][1][1]+=dp[i-1][1][0];dp[i][1][1]%=10000;
		}
		if(a[i]==0 || a[i]==3){
			dp[i][2][0]+=(dp[i-1][0][0]+dp[i-1][0][1]+dp[i-1][1][0]+dp[i-1][1][1]);dp[i][2][0]%=10000;
			dp[i][2][1]+=dp[i-1][2][0];dp[i][2][1]%=10000;
		}
	}
	cout<<(dp[n][0][0]+dp[n][0][1]+dp[n][1][0]+dp[n][1][1]+dp[n][2][0]+dp[n][2][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(0, 0, 0);
}

int solve(int i, int b1, int b2){
	if(i == n) 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;
}