Problem:
Problem A : ID
A大学ではIDの入力ミスが多発していた。
そこで、A大学は入力ミス防止のため新しいIDを発行することにした。
新しいIDには入力ミス防止のためにIDが正しいかどうかチェックする方法がある。
・全ての桁の数字の総和を求める。
・ただし、右端の桁を１番目として、偶数番目の桁の数字を２倍にする。
・２倍することによって数字が１０以上になった時、１の位の数字と１０の位の数字を加算した数字をその桁の数字とする。
・総和が１０で割り切れれば正しいID、そうでなければ間違いとする。
例として、53579というIDをチェックする。
全ての桁の数字の総和を求めるので、
5 + 3 + 5 + 7 + 9
ただし、偶数番目の桁の数字を２倍にするので、
5 +
6
+ 5 +
14
+ 9
２倍することによって数字が１０以上になった時、１の位の数字と１０の位の数字を加算した数字をその桁の数字とするので、
5 + 6 + 5 +
(1 + 4)
+ 9
以上より、総和は30となる。30は10で割り切れるので、53579は正しいIDである。
B君はA大学の大学生であり、新しいIDを発行してもらったが、IDの一部の桁を忘れてしまった。
しかし、忘れてしまった部分にどんな数字が入るか、いくつか候補を絞ることに成功した。
あなたの仕事は、B君のIDの正しい組み合わせが何通りあるかを求めることである。
Input
入力は以下のフォーマットで与えられる。
n
ID
m
a
0
a
1
... a
m-1
n
は
ID
の桁の数である。
ID
の各桁には0~9の数字または忘れた桁であるということを示す'*'という文字が入る。
m
は'*'に入る数字の候補の数である。
a
i
は'*'に入る数字の候補である。
入力は以下の制約を満たす
1 ≤
n
≤ 100,000
1 ≤
m
≤ 10
0 ≤
a
i
≤ 9
1 ≤ '*'の数 ≤ 7
Output
答えの値を１行に出力せよ
Sample Input 1
5
5*57*
2
3 9
Sample Output 1
1
Sample Input 2
15
2***9*2*6*1199*
9
0 1 2 3 4 6 7 8 9
Sample Output 2
478297

Submitted solutions:

code_snippet: #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
const int maxn=100010;

int a[10]={0,2,4,6,8,1,3,5,7,9};
int choose[10];
int sum=0,sum2=0,sum3=0;
int ans=0;
int n,m;
void dfs2(int x,int ss)
{
    if(x==sum3){
        if(ss%10==0){
            ans++;
        }
        return;
    }
    for(int i=0;i<m;i++){
        dfs2(x+1,ss+choose[i]);
    }
}
void dfs(int x,int ss)
{
    if(x==sum2){
        dfs2(0,ss);
        return;
    }
    for(int i=0;i<m;i++){
        dfs(x+1,ss+a[choose[i]]);
    }
}
int main()
{
    cin>>n;
    string s;
    cin>>s;
    cin>>m;
    for(int i=0;i<m;i++) cin>>choose[i];
    int len=s.size();
    for(int i=len-1;i>=0;i--){
        if(s[i]!='*'){
            if((len-i)%2==1){
                sum+=s[i]-'0';
            }
            else sum=sum+a[s[i]-'0'];
        }
        else{
            if((len-i)%2==1){
                sum3++;
            }
            else sum2++;
        }
    }
    dfs(0,sum);
    cout<<ans<<endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3336
final_rank: 1

code_snippet: #line 2 "/home/yuruhiya/programming/library/template/template.cpp"
#include <bits/stdc++.h>
#line 6 "/home/yuruhiya/programming/library/template/constants.cpp"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
#define unless(c) if (!(c))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r)

using namespace std;
using ll = long long;
using LD = long double;
using VB = vector<bool>;
using VVB = vector<VB>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VD = vector<LD>;
using PII = pair<int, int>;
using VP = vector<PII>;
using PLL = pair<ll, ll>;
using VPL = vector<PLL>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000000;
constexpr long long inf_ll = 1000000000000000000ll, MOD = 1000000007;
constexpr long double PI = 3.14159265358979323846, EPS = 1e-12;
#line 7 "/home/yuruhiya/programming/library/template/Input.cpp"
using namespace std;

#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
class Scanner {
	static int gc() {
		return getchar_unlocked();
	}
	static char next_char() {
		char c;
		read(c);
		return c;
	}
	template <class T> static void read(T& v) {
		cin >> v;
	}
	static void read(char& v) {
		while (isspace(v = gc()))
			;
	}
	static void read(bool& v) {
		v = next_char() != '0';
	}
	static void read(string& v) {
		v.clear();
		for (char c = next_char(); !isspace(c); c = gc()) v += c;
	}
	static void read(int& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(long long& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(double& v) {
		v = 0;
		double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	static void read(long double& v) {
		v = 0;
		long double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	template <class T, class U> static void read(pair<T, U>& v) {
		read(v.first);
		read(v.second);
	}
	template <class T> static void read(vector<T>& v) {
		for (auto& e : v) read(e);
	}
	template <size_t N = 0, class T> static void read_tuple_impl(T& v) {
		if constexpr (N < tuple_size_v<T>) {
			read(get<N>(v));
			read_tuple_impl<N + 1>(v);
		}
	}
	template <class... T> static void read(tuple<T...>& v) {
		read_tuple_impl(v);
	}
	struct ReadVectorHelper {
		size_t n;
		ReadVectorHelper(size_t _n) : n(_n) {}
		template <class T> operator vector<T>() {
			vector<T> v(n);
			read(v);
			return v;
		}
	};
	struct Read2DVectorHelper {
		size_t n, m;
		Read2DVectorHelper(const pair<size_t, size_t>& nm) : n(nm.first), m(nm.second) {}
		template <class T> operator vector<vector<T>>() {
			vector<vector<T>> v(n, vector<T>(m));
			read(v);
			return v;
		}
	};

public:
	string read_line() const {
		string v;
		for (char c = gc(); c != '\n' && c != '\0'; c = gc()) v += c;
		return v;
	}
	template <class T> T read() const {
		T v;
		read(v);
		return v;
	}
	template <class T> vector<T> read_vector(size_t n) const {
		vector<T> a(n);
		read(a);
		return a;
	}
	template <class T> operator T() const {
		return read<T>();
	}
	int operator--(int) const {
		return read<int>() - 1;
	}
	ReadVectorHelper operator[](size_t n) const {
		return ReadVectorHelper(n);
	}
	Read2DVectorHelper operator[](const pair<size_t, size_t>& nm) const {
		return Read2DVectorHelper(nm);
	}
	void operator()() const {}
	template <class H, class... T> void operator()(H&& h, T&&... t) const {
		read(h);
		operator()(forward<T>(t)...);
	}

private:
	template <template <class...> class, class...> struct Multiple;
	template <template <class...> class V, class Head, class... Tail>
	struct Multiple<V, Head, Tail...> {
		template <class... Args> using vec = V<vector<Head>, Args...>;
		using type = typename Multiple<vec, Tail...>::type;
	};
	template <template <class...> class V> struct Multiple<V> { using type = V<>; };
	template <class... T> using multiple_t = typename Multiple<tuple, T...>::type;
	template <size_t N = 0, class T> void multiple_impl(T& t) const {
		if constexpr (N < tuple_size_v<T>) {
			auto& vec = get<N>(t);
			using V = typename remove_reference_t<decltype(vec)>::value_type;
			vec.push_back(read<V>());
			multiple_impl<N + 1>(t);
		}
	}

public:
	template <class... T> auto multiple(size_t h) const {
		multiple_t<T...> result;
		while (h--) multiple_impl(result);
		return result;
	}
} in;
#define inputs(T, ...) \
	T __VA_ARGS__;     \
	in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(long long, __VA_ARGS__)
#define ins(...) inputs(string, __VA_ARGS__)
#line 7 "/home/yuruhiya/programming/library/template/Output.cpp"
#include <charconv>
#line 10 "/home/yuruhiya/programming/library/template/Output.cpp"
using namespace std;

struct BoolStr {
	const char *t, *f;
	BoolStr(const char* _t, const char* _f) : t(_t), f(_f) {}
} Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0");
struct DivStr {
	const char *d, *l;
	DivStr(const char* _d, const char* _l) : d(_d), l(_l) {}
} spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"),
    no_endl(" ", "");
class Printer {
	BoolStr B{Yes};
	DivStr D{spc};

public:
	void print(int v) const {
		char buf[12]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void print(long long v) const {
		char buf[21]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void print(bool v) const {
		print(v ? B.t : B.f);
	}
	void print(vector<bool>::reference v) const {
		print(v ? B.t : B.f);
	}
	void print(char v) const {
		putchar_unlocked(v);
	}
	void print(const char* v) const {
		fwrite_unlocked(v, 1, strlen(v), stdout);
	}
	void print(double v) const {
		printf("%.20f", v);
	}
	void print(long double v) const {
		printf("%.20Lf", v);
	}
	template <class T> void print(const T& v) const {
		cout << v;
	}
	template <class T, class U> void print(const pair<T, U>& v) const {
		print(v.first);
		print(D.d);
		print(v.second);
	}
	template <class InputIterater>
	void print_range(const InputIterater& begin, const InputIterater& end) const {
		for (InputIterater i = begin; i != end; ++i) {
			if (i != begin) print(D.d);
			print(*i);
		}
	}
	template <class T> void print(const vector<T>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T, size_t N> void print(const array<T, N>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T> void print(const vector<vector<T>>& v) const {
		for (size_t i = 0; i < v.size(); ++i) {
			if (i) print(D.l);
			print(v[i]);
		}
	}

	Printer() = default;
	Printer(const BoolStr& _boolstr, const DivStr& _divstr) : B(_boolstr), D(_divstr) {}
	Printer& operator()() {
		print(D.l);
		return *this;
	}
	template <class H> Printer& operator()(H&& h) {
		print(h);
		print(D.l);
		return *this;
	}
	template <class H, class... T> Printer& operator()(H&& h, T&&... t) {
		print(h);
		print(D.d);
		return operator()(forward<T>(t)...);
	}
	template <class InputIterator>
	Printer& range(const InputIterator& begin, const InputIterator& end) {
		print_range(begin, end);
		print(D.l);
		return *this;
	}
	template <class T> Printer& range(const T& a) {
		range(a.begin(), a.end());
		return *this;
	}
	template <class... T> void exit(T&&... t) {
		operator()(forward<T>(t)...);
		std::exit(EXIT_SUCCESS);
	}
	Printer& flush() {
		fflush_unlocked(stdout);
		return *this;
	}
	Printer& set(const BoolStr& b) {
		B = b;
		return *this;
	}
	Printer& set(const DivStr& d) {
		D = d;
		return *this;
	}
	Printer& set(const char* t, const char* f) {
		B = BoolStr(t, f);
		return *this;
	}
} out;
#line 3 "/home/yuruhiya/programming/library/template/Step.cpp"
using namespace std;

template <class T> struct Step {
	using value_type = T;

	class iterator {
		value_type a, b, c;

	public:
		constexpr iterator() : a(value_type()), b(value_type()), c(value_type()) {}
		constexpr iterator(value_type _b, value_type _c, value_type _s)
		    : a(_b), b(_c), c(_s) {}
		constexpr iterator& operator++() {
			--b;
			a += c;
			return *this;
		}
		constexpr iterator operator++(int) {
			iterator tmp = *this;
			--b;
			a += c;
			return tmp;
		}
		constexpr const value_type& operator*() const {
			return a;
		}
		constexpr const value_type* operator->() const {
			return &a;
		}
		constexpr bool operator==(const iterator& i) const {
			return b == i.b;
		}
		constexpr bool operator!=(const iterator& i) const {
			return !(b == i.b);
		}
		constexpr value_type start() const {
			return a;
		}
		constexpr value_type size() const {
			return b;
		}
		constexpr value_type step() const {
			return c;
		}
	};
	constexpr Step(value_type b, value_type c, value_type s) : be(b, c, s) {}
	constexpr iterator begin() const {
		return be;
	}
	constexpr iterator end() const {
		return en;
	}
	constexpr value_type start() const {
		return be.start();
	}
	constexpr value_type size() const {
		return be.size();
	}
	constexpr value_type step() const {
		return be.step();
	}
	constexpr value_type sum() const {
		return start() * size() + step() * (size() * (size() - 1) / 2);
	}
	operator vector<value_type>() const {
		return to_a();
	}
	auto to_a() const {
		vector<value_type> result;
		result.reserve(size());
		for (auto i : *this) {
			result.push_back(i);
		}
		return result;
	}

private:
	iterator be, en;
};
template <class T> constexpr auto step(T a) {
	return Step<T>(0, a, 1);
}
template <class T> constexpr auto step(T a, T b) {
	return Step<T>(a, b - a, 1);
}
template <class T> constexpr auto step(T a, T b, T c) {
	return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c);
}
#line 8 "/home/yuruhiya/programming/library/template/Ruby.cpp"
using namespace std;

template <class F> struct Callable {
	F func;
	Callable(const F& f) : func(f) {}
};
template <class T, class F> auto operator|(const T& v, const Callable<F>& c) {
	return c.func(v);
}

struct Sort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sort_impl& c) {
		sort(begin(v), end(v));
		return v;
	}
} Sort;
struct SortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) < f(j); });
			return v;
		});
	}
} SortBy;
struct RSort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(rbegin(v), rend(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const RSort_impl& c) {
		sort(rbegin(v), rend(v));
		return v;
	}
} RSort;
struct RSortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) > f(j); });
			return v;
		});
	}
} RSortBy;
struct Reverse_impl {
	template <class T> friend auto operator|(T v, const Reverse_impl& c) {
		reverse(begin(v), end(v));
		return v;
	}
} Reverse;
struct Unique_impl {
	template <class T> friend auto operator|(T v, const Unique_impl& c) {
		v.erase(unique(begin(v), end(v), end(v)));
		return v;
	}
} Unique;
struct Uniq_impl {
	template <class T> friend auto operator|(T v, const Uniq_impl& c) {
		sort(begin(v), end(v));
		v.erase(unique(begin(v), end(v)), end(v));
		return v;
	}
} Uniq;
struct Rotate_impl {
	auto operator()(int&& left) {
		return Callable([&](auto v) {
			int s = static_cast<int>(size(v));
			assert(-s <= left && left <= s);
			if (0 <= left) {
				rotate(begin(v), begin(v) + left, end(v));
			} else {
				rotate(begin(v), end(v) + left, end(v));
			}
			return v;
		});
	}
} Rotate;
struct Max_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *max_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Max_impl& c) {
		return *max_element(begin(v), end(v));
	}
} Max;
struct Min_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *min_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Min_impl& c) {
		return *min_element(begin(v), end(v));
	}
} Min;
struct MaxPos_impl {
	template <class T> friend auto operator|(T v, const MaxPos_impl& c) {
		return max_element(begin(v), end(v)) - begin(v);
	}
} MaxPos;
struct MinPos_impl {
	template <class T> friend auto operator|(T v, const MinPos_impl& c) {
		return min_element(begin(v), end(v)) - begin(v);
	}
} MinPos;
struct MaxBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_it = begin(v);
			auto max_val = f(*max_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_it = it;
					max_val = val;
				}
			}
			return *max_it;
		});
	}
} MaxBy;
struct MinBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_it = begin(v);
			auto min_val = f(*min_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_it = it;
					min_val = val;
				}
			}
			return *min_it;
		});
	}
} MinBy;
struct MaxOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_val = val;
				}
			}
			return max_val;
		});
	}
} MaxOf;
struct MinOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_val = val;
				}
			}
			return min_val;
		});
	}
} MinOf;
struct Count_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return count(begin(v), end(v), val); });
	}
} Count;
struct CountIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return count_if(begin(v), end(v), f); });
	}
} CountIf;
struct Index_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find(begin(v), end(v), val);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
	template <class V> auto operator()(const V& val, size_t i) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find(next(begin(v), i), end(v), val);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} Index;
struct IndexIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} IndexIf;
struct FindIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<typename decltype(v)::value_type> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(*result) : nullopt;
		});
	}
} FindIf;
struct Sum_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			return accumulate(next(begin(v)), end(v), f(*begin(v)),
			                  [&](const auto& a, const auto& b) { return a + f(b); });
		});
	}
	template <class T> friend auto operator|(T v, const Sum_impl& c) {
		return accumulate(begin(v), end(v), typename T::value_type{});
	}
} Sum;
struct Includes {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return find(begin(v), end(v), val) != end(v); });
	}
} Includes;
struct IncludesIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return find_if(begin(v), end(v), f) != end(v); });
	}
} IncludesIf;
struct RemoveIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) {
			v.erase(remove_if(begin(v), end(v), f), end(v));
			return v;
		});
	}
} RemoveIf;
struct Each_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				f(i);
			}
		});
	}
} Each;
struct EachConsPair_impl {
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, EachConsPair_impl& c) {
		vector<pair<value_type, value_type>> result;
		if (size(v) >= 2) {
			result.reserve(size(v) - 1);
			for (size_t i = 0; i < size(v) - 1; ++i) {
				result.emplace_back(v[i], v[i + 1]);
			}
		}
		return result;
	}
} EachConsPair;
struct Select_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using value_type = typename decltype(v)::value_type;
			vector<value_type> result;
			for (const auto& i : v) {
				if (f(i)) result.push_back(i);
			}
			return result;
		});
	}
} Select;
struct Map_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using result_type = invoke_result_t<F, typename decltype(v)::value_type>;
			vector<result_type> result;
			result.reserve(size(v));
			for (const auto& i : v) {
				result.push_back(f(i));
			}
			return result;
		});
	}
} Map;
struct Indexed_impl {
	template <class T> friend auto operator|(const T& v, Indexed_impl& c) {
		using value_type = typename T::value_type;
		vector<pair<value_type, int>> result;
		result.reserve(size(v));
		int index = 0;
		for (const auto& i : v) {
			result.emplace_back(i, index++);
		}
		return result;
	}
} Indexed;
struct AllOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (!f(i)) return false;
			}
			return true;
		});
	}
} AllOf;
struct AnyOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return true;
			}
			return false;
		});
	}
} AnyOf;
struct NoneOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return false;
			}
			return true;
		});
	}
} NoneOf;

struct Tally_impl {
	template <class F> auto operator()(size_t max_val) {
		return Callable([&](auto v) {
			vector<size_t> result(max_val);
			for (const auto& i : v) {
				result[static_cast<size_t>(i)]++;
			}
			return result;
		});
	}
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, Tally_impl& c) {
		map<value_type, size_t> result;
		for (const auto& i : v) {
			result[i]++;
		}
		return result;
	}
} Tally;

template <class T> auto operator*(const vector<T>& a, size_t n) {
	T result;
	for (size_t i = 0; i < n; ++i) {
		result.insert(result.end(), a.begin(), a.end());
	}
	return result;
}
auto operator*(string a, size_t n) {
	string result;
	for (size_t i = 0; i < n; ++i) {
		result += a;
	}
	return result;
}
template <class T, class U> auto& operator<<(vector<T>& a, const U& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T> auto& operator<<(string& a, const T& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T, class U> auto operator+(vector<T> a, const U& b) {
	a << b;
	return a;
}
template <class T> auto operator+(string a, const T& b) {
	a << b;
	return a;
}
#line 7 "/home/yuruhiya/programming/library/template/functions.cpp"
using namespace std;

template <class T = long long> constexpr T TEN(size_t n) {
	T result = 1;
	for (size_t i = 0; i < n; ++i) result *= 10;
	return result;
}
template <class T, class U,
          enable_if_t<is_integral_v<T> && is_integral_v<U>, nullptr_t> = nullptr>
constexpr auto div_ceil(T n, U m) {
	return (n + m - 1) / m;
}
template <class T, class U> constexpr auto div_ceil2(T n, U m) {
	return div_ceil(n, m) * m;
}
template <class T> constexpr T triangle(T n) {
	return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1);
}
template <class T> constexpr T nC2(T n) {
	return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1);
}
template <class T, class U> constexpr auto middle(const T& l, const U& r) {
	return l + (r - l) / 2;
}
template <class T, class U, class V>
constexpr bool in_range(const T& v, const U& lower, const V& upper) {
	return lower <= v && v < upper;
}
template <class T, enable_if_t<is_integral_v<T>, nullptr_t> = nullptr>
constexpr bool is_square(T n) {
	T s = sqrt(n);
	return s * s == n || (s + 1) * (s + 1) == n;
}
template <class T = long long> constexpr T BIT(int b) {
	return T(1) << b;
}
template <class T> constexpr int BIT(T x, int i) {
	return (x & (T(1) << i)) ? 1 : 0;
}
template <class T> constexpr int Sgn(T x) {
	return (0 < x) - (0 > x);
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Pow(T a, U n) {
	assert(n >= 0);
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result *= a;
			n--;
		} else {
			a *= a;
			n >>= 1;
		}
	}
	return result;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Powmod(T a, U n, T mod) {
	assert(n >= 0);
	if (a > mod) a %= mod;
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result = result * a % mod;
			n--;
		} else {
			a = a * a % mod;
			n >>= 1;
		}
	}
	return result;
}
template <class T> bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> int sz(const T& v) {
	return v.size();
}
template <class T, class U> int lower_index(const T& a, const U& v) {
	return lower_bound(all(a), v) - a.begin();
}
template <class T, class U> int upper_index(const T& a, const U& v) {
	return upper_bound(all(a), v) - a.begin();
}
template <class T> auto Slice(const T& v, size_t i, size_t len) {
	return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size())) : T();
}
template <class T, class U = typename T::value_type> U Gcdv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), gcd<U, U>);
}
template <class T, class U = typename T::value_type> U Lcmv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), lcm<U, U>);
}
namespace internal {
	template <class T, size_t N> auto make_vector(vector<int>& sizes, const T& init) {
		if constexpr (N == 1) {
			return vector(sizes[0], init);
		} else {
			int size = sizes[N - 1];
			sizes.pop_back();
			return vector(size, make_vector<T, N - 1>(sizes, init));
		}
	}
}  // namespace internal
template <class T, size_t N>
auto make_vector(const int (&sizes)[N], const T& init = T()) {
	vector s(rbegin(sizes), rend(sizes));
	return internal::make_vector<T, N>(s, init);
}
#line 9 "/home/yuruhiya/programming/library/template/template.cpp"
#if __has_include(<library/dump.hpp>)
#include <library/dump.hpp>
#define LOCAL
#else
#define dump(...) ((void)0)
#endif

template <class T> constexpr T oj_local(const T& oj, const T& local) {
#ifndef LOCAL
	return oj;
#else
	return local;
#endif
}
#line 2 "a.cpp"

template <class T, class F, class value_type = typename T::value_type>
void each_repeated_permutation(const T& array, size_t count, F f) {
	vector<value_type> permutation(count);
	auto dfs = [&](auto self, size_t size) -> void {
		if (size == count) {
			f(permutation);
		} else {
			for (const auto& i : array) {
				permutation[size] = i;
				self(self, size + 1);
			}
		}
	};
	dfs(dfs, 0);
}

int main() {
	ini(n);
	auto s = in.read<string>() |
	    Map([&](char c) { return c == '*' ? nullopt : optional(c - '0'); }) | Reverse;
	int sum = s | Indexed | Sum([&](auto p) {
		          auto [v, i] = p;
		          return v ? (*v * (i % 2 ? 2 : 1) - 1) % 9 + 1 : 0;
	          });
	ini(m);
	VI a = in[m];
	VI b = s | Indexed | Select([&](auto p) { return !p.first; }) |
	    Map([&](auto p) { return p.second % 2 ? 2 : 1; });

	dump(a, b);
	int ans = 0;
	each_repeated_permutation(a, b.size(), [&](const auto& perm) {
		int sum2 = 0;
		rep(i, sz(b)) {
			sum2 += (perm[i] * b[i] - 1) % 9 + 1;
		}
		ans += (sum + sum2) % 10 == 0;
	});
	out(ans);
}
accuracy: 1
time_ms: 130
memory_kb: 6216
final_rank: 11

code_snippet: #include <stdio.h>
int combination(int ,int ,int*);
int fact(int);
int nest(int ,int ,int ,int* ,int* ,int*);

int main(void) {
    int i;
	int n;
	char s;
	int ID;
	int sum=0;
	int odd_num = 0;
	int even_num = 0;
	scanf("%d",&n);
	scanf("%c",&s);
	for(i=0;i<n;i++){
		scanf("%c",&s);
	    if(s != '*')ID = s-'0';
	    else ID = -1;
		//ID=(s!='*')?(int)(s-'0'):-1;
		if(ID>-1){
			if(i % 2){
				if(ID > 5)sum += ID*2-9;
				else sum += ID*2;
			}else sum += ID;
		}else if(i % 2)even_num++;
		else odd_num++;
	}//printf("%d\n",sum);
	int m;
	scanf("%d",&m);
	int cand[10];
	for(i=0;i<m;i++)scanf("%d",&cand[i]);
	
	//printf("%d %d %d\n",odd_num,even_num,m);
	int odd_result;
	int even_result;
	int odd_sum=0;
	int even_sum=0;
	int consist_count = 0;
	int odd_ID_puttern[10];
	int even_ID_puttern[10];
	int dup_data[10] = {0};
	
	while((odd_result = nest(0,odd_num,m,cand,odd_ID_puttern,dup_data))+1){
		for(int i=0;i<odd_num;i++)odd_sum += odd_ID_puttern[i];
		odd_result = combination(odd_num,odd_result,dup_data);//printf("%d\n",odd_result);
		while((even_result = nest(1,even_num,m,cand,even_ID_puttern,dup_data))+1){
			for(int j=0;j<even_num;j++)even_sum += (even_ID_puttern[j] < 5)?2*even_ID_puttern[j]:2*even_ID_puttern[j]-9;
			even_result = combination(even_num,even_result,dup_data);//printf("%d\n",even_result);
			if(!((sum+odd_sum+even_sum)%10)){/*
				for(int k=0;k<odd_num;k++)printf("%d ",odd_ID_puttern[k]);printf(" ");
				for(int k=0;k<even_num;k++)printf("%d ",even_ID_puttern[k]);printf("\n");*/
			    consist_count++;// += (odd_result * even_result);
			}
				//for(int k=0;k<odd_num;k++)printf("%d ",odd_ID_puttern[k]);printf(" ");
				//for(int k=0;k<even_num;k++)printf("%d ",even_ID_puttern[k]);printf("\n");
			even_sum=0;
		}
		odd_sum=0;
	}
	printf("%d\n",consist_count);
	return 0;
}

int combination(int column ,int dup_num ,int *dup){
	int i,dup_val = 1;
	for(i=0;i<dup_num;i++)dup_val *= fact(dup[i]);
	//if(!(fact(column)/dup_val))printf("%d %d\n",column,dup[0]);
	return fact(column)/dup_val;
}

int fact(int num){
	int i,val=1;
	for(i=0;i<num;i++)val *= num-i;
	
	return val;
}

int nest(int adds ,int frame ,int cand_num ,int *cand ,int *ID_puttern ,int *dup_data){
	int i,s,c;
	static int combi_phase[2] = {0};
	static int ID_select[10][2] = {0};
	static int duplication[10][2] = {0};
    c=0;
    //for(i=0;i<4;i++)dup_data[i] = 0;
	while(c++<10000){
		if(ID_select[0][adds] >= cand_num){
			combi_phase[adds] = 0;
			for(i=0;i<8;i++)ID_select[i][adds] = 0;
			return -1;
		}
		//printf("%d\n",combi_phase[adds]);
		if(ID_select[combi_phase[adds]][adds] < cand_num){
			duplication[ID_select[combi_phase[adds]][adds]][adds]++;
			ID_puttern[combi_phase[adds]] = cand[ID_select[combi_phase[adds]][adds]];
			if(combi_phase[adds] != frame-1){
				ID_select[combi_phase[adds]+1][adds] = 0;
				//ID_select[combi_phase[adds]+1][adds] = ID_select[combi_phase[adds]][adds];
				combi_phase[adds]++;
			}else {
				//printf("%d[0] %d[1] %d[2] ",ID_select[0][adds],ID_select[1][adds],ID_select[2][adds]);
				/*for(i=0;i<frame;i++)printf("%d ",ID_puttern[i]);
				printf("\n");*/
				for(i=0,s=0;i<cand_num;i++){
					if(duplication[i][adds] > 1){
						dup_data[s++] = duplication[i][adds];
						//printf("%d ",duplication[i]);
					}
				}
				//printf("\n%d\n",s);
				duplication[ID_select[combi_phase[adds]][adds]++][adds]--;
				//ID_select[combi_phase[adds]][adds]++;
				//duplication[ID_select[combi_phase[adds]][adds]++]++;
				//if(s>=frame)printf("%d\n",s);
				return s;
			}
		}else{
			combi_phase[adds]--;
			duplication[ID_select[combi_phase[adds]][adds]++][adds]--;
			//ID_select[combi_phase[adds]][adds]++;
		}
	}
	return -2;
}
accuracy: 0.6363636363636364
time_ms: 140
memory_kb: 2688
final_rank: 15

code_snippet: #include <stdio.h>
int combination(int ,int ,int*);
int fact(int);
int nest(int ,int ,int ,int* ,int* ,int*);

int main(void) {
    int i;
	int n;
	char s;
	int ID;
	int sum=0;
	int odd_num = 0;
	int even_num = 0;
	scanf("%d",&n);
	scanf("%c",&s);
	for(i=0;i<n;i++){
		scanf("%c",&s);
	    if(s != '*')ID = s-'0';
	    else ID = -1;
		//ID=(s!='*')?(int)(s-'0'):-1;
		if(ID>-1){
			if(i % 2){
				if(ID > 5)sum += ID*2-9;
				else sum += ID*2;
			}else sum += ID;
		}else if(i % 2)even_num++;
		else odd_num++;
	}//printf("%d\n",sum);
	int m;
	scanf("%d",&m);
	int cand[10];
	for(i=0;i<m;i++)scanf("%d",&cand[i]);
	
	//printf("%d %d %d\n",odd_num,even_num,m);
	int odd_result;
	int even_result;
	int odd_sum=0;
	int even_sum=0;
	int consist_count = 0;
	int odd_ID_puttern[10];
	int even_ID_puttern[10];
	int dup_data[10] = {0};
	
	while((odd_result = nest(0,odd_num,m,cand,odd_ID_puttern,dup_data))+1){
		for(int i=0;i<odd_num;i++)odd_sum += odd_ID_puttern[i];
		odd_result = combination(odd_num,odd_result,dup_data);//printf("%d\n",odd_result);
		while((even_result = nest(1,even_num,m,cand,even_ID_puttern,dup_data))+1){
			for(int j=0;j<even_num;j++)even_sum += (even_ID_puttern[j] < 5)?2*even_ID_puttern[j]:2*even_ID_puttern[j]-9;
			even_result = combination(even_num,even_result,dup_data);//printf("%d\n",even_result);
			if(!((sum+odd_sum+even_sum)%10))consist_count++;// += (odd_result * even_result);
			even_sum=0;
		}
		odd_sum=0;
	}
	printf("%d\n",consist_count);
	return 0;
}

int combination(int column ,int dup_num ,int *dup){
	int i,dup_val = 1;
	for(i=0;i<dup_num;i++)dup_val *= fact(dup[i]);
	//if(!(fact(column)/dup_val))printf("%d %d\n",column,dup[0]);
	return fact(column)/dup_val;
}

int fact(int num){
	int i,val=1;
	for(i=0;i<num;i++)val *= num-i;
	
	return val;
}

int nest(int adds ,int frame ,int cand_num ,int *cand ,int *ID_puttern ,int *dup_data){
	int i,s,c;
	static int combi_phase[2] = {0};
	static int ID_select[10][2] = {0};
	static int duplication[10][2] = {0};
    c=0;
    //for(i=0;i<4;i++)dup_data[i] = 0;
	while(c++<10000){
		if(ID_select[0][adds] >= cand_num){
			combi_phase[adds] = 0;
			for(i=0;i<8;i++)ID_select[i][adds] = 0;
			return -1;
		}
		//printf("%d\n",combi_phase[adds]);
		if(ID_select[combi_phase[adds]][adds] < cand_num){
			duplication[ID_select[combi_phase[adds]][adds]][adds]++;
			ID_puttern[combi_phase[adds]] = cand[ID_select[combi_phase[adds]][adds]];
			if(combi_phase[adds] != frame-1){
				ID_select[combi_phase[adds]+1][adds] = 0;
				//ID_select[combi_phase[adds]+1][adds] = ID_select[combi_phase[adds]][adds];
				combi_phase[adds]++;
			}else {
				//printf("%d[0] %d[1] %d[2] ",ID_select[0][adds],ID_select[1][adds],ID_select[2][adds]);
				/*for(i=0;i<frame;i++)printf("%d ",ID_puttern[i]);
				printf("\n");*/
				for(i=0,s=0;i<cand_num;i++){
					if(duplication[i][adds] > 1){
						dup_data[s++] = duplication[i][adds];
						//printf("%d ",duplication[i]);
					}
				}
				//printf("\n%d\n",s);
				duplication[ID_select[combi_phase[adds]][adds]++][adds]--;
				//ID_select[combi_phase[adds]][adds]++;
				//duplication[ID_select[combi_phase[adds]][adds]++]++;
				//if(s>=frame)printf("%d\n",s);
				return s;
			}
		}else{
			combi_phase[adds]--;
			duplication[ID_select[combi_phase[adds]][adds]++][adds]--;
			//ID_select[combi_phase[adds]][adds]++;
		}
	}
	return -2;
}
accuracy: 0.6363636363636364
time_ms: 140
memory_kb: 2736
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using namespace std;

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int n;
int m;
string id;
int a[11];

ll ans = 0;
ll tmp = 0;

vector<pair<ll, ll>> vvv;

void solve(int k, ll sum) {
    if (k >= vvv.size()) {
        if ((sum + tmp) % 10 == 0) ans++;
        return;
    }

    int i = vvv[k].first;
    if (i%2) {
        // 2倍
        for (int j=0; j<m; ++j) {
            ll tmpv = a[j] * 2;
            while (tmpv >= 10) {
                tmpv = tmpv / 10 + tmpv % 10;
            }
            solve(k + 1, sum + tmpv);
        }
    }
    else {
        for (int j = 0; j < m; ++j) {
            ll tmpv = a[j];
            solve(k + 1, sum + tmpv);
        }
    }
    return;
}

int main() {
    cin >> n;
    cin >> id;
    cin >> m;
    rep(i, m) cin >> a[i];
    reverse(id.begin(), id.end());
    rep(i, id.size()) {
        if (id[i] == '*') {
            vvv.emplace_back(i, id[i]-'0');
            continue;
        }
        if (i%2) {
            ll k = (id[i] - '0') * 2;
            while (k >= 10) {
                k = k/10 + k%10;
            }
            tmp += k;
        }
        else {
            tmp += (id[i] - '0');
        }
    }
    //cerr << tmp << endl;
    solve(0, 0);
    cout << ans << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3292
final_rank: 3

code_snippet: #include<iostream>
#include<string.h>
#include<vector>

using namespace std;

int asterisk(int c, int g, int t, int s, int eAst, int* a, int m);

int main(void) {
    
    int n;
    string id;
    int m;
    vector<int> a;

    cin >> n;
    cin >> id;
    cin >> m;
    for (int i=0;i<m;i++) {
        int t;
        cin >> t;
        a.push_back(t);
    }

    int sum = 0;
    int oAst = 0;
    int eAst = 0;
    for (int i=0;i<id.length();i++) {
        if (id[i] == '*') {
            if (i%2 == 0) {
                oAst++;
            } else {
                eAst++;
            }
        } else {
            if (i%2 == 0) {
                sum += (id[i] - '0');
            } else {
                if ((id[i] - '0') > 4) {
                    sum += 1 + (id[i]-'0')+(id[i]-'0')-10;
                } else {
                    sum += (id[i]-'0')+(id[i]-'0');
                }
            }
        }
    }

    int t = (10 - (sum % 10)) % 10;
    // cout << sum << endl;
    // cout << t << endl;
    cout << asterisk(1, eAst+oAst, t, 0, eAst, &a.front(), m) << endl;

    return 0;
}

int asterisk(int c, int g, int t, int s, int eAst, int* a, int m) {
    if (c == g) {
        int sum = 0;
        for (int i=0;i<m;i++) {
            // for (int o=0;o<c;o++) cout << " ";
            // cout << a[i] << endl;
            if (c <= eAst) {
                if (a[i] > 4) {
                    if ((s + 1 + a[i] + a[i]) % 10 == t) {
                        sum++;
                        // cout << "catch!" << endl;
                    }
                } else {
                    if ((s + a[i] + a[i]) % 10 == t) {
                        sum++;
                        // cout << "catch!" << endl;
                    }
                }
            } else {
                if ((s + a[i]) % 10 == t) {
                    sum++;
                    // cout << "catch!" << endl;
                }
            }
        }
        return sum;
    } else {
        int sum = 0;
        for (int i=0;i<m;i++) {
            // for (int o=0;o<c;o++) cout << " ";
            // cout << a[i] << endl;
            if (c <= eAst) {
                if (a[i] > 4) {
                    sum += asterisk(c+1, g, t, (s+1+a[i]+a[i])%10, eAst, a, m);
                } else {
                    sum += asterisk(c+1, g, t, (s+a[i]+a[i])%10, eAst, a, m);
                }
            } else {
                sum += asterisk(c+1, g, t, (s+a[i])%10, eAst, a, m);
            }   
        }
        return sum;
    }
}
accuracy: 0.6363636363636364
time_ms: 20
memory_kb: 3324
final_rank: 13

code_snippet: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    reverse(all(s));
    int m;
    cin >> m;
    vi v(m);
    rep(i,m)cin >> v[i];
    vector<vi> dp(n+1,vi(10,0));
    //i桁目まで見て総和%10がjのときの通り数
    dp[0][0] = 1;
    rep(i,n)rep(j,10)if(dp[i][j]){
        //cout << i << " " << j << " " << dp[i][j] << endl;
        if(s[i] == '*'){
            rep(k,m){
                int ne = v[k];
                if(i%2) ne *= 2;
                ne = ne%10 + ne/10;
                //cout << " " << k << " " << j+ne << endl;
                dp[i+1][(j+ne)%10] += dp[i][j];
            }
        }else{
            int ne = s[i] - '0';
            if(i%2) ne *= 2;
            ne = ne%10 + ne/10;
            dp[i+1][(j+ne)%10] += dp[i][j];
        }
    }

    cout << dp[n][0] << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 14752
final_rank: 7

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int compress(int x){
    while(x > 9){
        int tmp = 0;
        while(x > 0)    tmp += x % 10, x /= 10;
        x = tmp;
    }
    return x;
}

int n, m;
string s;
vector<int> bias, use;
int sum = 0, cnt = 0, ans = 0;

void dfs(int pos, int accum){
    if(pos == cnt){
        if(accum % 10 == 0) ans++;
        return;
    }

    for(int i = 0; i < m; i++){
        dfs(pos+1, accum + compress(bias[pos] * use[i]));
    }
}

int main(){
    cin >> n >> s >> m;
    reverse(s.begin(), s.end());
    
    for(int i = 0; i < n; i++){
        if(s[i] == '*') bias.push_back(1 + i%2), cnt++;
        else            sum += compress((1+i%2)*(s[i]-'0'));
    }

    int a;
    for(int i = 0; i < m; i++){
        cin >> a;
        use.push_back(a);
    }

    dfs(0, sum);

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3320
final_rank: 6

code_snippet: #include<iostream>
#include<vector>
#include<set>
using namespace std;

int compress(int x){
    if(x > 9)   x = x/10 + x%10;
    return x;
}

int n, m;
string id;
vector<int> bias, use;
int sum = 0, cnt = 0;
set<int> s;

void dfs(int pos, int accum, int pat){
    if(pos == cnt){
        if(accum % 10 == 0) s.insert(pat);
        return;
    }

    for(int i = 0; i < m; i++){
        dfs(pos+1, accum+compress(bias[pos]*use[i]), 10*pat+use[i]);
    }
}

int main(){
    cin >> n >> id >> m;
    
    for(int i = 0; i < n; i++){
        if(id[i] == '*') bias.push_back(1 + i%2), cnt++;
        else             sum += compress((1+i%2)*(id[i]-'0'));
    }

    int a;
    for(int i = 0; i < m; i++){
        cin >> a;
        use.push_back(a);
    }

    dfs(0, sum, 0);

    cout << s.size() << endl;

    return 0;
}
accuracy: 0.6363636363636364
time_ms: 300
memory_kb: 49948
final_rank: 19

code_snippet: #include<iostream>
#include<vector>
using namespace std;

int compress(int x){
    while(x > 9){
        int tmp = 0;
        while(x > 0)    tmp += x % 10, x /= 10;
        x = tmp;
    }
    return x;
}

int n, m;
string s;
vector<int> bias, use;
int sum = 0, cnt = 0, ans = 0;

void dfs(int pos, int accum){
    if(pos == cnt){
        if(accum % 10 == 0) ans++;
        return;
    }

    for(int i = 0; i < m; i++){
        dfs(pos+1, accum + compress(bias[pos] * use[i]));
    }
}

int main(){
    cin >> n >> s >> m;
    
    for(int i = 0; i < n; i++){
        if(s[i] == '*') bias.push_back(1 + i%2), cnt++;
        else            sum += compress((1+i%2)*(s[i]-'0'));
    }

    int a;
    for(int i = 0; i < m; i++){
        cin >> a;
        use.push_back(a);
    }

    dfs(0, sum);

    cout << ans << endl;

    return 0;
}
accuracy: 0.6363636363636364
time_ms: 40
memory_kb: 3324
final_rank: 14

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

vector<int> unknown;
int sum;
int m;
int solve(int even, int odd){
  int res = sum;
  for(int i = 0; i < even; i++){
    int v = 2 * unknown[i];
    int adding = 0;
    if(v >= 10){
      adding += v%10;
      v /= 10;
      adding  += v%10;
      res += adding;
    }else{
      res+=v;
    }

    res %= 10;
  }
  for(int i = even; i < odd+even; i++){
    res += unknown[i];
    res %= 10;
  }
  return res%10 == 0;
}

int main(void){
  int n;
  cin >> n;
  int odd = 0, even = 0;
  string str;
  cin >> str;

  sum = 0;

  for(int i = 1; i <= n; i++){
    char c = str[n-i];
    if(c == '*'){
      if(i % 2 == 0) even++;
      if(i % 2 == 1) odd++;
    }else{
      int v = c - '0';
      if(i % 2 == 1)
        sum += v;
      else{
        v *= 2;
        if(v >= 10){
          sum += v%10;
          v /= 10;
          sum += v%10;
        }else{
          sum += v;
        }
      }
      sum %= 10;
    }
  }

  unknown = vector<int>(even + odd);

  cin >> m;
  vector<int> a(m);
  for(int i = 0; i < m; i++) cin >> a[i];

  int cnt = even + odd;
  int ans = 0;


  for(int i1 = 0; i1 < m; i1++){
    unknown[0] = a[i1];
    if(cnt == 1){
      ans += solve( even, odd);
      continue;
    }
    for(int i2 = 0; i2 < m; i2++){
      unknown[1] = a[i2];
      if(cnt == 2){

        ans += solve( even, odd);
        continue;
      }
      for(int i3 = 0; i3 < m; i3++){
        unknown[2] = a[i3];
        if(cnt == 3){
          ans += solve( even, odd);
          continue;

        }
        for(int i4 = 0; i4 < m; i4++){
          unknown[3] = a[i4];
          if(cnt == 4){
            ans += solve( even, odd);
            continue;

          }
          for(int i5 = 0; i5 < m; i5++){
            unknown[4] = a[i5];
            if(cnt == 5){
              ans += solve( even, odd);
              continue;

            }
            for(int i6 = 0; i6 < m; i6++){
              unknown[5] = a[i6];
              if(cnt == 6){
                ans += solve( even, odd);
                continue;

              }
              for(int i7 = 0; i7 < m; i7++){
                unknown[6] = a[i7];
                ans += solve( even, odd);
              }
            }
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 3268
final_rank: 12

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

int n;
string ID;
int m;
vector<int> a, b;
int64_t dp[133333][10];

int64_t dfs(int idx, int sum) {
  if (idx == b.size()) {
    return sum == 0;
  }

  int64_t res = 0;
  for (int i = 0; i < a.size(); ++i) {
    int x = a[i];
    if (b[idx]) {
      x *= 2;
      x = x % 10 + x / 10;
    }
    res += dfs(idx + 1, (sum + x) % 10);
  }

  return res;
}

signed main(int argc, char *argv[]) {
  memset(dp, -1, sizeof(dp));
  cin >> n >> ID >> m;
  a.resize(m);
  cin >> a;

  reverse(all(ID));
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    if (ID[i] == '*') {
      b.pb(i & 1);
      continue;
    }
    int x = ID[i] - '0';
    if (i & 1) {
      x *= 2;
      x = x % 10 + x / 10;
    }
    sum += x;
  }
  sum %= 10;
  cout << dfs(0, sum) << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 13752
final_rank: 8

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

int ans, d[11], n, m, num[11], cnt, S, c;
string s;

bool check(){
  
  int sum=0;
  
  for(int i=0;i<cnt;i++){
    
    int di=d[i];
    
    if(i<c) di*=2;
    
    if(di>=10) di=di%10+di/10;

    sum+=di;
  }

  return (sum+S)%10==0;
}

void dfs(int x){
  
  if(x==cnt){
    
    if(check()) ans++;

    return;
  }
  
  for(int i=0;i<m;i++){
    d[x]=num[i];
    dfs(x+1);
  }
  
}

int main(){

  cin>>n;
  
  cin>>s;
  
  reverse(s.begin(), s.end());
  
  for(int i=0;i<n;i++)
    if(s[i]=='*'){
      cnt++;
      if(i%2) c++;
    }

  for(int i=0;i<n;i++){
    if(s[i]=='*') continue;
    int t=s[i]-'0';
    if(i%2) t*=2;
    if(t>=10) t=t%10+t/10;
    S+=t;
  }  
  
  cin>>m;
  
  for(int i=0;i<m;i++) cin>>num[i];
  
  dfs(0);

  cout<<ans<<endl;
  
  return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3304
final_rank: 10

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

int ans, d[11], n, m, num[11], cnt;
string s;

bool check(){
  
  int idx=0;
  
  int cp[11];

  for(int i=0;i<n;i++){
    if(s[i]=='*') cp[i]=d[idx++];
    else cp[i]=s[i]-'0';
  }
  
  int sum=0;
  
  for(int i=0;i<n;i++){
    if(i%2) cp[i]*=2;
    if(cp[i]>=10) cp[i]=cp[i]%10+cp[i]/10;
    sum+=cp[i];
  }

  return sum%10==0;
}

void dfs(int x){
  
  if(x==cnt){
    
    if(check()) ans++;

    return;
  }
  
  for(int i=0;i<m;i++){
    d[x]=num[i];
    dfs(x+1);
  }
  
}

int main(){

  cin>>n;
  
  cin>>s;
  
  reverse(s.begin(), s.end());

  for(int i=0;i<n;i++)
    if(s[i]=='*') cnt++;
  
  cin>>m;
  
  for(int i=0;i<m;i++) cin>>num[i];
  
  dfs(0);

  cout<<ans<<endl;
  
  return 0;
}
accuracy: 0.18181818181818182
time_ms: 170
memory_kb: 3192
final_rank: 20

code_snippet: #include <iostream>
#include <cstdlib>

using namespace std;

int n = 0;
int even[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};
int edigit = 0;
int odigit = 0;
int sum = 0;
char ID[100001];
int m = 0;
int a[10];
int answer = 0;

int dfs(int depth, int _sum) {
    int count = 0;
    if (depth < edigit) {
        for (int i = 0; i < m; i++) count += dfs(depth+1, _sum+even[a[i]]);
    } else if (depth < edigit + odigit) {
        for (int i = 0; i < m; i++) count += dfs(depth+1, _sum+a[i]);
    } else if ((sum+_sum) % 10 == 0) count = 1;

    return count;
}

int main() {
    cin>>n;
    cin>>ID;
    for (int i = 0; i < n; i++) {
        char str[2] = {ID[i], '\0'};
        if (ID[i] == '*') (n-i) % 2 == 0 ? edigit++: odigit++;
        else (n-i) % 2 == 0 ? sum += even[atoi(str)] : sum += atoi(str);
    }
    sum %= 10;
    cin>>m;
    for (int i = 0; i < m; i++) cin>>a[i];
    cout<<dfs(0, 0)<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3180
final_rank: 2

code_snippet: #include<iostream>
#include<string>
#include<vector>
using namespace std;
long long cnt=0;
void dfs(int sum,int md,int a[],int depth,vector<int> point,int m){
  if(depth==md){
    if(sum%10==0)
      cnt++;
    return;
  }
  for(int i=0;i<m;i++){
    if(point[depth]==0){
      if((a[i]*2)/10)
	dfs((sum+((a[i]*2)/10)+((a[i]*2)%10)),point.size(),a,depth+1,point,m);
      else
	dfs((sum+(a[i]*2)),point.size(),a,depth+1,point,m);
    }else
      dfs((sum+a[i]),point.size(),a,depth+1,point,m);
  }
}
int main(){
  int s;
  cin>>s;
  string str;
  cin>>str;
  int m;
  cin>>m;
  int a[m];
  for(int i=0;i<m;i++)
    cin>>a[i];
  int k=0;
  int sum=0;
  vector<int> point;
  for(int i=str.size()-1;i>=0;i--){
    if(str[i]=='*'){
      k++;
      point.push_back(k%2);
    }else{
      if((++k)%2==0){
	int num=(str[i]-'0')*2;
	if(num/10)
	  sum+=((num/10)+(num%10));
      }else
	sum+=str[i]-'0';
    }
  }
  for(int i=0;i<m;i++){
    if(point[0]==0){
      if((a[i]*2)/10)
	dfs((sum+((a[i]*2)/10)+((a[i]*2)%10)),point.size(),a,1,point,m);
      else
	dfs((sum+(a[i]*2)),point.size(),a,1,point,m);
    }else
      dfs((sum+a[i]),point.size(),a,1,point,m);
  }
  cout<<cnt<<endl;
  return 0;
}
accuracy: 0.6363636363636364
time_ms: 320
memory_kb: 3196
final_rank: 17

code_snippet: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_map>
#include<string.h>
using namespace std;

vector<int>d;
vector<int>e;
int sum;
int ans;
int a;
void saiki(int o, int b) {
	if (o == e.size()) {
		if (((sum + b) % 10) == 0) {
			ans++;
		}
		return;
	}
	if (e[o]) {//??????
		for (int i = 0; i < d.size(); i++) {
			int K = d[i];
			K *= 2;
			if (K >= 10)K = K % 10 + 1;
			saiki(o + 1, b + K);
		}
	}
	else{
		for (int i = 0; i < d.size(); i++) {
			saiki(o + 1, b + d[i]);
		}
	}
}
signed main() {
	scanf("%d", &a);
	string b; cin >> b;
	int c; scanf("%d", &c);
	for (int e = 0; e < c; e++) {
		int f;scanf("%d", &f);
		d.push_back(f);
	}
	reverse(b.begin(), b.end());
	for (int i = 0; i < b.length(); i++) {
		if (b[i] == '*')e.push_back(i & 1);
		else {
			if (i & 1) {
				int f = b[i] - '0';
				f *= 2;
				if (f >= 10)f = f % 10 + 1;
				sum += f;
			}
			else {
				sum += b[i] - '0';
			}
		}
	}
	saiki(0, 0);
	printf("%d\n", ans);
}
accuracy: 1
time_ms: 30
memory_kb: 3400
final_rank: 4

code_snippet: #include<iostream>
#include<string>
#include<vector>
using namespace std;
int cnt=0;
void dfs(int sum,int md,int a[],int depth,vector<int> point,int m){
  if(depth==md){
    if(sum%10==0)
      cnt++;
    return;
  }
  for(int i=0;i<m;i++){
    if(point[depth]==0){
      if((a[i]*2)/10)
	dfs((sum+((a[i]*2)/10)+((a[i]*2)%10)),point.size(),a,depth+1,point,m);
      else
	dfs((sum+(a[i]*2)),point.size(),a,depth+1,point,m);
    }else
      dfs((sum+a[i]),point.size(),a,depth+1,point,m);
  }
}
int main(){
  int s;
  cin>>s;
  string str;
  cin>>str;
  int m;
  cin>>m;
  int a[m];
  for(int i=0;i<m;i++)
    cin>>a[i];
  int k=0;
  int sum=0;
  vector<int> point;
  for(int i=str.size()-1;i>=0;i--){
    if(str[i]=='*'){
      k++;
      point.push_back(k%2);
    }else{
      if((++k)%2==0){
	int num=(str[i]-'0')*2;
	if(num/10)
	  sum+=((num/10)+(num%10));
      }else
	sum+=str[i]-'0';
    }
  }
  for(int i=0;i<m;i++){
    if(point[0]==0){
      if((a[i]*2)/10)
	dfs((sum+((a[i]*2)/10)+((a[i]*2)%10)),point.size(),a,1,point,m);
      else
	dfs((sum+(a[i]*2)),point.size(),a,1,point,m);
    }else
      dfs((sum+a[i]),point.size(),a,1,point,m);
  }
  cout<<cnt<<endl;
  return 0;
}
accuracy: 0.6363636363636364
time_ms: 320
memory_kb: 3280
final_rank: 18

code_snippet: #include<iostream>
#include<vector>
using namespace std;
vector<vector<int> > dp;
int n;
int m;
vector<bool> line;
vector<int> chance;
int search(int, int);
int main() {
	cin >> n;
	int num = 0;
	char du;
	line.resize(n);
	dp.resize(n);
	for (int i = 0; i < n; ++i) {
		dp[i].resize(10);
		for (int j = 0; j < 10; ++j) {
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < n; ++i) {
		cin >> du;
		if (du == '*') {
			line[i] = true;
		}
		else {
			int ca = du - '0';
			line[i] = false;
			if ((n - i) % 2 == 0) {
				num += (ca * 2) / 10 + (ca * 2) % 10;
			}
			else {
				num += ca;
			}
		}
	}
	cin >> m;
	chance.resize(m);
	for (int i = 0; i < m; ++i) {
		cin >> chance[i];
	}
	cout << search(0, num % 10) << endl;
	return 0;
}
int search(int np, int nn) {
	if (np == n) {
		if (nn == 0)return 1;
		else return 0;
	}
	if (dp[np][nn] > -1)return dp[np][nn];
	int res = 0;
	if (line[np]) {
		for (int i = 0; i < m; ++i) {
			if ((n - np) % 2 == 0) {
				res += search(np + 1, (nn + (chance[i] * 2) / 10 + (chance[i] * 2) % 10) % 10);
			}
			else {
				res += search(np + 1, (nn + chance[i]) % 10);
			}
		}
	}
	else {
		res = search(np + 1, nn);
	}
	dp[np][nn] = res;
	return res;
}
accuracy: 1
time_ms: 20
memory_kb: 17564
final_rank: 9

code_snippet: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int a[20], pos[10];
int n, m, cnt = 0;
int ans = 0, sum = 0;

void dfs(int size, int Sum) {
	if (size == cnt) {
		if ((sum + Sum) % 10 == 0)ans++;
		return;
	}
	rep(i, m) {
		if (pos[size] % 2 == 1)
			dfs(size + 1, Sum + a[i] * 2 % 10 + a[i] * 2 / 10);
		else dfs(size + 1, Sum + a[i]);
	}
}
int main() {
	string id;
	cin >> n >> id >> m;
	rep(i, m)scanf("%d", &a[i]);
	rep(i, n) {
		if (id[i] == '*')pos[cnt++] = n - i - 1;
		else if ((n - i - 1) % 2 == 1)
			sum += (id[i] - '0') * 2 % 10 + (id[i] - '0') * 2 / 10;
		else sum += id[i] - '0';
	}
	dfs(0, 0);
	printf("%d\n", ans);
}
accuracy: 1
time_ms: 30
memory_kb: 3456
final_rank: 5