#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
using namespace std;
typedef __int64 LL;
typedef long double Ldb;
const int maxn = 10;
const Ldb eps = 1e-12;
int n;
struct Point
{
    Ldb x,y;
    Point() {}
    Point(Ldb _x,Ldb _y):x(_x),y(_y) {}
    Point operator + (const Point &t)const
    {
        return Point(x+t.x,y+t.y);
    }
    Point operator - (const Point &t)const
    {
        return Point(x-t.x,y-t.y);
    }
    Point operator * (const Ldb &t)const
    {
        return Point(x*t,y*t);
    }
    Point operator / (const Ldb &t)const
    {
        return Point(x/t,y/t);
    }
    bool operator < (const Point &t)const
    {
        return fabs(x-t.x) < eps ? y<t.y : x<t.x;
    }
    bool operator == (const Point &t)const
    {
        return fabs(x-t.x)<eps && fabs(y-t.y)<eps;
    }
    Ldb len()const
    {
        return sqrt(x*x+y*y);
    }
    Point rot90()const
    {
        return Point(-y,x);
    }
};

struct Circle
{
    Point o;
    Ldb r;
    Circle() {}
    Circle(Point _o,Ldb _r):o(_o),r(_r) {}
    friend vector<Point> operator & (const Circle &c1,const Circle &c2)
    {
        Ldb d=(c1.o-c2.o).len();
        if(d>c1.r+c2.r+eps || d<fabs(c1.r-c2.r)-eps)
            return vector<Point>();
        Ldb dt=(c1.r*c1.r-c2.r*c2.r)/d,d1=(d+dt)/2;
        Point dir=(c2.o-c1.o)/d,pcrs=c1.o+dir*d1;
        dt=sqrt(max(0.0L,c1.r*c1.r-d1*d1)),dir=dir.rot90();
        return vector<Point> {pcrs+dir*dt,pcrs-dir*dt};
    }
} p[maxn];
bool vis[maxn];
int fa[maxn],rk[maxn];
void init()
{
    for(int i=1; i<maxn; i++)
        fa[i] = i,rk[i] = 0;
}

int find_set(int x)
{
    if(fa[x]!=x)
        fa[x] = find_set(fa[x]);
    return fa[x];
}


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

//ostream& debug = cerr;
#include <boost/iostreams/stream.hpp>
boost::iostreams::stream< boost::iostreams::null_sink > nullOstream( ( boost::iostreams::null_sink() ) );
ostream& debug = nullOstream;

template <class T>
T intCeilDiv(T numerator, T denominator) {
    if (numerator == 0) return 0;
    if (((numerator > 0) - (numerator < 0)) * ((denominator > 0) - (denominator < 0)) < 0) {
        return numerator / denominator;
    }
    return ((numerator - 1) / denominator) + 1;
}
template <class T>
T intFloorDiv(T numerator, T denominator) {
    if (numerator == 0) return 0;
    if (((numerator > 0) - (numerator < 0)) * ((denominator > 0) - (denominator < 0)) < 0) {
        return ((numerator - 1) / denominator) - 1;
    }
    return numerator / denominator;
}

int pow(int base, int exp, int mod) {
    long long result = 1, baseLL = base;
    while (exp) {
        if (exp & 1) {
            result *= baseLL;
            result %= mod;
        }
        baseLL *= baseLL;
        baseLL %= mod;
        exp >>= 1;
    }
    return (result + mod) % mod;
}

int main() {
    debug << "test: " << intCeilDiv(-6, 5) << endl;
    debug << "test: " << -1 % 5 << endl;
    long long a, b, p, x;
    cin >> a >> b >> p >> x;
    debug << "a = " << a << endl;
    debug << "b = " << b << endl;
    debug << "p = " << p << endl;
    debug << "x = " << x << endl;
    long long total = 0;
    for (long long j = 1; j <= p - 1; j++) {
        debug << "-----\nj = " << j << endl;
        long long y = (b * pow(a, (p-1) - j, p)) % p;
        debug << "1/a^j = " << pow(a, (p-1) - j, p) << endl;
        debug << "a * inv a = " << (a * pow(a, (p-2), p)) % p << endl;
        debug << "y = " << y << endl;
        long long tMin = intCeilDiv (1-j + (y-j)*(p-1), (p-1)*p);
        long long tMax = intFloorDiv(x-j + (y-j)*(p-1), (p-1)*p);
        debug << tMin << " <= t <= " << tMax << endl;
        debug << "tMin = " << 1-j + (y-j)*(p-1) << " / " << (p-1)*p << endl;
        debug << "tMax = " << x-j + (y-j)*(p-1) << " / " << (p-1)*p << endl;
        total += max(0LL, tMax - tMin + 1);
        //return 0;
    }
    debug << "=====" << endl;
    cout << total << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
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;}
inline long long read(){
   long long f = 1, x = 0;char ch = getchar();
    while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
    return x * f;
}
const int maxn = 1e6 + 10;
// n * a^n * x + p * y = b;
LL exgcd(LL a,LL b,LL &x,LL &y){
    if (!b){
        x = 1; y = 0;
        return a;
    }else{
        int g = exgcd(b,a % b,x,y),tmp = x;
        x = y;
        y = tmp - (a / b) * y;
        return g;
    }
}
LL qpow(LL a,LL b,LL mod){
    LL base = a,ans = 1;
    while(b){
        if (b & 1) ans = ans * base % mod;
        base = base * base % mod;
        b >>= 1;
    }
    return ans % mod;
}
LL m[maxn],a[maxn];
LL lcm = 1;
LL solve(){
    LL ans = 0,x,y,g;
    for(int i=1; i<=2; i++){
        LL tmp = lcm / m[i];
        exgcd(tmp,m[i],x,y);
        x = (x % m[i] + m[i]) % m[i];
        ans = (ans + a[i] * x * tmp) % lcm;
    }
    return ans;
}
// n * a^(n % (p-1)) % p = b ;

// n % p == inv(a^(n % (p-1))) * b % p;

// n % (p-1) == i;

// a^(n % (p-1)) % p == c2;

// n % (p-1) == c2';
LL inv(LL a,LL p){
    return qpow(a,p-2,p);
}
int main(){
    LL A = read(),B = read(),p = read(),x = read();
    m[1] = p-1; m[2] = p;
    lcm = (p - 1) * p;
    LL ans = 0;
    for(int i=0; i<=p-1; i++){
        a[1] = i;
        a[2] = B * inv(qpow(A,i % (p-1),p),p) % p;
        // cout << a[2] << endl;
        LL res = solve();
        if (x >= res){
            ans = ans + (x - res) / (p * (p-1)) + 1;
        }
    }
    if (A != B && ans > 0) ans--;
    cout << ans << endl;
    return 0;
}


#pragma GCC optimize(2)
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ST sort
#define MAXN 100005
#define DB double
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define Int register int
#define XM XiangMeiHaoGuai
#define Pa pair<LL,LL>
#define Lson Son[x][0]
#define Rson Son[x][1]
using namespace std;
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' ||s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline LL Max(LL x,LL y)
{
	return x > y ? x : y;
}
inline LL Min(LL x,LL y)
{
	return x < y ? x : y;
}
LL Gcd(LL a,LL b)
{
	if (! b)
		return a;
	return Gcd(b, a % b);
}
inline LL Abs(LL x)
{
	if (x < 0)
		return -x;
	return x;
}
inline DB Fabs(DB x)
{
	if (x > 0)
		return x;
	return -x;
}
LL a, b, p, x;
inline LL QuickPow(LL x,LL y,LL Mod)
{
	x %= Mod;
	LL Res = 1, temp = x;
	while ( y )
	{
		if (y & 1)
			Res = Res * temp % Mod;
		temp = temp * temp % Mod;
		y /= 2;
	}
	return Res;
}
inline LL Inv(LL x)
{
	return QuickPow(x, p - 2, p);
}
inline LL Mo(LL x,LL Mod)
{
	return (x % Mod + Mod) % Mod;
}
inline Jie(LL n,LL Mi)
{
	LL Get = b * Inv( Mi ) % p;
	LL Dai = (p - 1) * Mo(n - Get, p) + n;
	if (Dai > x)
		return 0;
	return (x - Dai) / (p * (p - 1)) + 1;
}
int main()
{
	read( a ); read( b ); read( p ); read( x );
	LL Power = 1, Ans = 0;
	for (Int i = 1; i < p; ++ i)
	{
		Power = Power * a % p;
		LL Da = Jie(i, Power);
		Ans += Da;
	}
	printf("%lld", Ans);
	return 0;
}
/*
n * a ^ n ≡b (mod p)

*/p>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ST sort
#define MAXN 100005
#define DB double
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define Int register int
#define XM XiangMeiHaoGuai
#define Pa pair<LL,LL>
#define Lson Son[x][0]
#define Rson Son[x][1]
using namespace std;
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' ||s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline LL Max(LL x,LL y)
{
	return x > y ? x : y;
}
inline LL Min(LL x,LL y)
{
	return x < y ? x : y;
}
LL Gcd(LL a,LL b)
{
	if (! b)
		return a;
	return Gcd(b, a % b);
}
inline LL Abs(LL x)
{
	if (x < 0)
		return -x;
	return x;
}
inline DB Fabs(DB x)
{
	if (x > 0)
		return x;
	return -x;
}
LL a, b, p, x;
inline LL QuickPow(LL x,LL y,LL Mod)
{
	x %= Mod;
	LL Res = 1, temp = x;
	while ( y )
	{
		if (y & 1)
			Res = Res * temp % Mod;
		temp = temp * temp % Mod;
		y /= 2;
	}
	return Res;
}
inline LL Inv(LL x)
{
	return QuickPow(x, p - 2, p);
}
inline LL Mo(LL x,LL Mod)
{
	return ((x % Mod) + Mod) % Mod;
}
inline Jie(LL n,LL Mi)
{
	LL Get = b * Inv( Mi ) % p;
	LL Dai = (p - 1) * Mo(n - Get, p) + n;
	if (Dai > x)
		return 0;
	return (x - Dai) / (p * (p - 1)) + 1;
}
int main()
{
	read( a ); read( b ); read( p ); read( x );
	LL Power = 1, Ans = 0;
	for (Int i = 1; i < p; ++ i)
	{
		Power = Power * a % p;
		LL Da = Jie(i, Power);
		Ans += Da;
	}
	printf("%lld", Ans);
	return 0;
}
/*
n * a ^ n ≡b (mod p)

*/
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ST sort
#define MAXN 100005
#define DB double
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define Int register int
#define XM XiangMeiHaoGuai
#define Pa pair<LL,LL>
#define Lson Son[x][0]
#define Rson Son[x][1]
using namespace std;
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' ||s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline LL Max(LL x,LL y)
{
	return x > y ? x : y;
}
inline LL Min(LL x,LL y)
{
	return x < y ? x : y;
}
LL Gcd(LL a,LL b)
{
	if (! b)
		return a;
	return Gcd(b, a % b);
}
inline LL Abs(LL x)
{
	if (x < 0)
		return -x;
	return x;
}
inline DB Fabs(DB x)
{
	if (x > 0)
		return x;
	return -x;
}
LL a, b, p, x;
inline LL QuickPow(LL x,LL y,LL Mod)
{
	LL Res = 1, temp = x;
	while ( y )
	{
		if (y & 1)
			Res = Res * temp % Mod;
		temp = temp * temp % Mod;
		y /= 2;
	}
	return Res;
}
inline LL Inv(LL x)
{
	return QuickPow(x, p - 2, p);
}
inline LL Mo(LL x,LL Mod)
{
	return ((x % Mod) + Mod) % Mod;
}
inline Jie(LL n,LL Mi)
{
	LL Get = b * Inv( Mi ) % p;
	LL Dai = (p - 1) * Mo(n - Get, p) + n;
	if (Dai > x)
		return 0;
	return (x - Dai) / (p * (p - 1)) + 1;
}
int main()
{
	read( a ); read( b ); read( p ); read( x );
	LL Power = 1, Ans = 0;
	for (Int i = 1; i < p; ++ i)
	{
		Power = Power * a % p;
		LL Da = Jie(i, Power);
		Ans += Da;
	}
	printf("%lld", Ans);
	return 0;
}
/*
n * a ^ n ≡b (mod p)

*/


#include <iostream>
#include <cmath>

using namespace std;

#define ll long long

int mult(int a, int b, int mod)
{
    return ((ll) a * b) % mod;
}

int binaryPower(int n, int p, int mod)
{
    int acc = 1;
    while (p)
    {
        if (p & 1) acc = mult(acc, n, mod);
        n = mult(n, n, mod);
        p >>= 1;
    }
    return acc;
}

struct bezout_coefficients
{
    ll g, x, y; // x * a + y * b = gcd(a, b)
};

bezout_coefficients extended_gcd(ll a, ll b)
{
    array <ll, 3> A = {0, 1, a}, B = {1, 0, b};
    while (B[2] != 0)
    {
        ll q = A[2] / B[2];
        auto T = B;
        transform(A.begin(), A.end(), B.begin(), B.begin(), [q](ll x, ll y){return x - q * y;});
        A = T;
    }
    return {A[2], A[1], A[0]};
}

ll modularInverse(ll a, ll b)
{
    return extended_gcd(a, b).x;
}
}

int main()
{
    int a, b, p;
    ll x;
    cin>>a>>b>>p>>x;
    ll sol = 0;
    for (int rem = 0; rem < p - 1; rem++)
    {
        int z = (mult(b, modularInverse(binaryPower(a, rem, p), p), p));

        ll lb = ceil((double(1 - rem) / (p - 1) - (rem - z)) / p);
        ll ub = floor((double(x - rem) / (p - 1) - (rem - z)) / p);

        sol += ub >= lb ? ub - lb + 1 : 0;
    }
    cout<<sol<<'\n';
}


#include <iostream>
using namespace std;

int exgcd(int a, int b, int &x, int &y) {
	if(b) {
		int g = exgcd(b, a % b, x, y);
		int tmp = x;
		x = y, y = tmp - a / b * y;
		return g;
	} else {
		x = 1, y = 0;
		return a;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m, x, y, vx, vy;
	cin >> n >> m >> x >> y >> vx >> vy;

	int da = 0, db = 0;
	if(vx)
		da = vx > 0 ? n - x : x;
	else {
		if(vy && (x == 0 || x == n))
			cout << x << ' ' << (vy > 0 ? m : 0);
		else
			cout << "-1" << endl;
		return 0;
	}
	if(vy)
		db = vy > 0 ? m - y : y;
	else {
		if(vx && (y == 0 || y == m))
			cout << (vx > 0 ? n : 0) << ' ' << y;
		else
			cout << "-1" << endl;
		return 0;
	}
	long long t = db - da, dx, dy;
	int gcd = exgcd(n, -m, dx, dy);
	if(t % gcd) {
		cout << "-1" << endl;
		return 0;
	}
	dx = dx * t / gcd, dy = dy * t / gcd;;
	if(dx < 0) {
		int xdel = m / gcd, ydel = n / gcd;
		int f = (-dx - 1) / xdel + 1;
		dx += f * xdel, dy += f * ydel;
	}
	cout << ((dx & 1) ^ (vx > 0) ? n : 0) << ' ' << ((dy & 1) ^ (vy > 0) ? m : 0) << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace Fread {
	const int MAXN=1<<20;
	char buf[MAXN],*S,*T;
	inline char getchar() {
		if (S==T) {
			T=(S=buf)+fread(buf,1,MAXN,stdin);
			if (S==T) return EOF;
		}
		return *S++;
	}
}
inline int read() {
	int x(0),neg(1);
	char ch=getchar();
	while(!isdigit(ch)) {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=(x<<1)+(x<<3)+(ch-'0');
		ch=getchar();
	}
	return x*neg;
}
#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
#endif
int n,m,ox,oy,vx,vy;
inline int exgcd(int a,int b,int &x,int &y) {
	if (!b) {
		x=1,y=0;
		return a;
	}
	int res(exgcd(b,a%b,y,x));
	y-=(a/b)*x;
	return res;
}
signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read(),m=read(),ox=read(),oy=read(),vx=read(),vy=read();
	/*特判*/
	if (x%n==0 && y%m==0) {
		printf("%lld %lld\n",x,y);
		return 0;
	}

	/*判断平行*/
	if (vx==0) {
		if (ox==0 || ox==n) {
			if (vy==1) printf("%lld %lld\n",ox,m);
			else printf("%lld %lld\n",ox,0);
		}
		else puts("-1");
		return 0;
	}
	if (vy==0) {
		if (oy==0 || oy==m) {
			if (vx==1) printf("%lld %lld\n",n,oy);
			else printf("%lld %lld\n",0,oy);
		}
		else puts("-1");
		return 0;
	}

	/*非平行*/
	int flag1=0,flag2=0;
	if (vx==-1) flag1=1,ox=n-ox;
	if (vy==-1) flag2=1,oy=m-oy;
	/*an+(y-x)=bm*/
	/*an+bm=x-y*/
	int a(0),b(0),gcd(exgcd(n,m,a,b));
	int Mn=n/gcd,Mm=m/gcd;
	if ((ox-oy)%gcd!=0) {
		puts("-1");
		return 0;
	}
	int t=(ox-oy)%gcd;
	a=a*t,b=b*t;
	int aa=(a%Mm+Mm*2-1)%Mm+1,bb=-((ox-oy)-aa*n)/m;
	int ansx,ansy;
	if (!(aa%2)) ansx=0;
	else ansx=n;
	if (!(bb%2)) ansy=0;
	else ansy=m;
	if (flag1) {
		ansx=n-ansx;
	}
	if (flag2) {
		ansy=m-ansy;
	}
	printf("%lld %lld\n",ansx,ansy);
	return 0;
}


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

int gcd(int a, int b) {
	while (b) {
		int c = a % b;
		a = b;
		b = c;
	}
	return a;
}

int gcd_ext(int a, int b, long long& x, long long& y) {
	if (!b) {
		x = 1, y = 0;
		return a;
	}
	int g = gcd_ext(b, a % b, x, y);
	tie(x, y) = make_pair(y, x - (a/b) * y);
	return g;
}
int inv(int a, int m) {
	long long x, y;
	int g = gcd_ext(a, m, x, y);
	assert(g == 1);
	if (x < 0) {
		x = m - ((-x) % m);
	}
	else {
		x %= m;
	}
	return x;
}

int get(int a, int d, int m)
{
	int g = gcd(d, m);
	if (a % g != 0) return -1;

	a /= g;
	d /= g;
	m /= g;

	int k = mod_mult((m - a) % m, inv(d, m), m);
	return k;
}

int main()
{
	int n, m, x, y, vx, vy;
	ignore = scanf("%d %d %d %d %d %d", &n, &m, &x, &y, &vx, &vy);

	if (vx == 0) {
		if (x != 0 && x != n) printf("-1\n");
		else if (vy > 0) printf("%d %d\n", x, m);
		else printf("%d %d\n", x, 0);
		return 0;
	}
	if (vy == 0) {
		if (y != 0 && y != m) printf("-1\n");
		else if (vx > 0) printf("%d %d\n", n, y);
		else printf("%d %d\n", 0, y);
		return 0;
	}

	int a = y % m;
	if (vy < 0) a = (m - y) % m;

	if (x != 0 && x != n) {
		if (vx < 0) a = (a + x) % m;
		else a = (a + n - x) % m;
	}

	int d = n % m;

	int k = get(a, d, m);
	if (k == -1) {
		printf("-1\n");
		return 0;
	}

	long long t = (vx < 0 ? x % n : (n - x) % n) + k * 1LL * n;

	long long xx = x + t * vx;
	long long yy = y + t * vy;

	xx = abs(xx);
	yy = abs(yy);
	xx %= 2*n;
	yy %= 2*m;
	printf("%d %d\n", (int)xx, (int)yy);
}


#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 1e5+10;
const int MAXM = 3e3+10;

priority_queue<int> pq;

int A[MAXN];

plii inverse(int a,int b)
{
    if(a==1)return plii(1,0);
    if(b==1)return plii(1,a-1);
    if(b<=100){
        for(ll i=0;i<b;i++)
            if(((a*i)%b)==1)return plii(i,(a*i)/b);
    }

    if(a>b){
        plii cur = inverse(a%b,b);
        cur.second += (a/b)*cur.first;
        return cur;
    }
    else {
        plii cur = inverse(a,b%a);
        cur.first+=(b/a)*cur.second;
        return cur;
    }
}

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;

    scanf("%d%d%d%d%d%d",&n,&m,&x,&y,&a,&b);

    int ox = n,ex = 0,oy = m,ey = 0;

    if(a==-1)x = n-x,swap(ox,ex);
    if(b==-1)y = m-y,swap(oy,ey);

    int gcd = __gcd(n,m);

    if((y-x)%gcd){printf("-1") return 0;};

    int cur = (y-x);

    cur/=gcd;
    n/=gcd;
    m/=gcd;

    if(cur<0)cur = -cur, swap(n,m);

    plii ans = inverse(n,m);

    ans.first*=cur;
    ans.second*=cur;

    ans.first%=m;
    ans.second%=n;

    if(!ans.first)ans.first = m;
    if(!ans.second)ans.second = n;

    if(ans.first%2)printf("%d ",ox);
    else printf("%d ",ex);
    if(ans.second%2)printf("%d ",oy);
    else printf("%d ",ey);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=201,maxm=51;
const LL INF=0x3f3f3f3f3f3f3f3fLL;
int n,m,qtot,etot;
struct Point
{
	int x,y;
	void read()
	{
		scanf("%d%d",&x,&y);
	}
	bool operator<(Point const&t)const
	{
		return x<t.x||(x==t.x&&y<t.y);
	}
	Point operator-(Point const&t)const
	{
		return(Point){x-t.x,y-t.y};
	}
	LL det(Point const&t)const
	{
		return(LL)x*t.y-(LL)y*t.x;
	}
	int site()const
	{
		return x<0||(!x&&y<0);
	}
}p[maxn],q[maxn];
bool cmp(Point const&u,Point const&v)
{
	int sU=u.site(),sV=v.site();
	return sU<sV||(sU==sV&&u.det(v)>0);
}
struct Edge
{
	int u,v;
	Point vec;
	bool operator<(Edge const&t)const
	{
		return cmp(vec,t.vec);
	}
}e[maxn*(maxn>>1)];
LL f[maxn][maxm],ans;
int main(void)
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;++i)p[i].read();
	sort(p,p+n);
	for(int o=0;o<n;++o)
	{
		qtot=etot=0;
		for(int i=o;i<n;++i)q[qtot++]=p[i]-p[o];
		sort(q+1,q+qtot,cmp);
		for(int i=1;i<qtot;++i)
		{
			e[etot++]=(Edge){0,i,q[i]-q[0]};
			for(int j=i+1,k=i;j<qtot;++j)if((q[j]-q[i]).det(q[k]-q[i])<=0)
			{
				e[etot++]=(Edge){i,j,q[j]-q[i]};
				k=j;
			}
			e[etot++]=(Edge){i,0,q[0]-q[i]};
		}
		sort(e,e+etot);
		for(int i=0;i<qtot;++i)for(int j=0;j<=m;++j)f[i][j]=-INF;
		f[0][0]=0;
		for(int i=0;i<etot;++i)
		{
			int u=e[i].u,v=e[i].v;
			for(in tj=1;j<=m;++j)
			{
				LLtp=f[u][j-1]+q[u].det(q[v]);
				f[v][j]<tp&&(f[v][j]=tp);
			}
		}
		ans<f[0][m]&&(ans=f[0][m]);
	}
	printf("%lld.%c0\n",ans>>1,"05"[ans&1]);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
struct point{
	long long x , y;
	point(long long _x = 0 , long long _y = 0){
		x = _x;
		y = _y;
	}
	point operator + (const point &other) const {
		return point(x + other.x , y + other.y);
	}
	point operator - (const point &other) const {
		return point(x - other.x , y - other.y);
	}
	bool operator < (const point &other) const {
		if(y == other.y){
			return x < other.x;
		}
		return y < other.y;
	}
	void read(){
		scanf("%lld %lld" , &x , &y);
	}
};
long long dot(point a , point b){
	return a.x * b.x + a.y * b.y;
}
inline long long cross(point a , point b){
	return a.x * b.y - a.y * b.x;
}
inline int orient(point a , point b , point c){//orientation of point c with respect to line from a -> b
	long long val = cross(b - a , c - a);
	if(val > 0){
		return 1;//c comes anticlockwise on line from a -> b
	}
	if(val < 0){
		return -1;//c comes clockwise on line from a -> b
	}
	return 0;//c is collinear with line from a -> b
}
long long dist(point a , point b){
	return dot(a - b , a - b);
}
const int N = 205;
const int K = 55;
int n , k;
point arr[N];
point bottom;
int tot[N][N];
inline long long area(int a , int b , int c){
	return abs(cross(arr[b] - arr[a] , arr[c] - arr[a]));
}
bool inside(point p1 , point p2 , point p3 , point q){
	int o1 = orient(p1 , p2 , q);
	int o2 = orient(p2 , p3 , q);
	int o3 = orient(p3 , p1 , q);
	return (o1 == o2) && (o2 == o3) && (o3 != 0);
}
inline int get(int a , int b , int c){
	int res = 0;
	res += (tot[a][b] - inside(bottom , arr[a] , arr[b] , arr[c])) * orient(bottom , arr[a] , arr[b]);
	res += (tot[b][c] - inside(bottom , arr[b] , arr[c] , arr[a])) * orient(bottom , arr[b] , arr[c]);
	res += (tot[c][a] - inside(bottom , arr[c] , arr[a] , arr[b])) * orient(bottom , arr[c] , arr[a]);
	return res;
}
long long dp[2][N][N];
vector < int > v;
int pivot;
bool cmp(int a , int b){
	return orient(arr[pivot] , arr[a] , arr[b]) == -1;
}
bool cmp2(int a , int b){
	return orient(arr[v[pivot]] , arr[v[a]] , arr[v[b]]) == -1;
}
int nxt[N][N];
int prv[N][N];
long long solve(int idx){
	v.clear();
	v.emplace_back(idx);
	for(int i = 1 ; i <= n ; ++i){
		if(arr[i].y > arr[idx].y || (arr[i].y == arr[idx].y && arr[i].x > arr[idx].x)){
			v.emplace_back(i);
		}
	}
	if(v.size() < k){
		return;
	}
	pivot = v[0];
	sort(v.begin() + 1 , v.end() , cmp);
	int m = v.size();
	for(int i = 1 ; i < m ; ++i){
		nxt[i][0] = 0;
		for(int j = i + 1 ; j < m ; ++j){
			if(!get(v[0] , v[i] , v[j])){
				nxt[i][++nxt[i][0]] = j;
			}
		}
		prv[i][0] = 0;
		for(int j = 0 ; j < i ; ++j){
			prv[i][++prv[i][0]] = j;
		}
		pivot = i;
		sort(nxt[i] + 1 , nxt[i] + 1 + nxt[i][0] , cmp2);
		sort(prv[i] + 1 , prv[i] + 1 + prv[i][0] , cmp2);
	}
	for(int siz = k ; siz > 1 ; --siz){
		for(int last2 = 1 ; last2 < m ; ++last2){
			int ptr = nxt[last2][0];
			long long bst = -1LL << 50;
			for(int j = prv[last2][0] ; j >= 1 ; --j){
				int last1 = prv[last2][j];
				if(last1 && orient(arr[v[last1]] , arr[v[last2]] , arr[v[0]]) != -1){
					dp[siz & 1][last1][last2] = -1LL << 50;
					continue;
				}
				if(siz == k){
					dp[siz & 1][last1][last2] = 0;
					continue;
				}
				ptr = nxt[last2][0];
				bst = -1LL << 50;
				while(ptr >= 1 && orient(arr[v[last1]] , arr[v[last2]] , arr[v[nxt[last2][ptr]]]) == -1){
					bst = max(bst , dp[!(siz & 1)][last2][nxt[last2][ptr]] + area(v[0] , v[last2] , v[nxt[last2][ptr]]));
					--ptr;
				}
				dp[siz & 1][last1][last2] = bst;
			}
		}
	}
	long long res = 0;
	for(int i = 1 ; i < m ; ++i){
		res = max(res , dp[0][0][i]);
	}
	return res;
}
int main(){
	scanf("%d %d" , &n , &k);
	for(int i = 1 ; i <= n ; ++i){
		arr[i].read();
	}
	bottom = point(-1 , -1);
	for(int i = 1 ; i <= n ; ++i){
		tot[i][i] = 0;
		for(int j = i + 1 ; j <= n ; ++j){
			int res = 0;
			for(int k = 1 ; k <= n ; ++k){
				if(i == k || j == k){
					continue;
				}
				res += inside(bottom , arr[i] , arr[j] , arr[k]);
			}
			tot[i][j] = tot[j][i] = res;
		}
	}
	long long ans = 0;
	for(int i = 1 ; i <= n ; ++i){
		ans = max(ans , solve(i));
	}
	printf("%.2lf\n" , ans / 2.0);
}


/*
   О НЕТ! ОНИ ДОГОНЯЮТ!!!
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

struct pt
{
    int x, y;
};

pt operator - (const pt &a, const pt &b)
{
    return {a.x - b.x, a.y - b.y};
}

pt operator + (const pt &a, const pt &b)
{
    return {a.x + b.x, a.y + b.y};
}

ll operator * (const pt &a, const pt &b)
{
    return a.x * (ll) b.y - a.y * (ll) b.x;
}

ll len(const pt &p)
{
    return p.x * (ll) p.x + p.y * (ll) p.y;
}

pt s;

const int N = 200 + 7;

bool ok[N][N];
ll dp[N][N];
vector <int> g[N];
vector <pt> f;
pt mn;

bool operator < (const pt &a, const pt &b)
{
    if ((a - s) * (b - s) != 0)
    {
        return (a - s) * (b - s) < 0;
    }
    else
    {
        return len(a - s) < len(b - s);
    }
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n, cnt;
    cin >> n >> cnt;
    vector <pt> e;
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        e.push_back({x, y});
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        f.clear();
        for (int j = 0; j < n; j++)
        {
            if (e[j].x > e[i].x || (e[j].x == e[i].x && e[j].y > e[i].y))
            {
                f.push_back(e[j]);
            }
        }
        s = e[i];
        sort(f.begin(), f.end());
        int k = f.size();
        for (int i = 0; i < k; i++)
        {
            for (int j = i + 1; j < k; j++)
            {
                ok[i][j] = false;
            }
        }
        for (int i = 0; i < k; i++)
        {
            for (int j = i + 1; j < k; j++)
            {
                for (int t = i + 1; t < j; t++)
                {
                    if ((f[t] - f[i]) * (f[j] - f[t]) >= 0)
                    {
                        ok[i][j] = true;
                        break;
                    }
                }
                /*
                if (!ok[i][j])
                {
                    cout << f[i].x << ' ' << f[i].y << " -> " << f[j].x << ' ' << f[j].y << ' ' << s.x << ' ' << s.y << endl;
                }
                */
            }
        }
        vector <pair <int, int> > e;
        for (int i = 0; i < k; i++)
        {
            for (int j = i + 1; j < k; j++)
            {
                if (i != j && !ok[i][j])
                {
                    e.push_back({i, j});
                }
            }
        }
        pt cur = {-1, 10000000000};
        mn = s + cur;
        sort(e.begin(), e.end(), [] (pair <int, int> a, pair <int, int> b)
        {
            pt x = f[a.second] - f[a.first];
            pt y = f[b.second] - f[b.first];
            if (x * mn < 0 && y * mn < 0)
            {
                return x * y < 0;
            }
            else if (x * mn > 0 && y * mn > 0)
            {
                return x * y < 0;
            }
            else
            {
                return x * mn > 0;
            }
        });
        for (int i = 0; i < k; i++)
        {
            for (int j = 0; j < cnt - 1; j++)
            {
                dp[i][j] = 0;
            }
        }
        for (auto c : e)
        {
            int i = c.first, go = c.second;
            for (int j = 0; j < cnt - 1; j++)
            {
                dp[go][j + 1] = max(dp[go][j + 1], dp[i][j] + abs((f[i] - s) * (f[go] - s)));
            }
        }
        for (int i = 0; i < k; i++)
        {
            for (int j = 0; j < cnt - 1; j++)
            {
                ans = max(ans, dp[i][j]);
            }
        }
    }
    printf("%lld.%lld0\n", ans / 2, 5 * ans % 2);
}


#include<bits/stdc++.h>
const int maxn = 410;
using std::cin;
using std::cout;
int can[maxn][maxn][maxn];
int s[maxn][maxn][maxn];
std::bitset<maxn> set[maxn][maxn];
int a[maxn],b[maxn];
int n, k;
typedef long long ll;
inline ll cross(int x, int y, int z) {
	return ll(a[y] - a[x]) * (b[z] - b[x]) - ll(a[z] - a[x]) * (b[y] - b[x]);
}
struct seg { int x, y; };
inline double val(const seg & x) { return std::atan2(b[x.y] - b[x.x], a[x.y] - a[x.x]); }
inline bool cmp0(const seg & x, const seg & y) { return val(x) < val(y); }
inline ll calc(int x, int y, int z) {
	return cross(x, y, z);
}
ll dp[maxn][maxn][maxn];

inline void up(ll & x, ll y) {
	if(x < y) {
		x = y;
	}
}

int main() {
	std::ios::sync_with_stdio(false), std::cin.tie(0);
	cin >> n >> k;
	for(int i = 1;i <= n;++i) {
		cin >> a[i] >> b[i];
	}
	for(int i = 1;i <= n;++i) {
		for(int j = 1;j <= n;++j) {
			for(int k = 1;k <= n;++k) if(k != i && k != j && cross(i, j, k) > 0) {
				set[i][j].set(k);
			}
		}
	}
	for(int i = 1;i <= n;++i) {
		for(int j = 1;j <= n;++j) {
			for(int k = 1;k <= n;++k) {
				can[i][j][k] = (set[i][j] & set[j][k] & set[k][i]).none();
			}
		}
	}
	std::vector<seg> vec;
	for(int i = 1;i <= n;++i) {
		for(int j = 1;j <= n;++j) if(i != j) {
			vec.push_back((seg){ i, j });
		}
	}
	sort(vec.begin(), vec.end(), cmp0);
	for(int i = 1;i <= n;++i) {
		for(int j = 1;j <= n;++j) {
			for(int c = 1;c <= k;++c) {
				dp[i][j][k] = -1e18;
			}
		}
		dp[i][i][1] = 0;
	}
	for(const seg & x : vec) {
		for(int i = 1;i <= n;++i) {
			for(int cnt = 1;cnt <= k;++cnt) if(can[i][x.x][x.y]) {
				up(dp[i][x.y][cnt + 1], dp[i][x.x][cnt] + calc(i, x.x, x.y));
			}
		}
	}
	ll ans = 0;
	for(int i = 1;i <= n;++i) {
		up(ans, dp[i][i][k + 1]);
	}
	printf("%d.%d\n", ans >> 1, ans % 2 * 5);
}


/*
   We notice that there are only N^2 important states - (postition, t mod N). Let's make T mod N steps and see where we will be after that. This can be done in the most stupid way in O(N) time.
   Also let's for each position store the position we will arrive at after N steps. If this value for position x is to[x] the answer of our problem will be to[to[...[x]...]] (applied T / N times).
   Then after calculating the to[] array, we can simply find the cycle length of to[] and the reminder of (T / N) when divided by it. Then (T / N) <= N and we can easily find the answer in O(N).

   Now the hard part is to find the to[] array. We will go backwards. Initially set to[x] = x. Now we will use persistent treap (actually RBST) to find the actual to values. The main observation
   is that when decreasing T the to[] array will change just in two intervals. Then we can do the movements with a couple of merges and splits. The complexity will be O(N log N).

   As persistent treaps (RBST) tend to to increase their depth fast, we will rebuild our structure a couple of times.
*/

#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
const int MAX_MEM = (1 << 23);
const int B = 5000;

random_device rd;
mt19937 mt(rd());

struct node
{
	int sz, id;
	node *l, *r;

	node() { sz = id = 0; l = r = nullptr; }
	node(int i)
	{
		l = nullptr;
		r = nullptr;
		id = i;
		sz = 1;
	}
};

using pnode = node*;

int cnt_nodes = 0;
node ptr_list[MAX_MEM];

void init_memory()
{
	cnt_nodes = 0;
}

pnode new_node(int id)
{
	ptr_list[cnt_nodes].l = ptr_list[cnt_nodes].r = nullptr;
	ptr_list[cnt_nodes].sz = 1, ptr_list[cnt_nodes].id = id;
	return *ptr_list[cnt_nodes++];
}

inline int size(pnode t) { return t ? t->sz : 0; }

bool hey(int l, int r) { return (int)mt() % (l + r) < l; }

void pull(pnode &t)
{
	if(!t) return;
	t->sz = 1 + size(t->l) + size(t->r);
}

pnode copy(pnode &t)
{
	if(!t) return nullptr;

	pnode ret = new_node(0);
	ret->id = t->id;
	ret->l = t->l;
	ret->r = t->r;
	ret->sz = t->sz;

	return ret;
}

void split(pnode t, pnode &l, pnode &r, int k, int add = 0)
{
	if(!t) { l = r = nullptr; return; }

	int idx = size(t->l) + add;
	if(idx <= k)
	{
		l = copy(t);
		split(l->r, l->r, r, k, idx + 1);
		pull(l);
	}
	else
	{
		r = copy(t);
		split(r->l, l, r->l, k, add);
		pull(r);
	}
}

void merge(pnode &t, pnode l, pnode r)
{
	if(!l) { t = copy(r); return; }
	if(!r) { t = copy(l); return; }

	if(hey(size(l), size(r)))
		t = copy(l), merge(t->r, t->r, r);
	else
		t = copy(r), merge(t->l, l, t->l);

	pull(t);
}

vector<int> tmp_rec;

void get_li_tmp(pnode t)
{
	if(!t) return;
	get_li_tmp(t->l);
	tmp_rec.pb(t->id);
	get_li_tmp(t->r);
}

vector<int> get_li(pnode t)
{
	tmp_rec.clear();
	get_li_tmp(t);
	return tmp_rec;
}

pnode build(int l, int r, vector<int> &li)
{
	if(l > r) return nullptr;

	int mid = (l + r) >> 1;

	pnode ret = new_node(li[mid]);
	ret->l = build(l, mid - 1, li);
	ret->r = build(mid + 1, r, li);

	pull(ret);

	return ret;
}

int n, m, start_pos;
int64_t t;

void read()
{
	cin >> n >> m;
	cin >> start_pos >> t;
	start_pos--;
}

int to[MAXN];

void dfs(pnode t, int p = 0)
{
	if(!t) return;
	dfs(t->l, p);
	to[p] = t->id;
	dfs(t->r, p + size(t->l) + 1);
}

pnode root = nullptr;
vector<int> tmpp;

void rebuild()
{
	tmpp = get_li(root);
	cnt_nodes = 0;
	root = build(0, n - 1, tmpp);
}

pnode get(int l, int r)
{
	if(l < 0)
	{
		pnode ret;
		merge(ret, get(n + l, n - 1), get(0, r));
		return ret;
	}

	if(r >= n)
	{
		pnode ret;
		merge(ret, get(l, n - 1), get(0, r - n));
		return ret;
	}

	pnode dummy, dummy2, ret, mid;
	split(root, mid, dummy, r);
	split(mid, dummy2, ret, l - 1);
	return ret;
}

void solve()
{
	while(t % n)
	{
		if(start_pos < m) start_pos = (start_pos + (t % n)) % n;
		else start_pos = (start_pos + n - (t % n)) % n;
		t--;
	}

	t /= n;

	for(int i = 0; i < n; i++) tmpp.pb(i);
	root = build(0, n - 1, tmpp);

	for(int i = 0; i < n; i++)
	{
		pnode L = get(i, m + i - 1);
		pnode R = get(m - i, n - 1 - i);

		merge(root, L, R);
		if(i && i % B == 0)
			rebuild();
	}

	vector<int> clist = get_li(root);
	for(int i = 0; i < n; i++) to[i] = clist[i];

	for(int cnt = 0; t > 0 && cnt < n; cnt++, t--)
		start_pos = to[start_pos];

	if(t != 0)
	{
		int cycle_len = 1, u = to[start_pos];
		while(u != start_pos)
		{
			cycle_len++;
			u = to[u];
		}

		t %= cycle_len;
		while(t--)
			start_pos = to[start_pos];
	}

	cout << start_pos + 1 << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	init_memory();

	read();
	solve();
	return 0;
}


#include <bits/stdc++.h>
#define ll long long

#define TASKNAME ""

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const double EPS = 1e-8;

struct TNode {
    TNode *left, *right;
    int sz, x;
};

TNode *new_node(int x) {
    return new TNode({nullptr, nullptr, 1, x});
}

int safe_sz(TNode *root) {
    return (root ? root->sz : 0);
}

void relax(TNode *root) {
    if (!root) return;
    root->sz = safe_sz(root->left) + safe_sz(root->right) + 1;
}

TNode *merge(TNode *left, TNode *right) {
    if (!left) {
        return right;
    }
    if (!right) {
        return left;
    }
    TNode *node = new_node(-1);
    int sz1 = safe_sz(node->left), sz2 = safe_sz(node->right);
    if (rand() % (sz1 + sz2) < sz1) {
        node->left = merge(left, right->left);
        node->right = right->right;
        node->x = right->x;
    } else {
        node->right = merge(left->right, right);
        node->left = left->left;
        node->x = left->x;
    }
    relax(node);
    return node;
}

void split(TNode *root, int sz, TNode *&left, TNode *&right) {
    if (!root || !sz) {
        left = nullptr;
        right = root;
        return;
    }
    TNode *left1, *right1;
    if (safe_sz(root->left) >= sz) {
        split(root->left, sz, left1, right1);
        left = left1;
    }
    return;
}

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    ll n, m;
    cin >> n >> m;
    ll s, t;
    cin >> s >> t;
    s--;
    int len1 = m, len2 = n - m;
    unordered_map <pair <ll, ll>, bool> was;
    vector <pair <ll, ll> > path;
    while (t > 0) {
        if (was[{s, t % n}]) break;
        was[{s, t % n}] = true;
        path.push_back({s, t % n});
        if (s < m) {
            s = (s + t) % n;
        } else {
            s = ((s - t) % n + n) % n;
        }
        //cout << s << "\n";
        t--;
    }
    if (!t) {
        cout << s + 1 << "\n";
        return 0;
    }
    ll cycle = 1;
    while (path.back() != make_pair(s, t % n)) {
        path.pop_back();
        cycle++;
    }
    t %= cycle;
    while (t > 0) {
        if (s < m) {
            s = (s + t) % n;
        } else {
            s = ((s - t) % n + n) % n;
        }
        t--;
    }
    cout << s + 1;
}


#include <bits/stdc++.h>
#define ll long long

#define TASKNAME ""

using namespace std;

const ll INF = 1e9 + 7;
const ll MAXN = 1e5 + 7;
const double EPS = 1e-8;

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    ll n, m;
    cin >> n >> m;
    ll s;
    ll t;
    cin >> s >> t;
    s--;
    bitset <MAXN * MAXN> was;
    vector <ll> path;
    while (t > 0) {
        if (was[s * MAXN + t % n]) break;
        was[s * MAXN + t % n] = true;
        path.push_back(s * MAXN + t % n);
        if (s < m) {
            s = (s + t) % n;
        } else {
            s = ((s - t) % n + n) % n;
        }
        t--;
    }
    if (!t) {
        cout << s + 1 << "\n";
        return 0;
    }
    ll cycle = 1;
    while (path.back() != s * MAXN + t % n) {
        path.pop_back();
        cycle++;
    }
    t %= cycle;
    while (t > 0) {
        if (s < m) {
            s = (s + t) % n;
        } else {
            s = ((s - t) % n + n) % n;
        }
        t--;
    }
    cout << s + 1;
}


#include <iostream>
#include <cstdio>

#include <utility>

#include <cassert>
#include <ctime>
#include <iomanip>

using namespace std;

const int MAXN = 1e5 + 100;

typedef long long ll;
#define tll(x) static_cast<ll>(x)

typedef pair<int, int> pii;
#define mp make_pair
#define ff first
#define ss second

int N, root;

const int MAXS = MAXN * 800;
struct PBT {
public:
  int c[MAXS][2], v[MAXS], sz[MAXS], h[MAXS];
  int NXT;
  PBT() : NXT(1) {v[0] = -1, sz[0] = 0, h[0] = 0;};
  int upd(int n) {
    if(not(0 < n)) return n;
    sz[n] = sz[c[n][0]] + sz[c[n][1]] + 1;
    h[n] = max(h[c[n][0]], h[c[n][1]]) + 1;
    assert(n != c[n][0] and n != c[n][1]);
    return n;
  }
  int gsz(int n) {
    if(n == 0) return 0;
    return gsz(c[n][0]) + gsz(c[n][1]) + 1;
  }
  void asst(int n) {assert(gsz(n) == sz[n]);}
  int nn(const int& n = -1) {
    assert(NXT < MAXS);
    if(n == 0) return 0;
    if(0 < n) {
      for(int i = 0;i < 2;i++) c[NXT][i] = c[n][i];
      v[NXT] = v[n];
    } else {
      for(int i = 0;i < 2;i++) c[NXT][i] = 0;
      v[NXT] = -1;
    }
    upd(NXT);
    return NXT++;
  }
  int nnr(const int& q) {
    int n = nn();
    v[n] = q;
    return n;
  }
  int L(int& n, int p = 0) {
    assert(c[n][1]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][1]); else n = c[n][1];
    c[o][1] = c[n][0];
    upd(c[n][0] = o);
    return upd(n);
  }
  int R(int& n, int p = 0) {
    assert(c[n][0]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][0]); else n = c[n][0];
    c[o][0] = c[n][1];
    upd(c[n][1] = o);
    return upd(n);
  }
  bool bal(int& n, bool p = false) {   //here, we assume that n is already a copy
    int q = NXT;
    int b = h[c[n][0]] - h[c[n][1]], s, o = n;
    if(b < -1) {
      assert(s = c[n][1]);
      if(h[c[s][1]] + 1 == h[s]) {
        L(n, p ? 1 : 0);
      } else if(h[c[s][0]] + 1 == h[s]) {
        R(c[n][1], p ? 2 : 0);
        L(n, 0);
      } else assert(false);
    }
    else if(b > 1) {
      assert(s = c[n][0]);
      if(h[c[s][0]] + 1 == h[s]) {
        R(n, p ? 1 : 0);
      } else if (h[c[s][1]] + 1 == h[s]) {
        L(c[n][0], p ? 2 : 0);
        R(n, 0);
      } else assert(false);
    }
    else return false;
    return true;
  }
  int join(int a, int b, bool p = true) {  //here we assume a and b are already copies
    if(a == 0 or b == 0) return a ? a : b;
    if(h[a] < h[b]) {
      c[b][0] = join(a, p ? nn(c[b][0]) : c[b][0], p);
      upd(b);
      bal(b, p);
      return b;
    } else {
      c[a][1] = join(p ? nn(c[a][1]) : c[a][1], b, p);
      upd(a);
      bal(a, p);
      return a;
    }
  }
  int join2(int l, int m, int r) {    //assume all are copies, merges L and R at M
    if(h[l] + 1 < h[r]) {c[r][0] = join2(l, m, nn(c[r][0])); return upd(r);}
    if(h[r] + 1 < h[l]) {c[l][1] = join2(nn(c[l][1]), m, r); return upd(l);}
    c[m][1] = r;
    c[m][0] = l;
    upd(m);
    bal(m, 1);
    return m;
  }
  pii split(int a, int k) {   //always create new nodes, assume a is NOT a copy
    if(k == 0) return mp(0, nn(a));
    assert(0 < k);
    if(sz[c[a][0]] < k) {
      pii q = split(c[a][1], k - sz[c[a][0]] - 1);
      int r = join2(nn(c[a][0]), nnr(v[a]), q.ff);
      return mp(r, q.ss);
    } else {
      pii q = split(c[a][0], k);
      int r = join2(q.ss, nnr(v[a]), nn(c[a][1]));
      return mp(q.ff, r);
    }
  }
  int get(int l, int r) {   //inclusive - exclusive
    while(not(l < N)) l -= N, r -= N;
    while(l < 0) l += N, r += N;

    if(r > N) return join(get(l, N), get(N, r));
    pii f1 = split(root, r);
    pii f2 = split(f1.ff, l);

    return f2.ss;
  }
  void fill(int n, int * a, int * t = new int(0)) {
    if(n == 0) return;
    fill(c[n][0], a, t);
    a[(*t)++] = v[n];
    fill(c[n][1], a, t);
  }
  void pout(int n = root) {
    if(n == 0) return;
    pout(c[n][0]);
    cerr << v[n] << " ";
    pout(c[n][1]);
    if(n == root) cerr << "\n\n";
  }
} pbt;

int M, S;
ll T;

int to[40][MAXN];

void gen() {
  root = 0;
  for(int i = 0;i < N;i++) root = pbt.join(root, pbt.nnr(i), 0);
  for(int i = 1;i < N;i++) {
    int a = pbt.get(i, i + M);
    int b = pbt.get(M - i, N - i);
    assert(pbt.sz[a] == M and pbt.sz[b] == N - M);
    root = pbt.join(a, b);
    //pbt.pout();
    assert(pbt.sz[root] == N);
  }
  pbt.fill(root, to[0]);
}

void run() {
  for(int i = 1;i < 40;i++) {
    for(int j = 0;j < N;j++) {
      to[i][j] = to[i-1][to[i-1][j]];
    }
  }
}

void brute() {
  int q = static_cast<int>(T%N);
  for(;q;q--,T--) {
    if(S < M) S = (S + q)%N;
    else S = (S - q + N)%N;
  }
  assert(T%N == 0);
}

void solve() {
  scanf("%d%lld", &S, &T);
  --S;
  brute();
  int k = T/N;
  for(int i = 0;1 << i < k;i++) {
    if(k&(1<<i)) S = to[i][S];
  }
  printf("%d\n", S + 1);
}

int main() {
  clock_t timer = clock();
  cerr << setprecision(6);

  scanf("%d%d", &N, &M);
  gen();
  run();
  //for(int i = 0;i < N;i++) printf("%d\n", to[0][i]);
  solve();

  cerr << "Time Elapsed: " << static_cast<double>(clock() - timer)/CLOCKS_PER_SEC << "\n";

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k,f=0,c=1,s,m;
cin>>n>>k;
int a[n],b[k];
for(int i=0;i<n;i++) {
   cin>>a[i];
   }
b[f++]=a[0];
for(int i=1;i<n;i++)
{
for(int j=0;j<min(f,k);j++)
  {
  if (b[j]==a[i])
    break;
  }
if (int j==min(f,k)){
  c++;
if (f<k)
{
  b[f++]=a[i];
}
else
{int ma=0,l=0,lo;
for(s=0;s<k;s++){
for(m=i+1;m<n;m++)
{
if (b[s]==a[m])
  {l=m;
  break;
  }
}
if (m==n)
 l=n;
if (ma<=l)
  {ma=l;
  lo=s;
}
}
b[lo]=a[i];
}
}
}
cout<<c<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,x,cnt=0,a[100];
	set<int> s,t;
	cin>>n>>k;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=0;i<n;i++){
		x=a[i];
		if (s.find(x)==s.end()){
			++cnt;
			s.insert(x);
		}
		if (s.size()==k+1){
			t=s;
			t.erase(x);
			for (int j=i+1;j<n;j++){
				if (t.size()==1) break;
				t.erase(a[j]);
				return 0;
			}


#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <string.h>

#define read(x) scanf("%d", &x);
#define dbg(x) cout<<#x<<"= "<<x<<endl
#define INF 1000000007ll

using namespace std;

int n,m,q,x,y,f,z,maxi,mini,ansi,T,k,w,Q,tim;
int a[100005];

int next[100];

set<int> s;
map<int,int> ma;
set<int>::iterator it;

int main(){
    read(n);read(m);
    for(int i=1;i<=n;i++){
        read(a[i]);
    }

    for(int i=n;i>=1;i--){
        if(ma[a[i]]!=0){
            next[a[i]]=ma[a[i]];
        }else next[i]=INF;
        ma[a[i]]=i;
    }

    for(int i=1;i<=n;i++){
        if(s.find(a[i])==s.end()){
            q++;
            if(s.size()!=m){
                s.insert(a[i]);
            }else{
                int cnt=0,pos;
                for (it = s.begin(); it != s.end(); it++){
                        if(next[*it]>cnt){cnt=next[*it];pos=*it;}
                }
                s.erase(pos);
                s.insert(a[i]);
            }
        }
    }
    cout<<q<<endl;
    return 0;
}


#include<stdio.h>
#include<set>
#include<queue>
using namespace std;
int a[400005];
queue<int>ind[400005];
set<int>stb;
set<int>::iterator it;
struct node
{
	int index;
	int biao;
}M;
set<node>st;
bool operator<(node a,node b)
{
if(a.index==b.index) return a.biao<b.biao;
	return a.index>b.index;
}
int cot=0;
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		ind[a[i]].push(i);
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		it=stb.find(a[i]);
		if(it==stb.end())
		{
			ans++;
			if(cot<k)
				cot++;
			else {
			stb.erase(stb.find(st.begin()->biao));
			  st.erase(st.begin);
			}
			stb.insert(a[i]);
		}
		M.biao=a[i];
		if(!ind[a[i]].empty())
		{
		  M.biao=ind[a[i]].front();
		  ind[a[i]].pop();
	   }
	   else M.index=n;

		st.insert(M);
	}
	printf("%d\n",ans);
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dilip
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n, m, k;
            n = in.nextInt();
            m = in.nextInt();
            k = in.nextInt();
            if (m >= n && k >= n) out.println("Yes");
            else out.println("No");

        }

    }
}


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

int main()
{
    int n,m,k;
    cin>>n>>m>>k;

    if(m>=n && k>=n)
    {
        cout<<"Yes";
    }

    else{

        cout<<"No";
    }


#include <iostream>
using namespace std;
int n,m,k;
int main()
{
    cin>>n>>m>>k;
    if(m>=n and k>=n) cout<<"Yes";
    else cout<<"No";
    return 0;
}


    #include<bits/stdc++.h>
    #include<algorithm>
    using namespace std;
    #define mod 1e9+7
    #define FOR(a,c)   for ( int (a)=0; (a)<(c); (a)++)
    #define FORL(a,b,c)  for ( int (a)=(b); (a)<=(c); (a)++)
    #define FORR(a,b,c)  for (  int (a)=(b); (a)>=(c); (a)--)
    #define INF 1000000000000000003
    typedef long long int ll;
    typedef vector<long long int> vi;
    typedef pair<long long int,long long int> pi;
    typedef priority_queue<long long int> max_pq;
    typedef priority_queue<long long int, vector<long long int>, greater<long long int>> min_pq;
    #define F first
    #define S second
    #define PB push_back
    #define POB pop_back
    #define MP make_pair

    // Use inbuilt function  __gcd(a,b), __builtin_popcount(n)

   bool issor(ll arr[], ll n)
   {
    for(int i=1;i<=n;i++)
    {
        if(arr[i]!=i)
            return false;
    }
    return true;
   }

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);

        ll n,m,k;
        cin>>n;
        cin>>m>>k;
        ll mina = min(m,k);
        if(min>=n)
            cout<<"YES";
        else
            cout<<"NO";

        return 0;
    }


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

bool is_square(long long n) {
  long long s = sqrt(n);
  return s * s == n;
}

vector<long long> pf(long long n) {
  vector<long long> res;
  for (long long i = 2; i <= 1000000; i++) {
    if (n % i == 0) {
      res.push_back(i);
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n != 1) {
    if (is_square(n)) {
      n = sqrt(n);
    }
    res.push_back(n);
  }
  return res;
}

long long gcd(long long x, long long y) {
  while (y != 0) {
    long long tmp = x;
    x = y;
    y = tmp % y;
  }
  return x;
}

vector<long long> vec(vector<long long> &p, long long n) {
  vector<long long> res(p.size());
  for (int i = 0; i < res.size(); i++) {
    while (n % p[i] == 0) {
      res[i]++;
      n /= p[i];
    }
  }
  return res;
}

int main() {
  int n;
  long long X, Y;
  cin >> n >> X >> Y;
  auto py = pf(Y);
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    if (!py.empty() && gcd(py.back(), a[i]) != py.back()) {
      long long g = gcd(py.back(), a[i]);
      if (g != 1 && g != py.back()) {
        py.back() /= g;
        py.push_back(g);
      }
    }
  }
  if (Y % X != 0) {
    cout << 0 << endl;
    return 0;
  }
  const int m = py.size();
  vector<long long> dp(1 << m);
  vector<long long> vx = vec(px, X);
  vector<long long> vy = vec(py, Y);
  for (int i = 0; i < n; i++) {
    if (Y % a[i] != 0) continue;
    auto va = vec(py, a[i]);
    bool ok = true;
    int mask = 0;
    for (int j = 0; j < m; j++) {
      ok &= va[j] <= vy[j];
      if (va[j] < vy[j]) {
        mask |= 1 << j;
      }
    }
    if (!ok) continue;
    dp[mask]++;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 1 << m; j++) {
      if (j >> i & 1) {
        dp[j ^ 1 << i] += dp[j];
      }
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j << 1 << m; j++) {
      if (~j >> i & 1) {
        dp[j | 1 << i] -= dp[j];
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    auto va = vec(py, a[i]);
    bool ok = true;
    int mask = 0;
    for (int j = 0; j < m; j++) {
      ok &= va[j] >= vx[j];
      if (va[j] > vx[j] && vx[j] < vy[j]) {
        mask |= 1 << j;
      }
    }
    if (!ok) continue;
    ans += abs(dp[mask]);
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL gcd(LL a, LL b) {
  if (not a or not b) return a|b;
  return gcd(b, a % b);
}
LL lcm(LL a, LL b) {
  return a * b / gcd(a, b);
}
vector<LL> fast_OR_transform(vector<LL> f, bool inverse) {
  for (int i = 0; (2 << i) <= f.size(); ++i)
    for (int j = 0; j < f.size(); j += 2 << i)
      for (int k = 0; k < (1 << i); ++k)
        f[j + k + (1 << i)] += f[j + k] * (inverse? -1 : 1);
  return f;
}
vector<LL> rev(vector<LL> A) {
  for (int i = 0; i < A.size(); i += 2) swap(A[i], A[i ^ (A.size() - 1)]);
  return A;
}
vector<LL> fast_AND_transform(vector<LL> f, bool inverse) {
  return rev(fast_OR_transform(rev(f), inverse));
}

LL mul(LL x, LL y, LL mod) {
  LL m = x, s = 0;
  for (; y; y >>= 1, m <<= 1, m = m >= mod? m - mod: m)
    if (y&1) s += m, s = s >= mod? s - mod: s;
  return s;
}
LL powmod(LL x, LL p, LL mod) {
  LL s = 1, m = x % mod;
  for (; p; m = mul(m, m, mod), p >>= 1)
    if (p&1) s = mul(s, m, mod); // or consider int128
  return s;
}
bool miller_rabin(LL n, int s = 7) {
  const LL wits[7] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
  auto witness = [=](LL a, LL n, LL u, int t) {
    LL x = powmod(a, u, n), nx;
    for (int i = 0; i < t; ++i, x = nx){
      nx = mul(x, x, n);
      if (nx == 1 and x != 1 and x != n - 1) return 1;
    }
    return x != 1;
  };
  if (n < 2) return 0;
  if (n&1^1) return n == 2;
  LL u = n - 1, t = 0, a; // n == (u << t) + 1
  while (u&1^1) u >>= 1, ++t;
  while (s--)
    if ((a = wits[s] % n) and (witness(a, n, u, t))) return 0;
  return 1;
}
// Pollard_rho
LL pollard_rho(LL n) {
  auto f = [=](LL x, LL n) { return mul(x, x, n) + 1; };
  if (n&1^1) return 2;
  while (true) {
    LL x = rand() % (n - 1) + 1, y = 2, d = 1;
    for (int sz = 2; d == 1; y = x, sz <<= 1)
      for (int i = 0; i < sz and d <= 1; ++i)
        x = f(x, n), d = gcd(abs(x - y), n);
    if (d and n - d) return d;
  }
}
vector<pair<LL, int>> factor(LL m) {
  vector<pair<LL, int>> ans;
  while (m != 1) {
    LL cur = m;
    while (not miller_rabin(cur)) cur = pollard_rho(cur);
    ans.emplace_back(cur, 0);
    while (m % cur == 0) ++ans.back().second, m /= cur;
  }
  sort(ans.begin(), ans.end());
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  LL a, n, X, Y; cin >> n >> X >> Y;
  if (Y % X) cout << 0 << '\n', exit(0);
  auto factor_Y = factor(Y);
  int m = factor_Y.size();
  assert(m <= 20);
  vector<LL> left(1<<m, 0), right(1<<m, 0);
  vector<pair<LL, int>> factor_X;
  for (auto T: factor_Y) {
    static LL C_X = X;
    LL p, t; tie(p, t) = T;
    factor_X.emplace_back(p, 0);
    while (C_X % p == 0) C_X /= p, ++factor_X.back().second;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a;
    int maskl = 0, maskr = 0;
    bool can_left = a % X == 0, can_right = Y % a == 0;
    for (int j = 0; j < m; ++j) {
      LL p, tx, ty, ta = 0;
      tie(p, tx) = factor_X[j];
      tie(p, ty) = factor_Y[j];
      if (tx == ty) continue;
      while (a % p == 0) ++ta, a /= p;
      maskl |= (tx < ta) << j;
      maskr |= (ty > ta) << j;
    }
    if (can_left) ++left[maskl];
    if (can_right) ++right[maskr];
  }
  left = fast_AND_transform(left, false), right = fast_AND_transform(right, false);
  for (int i = 0; i < (1<<m); ++i) left[i] *= right[i];
  cout << fast_AND_transform(left, true)[0] << '\n';

}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define int long long
using namespace std;
vector<int> V;
int n,x,y,a[10100000],sum[(1<<20)],num[(1<<20)];
int gcd(int a,int b){
	return (b==0)?a:gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int get_state(int x){
	int S=0;
	for(int i=0;i<V.size();i++)
		if(x%V[i]==0)
			S|=(1<<i);
	return S;
}
namespace PR{
	inline long long pow(long long a,long long p,long long mod){
    register long long ans=1;
    while(p){
        if(p&1)
            ans=(long long)ans*a%mod;
        a=(long long)a*a%mod;
        p>>=1;
    }
    return ans;
	}
	inline long long gcd(long long a,long long b){
	    return (b==0)?a:gcd(b,a%b);
	}
	inline bool mr(long long n,long long p){
	    if(pow(n,p-1,p)!=1)
	        return false;
	    register long long k=p-1;
	    while(k%2==0){
	        k/=2;
	        register long long mid=pow(n,k,p);
	        if(mid==p-1)
	            return true;
	        if(mid!=1&&mid!=p-1)
	            return false;
	    }
	    return true;
	}
	inline bool prime(long long n){
	    if(n==2||n==3||n==7||n==61||n==103||n==24251)
	        return true;
	    return mr(2,n)&&mr(3,n)&&mr(61,n)&&mr(7,n)&&mr(24251,n)&&mr(103,n);
	}
	inline long long pollard_rho(long long n,long long c){
	    register long long i=1,k=2,x=(rand())%(n-1)+1,y=x;
	    while(1){
	        i++;
	        x=((__int128)x*x%n+c)%n;
	        register long long Gcd=gcd(n,(y-x+n)%n);
	        if(y==x)
	            return n;
	        if(Gcd!=1&&Gcd!=n)
	            return Gcd;
	        if(i==k){
	            y=x;
	            k<<=1;
	        }
	    }
	}
	inline void find(long long n,long long c){
	    if(prime(n)){
	    	V.push_back(n);
	        return;
	    }
	    register long long p=n,k=c;
	    while(p>=n){
	        p=pollard_rho(p,c--);
	    }
	    find(p,k);
	    find(n/p,k);
	}
}
signed main(){
//	getprime(10001000);
//	scanf("%lld",&y);
//	fj(y,10001000);
//	for(int i=0;i<V.size();i++)
//		printf("%lld ",V[i]);
//	printf("\n");

	scanf("%lld %lld %lld",&n,&x,&y);
	if(y%x){
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	PR::find(y,107);
	for(int i=1;i<=n;i++){
		if(a[i]%x==0){
			int state=get_state(a[i]/x);
			num[((1<<(V.size()))-1)^state]++;
		}
	}
	for(int i=0;i<(1<<V.size());i++){
		for(int j=i;j;j=(j-1)&i)
			sum[j]+=num[i];
		sum[0]+=num[i];
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(y%a[i]==0){
			int v=x;
			while(1){
				int Lcm=lcm(v,a[i]);
				if(Lcm==y)
					break;
				v=v*(y/Lcm);
			}
			v/=x;
			ans+=sum[get_state(v)];
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define int long long
using namespace std;
vector<int> V;
int n,x,y,a[10100000],sum[(1<<20)],num[(1<<20)];
int gcd(int a,int b){
	return (b==0)?a:gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int get_state(int x){
	int S=0;
	for(int i=0;i<V.size();i++)
		if(x%V[i]==0)
			S|=(1<<i);
	return S;
}
namespace PR{
	inline long long pow(long long a,long long p,long long mod){
    register long long ans=1;
    while(p){
        if(p&1)
            ans=(__int128)ans*a%mod;
        a=(__int128)a*a%mod;
        p>>=1;
    }
    return ans;
	}
	inline long long gcd(long long a,long long b){
	    return (b==0)?a:gcd(b,a%b);
	}
	inline bool mr(long long n,long long p){
	    if(pow(n,p-1,p)!=1)
	        return false;
	    register long long k=p-1;
	    while(k%2==0){
	        k/=2;
	        register long long mid=pow(n,k,p);
	        if(mid==p-1)
	            return true;
	        if(mid!=1&&mid!=p-1)
	            return false;
	    }
	    return true;
	}
	inline bool prime(long long n){
	    if(n==2||n==3||n==7||n==61||n==103||n==24251)
	        return true;
	    return mr(2,n)&&mr(3,n)&&mr(61,n)&&mr(7,n)&&mr(24251,n)&&mr(103,n);
	}
	inline long long pollard_rho(long long n,long long c){
	    register long long i=1,k=2,x=(rand())%(n-1)+1,y=x;
	    while(1){
	        i++;
	        x=((__int128)x*x%n+c)%n;
	        register long long Gcd=gcd(n,(y-x+n)%n);
	        if(y==x)
	            return n;
	        if(Gcd!=1&&Gcd!=n)
	            return Gcd;
	        if(i==k){
	            y=x;
	            k<<=1;
	        }
	    }
	}
	inline void find(long long n,long long c){
	    if(prime(n)){
	    	V.push_back(n);
	        return;
	    }
	    register long long p=n,k=c;
	    while(p>=n){
	        p=pollard_rho(p,c--);
	    }
	    find(p,k);
	    find(n/p,k);
	}
}
signed main(){
//	getprime(10001000);
//	scanf("%lld",&y);
//	fj(y,10001000);
//	for(int i=0;i<V.size();i++)
//		printf("%lld ",V[i]);
//	printf("\n");

	scanf("%lld %lld %lld",&n,&x,&y);
	if(y%x){
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	PR::find(y,107);
	for(int i=1;i<=n;i++){
		if(a[i]%x==0){
			int state=get_state(a[i]/x);
			num[((1<<(V.size()))-1)^state]++;
		}
	}
	for(int i=0;i<(1<<V.size());i++){
		for(int j=i;j;j=(j-1)&i)
			sum[j]+=num[i];
		sum[0]+=num[i];
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(y%a[i]==0){
			int v=x;
			while(1){
				int Lcm=lcm(v,a[i]);
				if(Lcm==y)
					break;
				v=v*(y/Lcm);
			}
			v/=x;
			ans+=sum[get_state(v)];
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<vector>
#define sf scanf
#define pf printf
#define fr freopen
#define ps for(;;)
#define lp(i,a,b) for(int i=a;i<=b;++i)
#define rp(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
ll f[2010][2010],g[2010],h[2010],p=1000000007,ans=0;
ll s[2010][2010];
int main(){
    lp(i,2,2000){
        lp(j,1,2000){
            if(j==1)f[i][j]=1;
            else f[i][j]=(f[i][j]+h[j-1])%p;
            g[j]=(g[j]+f[i][j])%p;
            h[j]=(h[j]+f[i][j])%p;
        }
        lp(j,1,2000)h[j]=(h[j]+g[j])%p;
    }
    lp(i,2,2000)
        lp(j,1,2000)
            s[i][j]=(s[i][j-1]+f[i][j])%p;
    int n,m;sf("%d%d",&n,&m);
    lp(i,1,n)
        lp(j,2,m)
            ans=(ans+f[j][i]*s[j][n-i+1]%p*(m-j+1)%p)%p;
    pf("%I64d\n",ans);
    ps;
    return 0;
}


/* 2013-07-26 09:13:44.790583 */#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#define mo 1000000007

using namespace std;

long long n, m, i, j, now1, now2, now, Ans;
long long f[2005][2005], f2[2005][2005];

int main()
{


#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
ll mo=1000000007;

ll dp[2002][2002],dp2[2002][2002],dp3[2002][2002];

void solve() {
    int i,j,k,l,r,x,y; string s;

    cin>>N>>M;

    for(x=2;x<=2000;x++) dp[x][0]=dp2[x][0]=dp3[x][0]=1;
    for(y=1;y<=2000;y++) {
        ll tot=0;
        for(x=2;x<=2000;x++) {
            tot+=dp[x][y-1];
            dp[x][y]=(dp[x-1][y]+tot)%mo;
            dp2[x][y]=(dp[x][y]+mo-dp[x][y-1])%mo;
            dp3[x][y]=(dp3[x][y-1]+dp2[x][y])%mo;
        }
    }

    int y1,y2,w;
    ll ret=0;
    FOR(y1,N) for(y2=y1;y2<N;y2++) {
        for(w=2;w<=M;w++) ret+=dp3[w][y1]*dp3[w][N-1-y2]%mo(M+1-w)%mo;
        ret%=mo;
    }
    cout << ret << endl;
}

int main(int argc,char** argv){
    string s;int i;
    if(argc==1) ios::sync_with_stdio(false);
    FOR(i,argc-1) s+=argv[i+1],s+='\n';
    FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
    solve(); return 0;
}


//#include <stdio.h>
//#include <iostream>
//#include <fstream>
//#include <algorithm>
//#include <vector>
//#include <string>
//#include <queue>
//#include <map>
//#include <set>
//#include <cmath>
//#include <sstream>
//#include <stack>
//#include <string.h>
//#include <list>
//#include <time.h>
//
//#define pb push_back
//#define mp make_pair
//#define X first
//#define Y second
//#define PI 3.14159265358979
//#define forn(i, n) for(int i = 0; i < n; ++i)
//#define ALL(x) x.begin(), x.end()
//#define L(s) (int)((s).size())
//#define sz(s) (int)((s).size())
//#define ms(x) memset(x,0,sizeof(x))
//#define ms1(x) memset(x,-1,sizeof(x))
//#define del(y,x) erase(y.begin()+x)
//
//typedef long long ll;
//using namespace std;
//typedef pair<int,int> pii;
//const int INF = 2147483647;
//const ll LLINF = 9223372036854775807LL;
//const int ST = 100010;
//const int ST1 = 1000010;
//const ll MOD = 1000000007;
//
//ll ABS(ll a) {
//    if(a<0)
//        return a*(-1);
//    else
//        return a;
//}
//
//int main() {
//#ifdef _DEBUG
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif
//
//
//    return 0;
//}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <stdio.h>

using namespace std;

void init()
{
	freopen("input.txt", "r", stdin);
}

int abs(int x)
{
	if (x < 0)
	{
		return -x;
	}
	return x;
}

int main()
{
	int n, m, x1, y1, x2, y2;
	cin >> n >> m >> x1 >> y1 >> x2 >> y2;
	n = abs(x1 - x2) + 1;
	m = abs(y1 - y2) + 1;
	if ((n >= 6) || (m >= 6))
	{
		cout << "Second"l;
		return 0;
	}
	if ((n <= 4) && (m <= 4))
	{
		cout << "First";
		return 0;
	}
	if (((n == 5) || (n == 4)) && ((m == 5) || (m == 4)))
	{
		cout << "Second";
		return 0;
	}
	cout << "First" << endl;
	return 0;
}


#include <iostream>
using namespace std;

int n,m,x1,y1,x2,y2,x,y;

int main()
{
    cin >> n >> m >> x1 >> y1 >> x2 >> y2;
    int x = abs(x1-x2);
    int y = abs(y1-y2);
    if (x <= 3 || y <=3) cout <<"First\n";
    else cout << "Second\n";
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int n, m;
int x1, y1, x2, y2;
int main() {
    scanf("%d %d", &n, &m);
    scanf("%d %d %d %d", &x1, &x2, &y1, &y2);
    int z1 = max(abs(y1 - x1) , abs(y2 - x2)), z2 = min(abs(y1 - x1) , abs(y2 - x2));
    if(abs(y1 - x1) >= 5 || abs(y2 - x2) >= 5 || (z1 == 4 && z2 >= 3)  cout << "Second" << endl;
    else    cout << "First" << endl;
    return 0;
}


//#define MY_DEBUG

#include <set>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#pragma comment(linker, "/STACK:64000000")

using namespace std;

#ifdef MY_DEBUG
#include <fstream>
ifstream cin("input.txt");
ofstream cout("output.txt");
//ifstream cin("game.in");
//ofstream cout("game.out");
#else
#include <iostream>
#endif

const long double eps =  1e-6;
const long long inf = 1000000007;
const long long linf = (long long)1e18;
const long double pi = acos(-1.0);
const int prime = 53;

inline void finclude(){
#ifdef MY_DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    srand(time(NULL));
}

long long mx[123][123] = {}, ans[123][123] = {}, he[123][123] = {}, mod = 12345;
int c[256] = {}, g[256] = {};

void build(vector<char> a, vector<int> b, int m){
    int d[256] = {}, x;
    for(int i = 0; i < m; ++i){
        x = i;
        for(int j = 'A'; j <= 'Z'; ++j){
            if (c[j] != 0){
                d[j] = x % c[j];
                x /= c[j];
            }
        }
        for(int j = 'A'; j <= 'Z'; ++j){
            if (c[j] != 0){
                x = i;
                x -= d[j] * g[j];
                d[j] = (d[j] + 1) % c[j];
                x += d[j] * g[j];
                ++mx[x][i];
            }
        }
    }
}

int main(){
    long long n, m = 1, K;
    cin >> n >> K;
    vector<char> a(K);
    vector<long long> b(K);
    for(int i = 0; i < K; ++i){
        cin >> a[i] >> b[i];
        if (c[a[i]] == 0)
            c[a[i]] = b[i];
        else
            c[a[i]] *= b[i];
        m *= b[i];
    }
    long long x = 1;
    for(int i = 'A'; i <= 'Z'; ++i){
        if (c[i] != 0){
            g[i] = x;
            x *= c[i];
        }
    }
    build(a, b, m);
    for(int i = 0; i < m; ++i)
        ans[i][i] = 1;
    while(n != 0){
        if (n % 2 == 1){
            --n;
            for(int i = 0; i < m; ++i){
                for(int j = 0; j < m; ++j){
                    he[i][j] = 0;
                    for(int k = 0; k < m; ++k)
                        he[i][j] += ans[i][k] * mx[k][j];
                }
            }
            for(int i = 0; i < m; ++i)
                for(int j = 0; j < m; ++j)
                    ans[i][j] = he[i][j] % mod;
        }
        n /= 2;
        for(int i = 0; i < m; ++i){
            for(int j = 0; j < m; ++j){
                he[i][j] = 0;
                for(int k = 0; k < m; ++k)
                    he[i][j] += mx[i][k] * mx[k][j];
            }
        }
        for(int i = 0; i < m; ++i)
            for(int j = 0; j < m; ++j)
                mx[i][j] = he[i][j] % mod;
    }
    long long an = 0;
    for(int i = 0; i < m; ++i){
        int x = i;
        int d[256] = {};
        bool find = false;
        for(int j = 'A'; j <= 'Z'; ++j){
            if (c[j] != 0){
                d[j] = x % c[j];
                x /= c[j];
            }
        }
        for(int j = 'A'; j <= 'Z'; ++j)
            for(int k = 0; k < K; ++k)
                if (a[k] == j && d[j] % b[k] == 0)
                    d[j] = 0;
        for(int j = 'A'; j <= 'Z'; ++j)
            if (d[j] != 0)
                find = true;
        if (find)
            continue;
        an = (an + ans[i][0]) % mod;
    }
    cout << an << '\n';
    return 0;
}


#include <array>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
namespace fio {
streambuf* in = cin.rdbuf();
char bb[1000000], *s = bb, *t = bb;
#define gc() \
  (s == t && (t = (s = bb) + in->sgetn(bb, 1000000), s == t) ? EOF : *s++)
inline long long read() {
  long long x = 0;
  char ch = gc();
  while (ch < 48) ch = gc();
  while (ch >= 48) x = x * 10 + ch - 48, ch = gc();
  return x;
}
}  // namespace fio
using fio::read;
long longn;
int m, llm;
int lim[26];
vector<int> road[26];
map<array<int, 26>, int> huaji;
array<int, 26> pm;
class mat {
 public:
  int val[125][125];
  int* operator[](int x) { return val[x]; }
  mat operator*(mat _) {
    mat ans;
    for (int i = 1; i <= llm; i++)
      for (int u = 1; u <= llm; u++) {
        ans[i][u] = 0;
        for (int j = 1; j <= llm; j++)
          ans[i][u] = (ans[i][u] + val[i][j] * _[j][u]) % 12345;
      }
    return ans;
  }
};
mat ksm(mat x, long long y) {
  mat ans = x;
  y--;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ans = ans * x;
  return ans;
}
mat base;
int ans;
int main() {
  n = read(), m = read();
  if (!n) return cout << 1, 0;
  if (!m) return cout << 0, 0;
  for (int i = 1, x, y; i <= m; i++)
    x = read() + '0' - 'A', road[x].emplace_back(y = read()),
    lim[x] = max(lim[x], 1) * road[x].back();
  while (pm[25] < max(lim[25], 1)) {
    huaji[pm] = ++llm, pm[0]++;
    for (int i = 0; i < 25; i++)
      if (lim[i])
        pm[i + 1] += pm[i] / lim[i], pm[i] %= lim[i];
      else
        pm[i + 1] += pm[i], pm[i] = 0;
  }
  for (pair<array<int, 26>, int> it : huaji)
    for (int i = 0; i < 26; i++)
      if (lim[i])
        it.first[i] = (it.first[i] + 1) % lim[i],
        base[it.second][huaji[it.first]]++,
        it.first[i] = (it.first[i] - 1 + lim[i]) % lim[i];
  base = ksm(base, n);
  for (pair<array<int, 26>, int> it : huaji) {
    bool flag = 1;
    for (int i = 0, fx = 0; flag && i < 26; i++, flag &= fx, fx = 0)
      if (!lim[i])
        fx = 1;
      else
        for (int p : road[i]) fx |= !(it.first[i] % p);
    flag ? ans = (ans + base[1][it.second]) % 12345 : ans;
  }
  cout << ans << endl;
}


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

typedef vector<vector<int> > Matrix;
typedef long long ll;

const int MOD = 12345;
int add(int a, int b) { return a+b-(a+b>=MOD)*MOD; }
int mult(int a, int b) { return (1LL*a*b)%MOD; }

Matrix make(int a, int b) { return Matrix(a,vector<int>(b)); }
Matrix mult(Matrix a, Matrix b) {
	Matrix res = make(a.size(),b[0].size());
	for (int i=0;i<a.size();i++) {
		for (int j=0;j<b[0].size();j++) {
			for (int k=0;k<a[0].size();k++) {
				res[i][j] = add(res[i][j],mult(a[i][k],b[k][j]));
			}
		}
	}
	return res;
}
Matrix modpow(Matrix x, ll p) {
	Matrix ans = make(x.size(),x.size());
	for (int i=0;i<x.size();i++) ans[i][i] = 1;
	while (p) {
		if (p&1) ans = mult(ans,x);
		p>>=1;
		x = mult(x,x);
	}
	return ans;
}

int n,m;
set<int> conditions[27];
int lcm[27];
int good[27][130];
int D = 0;
map<vector<int>,int> mp;
vector<int> states[125];

void getstates(vector<int> v, int cur){
	if(cur==26){
		states[D] = v;
		mp[v] = D;
		D++;
		//cout << v << endl;
		return;
	}
	for(int i=0;i<lcm[cur];i++){
		v[cur]=i;
		getstates(v, cur+1);
	}
}

int main(){

	cin >> n >> m;
	for(int i=0;i<m;i++){
		char c;int x;
		cin >> c >> x;
		conditions[c-'A'].insert(x);
	}
	for(int i=0;i<26;i++)lcm[i]=1;
	for(int i=0;i<26;i++)for(auto t:conditions[i])lcm[i]*=t;
	for(int i=0;i<26;i++){
		good[i][0]=1;
		for(auto t:conditions[i]){
			int cur = t;
			for(int j=0;j<lcm[i];j+=cur){
				good[i][j]=1;
			}
		}
	}
	vector<int> v(26);
	iota(v.begin(),v.end(),0);
	getstates(v, 0);
	Matrix A = make(D,D);
	for(int i=0;i<D;i++){
		vector<int> v = states[i];
		for(int j=0;j<26;j++)if(!conditions[j].empty()){
			int c = lcm[j];
			v[j] = (v[j]+1)%c;
			A[i][mp[v]]++;
			v[j] = (v[j]-1+c)%c;
		}
	}

	A = modpow(A, n);
	int ans = 0;
	for(int i=0;i<D;i++){
		vector<int> v = states[i];
		bool flag = true;
		for(int j=0;j<26;j++)if(!good[j][v[j]])flag = false;
		if(flag){
			ans = add(ans, A[0][i]);
		}
	}
	cout << ans << endl;

	return 0;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<deque>
using namespace std;
#define pb push_back
typedef long long lint;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
map<lint,vector <vector <lint> > > me;
int pro=1,mo=12345;
int it[30];
vector <vector <lint> > tmp;
vector <vector <lint> > rec(lint a){
	if(me[a].size()) return me[a];
	int i,j,k;
	vector <vector <lint> > ret=tmp,mae=rec(a/2),ato=rec(a-a/2);
	for(i=0;i<pro;i++) for(j=0;j<pro;j++) for(k=0;k<pro;k++){
		ret[i][j]=(ret[i][j]+mae[i][k]*ato[k][j])%mo;
	}
	return me[a]=ret;
}
int cal(int a,int b,int c){
	if((a/b)%c<c-1) return a+b;else return a-b*(c-1);
}
int main()
{
	int i,j,k,m,a;string s;lint out=0,n;
	memset(it,0,sizeof(it));
	vector <vector <pint> > it2;
	vector <vector <lint> > one,ret;
	vector <lint> cl;vector <pint> cl2;
	for(i=0;i<30;i++) it2.pb(cl2);
	for(i=0;i<125;i++) cl.pb(0);for(j=0;j<125;j++) tmp.pb(cl);one=tmp;
	cin>>n>>m;
	if(n==0){
		cout<<"1"<<endl;return 0;
	}
	if(m==0){
		cout<<"0"<<endl;return 0;
	}
	for(i=0;i<m;i++){
		cin>>s>>a;it[(s[0]-'A')]+=pro;it2[(s[0]-'A')].pb(mp(pro,a));
		pro*=a;
	}
	for(i=0;i<26;i++){
		if(it2[i].size()<1) continue;
		for(j=0;j<pro;j++){
			int x=j;
			for(k=0;k<it2[i].size();k++){
				pint t=it2[i][k];
				x=cal(x,t.fi,t.se);
//				cout<<t.fi<<' '<<t.se<<endl;
			}
//			cout<<i<<' '<<j<<' '<<x<<endl;
			one[j][x]=+=1;
		}
	}
	for(i=0;i<pro;i++){
		for(j=0;j<pro;j++){
//			cout<<one[i][j]<<' ';
		}
//		cout<<endl;
	}
	me[1]=one;ret=rec(n);
	for(i=0;i<pro;i++){
		int f=0;
		for(j=0;j<26;j++){
			if(it2[j].size()<1) continue;
			int f2=0;
			for(k=0;k<it2[j].size();k++){
				pint t=it2[j][k];
				if((i/t.fi)%t.se==0) f2=1;
			}
			if(f2<1) f=1;
		}
		if(f<1) out=(out+ret[0][i])%mo;
	}
	cout<<out<<endl;
	return 0;
}


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

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define ff first
#define ss second

typedef long long int ll;
typedef long double ld;
typedef short int sh;

inline void readI(int *i)
{
	register int t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=(t*znak);
}
inline void readUI(int *i)
{
	register int t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=t;
}
inline void readL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak*=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=(t*znak);
}
inline void readUL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=t;
}
inline void writeI(int i)
{
	if (i==0)
	{
		putchar(48);
	}
	else
	{
		if (i<0)
		{
		   i*=-1;
		   putchar(45);
		}
		int _tab[12];
		int wsk=0;
		while (i>0)
		{
			++wsk;
			_tab[wsk]=(i%10)+48;
			i/=10;
		}
		for (int j=wsk; j>=1; --j)
		{
			putchar(_tab[j]);
		}
	}
}
inline void writeL(ll l)
{
	if (l==0)
	{
		putchar(48);
	}
	else
	{
		if (l<0)
		{
		   l*=-1;
		   putchar(45);
		}
		int _tab[21];
		int wsk=0;
		while (l>0)
		{
			++wsk;
			_tab[wsk]=(l%10)+48;
			l/=10;
		}
		for (int j=wsk; j>=1; --j)
		{
			putchar(_tab[j]);
		}
	}
}
inline void writeS(string s)
{
	int l=s.length();
	for (int i=0; i<l; ++i)
	{
		putchar(s[i]);
	}
}
inline void writeC(char c)
{
	putchar(c);
}
inline void space()
{
	putchar(32);
}
inline void endl()
{
	putchar(10);
}

#define debug if(0)
#define debug2 if(1)
#define debug3 if(1)
#define debug4 if(1)
#define MAXN (int)(1e5)+5
#define ZAK (1<<20)+5

int n, r, llog;
int tab[3*MAXN];
int R[3*MAXN][20], L[3*MAXN][20];
int INF=1000696969;

void test_LR()
{
	for (int j=0; j<=llog; ++j)
	{
		for (int i=1; i<=3*n; ++i)
		{
			printf ("j=%d i=%d L[i][j]=%d R[i][j]=%d\n", j, i, L[i+r-1][j], R[i+r-1][j]);
		}
		endl();
	}
	endl();
}
void ustaw(int j)
{
	for (int i=r-1; i>=1; --i)
	{
		L[i][j]=min(L[i<<1][j], L[(i<<1)+1][j]);
		R[i][j]=max(R[i<<1][j], R[(i<<1)+1][j]);
	}
}
int query(int x, int lvl, int pp, int pk, int zp, int zk, int op)
{
	if (zk<pp || pk<zp)
	{
		if (op==0)
		{
			return INF;
		}
		else
		{
			return 0;
		}
	}
	if (zp<=pp && pk<=zk)
	{
		if (op==0)
		{
			return L[x][lvl];
		}
		else
		{
			return R[x][lvl];
		}
	}
	int sr=((pp+pk)>>1);
	if (op==0)
	{
		return min(query(x<<1, lvl, pp, sr, zp, zk, op), query((x<<1)+1, lvl, sr+1, pk, zp, zk, op));
	}
	else
	{
		return max(query(x<<1, lvl, pp, sr, zp, zk, op), query((x<<1)+1, lvl, sr+1, pk, zp, zk, op));
	}
}
int main()
{
	readI(&n);
	if (n==1)
	{
		printf ("0 ");
		return 0;
	}
	r=1;
	while (r<3*n)
	{
		r<<=1;
		++llog;
	}
	for (int j=0; j<=llog; ++j)
	{
		for (int i=1; i<=r; ++i)
		{
			L[i][j]=INF;
		}
	}
	for (int i=1; i<=n; ++i)
	{
		readI(&tab[i]);
		tab[i+n]=tab[i+(n<<1)]=tab[i];
		R[i+r-1][0]=min(3*n, i+tab[i]);
		R[i+n+r-1][0]=min(3*n, i+n+tab[i]);
		R[i+(n<<1)+r-1][0]=min(3*n, i+(n<<1)+tab[i]);
		L[i+r-1][0]=max(1, i-tab[i]);
		L[i+n+r-1][0]=max(1, i+n-tab[i]);
		L[i+(n<<1)+r-1][0]=max(1, i+(n<<1)-tab[i]);
	}
	ustaw(0);
	for (int j=1; j<=llog; ++j)
	{
		for (int i=1; i<=3*n; ++i)
		{
			int gg=query(1, j-1, 1, r, L[i+r-1][j-1], R[i+r-1][j-1], 0);
			gg=max(gg, 1);
			L[i+r-1][j]=gg;
			gg=query(1, j-1, 1, r, L[i+r-1][j-1], R[i+r-1][j-1], 1);
			gg=min(gg, 3*n);
			R[i+r-1][j]=gg;
		}
		ustaw(j);
	}
	debug
	{
		test_LR();
	}
	for (int i=n+1; i<=(n<<1); ++i)
	{
		debug
		{
			endl();
			endl();
		}
		int czas=0;
		int lewy, prawy;
		lewy=prawy=i;
		for (int j=llog; j>=0; --j)
		{
			debug
			{
				printf ("i=%d j=%d czas=%d lewy=%d prawy=%d L[lewy+r-1][j]=%d R[prawy+r-1][j]=%d\n", i, j, czas, lewy, prawy, L[lewy+r-1][j], R[prawy+r-1][j]);
			}
			int ll=query(1, j, 1, r, lewy, prawy, 0);
			int pp=query(1, j, 1, r, lewy, prawy, 1);
			if (pp-ll+1<n)
			{
				lewy=ll;
				prawy=pp;
				czas+=(1<<j);
			}
		}
		printf ("%d ", czas+1);
	}
	return 0;
}
/*
10
1 3 1 4 1 1 1 3 2 3
*/


#include <bits/stdc++.h>

using namespace std;
const int N = 4e5 + 10;

int n , a[N];

struct Node {
	int L , R;
} tr[20][N << 1];

Node jp[N][20];

Node merge(Node a,Node b) {
	if (a.R < b.R) a.R = b.R;
	if (a.L > b.L) a.L = b.L;
	return a;
}

void up(int o,int typ) {
	tr[typ][o] = merge(tr[typ][o << 1] , tr[typ][o << 1 | 1]);
}

void build(int o,int l,int r,int typ) {
	if (l == r) {

		tr[typ][o].L = jp[l][typ].L;
		tr[typ][o].R = jp[l][typ].R;
		return;
	}
	int mid = l + r >> 1;
	build(o << 1 , l , mid , typ);
	build(o << 1 | 1 , mid + 1 , r , typ);
	up(o , typ);
}

Node query(int o,int l,int r,int ql,int qr,int typ) {

//	printf("%d %d %d %d\n",l,r,ql,qr);
	if (ql <= l && r <= qr) {
		return tr[typ][o];
	}
	int mid = l + r >> 1;
	if (ql <= mid && mid < qr) {
		return merge( query(o << 1 , l , mid , ql , qr , typ) , query(o << 1 | 1 , mid + 1 , r , ql , qr , typ) );
	} else {
		if (ql <= mid) return query(o << 1 , l , mid , ql , qr , typ);
		else 		   return query(o << 1 | 1 , mid + 1 , r , ql , qr , typ);
	}
}

void init() {

	for (int i = 1;i <= n * 3;i++){
		jp[i][0].L = max(1 , i - a[i]);
		jp[i][0].R = min(n * 3 , i + a[i]);
	}

	build(1 , 1 , n * 3 , 0);

	for (int j = 1; j < 20;j++){

		for (int i = 1; i <= n * 3; i++) {
			jp[i][j] = query(1 , 1 , n * 3 , jp[i][j - 1].L , jp[i][j - 1].R , j - 1);
		}
		build(1 , 1 , n * 3 , j);
	}

}

bool check(int pos,int time) {

	Node ans = (Node){pos , pos};

	for (int Lg = 0;Lg < 20;Lg++){
		if (time & (1 << Lg) ){
			ans = query(1 , 1 , n * 3 , ans.L , ans.R , Lg);
		}
	}

	return ans.R - ans.L >= n;
}

int main() {
	cin >> n;

	for (int i = 1; i <= n; i++) scanf("%d",&a[i]) , a[ 2 * n + i ] = a[n+i] = a[i];

	init();

	for (int i = 1;i <= n;i++){
		int L = 1 , R = n , ans = n;

		while (L <= R){
			int mid = L + R >> 1;
			if (check(i + n , mid)){
				ans = mid;
				R = mid - 1;
			}else{
				L = mid + 1;
			}
		}

		printf("%d ",ans);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 3e5 + 10;

int n , a[N];

struct Node {
	int L , R;
} tr[19][N << 1];

Node jp[N][19];

Node merge(Node a,Node b) {
	if (a.R < b.R) a.R = b.R;
	if (a.L > b.L) a.L = b.L;
	return a;
}

void up(int o,int typ) {
	tr[typ][o] = merge(tr[typ][o << 1] , tr[typ][o << 1 | 1]);
}

void build(int o,int l,int r,int typ) {
	if (l == r) {

		tr[typ][o].L = jp[l][typ].L;
		tr[typ][o].R = jp[l][typ].R;
		return;
	}
	int mid = l + r >> 1;
	build(o << 1 , l , mid , typ);
	build(o << 1 | 1 , mid + 1 , r , typ);
	up(o , typ);
}

Node query(int o,int l,int r,int ql,int qr,int typ) {

//	printf("%d %d %d %d\n",l,r,ql,qr);
	if (ql <= l && r <= qr) {
		return tr[typ][o];
	}
	int mid = l + r >> 1;
	if (ql <= mid && mid < qr) {
		return merge( query(o << 1 , l , mid , ql , qr , typ) , query(o << 1 | 1 , mid + 1 , r , ql , qr , typ) );
	} else {
		if (ql <= mid) return query(o << 1 , l , mid , ql , qr , typ);
		else 		   return query(o << 1 | 1 , mid + 1 , r , ql , qr , typ);
	}
}

void init() {

	for (int i = 1;i <= n * 3;i++){
		jp[i][0].L = max(1 , i - a[i]);
		jp[i][0].R = min(n * 3 , i + a[i]);
	}

	build(1 , 1 , n * 3 , 0);

	for (int j = 1; j < 19;j++){

		for (int i = 1; i <= n * 3; i++) {
			jp[i][j] = query(1 , 1 , n * 3 , jp[i][j - 1].L , jp[i][j - 1].R , j - 1);
		}
		build(1 , 1 , n * 3 , j);
	}

}

bool check(int pos,int time) {

	Node ans = (Node){pos , pos};

	for (int Lg = 0;Lg < 19;Lg++){
		if (time & (1 << Lg) ){
			ans = query(1 , 1 , n * 3 , ans.L , ans.R , Lg);
		}
	}

	return ans.R - ans.L >= n;
}

int main() {
	cin >> n;

	for (int i = 1; i <= n; i++) scanf("%d",&a[i]) , a[n+i] = a[i] , a[ 2 * n + i ] = a[i];

	init();

	for (int i = 1;i <= n;i++){
		int L = 1 , R = n , ans = n;

		while (L <= R){
			int mid = L + R >> 1;
			if (check(i + n , mid)){
				ans = mid;
				R = mid - 1;
			}else{
				L = mid + 1;
			}
		}

		printf("%d ",ans);
	}

	return 0;
}


    #include<bits/stdc++.h>
    #define rep(i,a,n) for(int i=a;i<=n;i++)
    #define per(i,a,n) for(int i=n;i>=a;i--)
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define maxn 100000
    #define mod 1000000007
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef vector<int> vi;

    int n;
    int a[maxn+5];
    int lg[maxn+5];
    pii st[18][18][maxn+5];

    pii Merge(pii a,pii b,int l)
    {
        return mp(max(a.fi,b.fi-l),max(a.se,b.se+l));
    }

    pii ask(int s,int l,int r,int x)
    {
        int k=lg[x];
        r=(r-(1<<k)+1+n)%n;
        return Merge(st[s][k][l],st[s][k][r],x-(1<<k));
    }

    int main()
    {
        rep(i,2,maxn) lg[i]=lg[i>>1]+1;

        scanf("%d",&n);
        rep(i,0,n-1) scanf("%d",&a[i]);
        if(n==1)
        {
            printf("0\n");
            return 0;
        }
        rep(i,0,n-1) st[0][0][i]=mp(a[i],a[i]);
        rep(i,1,16) rep(j,0,n-1)
            st[0][i][j]=Merge(st[0][i-1][j],st[0][i-1][(j+(1<<i-1))%n],1<<i-1);
        rep(s,1,16)
        {
            rep(i,0,16) rep(j,0,n-1)
            {
                if(st[s-1][i][j].fi+st[s-1][i][j].se+1>=n) st[s][i][j]=st[s-1][i][j];
                else
                {
                    int l=(j-st[s-1][i][j].fi+n)%n,r=(j+st[s-1][i][j].se)%n,x=st[s-1][i][j].fi+st[s-1][i][j].se+1;
                    st[s][i][j]=ask(s-1,l,r,x);
                    st[s][i][j].fi+=st[s-1][i][j].fi;
                    st[s][i][j].se-=st[s-1][i][j].fi;
                }
            }
        }
        rep(i,0,n-1)
        {
            pii now(0,0);
            int ans=0;
            per(s,0,16)
            {
                int l=(i-now.fi+n)%n,r=(i+now.se)%n,x=now.fi+now.se+1;
                pii res=ask(s,l,r,x);
                if(res.fi+res.se+1<n)
                {
                    res.fi+=now.fi;
                    res.se-=now.fi;
                    now=res;
                    ans|=(1<<s);
                    if( n == 10000 && a[0] == 36 )cout << s <<  " "
                }
            }
            if( n == 10000 && a[0] == 36 )cn;
            printf("%d%c",ans+1," \n"[i==n-1]);
            if( n == 10000 && a[0] == 36 )
        }
        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
#define int long long

struct pos {
    int x, y, z, dx, dy, dz, color;
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n, m, k;
    cin >> n >> m >> k;

    vector<vector<vector<int>>> result(n, vector<vector<int>>(m, vector<int>(k, -1)));

    queue<pos> todo;
    map<tuple<int, int, int>, vector<pos>> done;

    for(int i = 0; i < m; i++) for(int j = 0; j < k; j++) {int x; cin >> x; todo.push({0, i, j, 1, 0, 0, x}); }
    for(int i = 0; i < m; i++) for(int j = 0; j < k; j++) {int x; cin >> x; todo.push({n - 1, i, j, -1, 0, 0, x});}
    for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) {int x; cin >> x; todo.push({i, 0, j, 0, 1, 0, x}); }
    for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) {int x; cin >> x; todo.push({i, m - 1, j, 0, -1, 0, x});}
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) {int x; cin >> x; todo.push({i, j, 0, 0, 0, 1, x}); }
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) {int x; cin >> x; todo.push({i, j, k - 1, 0, 0, -1, x});}

    while(!todo.empty()){
        pos p = todo.front();
        todo.pop();

        if(done.find({p.x, p.y, p.z}) == done.end()) done[{p.x, p.y, p.z}] = vector<pos>();
        done[{p.x, p.y, p.z}].push_back(p);

        if(p.color == 0 || (result[p.x][p.y][p.z] != -1 && result[p.x][p.y][p.z] != p.color)){
            result[p.x][p.y][p.z] = 0;

            for(pos pp : done[{p.x, p.y, p.z}]){
                if(pp.x + pp.dx < 0 || pp.x + pp.dx >= n || pp.y + pp.dy < 0 || pp.y + pp.dy >= m || pp.z + pp.dz < 0 || pp.z + pp.dz >= k){
                    if(pp.color != 0){
                        cout << -1 << endl;
                        return 0;
                    }
                } else {
                    todo.push({pp.x + pp.dx, pp.y + pp.dy, pp.z + pp.dz, pp.dx, pp.dy, pp.dz, pp.color});
                }
            }

            done[{p.x, p.y, p.z}].clear();
        } else if(result[p.x][p.y][p.z] == -1){
            result[p.x][p.y][p.z] = p.color;
        }
    }

    for(int a = 0; a < n; a++) {
        for(int b = 0; b < m; b++) {
            for(int c = 0; c < k; c++) {
                cout << max(0LL, result[a][b][c]) << " ";
            }
            cout << endl;
        }
        cout << endl;
    }
}


// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

template <typename T>
struct vec3 {
	int N[3];
	vector<T> data;

	vec3() = default;
	vec3(int N0, int N1, int N2, T val = 0) : N{N0, N1, N2} {
		data.resize(N0*N1*N2, val);
	}

	T & operator()(int i0, int i1, int i2) {
		return data[(i0*N[1]+i1)*N[2]+i2];
	}
};

template <typename T>
struct vec2 {
	int N[2];
	vector<T> data;

	vec2() = default;
	vec2(int N0, int N1, T val = 0) : N{N0, N1} {
		data.resize(N0*N1, val);
	}

	T & operator()(int i0, int i1) {
		return data[i0*N[1]+i1];
	}
};

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N[3];
	for(int i = 0; i < 3; i++) cin >> N[i];
	vec2<int> A[3][2];
	int dim[3][2];
	for(int k = 0; k < 3; k++) for(int l = 0; l < 2; l++) {
		dim[k][0] = k ? 0 : 1;
		dim[k][1] = 3-k-dim[k][0];
		A[k][l] = vec2<int>(N[dim[k][0]], N[dim[k][1]]);
		for(int i = 0; i < N[dim[k][0]]; i++)
			for(int j = 0; j < N[dim[k][1]]; j++)
				cin >> A[k][l][i,j];
	}
	vec3<int> ans(N[0], N[1], N[2], -1);
	for(int k = 0; k < 3; k++)
		for(int i = 0; i < N[dim[k][0]]; i++)
			for(int j = 0; j < N[dim[k][1]]; j++)
				if(!A[k][0](i,j) || !A[k][1](i,j)) {
					if(A[k][0](i,j) || A[k][1](i,j)) {
						cout << "-1\n";
						return 0;
					}
					int idx[3];
					idx[dim[k][0]] = i;
					idx[dim[k][1]] = j;
					for(idx[k] = 0; idx[k] < N[k]; idx[k]++) ans(idx[0],idx[1],idx[2]) = 0;
				}
	vec3<int> border[8];
	for(int c = 0; c < 8; c++) border[c] = vec3<int>(N[0], N[1], N[2], 0);
	vec3<int> cur[8];
	for(int c = 0; c < 8; c++) cur[c] = vec3<int>(N[0], N[1], N[2], -1);
	vec2<int> B[8][3];
	for(int c = 0; c < 8; c++)
		for(int k = 0; k < 3; k++) {
			int x = (c>>k)&1;
			B[c][k] = vec2<int>(N[dim[k][0]], N[dim[k][1]], 0);
			for(int i = 0; i < N[dim[k][0]]; i++)
				for(int j = 0; j < N[dim[k][1]]; j++) {
					int i_r = i, j_r = j;
					if((c>>dim[k][0])&1) i_r = N[dim[k][0]]-1-i;
					if((c>>dim[k][1])&1) j_r = N[dim[k][1]]-1-j;
					B[c][k](i_r,j_r) = A[k][x](i,j);
				}
		}
	for(int r = 0; r < 2; r++) for(int c = 0; c < 8; c++) {
		for(int i = 0; i < N[0]; i++)
			for(int j = 0; j < N[1]; j++)
				for(int k = 0; k < N[2]; k++) {
					if(i == 0) border[c](i,j,k) |= 1;
					if(j == 0) border[c](i,j,k) |= 2;
					if(k == 0) border[c](i,j,k) |= 4;
					int i_r = i, j_r = j, k_r = k;
					if(c&1) i_r = N[0]-1-i;
					if(c&2) j_r = N[1]-1-j;
					if(c&4) k_r = N[2]-1-k;
					if(ans(i,j,k) == 0) cur[c](i_r,j_r,k_r) = 0;
				}
		for(int i = 0; i < N[0]; i++)
			for(int j = 0; j < N[1]; j++)
				for(int k = 0; k < N[2]; k++) {
					if(!border[c](i,j,k)) continue;
					int idx[3] = {i, j, k};
					if(cur[c](i,j,k) == -1) for(int l = 0; l < 3; l++) if((border[c](i,j,k)>>l)&1) {
						if(cur[c](i,j,k) == -1) cur[c](i,j,k) = B[c][l](idx[dim[l][0]],idx[dim[l][1]]);
						else if(cur[c](i,j,k) != B[c][l](idx[dim[l][0]],idx[dim[l][1]])) cur[c](i,j,k) = 0;
					}
					int b = border[c](i,j,k);
					if(cur[c](i,j,k) == 0) {
						for(int l = 0; l < 3; l++) {
							idx[l]++;
							if(idx[l] != N[l]) border[c](idx[0],idx[1],idx[2]) |= b & (1<<l);
							idx[l]--;
						}
					}
					else {

					}
				}
		for(int i = 0; i < N[0]; i++)
			for(int j = 0; j < N[1]; j++)
				for(int k = 0; k < N[2]; k++) {
					int i_r = i, j_r = j, k_r = k;
					if(c&1) i_r = N[0]-1-i;
					if(c&2) j_r = N[1]-1-j;
					if(c&4) k_r = N[2]-1-k;
					if(cur[c](i,j,k) != -1) {
						if(ans(i_r,j_r,k_r) != -1 && cur[c](i,j,k) != ans(i_r,j_r,k_r)) ans(i_r,j_r,k_r) = 0;
						else ans(i_r,j_r,k_r) = cur[c](i,j,k);
					}
				}
	}
	for(int k = 0; k < 3; k++)
		for(int i = 0; i < N[dim[k][0]]; i++)
			for(int j = 0; j < N[dim[k][1]]; j++)
				if(A[k][0](i,j)) {
					int idx[3];
					idx[dim[k][0]] = i;
					idx[dim[k][1]] = j;
					idx[k] = 0;
					while(idx[k] < N[k] && !ans(idx[0],idx[1],idx[2])) idx[k]++;
					if(idx[k] == N[k] || ans(idx[0],idx[1],idx[2]) != A[k][0](i,j)) {
						cout << "-1\n";
						return 0;
					}
					idx[k] = N[k]-1;
					while(idx[k] >= 0 && !ans(idx[0],idx[1],idx[2])) idx[k]--;
					if(idx[k] == -1 || ans(idx[0],idx[1],idx[2]) != A[k][1](i,j)) {
						cout << "-1\n";
						return 0;
					}
				}
	for(int i = 0; i < N[0]; i++)
		for(int j = 0; j < N[1]; j++)
			for(int k = 0; k < N[2]; k++)
				if(ans(i,j,k) == -1) ans(i,j,k) = 0;
	for(int i = 0; i < N[0]; i++) {
		if(i) cout << "\n";
		for(int j = 0; j < N[1]; j++) for(int k = 0; k < N[2]; k++)
			cout << ans(i,j,k) << ((k == N[2]-1) ? "\n" : " ");
	}
	return 0;
}

// look at my code
// my code is amazing


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()
#define left left228
#define right right228
template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

struct triple{
	int x, y, z;
	triple() {}
	triple(int _x, int _y, int _z) {
		x = _x, y = _y, z = _z;
	}
};

int n, m, k;

vector<vector<int>> up, down, left, right, top, bottom;

void Read(vector<vector<int>> & have, int a, int b) {
	have.resize(a, vector<int> (b));
	for (auto &i : have)
		for (auto &j : i)
			cin >> j;
}

void read() {
	cin >> n >> m >> k;
	Read(left, m, k);
	Read(right, m, k);
	Read(top, n, k);
	Read(bottom, n, k);
	Read(down, n, m);
	Read(up, n, m);
}

bool operator==(const triple & a, const triple & b) {
	return tie(a.x, a.y, a.z) == tie(b.x, b.y, b.z);
}

vector<vector<vector<triple>>> par[3];
vector<vector<vector<int>>> Min[3], Max[3];

triple get_par(triple a, int it) {
	if (a == par[it][a.x][a.y][a.z]) return a;
	return par[it][a.x][a.y][a.z] = get_par(par[it][a.x][a.y][a.z], it);
}

void uni(triple a, triple b, int it) {
	a = get_par(a, it);
	b = get_par(b, it);
	if (a == b) return;
	par[it][b.x][b.y][b.z] = a;
	chkmin(Min[it][a.x][a.y][a.z], Min[it][b.x][b.y][b.z]);
	chkmax(Max[it][a.x][a.y][a.z], Max[it][b.x][b.y][b.z]);
}

void no() {
	cout << -1 << endl;
	exit(0);
}

vector<vector<vector<bool>>> used;
queue<triple> q;

int get_color(int x, int y, int z) {
	set<int> color;
	triple a;

	// get_left
	if (x != 0) {
		a = {x - 1, y, z};
		a = get_par(a, 0);
	}
	if (x == 0 || (Min[0][a.x][a.y][a.z] == 0 && used[x - 1][y][z])) {
		color.insert(left[y][z]);
	}

	// get_right
	if (x != n - 1) {
		a = {x + 1, y, z};
		a = get_par(a, 0);
	}
	if (x == n - 1 || (Max[0][a.x][a.y][a.z] == n - 1 && used[x + 1][y][z])) {
		color.insert(right[y][z]);
	}

	// get top
	if (y != 0) {
		a = {x, y - 1, z};
		a = get_par(a, 1);
	}
	if (y == 0 || (Min[1][a.x][a.y][a.z] == 0 && used[x][y - 1][z])) {
		color.insert(top[x][z]);
	}

	// get bottom
	if (y != m - 1) {
		a = {x, y + 1, z};
		a = get_par(a, 1);
	}
	if (y == m - 1 || (Max[1][a.x][a.y][a.z] == m - 1 && used[x][y + 1][z])) {
		color.insert(bottom[x][z]);
	}

	// get down
	if (z != 0) {
		a = {x, y, z - 1};
		a = get_par(a, 2);
	}
	if (z == 0 || (Min[2][a.x][a.y][a.z] == 0 && used[x][y][z - 1])) {
		color.insert(down[x][y]);
	}

	// get up
	if (z != k - 1) {
		a = {x, y, z + 1};
		a = get_par(a, 2);
	}
	if (z == k - 1 || (Max[2][a.x][a.y][a.z] == k - 1 && used[x][y][z + 1])) {
		color.insert(up[x][y]);
	}

	if (color.empty()) return -1;
	if (color.size() >= 2) return 0;
	return *color.begin();
}

void build() {
	used.assign(n, vector<vector<bool>> (m, vector<bool> (k, false)));
	for (int i = 0; i < 3; i++) {
		par[i].resize(n, vector<vector<triple>> (m, vector<triple> (k)));
		Min[i].resize(n, vector<vector<int>> (m, vector<int> (k)));
		Max[i].resize(n, vector<vector<int>> (m, vector<int> (k)));
	}
	for (int x = 0; x < n; x++) {
		for (int y = 0; y < m; y++) {
			for (int z = 0; z < k; z++) {
				for (int it = 0; it < 3; it++) {
					par[it][x][y][z] = {x, y, z};
				}
				Min[0][x][y][z] = x;
				Max[0][x][y][z] = x;
				Min[1][x][y][z] = y;
				Max[1][x][y][z] = y;
				Min[2][x][y][z] = z;
				Max[2][x][y][z] = z;
			}
		}
	}

	for (int x = 0; x < n; x++) {
		for (int y = 0; y < m; y++) {
			for (int z = 0; z < k; z++) {
				if (!get_color(x, y, z)) {
					q.push({x, y, z});
					used[x][y][z] = true;
				}
			}
		}
	}
}

vector<int> dx = {-1, 1, 0, 0, 0, 0};
vector<int> dy = {0, 0, -1, 1, 0, 0};
vector<int> dz = {0, 0, 0, 0, -1, 1};

bool check(int x, int y, int z) {
	return x >= 0 && x < n && y >= 0 && y < m && z >= 0 && z < k;
}

void del(int x, int y, int z) {
	for (int i = 0; i < 6; i++) {
		int nx = x + dx[i], ny = y + dy[i], nz = z + dz[i];
		if (!check(nx, ny, nz)) continue;
		if (!used[nx][ny][nz]) continue;
		uni({x, y, z}, {nx, ny, nz}, i / 2);
	}
}

void bfs() {
	while (!q.empty()) {
		auto v = q.front();
		int x = v.x, y = v.y, z = v.z;
		q.pop();
		del(x, y, z);
		for (int i = 0; i < 6; i++) {
			int nx = x + dx[i], ny = y + dy[i], nz = z + dz[i];
			if (!check(nx, ny, nz)) continue;
			if (get_color(nx, ny, nz)) continue;

			if (used[nx][ny][nz]) {
				auto a = triple(nx, ny, nz);
				a = get_par(a, i / 2);
				int & fupd;
				if (i / 2 == 0) fupd = nx;
				else if (i / 2 == 1) fupd = ny;
				else fupd = nz;
				if (i % 2 == 0) {
					fupd = Min[i / 2][a.x][a.y][a.z] - 1;
				}
				else {
					fupd = Max[i / 2][a.x][a.y][a.z] + 1;
				}
				if (!check(nx, ny, nz)) continue;
				if (get_color(nx, ny, nz)) continue;
			}
			if (used[nx][ny][nz]) continue;
			used[nx][ny][nz] = true;
			q.push({nx, ny, nz});
		}
	}
}

void check_ans() {
	for (int y = 0; y < m; y++) {
		for (int z = 0; z < k; z++) {
			bool flag = false;
			for (int x = 0; x < n; x++) {
				if (!used[x][y][z]) {
					flag = true;
				}
			}
			if (!flag) {
				if (left[y][z] || right[y][z]) {
					no();
				}
			}
		}
	}
	for (int x = 0; x < n; x++) {
		for (int z = 0; z < k; z++) {
			bool flag = false;
			for (int y = 0; y < m; y++) {
				if (!used[x][y][z]) {
					flag = true;
				}
			}
			if (!flag) {
				if (top[x][z] || bottom[x][z]) {
					no();
				}
			}
		}
	}
	for (int x = 0; x < n; x++) {
		for (int y = 0; y < m; y++) {
			bool flag = false;
			for (int z = 0; z < k; z++) {
				if (!used[x][y][z]) {
					flag = true;
				}
			}
			if (!flag) {
				if (up[x][y] || down[x][y]) {
					no();
				}
			}
		}
	}
}

void run() {
	build();
	bfs();
	check_ans();
}

void write() {
	for (int x = 0; x < n; x++) {
		for (int y = 0; y < m; y++) {
			for (int z = 0; z < k; z++) {
				int ans = get_color(x, y, z);
				if (ans == -1) ans = 0;
				if (used[x][y][z]) ans = 0;
				cout << ans << " ";
			}
		}
	}
	cout << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}