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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MOD = 10000;
void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }

int N, K;
int a[210];

int dp[210][5][5];

int main() {
    while (cin >> N >> K) {
        memset(a, -1, sizeof(a));
        for (int i = 0; i < K; ++i) {
            int h, w; cin >> h >> w; --h;
            a[h] = w;
        }
        
        memset(dp, 0, sizeof(dp));
        dp[0][0][0] = 1;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j <= 3; ++j) {
                for (int k = 0; k <= 3; ++k) {
                    //if (dp[i][j][k]) cout << i << ", " << j << ", " << k << " : " << dp[i][j][k] << endl;
                    
                    for (int l = 1; l <= 3; ++l) {
                        if (j == k && k == l) continue;
                        if (a[i] != -1 && a[i] != l) continue;
                        
                        add(dp[i+1][l][j], dp[i][j][k]);
                    }
                }
            }
        }
        
        int res = 0;
        for (int j = 1; j <= 3; ++j) for (int k = 1; k <= 3; ++k) add(res, dp[N][j][k]);
        
        cout << res << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>

#define MOD (10000)

using namespace std;

int memo[101][4][2];
int ready[101];

int n, k;

int countWay(int day, int pasta, int how)
{
	if (how > 1) return (0);
	if (day && memo[day][pasta][how] >= 0) return (memo[day][pasta][how]);
	
	if (day == n){
		if (ready[n] && pasta != ready[n]) return (0);
		return (1);
	}
	
	int ret;
	
	ret = 0;
	if (ready[day]){
		ret = countWay(day + 1, ready[day], pasta == ready[day] ? how + 1 : 0) % MOD;
	}
	else {
		for (int i = 1; i <= 3; i++){
			ret = (ret + countWay(day + 1, i, pasta == i ? how + 1 : 0)) % MOD;
		}
	}
	if (day) return (memo[day][pasta][how] = ret);
	return (ret);
}

int main()
{
	scanf("%d %d", &n, &k);
	
	for (int i = 0; i < k; i++){
		int when, what;
		scanf("%d %d", &when, &what);
		ready[when] = what;
	}
	
	memset(memo, -1, sizeof(memo));
	
	printf("%d\n", countWay(0, -1, 0));
	
	return (0);
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[101] = { 0 };
	int n;
	int i;
	cin >> n >> i;
	for (int v = 0; v < i; v++){
		int y, x;
		cin >> y >> x;
		a[y] = { x };

	}
	int f;
	if (a[1] = a[2] != a[3]){
		if (a[1] != 0){
			f = 2;
		}
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[1] = a[3] != a[2]){
		if (a[1] != 0)
			f = 2;
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[3] = a[2] != a[1]){
		if (a[2] != 0)
			f = 2;
		if (a[2] = 0){
			f = 8;
		}
	}
	if (a[1] = a[2] = a[3]){
		if (a[1] = 0){
			f = 24;
		}
		if (a[1] != 0){
			f = 1;
		}

	}

	for (int v = 4; v <= n; v++){
		if (a[v] = 0){
			if (a[v - 2] = a[v - 1] != 0){
				f = f * 2;
			}
			if (a[v - 2] != a[v - 1] != 0){
				f = f * 3;
			}
			if (a[v - 2] = 0 != a[v - 1]){
				f = f * 3 -1;
			}
			if (a[v - 1] = 0 != a[v - 2]){
				f = f * 3 -1;
			}
		
		}
	}
	        cout << f%10000 << endl;
        	return 0;
}

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

using namespace std;

int n,k,q[110];
int mem[110][5][5];
static const int mod = 10000;
int dfs(int day,int p,int pp){
    int ans=0;
    if(day==0)return 1;
    if(mem[day][p][pp]!=-1)return mem[day][p][pp];
    if(q[day]!=0){
        if(p==pp&&q[day]==p)return 0;
        ans=dfs(day-1,q[day],p);
        return mem[day][p][pp]=ans;
    }
    for(int i=1;i<=3;i++){
        if(p==pp&&p==i) continue;
        ans+=dfs(day-1,i,p);
    }
    ans=ans%mod;
    mem[day][p][pp]=ans;
    return ans;
}

signed main(){
    cin>>n>>k;
    memset(mem,-1,sizeof(mem));
    int a,b;
    for(int i=1;i<=k;++i){
        cin>>a>>b;
        q[a]=b;
    }
    cout<<dfs(n,0,0)<<endl;
}