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<iostream>
#define MOD 10000
using namespace std;
int main(){
    int n,k,P[100]={0};
    cin>>n>>k;
    for(int i=0;i<k;i++){
        int d,s;
        cin>>d>>s;
        P[d-1]=s;
    }
    int dp[100][3][2]={{{0}}};
    for(int i=0;i<3;i++)dp[0][i][0]=1;

    for(int i=0;i<n;i++){
        if(P[i])
            for(int j=0;j<3;j++)
                if(!(P[i]-1==j))dp[i][j][0]=dp[i][j][1]=0;
        if(i+1==n)break;
        for(int j=0;j<3;j++){
            for(int k=0;k<2;k++){
                int c;
                for(int l=0;l<3;l++){
                    if(j==l)c=k+1;
                    else c=0;
                    if(c==2)continue;
                    dp[i+1][l][c]+=dp[i][j][k];
                    dp[i+1][l][c]%=MOD;
                }
            }
        }

    }
    int sum=0;
    for(int i=0;i<3;i++){
        for(int j=0;j<2;j++){
            sum+=dp[n-1][i][j];
            sum%=MOD;
        }
    }
    cout<<sum<<endl;

}

C++: #include<iostream>
#include<map>
using namespace std;
int main(){
  int n,m;
  map<int,int> day;
  cin >>n>>m;
  for(int i=0,a,b; i<m; i++){
    cin >>a>>b;
    day[a-1] = b;
  }
  int dp[101][3][3];
  for(int i=0; i<9; i++) dp[1][i/3][i%3] = 1;
  if(day[0]!=0)
    for(int i=0; i<9; i++)
      if(i/3!=day[0]-1) dp[1][i/3][i%3] = 0;
  for(int i=1; i<n; i++){
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
	for(int l=0; l<3; l++){
	  if(j != k || k != l) dp[i][k][l]+=dp[i-1][j][k];
	  dp[i][k][l]%=10000;
	}
      }
    }
    if(day[i]!=0)
      for(int j=0; j<9; j++)
	if(j%3!=day[i]-1) dp[i][j/3][j%3] = 0;
  }
  int ans = 0;
  for(int i=0; i<9; i++) ans+=dp[n-1][i/3][i%3];
  cout <<ans%10000<<endl;
  return 0;
}

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];
    }

    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;
}

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

int main() {
	int n,k;
	cin>>n>>k;
	int day[n],pasta[n];
	
	for(int i=0;i<n;i++){
		day[i]=0;
		pasta[i]=0;
	}
	
	for(int i=0;i<k;i++){
		int a,b;
		cin>>a>>b;
		pasta[a-1]=b;
	}
	
	for(int i=0;i<n;i++){
		if(pasta[i]!=0){
			day[i]=1;
		}
		else if(pasta[i-2]==pasta[i-1]){
			if(pasta[i-2]!=0){
				day[i]=2;
			}
			else day[i]=3;
		}
		else if(pasta[i-1]==pasta[i+1]){
			if(pasta[i-1]!=0){
				day[i]=2;
			}
			else day[i]=3;
		}
		else if(pasta[i+1]==pasta[i+2]){
			if(pasta[i+1]!=0){
				day[i]=2;
			}
			else day[i]=3;
		}
		else day[i]=3;
	}
	
	int ans=1;
	for(int i=0;i<n;i++){
		ans=ans*day[i];
	}
	
	cout<<ans%10000<<endl;
	return 0;
}

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

using namespace std;

#define MAX 114
const int MOD = 10000;

void add(int &a, int b)
{    
    a = (a + b) % MOD;
}

int main()
{
    int N, M, a, b;
    cin >> N >> M;
    vector<int> p(N, -1);
    for (int i = 0; i < M; i++) {
        cin >> a >> b; a--; b--;
        p[a] = b;
    }
    
    int dp[MAX][4][4] = {{{}}};
    dp[0][3][3] = 1;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                if (dp[i][j][k] == 0) continue;
                if (p[i] >= 0) {
                    if (k == j && j == p[i]) continue;
                    add(dp[i+1][p[i]][j], dp[i][j][k]);
                } else {
                    for (int l = 0; l < 3; l++) {
                        if (k == j && j == l) continue;
                        add(dp[i+1][l][j], dp[i][j][k]);
                    }
                }                    
            }
        }
    }
    int res = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            add(res, dp[N][i][j]);
        }
    }
    cout << res << endl;
    return 0;
}