QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#699905#9536. Athlete Welcome Ceremonyucup-team008#AC ✓163ms296552kbC++2314.6kb2024-11-02 11:11:482024-11-02 11:11:49

Judging History

This is the latest submission verdict.

  • [2024-11-02 11:11:49]
  • Judged
  • Verdict: AC
  • Time: 163ms
  • Memory: 296552kb
  • [2024-11-02 11:11:48]
  • Submitted

answer

// {{{ y0105w49 template 24K21
// hi mom
#ifndef NULL
#ifdef __GNUC__
#ifndef __clang__
// #include <bits/stdc++.h>
#include <bits/extc++.h>
#include <tr2/dynamic_bitset>
#define EXTS
#else
#ifdef ARST
#include <bits/clang++.h>
#else
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
// #include <cuchar>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif
#if __cplusplus >= 201703L
#include <any>
#include <charconv>
// #include <execution>
#include <filesystem>
#include <optional>
// #include <memory_resource>
#include <string_view>
#include <variant>
#endif
#if __cplusplus >= 202002L
#include <barrier>
#include <bit>
#include <compare>
#include <concepts>
#if __cpp_impl_coroutine
# include <coroutine>
#endif
#include <latch>
#include <numbers>
#include <ranges>
#include <span>
// #include <stop_token>
#include <semaphore>
// #include <source_location>
// #include <syncstream>
#include <version>
#endif
#if __cplusplus > 202002L
// #include <expected>
// #include <spanstream>
#if __has_include(<stacktrace>)
# include <stacktrace>
#endif
#include <stdatomic.h>
#endif
#endif
#endif
#else
#error "unsupported"
#endif
#endif
using namespace std;
#ifdef ARST
#define JO 1
#define OJ 0
#else
#define JO 0
#define OJ 1
#endif
#define STR(x) #x
#define GCCDIAG(s) _Pragma(STR(GCC diagnostic s)) static_assert(true)
#define Wsave GCCDIAG(push)
#define Wpop GCCDIAG(pop)
#define Wsupp(w) GCCDIAG(ignored "-W" w)
#define Wpush(w) Wsave; Wsupp(w)
#define typeof __typeof__
namespace gbd_ns {
	template<typename C> struct is_iterable {
		template<class T> static long check(...);
		template<class T> static char check(int,typename T::const_iterator = C().end());
		enum {
			value = sizeof(check<C>(0)) == sizeof(char),
			neg_value = sizeof(check<C>(0)) != sizeof(char)
		};
	};
	template<class T> struct _gbd3C;
	template<class T> ostream &_gbd3(ostream &os,const T &x) { return _gbd3C<T>::call(os,x); }
	template<> ostream &_gbd3(ostream &os,const string &x) { return os<<'"'<<x<<'"'; }
	template<> ostream &_gbd3(ostream &os,char *const &x) { return os<<'"'<<x<<'"'; }
	template<class T> ostream &_gbd3_5(ostream &os,const T &x) { return _gbd3(os,x); }
	template<class A,class B> ostream &_gbd4(ostream &os,const pair<A,B> &p) {
		_gbd3(os<<'(',p.first);
		_gbd3(os<<',',p.second);
		return os<<')';
	}
	template<class T,size_t N> struct _gbd4_tupleC {
		static void call(ostream &os,const T &t) {
			_gbd4_tupleC<T,N-1>::call(os,t);
			os<<','<<get<N-1>(t);
		}
	};
	template<class T> struct _gbd4_tupleC<T,1> {
		static void call(ostream &os,const T &t) { os<<get<0>(t); }
	};
	template<typename... Types> ostream &_gbd4(ostream &os,const tuple<Types...> &t) {
		os<<'(';
		_gbd4_tupleC<tuple<Types...>,sizeof...(Types)>::call(os,t);
		return os<<')';
	}
	template<> ostream &_gbd4(ostream &os,const tuple<> &t) { (void)t; return os<<"()"; }
	template<class T> ostream &_gbd4(ostream &os,const T &x) {
		return os<<x;
	}
	template<class T> struct _gbd3C {
		template<class U=T> static ostream &call(ostream &os,enable_if_t<is_iterable<U>::value,const T> &V) {
			os<<"{";
			bool ff=0;
			for(const auto &E:V) _gbd3_5<decltype(E)>(ff?os<<",":os,E), ff=1;
			return os<<"}";
		}
		template<class U=T> static ostream &call(ostream &os,enable_if_t<is_iterable<U>::neg_value,const T> &x) {
			return _gbd4(os,x);
		}
	};
	template<class T,typename... Args> ostream &_gbd2(ostream &os,bool,vector<string>::iterator nm,const T &x,Args&&... args);
	ostream &_gbd2(ostream &os,bool,vector<string>::iterator) { return os; }
	template<typename... Args> ostream &_gbd2(ostream &os,bool fi,vector<string>::iterator nm,const char *x,Args&&... args) {
		return _gbd2(os<<(fi?"":"  ")<<x,0,nm+1,args...);
	}
	template<class T,typename... Args> ostream &_gbd2(ostream &os,bool fi,vector<string>::iterator nm,const T &x,Args&&... args) {
		return _gbd2(_gbd3<T>(os<<(fi?"":"  ")<<*nm<<"=",x),0,nm+1,args...);
	}
	vector<string> split(string s) {
		vector<string> Z;
		string z="";
		s+=',';
		int dep=0;
		for(char c:s) {
			if(c==',' && !dep) Z.push_back(z),z="";
			else z+=c;
			if(c=='(' || c=='{' || c=='[') ++dep;
			if(c==')' || c=='}' || c==']') --dep;
		}
		return Z;
	}
	template<typename... Args> ostream &_gbd1(ostream &os,const string &nm,Args&&... args) {
		return _gbd2(os,1,split(nm).begin(),args...);
	}
	template<typename... Args> string _gbd1(const string &nm,Args&&... args) {
		ostringstream oss;
		_gbd2(oss,1,split(nm).begin(),args...);
		return oss.str();
	}
}
bool DBG=1,EMACS=0;
#define dbg(...) (JO&&DBG?gbd_ns::_gbd1(cerr<<"\033[38;5;5m"<<__FILE__<<":"<<__LINE__<<(EMACS?":note: ":": "),#__VA_ARGS__,__VA_ARGS__)<<"\033[0m"<<endl:cerr)
#define dbgt(...) dbg(fmt_time(),__VA_ARGS__)
#define fmt(...) gbd_ns::_gbd1(#__VA_ARGS__,__VA_ARGS__)
template<class Fun> struct _y_combinator_result {
	Fun _fun;
	template<class T> explicit _y_combinator_result(T &&fun) : _fun(forward<T>(fun)) {}
	template<typename... Args> decltype(auto) operator()(Args&&... args) {
		return _fun(ref(*this),forward<Args>(args)...);
	}
};
template<class Fun> [[nodiscard]] decltype(auto) fix(Fun &&fun) {
	return _y_combinator_result<decay_t<Fun>>(forward<Fun>(fun));
}
#define nop void()
#define sz(x) (int((x).size()))
#define all(v) (v).begin(),(v).end()
#define forenum(i,...) for(int i:{-1}) for(__VA_ARGS__) if(++i,0) assert(0); else
#define forenumll(i,...) for(long long i:{-1}) for(__VA_ARGS__) if(++i,0) assert(0); else
#define forbs(k,i,bs) for(ptrdiff_t k=0,i=(bs)._Find_first();i<(ptrdiff_t)(bs).size();i=(bs)._Find_next(i),++k)
#define fordbs(k,i,bs) for(ptrdiff_t k=0,i=(bs).find_first();i<(ptrdiff_t)(bs).size();i=(bs).find_next(i),++k)
#define get(x,i) get<i>(x)
template<class T> T &smin(T &x,const T &y) { return y<x?x=y:x; }
template<class T> T &smax(T &x,const T &y) { return y>x?x=y:x; }
template<class T> bool inb(const T &x,const T &l,const T &r) { return l<=x&&x<=r; }
template<class T> bool cinb(const T &x,const T &l,const T &r) { return l<=r?l<=x&&x<=r:l<=x||x<=r; }
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
template<template<class> class C,class T> T popv(C<T> &v) { T z=v.back(); v.pop_back(); return z; }
template<template<class> class C,class T> T popq(C<T> &v) { T z=v.top(); v.pop(); return z; }
template<template<class> class C,class T> T pops(C<T> &v) { T z=*v.begin(); v.erase(v.begin()); return z; }
template<template<class,class> class C,class K,class V> pair<K,V> popm(C<K,V> &v) { pair<K,V> z=*v.begin(); v.erase(v.begin()); return z; }
template<template<class> class C,class T> void erase1(C<T> &v,const T &x) { v.erase(v.find(x)); }
template<template<class> class C,class T> int lbi(C<T> &v,const T &x) { return int(lower_bound(all(v),x)-v.begin()); }
template<template<class> class C,class T> int findi(C<T> &v,const T &x) { auto it=lower_bound(all(v),x); return it!=v.end()&&*it==x?int(it-v.begin()):-1; }
template<class V> int sortu(V &v) { sort(all(v)); int z=int(unique(all(v))-v.begin()); v.resize(z); return z; }
template<typename T,typename... Args> T tee(T (*f)(Args... args),Args&&... args) { T z=f(forward<Args>(args)...); cout<<z<<endl; return z; }
template<typename... Args> void tee(void (*f)(Args... args),Args&&... args) { f(forward<Args>(args)...); }
#ifdef EXTS
template<class S,class T> using omap=__gnu_pbds::tree<S,T,less<S>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<class T> using oset=omap<T,__gnu_pbds::null_type>;
template<class T> using rope=__gnu_cxx::rope<T>;
using dbitset=tr2::dynamic_bitset<>;
#endif
constexpr int e0=1, e1=10, e2=100, e3=1000;
constexpr int e4=10*e3, e5=100*e3, e6=1000*e3;
constexpr int e7=10*e6, e8=100*e6, e9=1000*e6;
constexpr long long e10=10LL*e9, e11=100LL*e9, e12=1000LL*e9;
constexpr long long e13=10*e12, e14=100*e12, e15=1000*e12;
constexpr long long e16=10*e15, e17=100*e15, e18=1000*e15;
constexpr __int128_t e21=__int128_t(e3)*e18, e24=__int128_t(e6)*e18, e27=__int128_t(e9)*e18;
constexpr __int128_t e30=e3*e27, e33=e6*e27, e36=e9*e27;
using ulll=__uint128_t;
using lll=__int128_t;
using ull=unsigned long long;
using ll=long long;
using uint=unsigned int;
using ushort=unsigned short;
using uchar=char;
using ld=long double;
#ifdef EXTS
using lld=__float128;
#endif
long long START_TIME=chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now().time_since_epoch()).count();
inline long long now_U_03BC_s() { return chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now().time_since_epoch()).count()-START_TIME; }
const char *fmt_time(long long U_03BC_s=now_U_03BC_s()) { static char dur[20]; sprintf(dur,"%llu.%03llus",U_03BC_s/e6,(U_03BC_s%e6)/e3); return dur; }
#define timed(cb) do { dbg("timed "#cb" ..."); unsigned long long start=now_U_03BC_s(); cb; dbg("timed "#cb" took",fmt_time(now_U_03BC_s()-start)); } while(0)
int arg1; bool inp; vector<string> args;
unsigned seed=unsigned(JO&&getenv("sd")?atoi(getenv("sd")):OJ?START_TIME:START_TIME%e5);
mt19937 igen(seed<<1),gen(seed<<1|1);
#define irand(...) (assert(!inp),_rand(igen,__VA_ARGS__))
#define rand(...) _rand(gen,__VA_ARGS__)
template<class T> enable_if_t<numeric_limits<T>::is_integer,T> _rand(mt19937 &g,T l,T r) { return uniform_int_distribution<T>(l,r)(g); }
template<class T> enable_if_t<numeric_limits<T>::is_integer,T> _rand(mt19937 &g,T n) { return _rand(g,T(1),n); }
[[deprecated]] int _rand(mt19937 &g) { return _rand(g,0,numeric_limits<int>::max()); }
template<class T> enable_if_t<numeric_limits<T>::is_iec559,T> _rand(mt19937 &g,T l,T r) { return uniform_real_distribution<T>(l,r)(g); }
bool _rand(mt19937 &g,double p) { return bernoulli_distribution(p)(g); }
template<class T> T _rand(mt19937 &g,initializer_list<T> il) { return *(il.begin()+_rand(g,0,(int)il.size()-1)); }
template<class T> T _rand(mt19937 &g,double p,T a,T b) { return _rand(g,p)?a:b; }
template<class T> T _rand(mt19937 &g,initializer_list<T> il,initializer_list<double> wt) { assert(il.size()==wt.size()); return *(il.begin()+discrete_distribution<int>(wt)(g)); }
#define random_shuffle(...) static_assert(false,"random_shuffle deprecated, use shuffle")
#define ine(x,e) (inp?cin>>(x),nop:((x)=(e),nop))
#define inr(x,...) ine(x,irand(__VA_ARGS__))
#define endl '\n'
string garb;
void exit0() { DBG=1; dbgt("gg (early)",seed); exit(0); }
#ifndef MAIN
#define MAIN _main
#endif
void MAIN();
int32_t main([[maybe_unused]]int argc,[[maybe_unused]]char *argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(0); cin.exceptions(ios_base::failbit | ios_base::badbit);
	arg1=0,args={argv,argv+argc};
	if(sz(args)>1) {
		if(args[1][0]=='i') freopen((string(__FILE__).substr(0,string(__FILE__).find('.'))+"."+args[1].substr(1)+".in").c_str(),"r",stdin);
		else if(args[1][0]=='I') freopen(args[1].substr(1).c_str(),"r",stdin);
		else arg1=stoi(args[1]);
	}
	inp=!arg1;
	if(JO && getenv("EMACS")) EMACS=1;
	dbgt(arg1,seed,args);
	#ifdef QUIET
	DBG=0;
	#endif
	MAIN();
	DBG=1;
	dbgt("gg;wp",seed);
	return 0;
}
constexpr int inf=e9+99;
constexpr ll linf=1LL*e9*e9+99;
#if __cplusplus >= 202002L
constexpr long double U_03C4__ld=2*numbers::pi_v<long double>;
#else
const long double U_03C4__ld=2*acosl(-1);
#endif
#define U_03C4_ ((flt)U_03C4__ld)
constexpr long double U_03B5__ld=1e-8l;
#define U_03B5_ ((flt)U_03B5__ld)
// }}}
using flt=double; //CARE
constexpr int P=e9+7;//998'244'353;
void add(int &x,int y) { if((x+=y)>=P) x-=P; }


const int N=304;




auto solve() { /* CURSOR START */
	int n,qn; ine(n,arg1), ine(qn,n*n);
	string s(n,'.'); if(inp) cin>>s; else for(char &c:s) c=irand({'?',irand('a','c')});
	dbg(n,qn,s);

	static int dp[N][3][N][N];
	if(s.back()=='?') {
		++dp[n-1][0][1][0];
		++dp[n-1][1][0][1];
		++dp[n-1][2][0][0];
	} else ++dp[n-1][s.back()-'a'][0][0];
	for(int i=n-2;i>=0;i--) {
		if(s[i]=='?') {
			for(int c:{0,1,2}) for(int d:{0,1,2}) if(d!=c) {
					for(int x=(c==0);x<N;x++) for(int y=(c==1);y<N;y++) {
							add(dp[i][c][x][y],dp[i+1][d][x-int(c==0)][y-int(c==1)]);
						}
					}
		} else {
			int c=s[i]-'a';
			for(int d:{0,1,2}) if(d!=c) {
					for(int x=0;x<N;x++) for(int y=0;y<N;y++) {
							add(dp[i][c][x][y],dp[i+1][d][x][y]);
						}
				}
		}
	}
	static int dpo[N][N];
	for(int c:{0,1,2}) for(int x=0;x<N;x++) for(int y=0;y<N;y++) add(dpo[x][y],dp[0][c][x][y]);
	for(int x=0;x<5;x++) dbg(x,vector<int>(dpo[x],dpo[x]+5));

	static int PS[N][N];
	for(int x=0;x<N;x++) for(int y=1;y<N;y++) PS[x][y]=PS[x][y-1], add(PS[x][y],dpo[x][y-1]);

	int qc=0; for(char c:s) if(c=='?') ++qc;
	for(;qn--;) {
		int X,Y,Z; inr(X,n), inr(Y,n) ,inr(Z,n);
		int ans=0;
		// for(int x=0;x<=X;x++) for(int y=0;y<=Y;y++) if(qc-x-y<=Z) add(ans,dpo[x][y]);
		for(int x=0;x<=X;x++) {
			int rig=Y;
			int lef=qc-x-Z;
			if(lef<0) lef=0;
			if(lef>rig) continue;
			add(ans,PS[x][rig+1]), add(ans,P-PS[x][lef]);
		}
		cout<<ans<<endl;
	}
}



void _main() { int NTC=1;
	// ine(NTC,5);
	for(int TC=1;TC<=NTC;TC++) {
		// cout<<"Case #"<<TC<<": ";
		tee(solve);
	}
	if(JO&&inp) assert((cin>>ws).eof());
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 10392kb

input:

6 3
a?b??c
2 2 2
1 1 1
1 0 2

output:

3
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 6ms
memory: 12788kb

input:

6 3
??????
2 2 2
2 3 3
3 3 3

output:

30
72
96

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 2ms
memory: 6636kb

input:

1 1
?
0 1 1

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 0ms
memory: 10292kb

input:

10 10
acab?cbaca
0 2 0
1 1 2
4 2 3
1 1 1
3 5 1
0 5 2
2 2 0
1 2 5
4 3 0
1 1 3

output:

0
1
1
1
1
0
1
1
1
1

result:

ok 10 lines

Test #5:

score: 0
Accepted
time: 6ms
memory: 11532kb

input:

10 10
?c?c?cbac?
10 5 1
5 8 7
9 2 6
5 7 1
5 2 6
5 6 5
5 10 3
9 1 10
2 5 9
1 2 9

output:

16
16
11
16
11
16
16
5
11
0

result:

ok 10 lines

Test #6:

score: 0
Accepted
time: 4ms
memory: 27716kb

input:

50 100
?abacbacab?cbcbcb?acabcbabcbcacbababc?caba?acacbca
8 3 8
2 4 8
8 7 3
0 9 2
10 8 7
7 6 5
4 10 2
6 9 3
3 6 6
9 10 8
2 5 8
8 1 0
3 5 0
1 0 6
5 0 8
6 5 5
1 7 9
7 7 10
4 7 5
6 6 4
10 1 2
4 1 7
10 0 8
7 6 3
1 9 1
4 7 2
8 4 0
8 6 1
5 10 4
5 8 2
5 8 4
4 5 9
5 2 1
1 10 9
4 10 1
8 4 3
8 9 9
8 0 1
0 8 0...

output:

8
8
8
0
8
8
6
8
8
8
8
0
0
0
1
8
4
8
8
8
2
4
1
8
1
6
0
2
8
6
8
8
1
4
2
8
8
0
0
8
2
0
8
8
8
4
8
8
8
8
2
0
0
4
8
8
1
8
7
6
7
0
8
8
8
0
4
7
8
4
0
8
0
4
8
8
8
7
8
4
7
2
8
8
8
0
2
2
8
8
8
4
4
0
8
0
8
8
1
1

result:

ok 100 lines

Test #7:

score: 0
Accepted
time: 20ms
memory: 43932kb

input:

50 100
b????????bca?????c?b??ca?acac?b?b???ca?ab???a?a???
35 43 36
12 49 47
7 11 34
38 44 22
42 17 10
49 8 38
18 26 44
6 18 14
28 29 6
48 32 47
29 15 48
1 5 33
24 17 18
10 27 32
19 10 34
2 23 9
14 24 39
46 12 34
9 49 26
21 8 46
43 43 3
31 16 2
8 27 7
24 41 35
17 25 31
0 13 47
24 31 23
33 40 30
36 39...

output:

34272000
31599360
497244
34272000
17637520
12290752
34272000
93044
415832
34272000
34272000
0
34272000
16360704
27933952
0
34272000
33886976
7896832
12290752
718
24
0
34272000
34272000
0
34272000
34272000
34272000
32254720
0
5666944
34256640
34272000
34272000
12290752
30493248
34256640
20630016
0
10...

result:

ok 100 lines

Test #8:

score: 0
Accepted
time: 35ms
memory: 46020kb

input:

100 1000
c?cbababcabacbacbacacbacabcbabababacababcbcab?cbabacbacbcbcacbab?bcabcbcababcacbabacbcb?babcbab?baca
13 11 4
4 17 20
14 5 2
16 14 15
8 12 17
19 5 11
5 17 12
20 7 6
19 10 1
6 5 0
13 1 9
7 17 1
20 4 16
11 12 18
19 2 16
18 1 11
19 16 3
7 1 0
6 9 16
6 9 16
6 20 7
0 16 20
1 2 8
16 5 20
18 14 18
...

output:

16
15
14
16
16
16
16
16
8
2
16
8
16
16
16
16
16
2
16
16
16
0
1
16
16
5
1
5
16
16
16
16
16
15
16
13
16
15
2
16
16
1
8
16
16
16
15
0
16
15
16
16
16
16
8
8
16
16
16
16
16
16
8
16
16
1
8
8
16
16
1
16
1
0
16
2
2
16
7
16
16
8
16
16
16
16
1
16
14
16
16
16
16
5
16
16
14
16
11
16
15
11
2
1
8
16
16
7
16
5
16
...

result:

ok 1000 lines

Test #9:

score: 0
Accepted
time: 36ms
memory: 109704kb

input:

100 1000
?????c??????????????????????????b???a????a?????????????????????????c????????????????????????????????
43 38 20
27 40 32
39 27 33
28 50 43
50 3 46
38 46 14
42 48 10
45 25 28
49 10 49
38 17 42
41 49 22
41 18 44
46 47 25
17 44 35
34 43 22
47 42 32
32 44 40
36 41 24
45 38 45
49 44 18
42 34 32
43...

output:

490475656
143989836
119661929
707864467
10104
219100551
479284703
764218529
903846231
659694548
204287063
105920502
191779504
182802705
215438611
938692318
797581204
903917420
893995828
287222624
578695829
95654849
457810426
709349795
85961844
923330494
783007506
111119718
295402274
241594071
551680...

result:

ok 1000 lines

Test #10:

score: 0
Accepted
time: 16ms
memory: 65404kb

input:

100 1000
c???cacacbcab?cb?acb???ac?bab?bcbcbc?c?bcbcaba??b?ba?c?aca?a?bac?cbcbcba??ca?b????ac?baba?ab?cba?c?c
99 70 32
52 98 84
12 78 77
84 8 87
16 36 0
48 70 100
25 4 15
95 54 35
33 35 90
20 4 69
6 11 76
27 96 48
16 24 18
99 48 1
43 54 35
9 81 75
27 58 52
50 94 14
29 67 27
59 68 53
42 31 46
12 90 2...

output:

380160
380160
226896
64156
0
380160
92
380160
380160
92
0
380160
379648
0
380160
22500
380160
380160
380160
380160
380160
226896
380160
380160
226896
0
380160
380160
380160
380160
152672
380160
5624
226896
380160
380160
379648
0
380160
380160
366848
380160
226896
380160
92
374912
5624
380160
380160
...

result:

ok 1000 lines

Test #11:

score: 0
Accepted
time: 65ms
memory: 115632kb

input:

300 100000
abcacacbabacbcababcacacb?babacbcbacbcababcbcbabcacbcbacacabacacacbacbcbcacbabacbcbcbabcacbababcabcabcabababacbcacbacabcbacbacacacbababababacbcababcbcacacbcbabacabcabababcabacbcbcbabcabacbabacacbcbcacacacbcabcbabcbcabababababcacabcabababcbcbcbcbcabacbabacbabcacbcababacacbcbababababcacacaba...

output:

1
2
2
2
2
1
2
2
2
2
1
1
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
1
1
2
2
2
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
0
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
1
2
2
1
2
2
2
2
1
2
2
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 100000 lines

Test #12:

score: 0
Accepted
time: 52ms
memory: 119016kb

input:

300 100000
bcacbacacabacacbacacbabcabcacabcabcbcaba?cacbabcbacbabcbacacabacabcbacabcacacbcbabcbcabcabacbacbacabacabababcbcbcbabcbacbacabcacacabacbcbababcbcabacbabcbabacabcbabcbababababcbcbabacbacacbcabcabcbcbcbcabacabacacacbcbacabacbabca?acacbcacacbcbabacbcbcabca?babcacbc?acbacabacbcbcbcbacabababacb...

output:

4
4
4
4
0
4
4
4
4
4
4
4
4
4
0
1
3
3
4
4
4
1
4
0
4
0
4
4
4
4
4
4
4
0
4
1
1
4
4
0
4
3
4
4
4
4
4
4
4
3
4
1
1
3
4
0
4
4
3
4
4
4
4
4
4
4
4
4
4
0
4
4
4
3
4
3
4
4
4
1
4
3
0
4
4
4
4
4
0
4
0
4
4
4
4
1
4
4
4
4
4
0
1
4
4
1
4
0
4
3
4
0
4
3
1
0
4
4
1
1
4
4
4
3
4
4
4
3
0
4
1
4
4
4
0
4
4
4
4
1
0
4
1
0
4
4
4
4
4
4
...

result:

ok 100000 lines

Test #13:

score: 0
Accepted
time: 84ms
memory: 134832kb

input:

300 100000
bcbabcab?bab??acacbcabacbacbcacacbabcab?bcbcb?bababcabcabcabca?abcbc?bcacacb?abababcbcbcbcbaba?cba?abcabc?ababacbcbc?acbabcacacbabcab?ca?b?babcbacbacbcbcbacbc?c?cababcacbc?bcbcabcacbabc?acbabcbacac?cbcb?abcbabacabcbacabcacababcbabcbcb??bacbcbacabc?cabacac?cab?cabacacbcacacbabacacabcab?bac...

output:

20336
14528
22504
24576
24576
16992
24576
24576
24576
0
24576
1500
24576
24576
24576
0
23592
7808
24576
0
24576
23592
24576
24576
0
640
24576
2576
24392
24576
624
24576
24576
0
8
24448
8
24576
104
0
24576
24576
24392
0
0
24576
24576
24576
0
24576
24392
24576
24576
24576
23488
24576
24576
24576
24448...

result:

ok 100000 lines

Test #14:

score: 0
Accepted
time: 90ms
memory: 174704kb

input:

300 100000
cbabacacabcaca?abcb?b??cbc??cbacb?acab?b?bcabc?a??bab?a?a?a?ca?acac????c?c?caba?a???bcab?ababababc??babacacacbacabcb?bab?bcab?bacb???ba???c?b?cb?bababac?cb??acacbcba?acaca??bacb?cbc?c?bcbcbab?ba?c??bacacab?b?b?ac??babcbcb?bcbcbcb?c?c?cbac?ba?a?abc?cab?bc?ca?abacaca?abc??ac?aca?a??ca?cac??...

output:

964413406
726709206
0
110704627
192317202
753035749
238645875
836077477
0
0
67075693
196248
337185872
684300992
551066954
512400928
894774207
441158600
632725062
60181080
460670453
301321033
206790308
549405433
258628038
0
719626090
0
800239318
716729053
580760175
749271169
414309213
431703326
12786...

result:

ok 100000 lines

Test #15:

score: 0
Accepted
time: 96ms
memory: 162912kb

input:

300 100000
cbacacacbcba??bc???ab??bca?acabcbcb?cac?babacbac?ba??cbcbac?cb?abacaca?ac?c?caba?ac?cabc?ba?cbaba??ba??abcabac?abab?cabcacbc?cab??aca?bc??babacacab?c?babcacacb?cba?ac?a?abacabcbcbcaca?ab?bcabababc??ababa?abc???acbacbabcac?a?acabcac?cbabac?bacab??c?a??babcbacac??aca?bcba?ab?bcbacbacbabab?b...

output:

868189535
868189535
0
868189535
495627643
0
868189535
929370324
868189535
868189535
1474560
0
0
868189535
868189535
868189535
688551450
868189535
868189535
0
868189535
868189535
868189535
868189535
9381984
868189535
868189535
868189535
868189535
20457120
868189535
868189535
635204610
868189535
86818...

result:

ok 100000 lines

Test #16:

score: 0
Accepted
time: 116ms
memory: 172184kb

input:

300 100000
cbac?cac?cbcbca?abacba?ac?acab????abaca?abcbcabc?c??acb???b?ac??bcb?cacacabac?b?bc?a?b?abcac??a?acacab?bacacab??ca?b?c?acacabcbacacbc?c?acbcabcaca?a?cb?a??abcacab?b?cacb??ac??c?a?bacb?bacbaba?a?bc?babca??bababcababcab?ba?cba??cb?b?abc?cbcab?ba?ca?bacb??ca?bcb??cacbcbca???cbac?bacbc?cac?bc...

output:

63065600
280135711
280135711
280135711
280135711
280135711
280135711
280135711
0
579883317
270080
280135711
0
280135711
280135711
539129922
280135711
280135711
539129922
0
280135711
280135711
280135711
0
280135711
270080
256
280135711
280135711
280135711
280135711
280135711
280135711
631211594
28013...

result:

ok 100000 lines

Test #17:

score: 0
Accepted
time: 163ms
memory: 296052kb

input:

300 100000
??????a?a??c?c?????a??????????b???????????????????????????????????bc?b???????b????????c??????????a????????bc??a????????????c????a?????????????a?????b?????a????????c??ba????b?b???????????c?????????cbc?????????????????b???ab?b????ac?b??c??????c??a??ab???a?????b?????????a??b???????????ba????...

output:

356410997
164744264
978926692
879215541
267745269
399413378
667881560
356410997
818851047
356410997
989150636
266480908
0
356410997
303796242
234869176
137612115
356410997
0
24290767
273625930
411968196
567490332
356410997
0
356410997
807134302
646186244
356410997
356410997
577546772
527886169
35641...

result:

ok 100000 lines

Test #18:

score: 0
Accepted
time: 156ms
memory: 296552kb

input:

300 100000
?a?????????????????b??b??ac?????????????????????b???????c??a??????c????????ac??a???a????a????c????????????bc?????b???c???ab?????????????????????c??????c?b???????a?a?????????c??b??c???b????a?c????????????????c?bc????b???????????b????????bc????c????????????????????a?????????c?????a?????????...

output:

421472289
555100087
555100087
880376766
555100087
0
0
931054200
106211865
993171009
555100087
486740217
555100087
0
555100087
190774849
555100087
336407512
0
0
655515061
555100087
0
309808634
992320113
362042447
0
461962238
830139091
238473131
555100087
0
555100087
555100087
992320113
555100087
1745...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed