#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll=long long; using ld=long double; using ull=unsigned long long; using i128 = __int128_t; #define rep(i,n) for(ll i=0;i=0;i--) #define rep3(i,a,b) for(ll i=a;i<=ll(b);i++) #define rep4(i,a,b) for(ll i=a;i>=ll(b);i--) #define forv(i,V) for(const auto& i:V) #define all(x) x.begin(),x.end() #define fi first #define se second #define SIZE(x) int(x.size()) //constexpr ll mod=998244353; //constexpr ll mod=1000000007; #define pi 3.14159265358979323 #define INF32 2147483647 #define INF64 9223372036854775807 #define faster ios::sync_with_stdio(false);std::cin.tie(nullptr) #define pii pair #define pll pair #define pb push_back #define eb emplace_back #define mp make_pair #define rev reverse #define vi vector #define vll vector #define vpi vector> #define vpll vector> #define vvi vector> #define vvll vector> #define prq priority_queue #define lb lower_bound #define ub upper_bound #define popcnt __builtin_popcountll #define TLE while(true) #define RE assert(false); #define MLE vector>> mle_mle(400,vector>(1000,vector(1000))); const string YESNO[2] = {"NO", "YES"}; const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; #define rall(n) (n).rbegin(),(n).rend() #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) template ostream &operator<<(ostream&os,const pair&p){os< istream &operator>>(istream&is,pair&p){is>>p.first>>p.second;return is;} template ostream &operator<<(ostream&os,const vector&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;} template istream &operator>>(istream&is,vector&v){for(T &in:v){is>>in;}return is;} void scan(){} template void scan(Head&head,Tail&... tail){cin>>head;scan(tail...);} template void print(const T &t){cout< void print(const Head &head, const Tail &... tail){cout< void fin(const T &... a){print(a...);exit(0);} ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max((ll)b,a);} ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min((ll)b,a);} //a以上b以下の個数 template ll RangeOK(ll a,ll b,vector &v){ return max(ub(all(v),b)-lb(all(v),a),0); } template vector compress(vector &X) { vector vals = X; sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); for (int i = 0; i < (int)X.size(); i++) { X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin(); } return vals; } //setprecision(20) namespace yakisoba{ struct dsu{ dsu() : _n(0) {} dsu(int n) : _n(n), parent(n, -1), groupsize(n) {} int merge(int a,int b){ if(a<0||a>=_n||b<0||b>=_n) cerr<<"UnionFind Range out:"<parent[y]) swap(x,y); parent[x]+=parent[y]; parent[y]=x; return x; } bool same(int a,int b){ if(a<0||a>=_n||b<0||b>=_n) cerr<<"UnionFind Range out:"<=_n) cerr<<"UnionFind Range out:"<=_n) cerr<<"UnionFind Range out:"<> groups(){ vector group_size(_n),leader_list(_n); for(int i=0;i<_n;i++){ leader_list[i]=leader(i); group_size[leader_list[i]]++; } vector> ans(_n); for(int i=0;i<_n;i++){ ans[i].reserve(group_size[i]); } for(int i=0;i<_n;i++){ ans[leader_list[i]].push_back(i); } ans.erase(remove_if(ans.begin(),ans.end(),[&](const vector& v){return v.empty();}),ans.end()); return ans; } public: int groupsize; private: //代表元はそのグループの要素数を符号を反転させて持つ //それ以外は親を持つ int _n; vector parent; }; } using namespace yakisoba; pll nextday(ll a,ll b){ if(a==1||a==3||a==5||a==7||a==8||a==10||a==12){ if(b==31) b=1,a++; else b++; if(a==13) a=1; return {a,b}; } if(a==4||a==6||a==9||a==11){ if(b==30) b=1,a++; else b++; return {a,b}; } if(b==28) b=1,a++; else b++; return {a,b}; } int main(){ faster; LL(m,d,k); vll v(10); for(int i=0;i<7;i++){ v[m/10]=1; v[d/10]=1; v[m%10]=1; v[d%10]=1; pll z=nextday(m,d); m=z.fi,d=z.se; } if(count(all(v),1)