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 <string.h>
using namespace std;

int main()
{
	int n, k, t = 0, c = 0, b = 0, tt = 0, cc = 0, bb = 0;
	int p[100];

	memset(p, 0, sizeof(p));

	cin >> n >> k;

	for (int i = 0; i < k; i++) {
		int a, b;

		cin >> a >> b;
		p[a - 1] = b;
	}

	if (p[0] == 1)
		t = 1;
	else if (p[0] == 2)
		c = 1;
	else if (p[0] == 3)
		b = 1;
	else {
		t = 1;
		c = 1;
		b = 1;
	}

	for (int i = 1; i < n; i++) {
		int ty = t, cy = c, by = b, tp = tt, cp = cc, bp = bb;
		t = 0;
		c = 0;
		b = 0;
		tt = 0;
		cc = 0;
		bb = 0;

		if (p[i] == 1 || p[i] == 0) {
			t = (cy + by + cp + bp) % 10000;
			tt = ty;
		}

		if (p[i] == 2 || p[i] == 0) {
			c = (by + ty + bp + tp) % 10000;
			cc = cy;
		}

		if (p[i] == 3 || p[i] == 0) {
			b = (ty + cy + tp + cp) % 10000;
			bb = by;
		}
	}

	cout << (t + c + b + tt + cc + bb) % 10000 << endl;

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int N, K;
int dp[105][3][3]; // dp[?????\??????][?????\???????????\???][?????\???????????\???]
int menu[105];

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

    memset(menu, -1, sizeof menu);

    rep(i, K) {
        int a, b; cin >> a >> b;
        menu[a] = b - 1;
    }

    dp[0][0][1] = 1;

    if (menu[0] != -1) {
        dp[1][menu[0]][0] = 1;
    } else {
        rep(i, 3) {
            dp[1][i][0] = 1;
        }
    }

    if (menu[1] != -1) {
        rep(i, 3) {
            rep(j, 3) {
                dp[2][menu[1]][i] += dp[1][i][j];
                dp[2][menu[1]][i] %= 10000;
            }
        }
    } else {
        rep(i, 3) rep(j, 3) rep(k, 3) {
            dp[2][i][j] += dp[1][j][k];
            dp[2][i][j] %= 10000;
        }
    }

    for (int i = 2; i < N; ++i) {
        if (menu[i] != -1) {
            rep(j, 3) {
                rep(k, 3) {
                    if (menu[i] == j && j == k) continue;
                    dp[i + 1][menu[i]][j] += dp[i][j][k];
                    dp[i + 1][menu[i]][j] %= 10000;
                }
            }
        } else {
            rep(j, 3) {
                rep(k, 3) {
                    rep(l, 3) {
                        if (j == k && k == l) continue;
                        dp[i + 1][j][k] += dp[i][k][l];
                        dp[i + 1][j][k] %= 10000;
                    }
                }
            }
        }
    }

    int ans = 0;

    rep(i, 3) rep(j, 3) {
        ans += dp[N][i][j];
        ans %= 10000;
    }

    cout << ans << endl;
}

C++: #include<iostream>
#include<vector>
#include<map>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int main()
{
  int N,K;
  cin >> N >> K;

  vector<vector<P> > vec;
  vec.resize(3);
  vec[0].resize(2),vec[1].resize(2),vec[2].resize(2);
  vec[0][0] = vec[1][0] = vec[2][0] = P(1,0);//P(1,2)
  map<int,int> Kdays;
  for(int i=0;i<K;i++)
    {
      int a,b;
      cin >> a >> b;
      a--,b--;
      Kdays[a] = b;
    }
  
  for(int i=0;i<N-1;i++)
    {
      vec[0][1] = vec[1][1] = vec[2][1] = P(0,0);

      int pasta = -1;
      if(Kdays.find(i) != Kdays.end())
	pasta = Kdays[i];
    
      for(int j=0;j<3;j++)
	{
	  if(pasta != -1 && pasta != j)
	    continue;

	  for(int k=0;k<3;k++)
	    {
	      if(vec[j][0].F != 0)
		{
		  if(j == k)
		    vec[k][1].S += vec[j][0].F%10000;
		  else
		    vec[k][1].F += vec[j][0].F%10000;
		} 

	      if(vec[j][0].S != 0 && j != k)
		  vec[k][1].F += vec[j][0].S%10000;
	    }
	}    

    
      vec[0][0] = vec[0][1], vec[1][0] = vec[1][1], vec[2][0] = vec[2][1];
    
    }

  long long ans = 0;
  int pasta = -1;
  if(Kdays.find(N-1) != Kdays.end())
    pasta = Kdays[N-1];
    
  for(int i=0;i<3;i++)
    if(pasta != -1 && pasta != i)
      continue;
    else
      ans += vec[i][0].F%10000,ans += vec[i][0].S%10000;
    
  cout << ans%10000 << endl;

  return 0;
}