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 <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <map>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define MAX_N 105
int vx [4]= {1,0,-1,0};
int vy [4]= {0,1,0,-1};
long long  dp[MAX_N][4][4];//dp[date][today][yesterday]
int V[MAX_N],W[MAX_N];
int data[MAX_N],B[MAX_N];
int K ,N;
using namespace std;
void init(){
    REP(i,4)REP(j,4)dp[2][i][j]=1;
    REP(j,K){
      if(data[j]==1)
        switch (B[j]) {
          case 1 : FOR(l,1,4){dp[2][l][2]=0;dp[2][l][3]=0;}break;
          case 2 : FOR(l,1,4){dp[2][l][1]=0;dp[2][l][3]=0;}break;
          case 3 : FOR(l,1,4){dp[2][l][1]=0;dp[2][l][2]=0;}break;
        }
        else if (data[j]==2)
        switch (B[j]) {
          case 1 : FOR(l,1,4){dp[2][2][l]=0;dp[2][3][l]=0;}break;
          case 2 : FOR(l,1,4){dp[2][1][l]=0;dp[2][3][l]=0;}break;
          case 3 : FOR(l,1,4){dp[2][1][l]=0;dp[2][2][l]=0;}break;
        }

      }
  for(int i=3;i<=N;i++){
    dp[i][1][1]= dp[i-1][1][2]+dp[i-1][1][3];
    dp[i][2][2]= dp[i-1][2][1]+dp[i-1][2][3];
    dp[i][3][3]= dp[i-1][3][2]+dp[i-1][3][1];
    dp[i][1][2]= dp[i-1][2][1]+dp[i-1][2][2]+dp[i-1][2][3];
    dp[i][1][3]= dp[i-1][3][1]+dp[i-1][3][2]+dp[i-1][3][3];
    dp[i][2][1]= dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][1][3];
    dp[i][2][3]= dp[i-1][3][1]+dp[i-1][3][2]+dp[i-1][3][3];
    dp[i][3][1]= dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][1][3];
    dp[i][3][2]= dp[i-1][2][1]+dp[i-1][2][2]+dp[i-1][2][3];
    REP(x,4)REP(y,4)dp[i][x][y]%=10000;
    REP(j,K){
      if(data[j]==i){
        switch (B[j]) {
          case 1 : FOR(l,1,4){dp[i][2][l]=0;dp[i][3][l]=0;}break;
          case 2 : FOR(l,1,4){dp[i][1][l]=0;dp[i][3][l]=0;}break;
          case 3 : FOR(l,1,4){dp[i][1][l]=0;dp[i][2][l]=0;}break;
        }
      }
    }
  }
  long long total=0;
    for(int j =1 ;j<=3;j++){
      for(int l =1;l<=3;l++){
        total += dp[N][j][l];
        total %= 10000;
        //cout << '[' <<j<<','<<l<<']'<<dp[N][j][l]<<endl;
      }

  }
  cout << total <<endl;

}
void solve(){
  cin >> N >> K;
  REP(i,K){
    cin >> data[i]>>B[i];
  }
  init();

}
int main(){
    solve();
}

C++: #include<bits/stdc++.h>
using namespace std;

using i64 = int64_t;

constexpr i64 MOD = 10000;

i64 dp[102][4][4]={0};

int main(){
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> v;
    for(int i=0;i<k;++i){
        int a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(v.begin(), v.end());
    dp[0][0][0] = 1;
    int d = 0;
    for(int i=1;i<=n;++i){
        for(int j=0;j<4;++j){
            for(int k=0;k<4;++k){
                if(v[d].first == i){
                    if(j == k && k == v[d].second)continue;
                    dp[i][k][v[d].second] += dp[i-1][j][k];
                    dp[i][k][v[d].second] %= MOD;
                }else{
                    for(int l=1;l<4;++l){
                        if(j == k && k == l)continue;
                        dp[i][k][l] += dp[i-1][j][k];
                        dp[i][k][l] %= MOD;
                    }
                }
            }
        }
        if(v[d].first == i)d++;
    }

    i64 ans = 0;
    for(int i=1;i<4;++i){
        for(int j=1;j<4;++j){
            ans += dp[n][i][j];
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	int n, k, l, m;
	cin >> n >> k;
	int krsw[101][3] = {};
	int a[100] = {} ;
	for(int i = 0; i < k; i++) {
		cin >> l >> m;
		a[l] = m;
	}
	if(a[1]) krsw[1][a[1]] = 1;
	else { krsw[1][1] = 1; krsw[1][2] = 1; krsw[1][3] = 1; }
	for(int hi = 2; hi <= n; hi++) {
		if(a[hi]) {
			krsw[hi][a[hi]] = krsw[hi - 1][1] + krsw[hi - 1][2] + krsw[hi - 1][3];
			if(krsw[hi - 1][a[hi]] > 0 && krsw[hi - 2][a[hi]] > 0)
				krsw[hi][a[hi]] -= krsw[hi - 2][a[hi]];
			krsw[hi][a[hi]] %= 10000;
			if(krsw[hi][a[hi]]<0)krsw[hi][a[hi]]=0;
		}
		else
			for(int i = 1; i <= 3; i++) {
				krsw[hi][i] = krsw[hi - 1][1] + krsw[hi - 1][2] + krsw[hi - 1][3];
				if(krsw[hi - 1][i] > 0 && krsw[hi - 2][i] > 0)
					krsw[hi][i] -= krsw[hi - 2][i];
				krsw[hi][i] %= 10000;
				if(krsw[hi][i]<0)krsw[hi][i]=0;
			}
	}
	cout << (krsw[n][1] + krsw[n][2] + krsw[n][3]) % 10000 << endl;
	return 0;
}