#include <bits/stdc++.h>
#define cpx complex<double>
#define pb push_back
using namespace std;
int N = 1 << 19;
const double pi = acos(-1);
vector<cpx> A, B, C;
cpx ei(double x){
return cpx(cos(x), sin(x));
}
void FFT(vector<cpx> &F, int inv){
int n = F.size(), h = n >> 1;
cpx w = ei(2 * inv * pi / n), x = 1;
if(n == 1) return;
vector<cpx> L, R;
for(int i = 0; i < n; i++){
if(i & 1) R.pb(F[i]);
else L.pb(F[i]);
}
FFT(L, inv), FFT(R, inv);
for(int i = 0; i < n; i++, x *= w){
F[i] = L[i % h] + x * R[i % h];
}
}
signed main(){
//input
FFT(A, 1), FFT(B, 1);
for(int i = 0; i < N; i++){
C.pb(A[i] * B[i]);
}
FFT(C, -1);
//output
return 0;
}
#include <bits/stdc++.h>
#define cpx complex<double>
using namespace std;
int N = 1 << 19;
const double pi = acos(-1);
array<cpx, 1 << 19> A, B, C;
cpx ei(double x){
return cpx(cos(x), sin(x));
}
void FFT(array<cpx, 1 << 19> &F, int inv){
cpx x, w, f;
for(int i = 0, k = 0; i < N; i++, k = 0){
for(int j = 1; j < N; j <<= 1) k <<= 1, k |= !!(i & j);
if(i < k) swap(F[i], F[k]);
}
for(int k = 1; k < N; k <<= 1){
w = ei(inv * pi / k);
for(int j = 0; j < N; j += k << 1){
x = 1;
for(int i = j; i < j + k; i++, x *= w){
f = x * F[i + k];
F[i + k] = F[i] - f;
F[i] += f;
}
}
}
}
signed main(){
//input
FFT(A, 1), FFT(B, 1);
for(int i = 0; i < N; i++){
C[i] = A[i] * B[i];
}
FFT(C, -1);
//output
return 0;
}
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N = 1 << 20, iN;
const int g = 3, p = 998244353;
array<int, 1 << 21> A, B, C;
int exp(int x, int k){
int s = 1;
for(int i = 1; i <= k; i <<= 1, x = x * x % p){
if(i & k) s = s * x % p;
}
return s;
}
void NTT(array<int, 1 << 20> &F, int inv){
int w, f;
for(int i = 0, k = 0; i < N; i++, k = 0){
for(int j = 1; j < N; j <<= 1) k <<= 1, k |= !!(i & j);
if(i < k) swap(F[i], F[k]);
}
for(int k = 1; k < N; k <<= 1){
w = exp(g, (p - 1) / (k << 1) * (p - 1 + inv));
for(int j = 0; j < N; j += k << 1){
for(int i = j, x = 1; i < j + k; i++, x = x * w % p){
f = x * F[i + k] % p;
F[i + k] = (F[i] - f + p) % p;
F[i] = (F[i] + f) % p;
}
}
}
}
signed main(){
//input
iN = exp(N, p - 2);
NTT(A, 1), NTT(B, 1);
for(int i = 0; i < N; i++) C[i] = A[i] * B[i] % p;
NTT(C, -1);
for(int i = 0; i < N; i++) C[i] = C[i] * iN % p;
//output
return 0;
}
#include <bits/stdc++.h>
#define int long long
#define cpx complex<double>
using namespace std;
int N = 1 << 19;
const double pi = acos(-1);
array<cpx, 1 << 19> A, B, C;
cpx ei(double x){
return cpx(cos(x), sin(x));
}
void FFT(array<cpx, 1 << 19> &F, int inv){
cpx x, w, f;
for(int i = 0, k = 0; i < N; i++, k = 0){
for(int j = 1; j < N; j <<= 1) k <<= 1, k |= !!(i & j);
if(i < k) swap(F[i], F[k]);
}
for(int k = 1; k < N; k <<= 1){
w = ei(inv * pi / k);
for(int j = 0; j < N; j += k << 1){
x = 1;
for(int i = j; i < j + k; i++, x *= w){
f = x * F[i + k];
F[i + k] = F[i] - f;
F[i] += f;
}
}
}
}
int rnd(double x){
double z = (int)x;
if(x - z >= 0.5) return (int)z + 1;
else return (int)z;
}
signed main(){
int k, n, m, a, b;
cin >> k >> n >> m;
for(int i = 0; i < n; i++){
cin >> a;
A[a] += 1;
}
for(int i = 0; i < m; i++){
cin >> b;
B[b] += 1;
}
FFT(A, 1), FFT(B, 1);
for(int i = 0; i < N; i++){
C[i] = A[i] * B[i];
}
FFT(C, -1);
for(int i = 2; i <= k << 1; i++){
cout << rnd(C[i].real() / N) << " ";
}
cout << "\n";
return 0;
}
#include <bits/stdc++.h>
#define cmp complex<double>
#define int long long
using namespace std;
const int N = 1 << 19;
const double pi = acos(-1);
array<cmp, 1 << 19> A, B, C;
cmp ei(double d){
return {cos(d), sin(d)};
}
void FFT(array<cmp, 1 << 19> &F, int inv){
cmp w, x, f;
for(int i = 0, k = 0; i < N; i++, k = 0){
for(int j = 1; j < N; j <<= 1) k <<= 1, k |= !!(i & j);
if(i < k) swap(F[i], F[k]);
}
for(int k = 1; k < N; k <<= 1){
w = ei(inv * pi / k);
for(int j = 0; j < N; j += k << 1){
x = 1;
for(int i = j; i < j + k; i++, x *= w){
f = x * F[i + k];
F[i + k] = F[i] - f;
F[i] += f;
}
}
}
}
int rnd(double x){
double z = (int)x;
if(x - z >= 0.5) return (int)z + 1;
else return (int)z;
}
signed main(){
int n;
string S;
cin >> S;
n = S.size();
for(int i = 0; i < n; i++){
A[i] = S[i] ^ '0';
B[n - i - 1] = A[i];
}
FFT(A, 1), FFT(B, 1);
for(int i = 0; i < N; i++) C[i] = A[i] * B[i];
FFT(C, -1);
for(int i = n; i < (n << 1) - 1; i++){
cout << rnd(C[i].real() / (double)N) << " ";
}
cout << "\n";
return 0;
}
#include <bits/stdc++.h>
#define cmp complex<double>
#define int long long
using namespace std;
const int N = 1 << 19;
const double pi = acos(-1);
array<cmp, 1 << 19> A, B, C;
cmp ei(double d){
return {cos(d), sin(d)};
}
void FFT(array<cmp, 1 << 19> &F, int inv){
cmp w, x, f;
for(int i = 0, k = 0; i < N; i++, k = 0){
for(int j = 1; j < N; j <<= 1) k <<= 1, k |= !!(i & j);
if(i < k) swap(F[i], F[k]);
}
for(int k = 1; k < N; k <<= 1){
w = ei(inv * pi / k);
for(int j = 0; j < N; j += k << 1){
x = 1;
for(int i = j; i < j + k; i++, x *= w){
f = x * F[i + k];
F[i + k] = F[i] - f;
F[i] += f;
}
}
}
}
int rnd(double x){
double z = (int)x;
if(x - z >= 0.5) return (int)z + 1;
else return (int)z;
}
signed main(){
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> A[i];
for(int i = m - 1; i >= 0; i--) cin >> B[i];
FFT(A, 1), FFT(B, 1);
for(int i = 0; i < N; i++) C[i] = A[i] * B[i];
FFT(C, -1);
for(int i = 0; i < n + m - 1; i++){
cout << rnd(C[i].real() / (double)N) << " ";
}
cout << "\n";
return 0;
}
#include <bits/stdc++.h>
#define int long long
#define cpx complex<double>
using namespace std;
const int N = 1 << 19;
const double pi = acos(-1);
array<cpx, 1 << 19> A, B, C, X;
cpx ei(double x){
return {cos(x), sin(x)};
}
void FFT(array<cpx, 1 << 19> &F, int inv){
cpx w, x, f;
for(int i = 0, k = 0; i < N; i++, k = 0){
for(int j = 1; j < N; j <<= 1) k <<= 1, k |= !!(i & j);
if(i < k) swap(F[i], F[k]);
}
for(int k = 1; k < N; k <<= 1){
w = ei(inv * pi / k);
for(int j = 0; j < N; j += k << 1){
x = 1;
for(int i = j; i < j + k; i++, x *= w){
f = x * F[i + k];
F[i + k] = F[i] - f;
F[i] += f;
}
}
}
}
int rnd(double x){
double z = (int)x;
if(x - z >= 0.5) return (int)z + 1;
else return (int)z;
}
signed main(){
int n, pre = 0, zero = 0, cnt = 0;
string S;
cin >> S;
n = S.size();
B[n] = {1, 0};
for(char s : S){
if(s == '1'){
pre++;
zero += cnt * (cnt + 1) / 2;
cnt = 0;
}else cnt++;
A[pre] += 1;
B[n - pre] += 1;
}
zero += cnt * (cnt + 1) / 2;
FFT(A, 1), FFT(B, 1);
for(int i = 0; i < N; i++) C[i] = A[i] * B[i];
FFT(C, -1);
cout << zero << " ";
for(int i = n + 1; i <= 2 * n; i++){
cout << rnd(C[i].real() / (double)N) << " ";
}
cout << "\n";
return 0;
}
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N, iN;
const int g1 = 3, g2 = 31, p1 = 1004535809, p2 = 2013265921, pp = p1 * p2;
array<int, 1 << 20> A, B, P, Q, C1, C2, C, rev;
void trans(string &s, array<int, 1 << 20> &S){
int n = s.size();
reverse(s.begin(), s.end());
for(int i = 0; i < n; i += 6){
for(int j = min(i + 6, n) - 1; j >= i; j--){
S[i / 6] *= 10;
S[i / 6] += s[j] ^ '0';
}
}
}
int find(int n){
for(int i = 1; i <= 1 << 20; i <<= 1){
if(i > 2 * n) return i;
}
}
int exp(int x, int k, bool t){
int s = 1;
for(int i = 1; i <= k; i <<= 1){
if(i & k){
if(t) s = s * x % p1;
else s = s * x % p2;
}
if(t) x = x * x % p1;
else x = x * x % p2;
}
return s;
}
int mul(int x, int k){
int s = 0;
for(int i = 1; i <= k; i <<= 1, x = (x << 1) % pp){
if(i & k) s = (s + x) % pp;
}
return s;
}
void NTT(array<int, 1 << 20> &F, int inv, bool t){
int w, f;
for(int i = 0; i < N; i++) if(i < rev[i]) swap(F[i], F[rev[i]]);
for(int k = 1; k < N; k <<= 1){
if(t) w = exp(g1, (p1 - 1) / (k << 1) * (p1 - 1 + inv), 1);
else w = exp(g2, (p2 - 1) / (k << 1) * (p2 - 1 + inv), 0);
for(int j = 0; j < N; j += k << 1){
for(int i = j, x = 1; i < j + k; i++){
if(t){
f = x * F[i + k] % p1;
F[i + k] = (F[i] - f + p1) % p1;
F[i] = (F[i] + f) % p1;
x = x * w % p1;
}else{
f = x * F[i + k] % p2;
F[i + k] = (F[i] - f + p2) % p2;
F[i] = (F[i] + f) % p2;
x = x * w % p2;
}
}
}
}
}
void out(array<int, 1 << 20> &S){
string s;
int car = 0, v;
for(int i = 0; i < N; i++){
S[i] += car;
car = S[i] / 1000000;
S[i] %= 1000000;
}
for(; car; car /= 10) s += ((car % 10) + '0');
reverse(s.begin(), s.end());
for(int i = N - 1; i >= 0; i--){
for(int k = 100000; k; k /= 10){
s += (S[i] / k + '0');
S[i] %= k;
}
}
for(v = 0; s[v] == '0' && v < s.size(); v++);
for(; v < s.size(); v++) cout << s[v];
cout << "\n";
}
void RUN(array<int, 1 << 20> &R, bool t){
if(t) iN = exp(N, p1 - 2, 1);
else iN = exp(N, p2 - 2, 0);
P = A, Q = B;
NTT(P, 1, t), NTT(Q, 1, t);
for(int i = 0; i < N; i++){
if(t) R[i] = P[i] * Q[i] % p1;
else R[i] = P[i] * Q[i] % p2;
}
NTT(R, -1, t);
for(int i = 0; i < N; i++){
if(t) R[i] = R[i] * iN % p1;
else R[i] = R[i] * iN % p2;
}
}
signed main(){
int ip1, ip2, p1p, p2p;
string a, b;
cin >> a >> b;
N = find(max(a.size(), b.size()) / 6 + 1);
trans(a, A);
trans(b, B);
for(int i = 0, k = 0; i < N; i++, k = 0){
for(int j = 1; j < N; j <<= 1) k <<= 1, k |= !!(i & j);
rev[i] = k;
}
ip2 = exp(p2, p1 - 2, 1), ip1 = exp(p1, p2 - 2, 0);
p1p = p1 * ip1, p2p = p2 * ip2;
RUN(C1, 1);
RUN(C2, 0);
for(int i = 0; i < N; i++) C[i] = (mul(C1[i], p2p) + mul(C2[i], p1p)) % pp;
out(C);
return 0;
}