#include <bits/stdc++.h>
using namespace std;
typedef double ftype;
typedef complex<ftype> point;
typedef complex<point> quater;
#define qA real()
#define qB imag()
#define qs qA.real()
#define qx qA.imag()
#define qy qB.real()
#define qz qB.imag()
quater operator * (quater a, quater b)
{
return {{a.qA * b.qA - a.qB * conj(b.qB)},
{a.qA * b.qB + a.qB * conj(b.qA)}};
}
quater conj(quater a)
{
return {conj(a.qA), - a.qB};
}
ftype norm(quater a)
{
return (a * conj(a)).qs;
}
ftype abs(quater a)
{
return sqrt(norm(a));
}
quater operator / (quater a, quater b)
{
return a * conj(b) / point(norm(b));
}
quater vec(ftype x, ftype y, ftype z)
{
return {{0, x}, {y, z}};
}
quater vec(quater a)
{
return a -= a.qs;
}
ftype dot(quater a, quater b)
{
return -(a * b).qs;
}
quater cross(quater a, quater b)
{
return vec(a * b);
}
ftype mix(quater a, quater b, quater c)
{
return dot(a, cross(b, c));
}
quater conj(quater a, quater g)
{
return g * a / g;
}
quater rotation(quater i, ftype phi)
{
return point(cos(phi / 2)) + i * point(sin(phi / 2));
}
quater rotate(quater a, quater i, ftype phi)
{
return conj(a, rotation(i, phi));
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
const double pi = acos(-1.);
quater A = vec(0, 0, 1);
quater B = vec(1, 0, 0);
double phi = pi / 4;
cout << rotate(B, A, phi) << "\n";
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBkb3VibGUgZnR5cGU7CnR5cGVkZWYgY29tcGxleDxmdHlwZT4gcG9pbnQ7CnR5cGVkZWYgY29tcGxleDxwb2ludD4gcXVhdGVyOwojZGVmaW5lIHFBIHJlYWwoKQojZGVmaW5lIHFCIGltYWcoKQojZGVmaW5lIHFzIHFBLnJlYWwoKQojZGVmaW5lIHF4IHFBLmltYWcoKQojZGVmaW5lIHF5IHFCLnJlYWwoKQojZGVmaW5lIHF6IHFCLmltYWcoKQoKcXVhd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