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 <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define MOD 10000

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n,0);
  rep(i,k){
    int p,q;
    cin>>p>>q;
    a[p-1]=q;
  }

  vector<vector<long>> dp(n+1, vector<long>(7,0));
  dp[0][0]=1;
  rep(i,n){
    repl(j,1,4){
      if(a[i]==0 || a[i]==j){
        dp[i+1][j] = dp[i][0] - dp[i][j+3] - dp[i][j];
        dp[i+1][j+3] = dp[i][j];
        dp[i+1][0] += dp[i+1][j] + dp[i+1][j+3];
      }
    }
    dp[i+1][0]%=MOD;
  }
  while(dp[n][0]<0) dp[n][0]+=MOD;

  cout << dp[n][0] << endl;

  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int dp[110][3][2];
int num[110];

signed main(){
	int n,k;
	cin>>n>>k;
	memset(num,-1,sizeof(num));
	rep(i,0,k){
		int a,b;
		cin>>a>>b;
		a--; b--;
		num[a]=b;
	}
	if(num[0]==-1) rep(i,0,3) dp[0][i][0]=1;
	else dp[0][num[0]][0]=1;

	rep(i,1,n){
		rep(j,0,3){
			if(!(num[i]==-1||num[i]==j)) continue;
			dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][0])%10000;
			rep(k,0,3){
				if(j==k) continue;
				dp[i][j][0]=(dp[i][j][0]+dp[i-1][k][0]+dp[i-1][k][1])%10000;
			}
		}
	}
	int ans=0;
	rep(i,0,3) rep(j,0,2) ans+=dp[n-1][i][j];
	o(ans%10000);
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

ll ans;
int plan[128];
int memo[128][4][4];
int num;

// n : day, next : kind of pasta, c : 今日選んだパスタが何日続いたか 
int pasta(int n, int prev, int c)
{
	if(c == 2)
	{
		return 0;
	}
	else if(n == num)
	{
		return 1;
	}
	else if(memo[n][prev][c])
	{
		return memo[n][prev][c];
	}
	int ans = 0;
	if(plan[n+1] != 0)
	{
		if(plan[n+1] == prev)
			ans = pasta(n+1, plan[n+1], c+1); 
		else
			ans =  pasta(n+1, plan[n+1], 0);
	}
	else
	{
		for(int i = 1; i <= 3; i++)
		{
			if(prev == i)
				ans +=  pasta(n+1, i, c+1);
			else
				ans +=  pasta(n+1, i, 0) ;
		}
	}

	return memo[n][prev][c] = ans % 10000;
}

int main()
{
	int K, wk, tk;
	ans = 0;
	cin >> num >> K;
	for(int i = 0; i < K; i++)
	{
		cin >> wk >> tk;
		plan[wk] = tk;
	}
	if(plan[1] == 0)
	{
		cout << pasta(0, 0, 0)<< endl;
	}
	else
	{
		cout << pasta(1, plan[1], 0)<<endl;
	}

}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
int n, k, dp[5][5][123], a[123];
signed main() {
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int x, y; cin >> x >> y;
		a[x] = y;
	}
	dp[2][1][1] = (a[1] != 2 && a[1] != 3);
	dp[3][2][1] = (a[1] != 1 && a[1] != 3);
	dp[1][3][1] = (a[1] != 1 && a[1] != 2);
	for (int i = 2; i <= n; i++) {
		if (a[i] != 2 && a[i] != 3) {
			dp[1][1][i] = 000000000000000 + dp[2][1][i - 1] + dp[3][1][i - 1]; dp[1][1][i] %= 10000;
			dp[2][1][i] = dp[1][2][i - 1] + dp[2][2][i - 1] + dp[3][2][i - 1]; dp[2][1][i] %= 10000;
			dp[3][1][i] = dp[1][3][i - 1] + dp[2][3][i - 1] + dp[3][3][i - 1]; dp[3][1][i] %= 10000;
		}
		if (a[i] != 1 && a[i] != 3) {
			dp[1][2][i] = dp[1][1][i - 1] + dp[2][1][i - 1] + dp[3][1][i - 1]; dp[1][2][i] %= 10000;
			dp[2][2][i] = dp[1][2][i - 1] + 000000000000000 + dp[3][2][i - 1]; dp[2][2][i] %= 10000;
			dp[3][2][i] = dp[1][3][i - 1] + dp[2][3][i - 1] + dp[3][3][i - 1]; dp[3][2][i] %= 10000;
		}
		if (a[i] != 1 && a[i] != 2) {
			dp[1][3][i] = dp[1][1][i - 1] + dp[2][1][i - 1] + dp[3][1][i - 1]; dp[1][3][i] %= 10000;
			dp[2][3][i] = dp[1][2][i - 1] + dp[2][2][i - 1] + dp[3][2][i - 1]; dp[2][3][i] %= 10000;
			dp[3][3][i] = dp[1][3][i - 1] + dp[2][3][i - 1] + 000000000000000; dp[3][3][i] %= 10000;
		}
	}
	int ans = 0;
	for (int i = 1; i <= 4; i++)for (int j = 1; j <= 3; j++) { ans += dp[i][j][n]; ans %= 10000; }
	cout << ans << endl;
}