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>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;

int main(){
  int n, k;
  cin >> n >> k;
  vector<pair<int,int>> a(k);
  rep(i,k){
    cin >> a[i].first >> a[i].second;
    a[i].second--;
  }
  sort(a.begin(),a.end());
  vector<vector<vector<vector<int>>>> dp(n+1,vector<vector<vector<int>>>(3,vector<vector<int>>(3,vector<int>(3))));
  dp[0][0][0][0]=1;
  int f=0;
  for(int i=1; i<=2; i++){
    while(f<k-1 && a[f].first<i)
      f++;
    rep(j,3){
      rep(l,3){
        rep(m,3){
          rep(o,3){
            if(a[f].first==i && a[f].second!=o)
              continue;
            dp[i][l][m][o] += dp[i-1][j][l][m];
            dp[i][l][m][o] %= 10000;
          }
        }
      }
    }
  }
  for(int i=3; i<=n; i++){
    while(f<k-1 && a[f].first<i)
      f++;
    rep(j,3){
      rep(l,3){
        rep(m,3){
          rep(o,3){
            if(l==m&&m==o)
              continue;
            if(a[f].first==i && a[f].second!=o)
              continue;
            dp[i][l][m][o] += dp[i-1][j][l][m];
            dp[i][l][m][o] %= 10000;
          }
        }
      }
    }
  }
  int res=0;
  rep(i,3){
    rep(j,3){
      rep(l,3){
        res += dp[n][i][j][l];
        res %= 10000;
      }
    }
  }
  cout << res << endl;
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int k;
int a,q[200]={0};
int b,w[200]={0};
int cnt1=0,cnt2=0,cnt3=0;
int cnt=0,ans=0,co=0;
void check (int x);
int main(void){
    cin>>n>>k;

	for(int i=0;i<k;i++){
        cin>>a;
        cin>>b;
        q[a]=b;
	}
	/*for(int i=1;i<=20;i++){
	n=i;*/
	check(0);

    cout<<ans<<endl;
    /*co=0;
    ans=0;
	}	*/
	return 0;
}
void check(int x){
    //x==1 ? cout<<"-"<<(co+1)/2<<endl : x==2 ? cout<<"--"<<(co+1)/2<<endl : x==3 ? cout<<"---"<<(co+1)/2<<endl : cout<<"----"<<(co+1)/2<<endl;
    //cout<<"."<<x<<"."<<co<<endl;

    if(x==n){
        ans++;
        if(ans>=10000)ans-=10000;
        //cout<<"+"<<co<<endl;
        return;
    }
    if(q[x]!=0){
        if(q[x]==1){
            if(co==2)return;
            else if(co==1)co++;
            else co=1;
            check(x+1);
        }
        else if(q[x]==2){
            if(co==4)return;
            else if(co==3)co++;
            else co=3;
            check(x+1);
        }
        else if(q[x]==3){
            if(co==6)return;
            else if(co==5)co++;
            else co=5;
            check(x+1);
        }

    }
    else{

        if(co!=2){
            int sub=co;
            if(co==1)co++;
            else co=1;
            check(x+1);
            co=sub;
        }
        if(co!=4){
            int sub=co;
            if(co==3)co++;
            else co=3;
            check(x+1);
            co=sub;
        }
        if(co!=6){
            int sub=co;
            if(co==5)co++;
            else co=5;
            check(x+1);
            co=sub;
        }
    }


}

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 %= MOD;
        ans += dp[n - 1][i][1];
        ans %= MOD;
    }
    cout <<ans <<endl;


    return 0;
}