#include<iostream>
#include<cstdlib>
#include "cmath"
#include<string>
#include<vector>
#include<sstream>
#include<unordered_map>

const long long mod = 10e9 + 7;
const int MAX = 2 * 10e5 + 1;
std::vector<int> cycles;
int visited[MAX];
int cnt = 0;
int a[MAX];

void dfsc(int v) {
    cycles[cnt]++;
    visited[v] = 3;
    if (visited[a[v]] == 3)
        return;
    dfsc(a[v]);
}

void dfs(int v) {
    visited[v] = 2;
    if (visited[a[v]] == 0) {
        dfs(a[v]);
    }
    else if (visited[a[v]] == 1) {
        visited[v] = 1;
        return;
    }

    else {
        cycles.push_back(0);
        dfsc(v);
        cnt++;
    }
    visited[v] = 1;
}

int main() {
    int n;
   // freopen("file.in", "r", stdin);

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cin >> n;

   ;
    for (int i = 1; i <= n; ++i)
        std::cin >> a[i];

    long long steps[n + 1];
    steps[0] = 1;
    steps[1] = 2;
    for (int i = 2; i <= n; ++i)
        steps[i] = (steps[i - 1] * 2 + mod) % mod;

    for (int i = 1; i <= n; ++i)
        if (visited[i] == 0)
            dfs(i);

    int cnt = n;
    long long ans = 0;
    for (int i = 0; i < cycles.size(); ++i) {
        if (ans == 0)
            ans = (steps[cycles[i]] - 2) % mod;
        else
            ans = (ans * (steps[cycles[i]] - 2)) % mod;
        cnt -= cycles[i];
    }
    ans = (ans * steps[cnt]) % mod;
    if (ans < 0)
        ans += mod;

    std::cout << ans;
}


#include<iostream>
#include<cstdlib>
#include "cmath"
#include<string>
#include<vector>
#include<sstream>
#include<unordered_map>

const long long mod = 10e9 + 7;
const int MAX = 2 * 10e5 + 1;
std::vector<int> cycles;
int visited[MAX];
int cnt = 0;
int a[MAX];

void dfsc(int v) {
    cycles[cnt]++;
   // std::cout << v << " cyc\n";
    visited[v] = 3;
   //std::cout << a[v] << " " <<visited[a[v]] << '\n';
    if (visited[a[v]] == 3)
        return;
    dfsc(a[v]);
}

void dfs(int v) {
    visited[v] = 2;

    if (visited[a[v]] == 0) {
        dfs(a[v]);
    }
    else if (visited[a[v]] == 1) {
        visited[v] = 1;
        return;
    }

    else {
        cycles.push_back(0);
      //  std::cout << v << " a\n";
        dfsc(v);
        cnt++;
    }
    visited[v] = 1;
}

int main() {
    int n;
  //  freopen("file.in", "r", stdin);

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cin >> n;

   ;
    for (int i = 1; i <= n; ++i)
        std::cin >> a[i];

    long long steps[n + 1];
    steps[0] = 1;
    steps[1] = 2;
    for (int i = 2; i <= n; ++i)
        steps[i] = (steps[i - 1] * 2LL) % mod;

    for (int i = 1; i <= n; ++i)
        if (visited[i] == 0)
            dfs(i);

    int compcnt = n;
    long long ans = 1;
    for (int i = 0; i < cycles.size(); ++i) {
        ans = (ans * (steps[cycles[i]] - 2)) % mod;
        compcnt -= cycles[i];
    }
    ans = (ans * steps[compcnt]) % mod;
   // std::cout << cnt <<  " ? " << cycles.size() << '\n';
    if (ans < 0)
        ans += mod;
    int ansf = ans;
    std::cout << ansf;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1000000000+7;
int head[200005],pnt[400005],nxt[400005],E=0,vis[200005],w[200005],cnt=0,dep[200005];
map<pair<int,int> ,int>mp;
ll ksm(int k)
{
    ll temp=1,ki=2;
    while(k)
    {
        if(k%2)temp=temp*ki%MOD;
        k/=2;
        ki*=ki%MOD;
    }
    return temp%MOD;
}
void add_edge(int a,int b)
{
    pnt[E]=b;
    nxt[E]=head[a];
    head[a]=E++;
}
void dfs(int u,int d,int pre)
{
    vis[u]=1;
    dep[u]=d;
    for(int i=head[u];i!=-1;i=nxt[i])
    {
        int v=pnt[i];
        if(v==pre)continue;
        if(!vis[v])dfs(v,d+1,u);
        else if(vis[v]==1)
        {
            w[++cnt]=dep[u]-dep[v]+1;
        }
        //cout<<u<<' '<<v<<endl;
    }
    vis[u]=2;
}
int main()
{
    memset(head,-1,sizeof(head));
    int n;
    scanf("%d",&n);
    int tot=n;
    for(int i=1;i<=n;++i)
    {
        int kk;
        scanf("%d",&kk);
        if(mp[make_pair(kk,i)]!=1)
        {
            add_edge(i,kk);
            add_edge(kk,i);
            mp[make_pair(i,kk)]=1;
        }
        else --tot;
    }
    int sum=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
    {
        if(!vis[i])
        {
            dfs(i,0,-1);
        }
    }
    for(int i=1;i<=cnt;++i)
    {
        sum+=w[i];
        ans*=(ksm(w[i])-2)%MOD;
    }
    ans*=ksm(tot-sum)%MOD;
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1000000007;
int head[200005],pnt[400005],nxt[400005],E=0,vis[200005],w[200005],cnt=0,dep[200005];
map<pair<int,int> ,int>mp;
ll ksm(int k)
{
    ll temp=1,ki=2;
    while(k)
    {
        if(k%2)temp=temp*ki%MOD;
        k/=2;
        ki*=ki%MOD;
    }
    return temp%MOD;
}
void add_edge(int a,int b)
{
    pnt[E]=b;
    nxt[E]=head[a];
    head[a]=E++;
}
void dfs(int u,int d,int pre)
{
    vis[u]=1;
    dep[u]=d;
    for(int i=head[u];i!=-1;i=nxt[i])
    {
        int v=pnt[i];
        if(v==pre)continue;
        if(!vis[v])dfs(v,d+1,u);
        else if(vis[v]==1)
        {
            w[++cnt]=dep[u]-dep[v]+1;
        }
    }
    vis[u]=2;
}
int main()
{
    memset(head,-1,sizeof(head));
    int n;
    scanf("%d",&n);
    int tot=n;
    for(int i=1;i<=n;++i)
    {
        int kk;
        scanf("%d",&kk);
        if(mp[make_pair(kk,i)]!=1)
        {
            add_edge(i,kk);
            add_edge(kk,i);
            mp[make_pair(i,kk)]=1;
        }
        else --tot;
    }
    int sum=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
    {
        if(!vis[i])
        {
            dfs(i,0,-1);
        }
    }
    for(int i=1;i<=cnt;++i)
    {
        sum+=w[i];
        ans*=(ksm(w[i])-2)%MOD;
    }
    ans*=ksm(tot-sum)%MOD;
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const ll MOD=1000000007;
int head[200005],pnt[400005],nxt[400005],E=0,vis[200005],cnt=0,dep[200005];
ll w[200005];
map<pair<int,int> ,int>mp;
ll ksm(ll k)
{
    ll temp=1,ki=2;
    while(k)
    {
        if(k%2)temp=temp%MOD*ki%MOD;
        k/=2;
        ki*=ki%MOD;
    }
    return temp%MOD;
}
void add_edge(int a,int b)
{
    pnt[E]=b;
    nxt[E]=head[a];
    head[a]=E++;
}
void dfs(int u,int d,int pre)
{
    vis[u]=1;
    dep[u]=d;
    for(int i=head[u];i!=-1;i=nxt[i])
    {
        int v=pnt[i];
        if(v==pre)continue;
        if(!vis[v])dfs(v,d+1,u);
        else if(vis[v]==1)
        {
            w[++cnt]=dep[u]-dep[v]+1;
        }
    }
    vis[u]=2;
}
int main()
{
    memset(head,-1,sizeof(head));
    int n;
    scanf("%d",&n);
    int tot=n;
    for(int i=1;i<=n;++i)
    {
        int kk;
        scanf("%d",&kk);
        if(mp[make_pair(i,kk)]!=1&&mp[make_pair(kk,i)]!=1)
        {
            add_edge(i,kk);
            add_edge(kk,i);
            mp[make_pair(i,kk)]=1;
            mp[make_pair(kk,i)]=1;
        }else --tot;
    }
    int sum=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
    {
        if(!vis[i])
        {
            dfs(i,0,-1);
        }
    }
    for(int i=1;i<=cnt;++i)
    {
        sum+=w[i];
        ans=ans%MOD*(ksm(w[i])-2)%MOD;
    }
    ans*=ksm(tot-sum)%MOD;
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1000000007;
int head[200005],pnt[400005],nxt[400005],E=0,vis[200005],cnt=0,dep[200005];
ll w[200005];
map<pair<int,int> ,int>mp;
ll ksm(ll k)
{
    ll temp=1,ki=2;
    while(k)
    {
        if(k%2)temp=temp*ki%MOD;
        k/=2;
        ki*=ki%MOD;
    }
    return temp%MOD;
}
void add_edge(int a,int b)
{
    pnt[E]=b;
    nxt[E]=head[a];
    head[a]=E++;
}
void dfs(int u,int d,int pre)
{
    vis[u]=1;
    dep[u]=d;
    for(int i=head[u];i!=-1;i=nxt[i])
    {
        int v=pnt[i];
        if(v==pre)continue;
        if(!vis[v])dfs(v,d+1,u);
        else if(vis[v]==1)
        {
            w[++cnt]=dep[u]-dep[v]+1;
        }
    }
    vis[u]=2;
}
int main()
{
    memset(head,-1,sizeof(head));
    int n;
    scanf("%d",&n);
    int tot=n;
    for(int i=1;i<=n;++i)
    {
        int kk;
        scanf("%d",&kk);
        if(mp[make_pair(i,kk)]!=1&&mp[make_pair(kk,i)]!=1)
        {
            add_edge(i,kk);
            add_edge(kk,i);
            mp[make_pair(i,kk)]=1;
            mp[make_pair(kk,i)]=1;
        }else --tot;
    }
    int sum=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
    {
        if(!vis[i])
        {
            dfs(i,0,-1);
        }
    }
    for(int i=1;i<=cnt;++i)
    {
        sum+=w[i];
        ans=ans%MOD*(ksm(w[i])-2)%MOD;
    }
    ans*=ksm(tot-sum)%MOD;
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1000000007;
int head[200005],pnt[400005],nxt[400005],E=0,vis[200005],cnt=0,dep[200005];
ll w[200005];
ll ksm(ll k)
{
    ll temp=1,ki=2;
    while(k)
    {
        if(k%2)temp=temp%MOD*ki%MOD;
        k/=2;
        ki=ki%MOD*ki%MOD;
    }
    return temp%MOD;
}
void add_edge(int a,int b)
{
    pnt[E]=b;
    nxt[E]=head[a];
    head[a]=E++;
}
void dfs(int u,int d)
{
    vis[u]=1;
    dep[u]=d;
    for(int i=head[u];i!=-1;i=nxt[i])
    {
        int v=pnt[i];
        if(!vis[v])dfs(v,d+1);
        else if(vis[v]==1)
        {
            w[++cnt]=dep[u]-dep[v]+1;
        }
    }
    vis[u]=2;
}
int main()
{
    memset(head,-1,sizeof(head));
    int n;
    scanf("%d",&n);
    int tot=n;
    for(int i=1;i<=n;++i)
    {
        int kk;
        scanf("%d",&kk);
        add_edge(i,kk);
    }
    int sum=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
    {
        if(!dep[i])
        {
            dfs(i,0);
        }
    }
    for(int i=1;i<=cnt;++i)
    {
        sum+=w[i];
        ans=ans%MOD*(ksm(w[i])-2)%MOD;
    }
    ans=ans%MOD*ksm(tot-sum)%MOD;
    printf("%lld\n",ans%MOD);
    return 0;
}


    #include<bits/stdc++.h>
    #define ll unsigned long long
    using namespace std;
    const ll MOD=1000000007;
    int head[200005],pnt[400005],nxt[400005],E=0,vis[200005],cnt=0,dep[200005];
    ll w[200005];
    map<pair<int,int> ,int>mp;
    ll ksm(ll k)
    {
        ll temp=1,ki=2;
        while(k)
        {
            if(k%2)temp=temp%MOD*ki%MOD;
            k/=2;
            ki=ki%MOD*ki%MOD;
        }
        return temp%MOD;
    }
    void add_edge(int a,int b)
    {
        pnt[E]=b;
        nxt[E]=head[a];
        head[a]=E++;
    }
    void dfs(int u,int d,int pre)
    {
        vis[u]=1;
        dep[u]=d;
        for(int i=head[u];i!=-1;i=nxt[i])
        {
            int v=pnt[i];
            if(v==pre)continue;
            if(!vis[v])dfs(v,d+1,u);
            else if(vis[v]==1)
            {
                w[++cnt]=dep[u]-dep[v]+1;
            }
        }
        vis[u]=2;
    }
    int main()
    {
        memset(head,-1,sizeof(head));
        int n;
        scanf("%d",&n);
        int tot=n;
        for(int i=1;i<=n;++i)
        {
            int kk;
            scanf("%d",&kk);
            if(mp[make_pair(i,kk)]!=1&&mp[make_pair(kk,i)]!=1)
            {
                add_edge(i,kk);
                add_edge(kk,i);
                mp[make_pair(i,kk)]=1;
                mp[make_pair(kk,i)]=1;
            }else --tot;
        }
        int sum=0;
        ll ans=1;
        for(int i=1;i<=n;++i)
        {
            if(!vis[i])
            {
                dfs(i,0,-1);
            }
        }
        for(int i=1;i<=cnt;++i)
        {
            sum+=w[i];
            ans=ans%MOD*(ksm(w[i])-2)%MOD;
        }
        ans=ans%MOD*ksm(tot-sum)%MOD;
        printf("%lld\n",ans%MOD);
        return 0;
    }


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1000000007;
int head[200005],pnt[400005],nxt[400005],E=0,vis[200005],w[200005],cnt=0,dep[200005];
map<pair<int,int> ,int>mp;
ll ksm(int k)
{
    ll temp=1,ki=2;
    while(k)
    {
        if(k%2)temp=temp*ki%MOD;
        k/=2;
        ki*=ki%MOD;
    }
    return temp%MOD;
}
void add_edge(int a,int b)
{
    pnt[E]=b;
    nxt[E]=head[a];
    head[a]=E++;
}
void dfs(int u,int d,int pre)
{
    vis[u]=1;
    dep[u]=d;
    for(int i=head[u];i!=-1;i=nxt[i])
    {
        int v=pnt[i];
        if(v==pre)continue;
        if(!vis[v])dfs(v,d+1,u);
        else if(vis[v]==1)
        {
            w[++cnt]=dep[u]-dep[v]+1;
        }
    }
    vis[u]=2;
}
int main()
{
    memset(head,-1,sizeof(head));
    int n;
    scanf("%d",&n);
    int tot=n;
    for(int i=1;i<=n;++i)
    {
        int kk;
        scanf("%d",&kk);
        if(mp[make_pair(i,kk)]!=1&&mp[make_pair(kk,i)]!=1)
        {
            add_edge(i,kk);
            add_edge(kk,i);
            mp[make_pair(i,kk)]=1;
            mp[make_pair(kk,i)]=1;
        }else --tot;
    }
    int sum=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
    {
        if(!vis[i])
        {
            dfs(i,0,-1);
        }
    }
    for(int i=1;i<=cnt;++i)
    {
        sum+=w[i];
        ans=ans%MOD*(ksm(w[i])-2)%MOD;
    }
    ans*=ksm(tot-sum)%MOD;
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1000000007;
int head[200005],pnt[400005],nxt[400005],E=0,vis[200005],cnt=0,dep[200005];
ll w[200005];
map<pair<int,int> ,int>mp;
ll ksm(ll k)
{
    ll temp=1,ki=2;
    while(k)
    {
        if(k%2)temp=temp%MOD*ki%MOD;
        k/=2;
        ki*=ki%MOD;
    }
    return temp%MOD;
}
void add_edge(int a,int b)
{
    pnt[E]=b;
    nxt[E]=head[a];
    head[a]=E++;
}
void dfs(int u,int d,int pre)
{
    vis[u]=1;
    dep[u]=d;
    for(int i=head[u];i!=-1;i=nxt[i])
    {
        int v=pnt[i];
        if(v==pre)continue;
        if(!vis[v])dfs(v,d+1,u);
        else if(vis[v]==1)
        {
            w[++cnt]=dep[u]-dep[v]+1;
        }
    }
    vis[u]=2;
}
int main()
{
    memset(head,-1,sizeof(head));
    int n;
    scanf("%d",&n);
    int tot=n;
    for(int i=1;i<=n;++i)
    {
        int kk;
        scanf("%d",&kk);
        if(mp[make_pair(i,kk)]!=1&&mp[make_pair(kk,i)]!=1)
        {
            add_edge(i,kk);
            add_edge(kk,i);
            mp[make_pair(i,kk)]=1;
            mp[make_pair(kk,i)]=1;
        }else --tot;
    }
    int sum=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
    {
        if(!vis[i])
        {
            dfs(i,0,-1);
        }
    }
    for(int i=1;i<=cnt;++i)
    {
        sum+=w[i];
        ans=ans%MOD*(ksm(w[i])-2)%MOD;
    }
    ans*=ksm(tot-sum)%MOD;
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1000000007;
int head[200005],pnt[400005],nxt[400005],E=0,vis[200005],cnt=0,dep[200005];
ll w[200005];
ll ksm(ll k)
{
    ll temp=1,ki=2;
    while(k)
    {
        if(k%2)temp=temp%MOD*ki%MOD;
        k/=2;
        ki*=ki%MOD;
    }
    return temp%MOD;
}
void add_edge(int a,int b)
{
    pnt[E]=b;
    nxt[E]=head[a];
    head[a]=E++;
}
void dfs(int u,int d)
{
    vis[u]=1;
    dep[u]=d;
    for(int i=head[u];i!=-1;i=nxt[i])
    {
        int v=pnt[i];
        if(!vis[v])dfs(v,d+1);
        else if(vis[v]==1)
        {
            w[++cnt]=dep[u]-dep[v]+1;
        }
    }
    vis[u]=2;
}
int main()
{
    memset(head,-1,sizeof(head));
    int n;
    scanf("%d",&n);
    int tot=n;
    for(int i=1;i<=n;++i)
    {
        int kk;
        scanf("%d",&kk);
        add_edge(i,kk);
    }
    int sum=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
    {
        if(!vis[i])
        {
            dfs(i,0);
        }
    }
    for(int i=1;i<=cnt;++i)
    {
        sum+=w[i];
        ans=ans%MOD*(ksm(w[i])-2)%MOD;
    }
    ans*=ksm(tot-sum)%MOD;
    printf("%lld\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<iomanip>
#include<cmath>
#include<bitset>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
#define INF (1ll<<60)-1
#define Max 1e9
using namespace std;
int n;
int a[200100];
int head[200100],tot;
const ll mod=1000000007;
struct edge{
    int v,next;
}e[600100];
void Add(int u,int v){
    e[tot].v=v;
    e[tot].next=head[u];
    head[u]=tot++;
}
int vis[200100],cnt=0,ans=0;
int sz[200100];
void DFS(int x){
    vis[x]=1;
    ++cnt;
    sz[x]=cnt;
    for(int i=head[x];i!=-1;i=e[i].next){
        int v=e[i].v;
        if(vis[v]==0) DFS(v);
        else {
            ans=cnt-sz[v]+1;
            return ;
        }
    }
}
int main(){
    scanf("%d",&n);
    mst(head,-1);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        Add(i,a[i]);
    }
    ans=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            cnt=0;
            DFS(i);
            if(ans) break;
        }
    }
    ll num=1;
    for(int i=1;i<=ans;i++){
        num*=2;
        num%=mod;
    }
    num-=2;
    num=(num%mod+mod)%mod;
    for(int i=1;i<=n-ans;i++) {
        num*=2;
        num%=mod;
    }
    printf("%I64d\n",(num%mod+mod)%mod);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<iomanip>
#include<cmath>
#include<bitset>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
#define INF (1ll<<60)-1
#define Max 1e9
using namespace std;
int n;
int a[200100];
int head[200100],tot=0;
const ll mod=1000000007;
struct edge{
    int v,next;
}e[1000100];
void Add(int u,int v){
    e[tot].v=v;
    e[tot].next=head[u];
    head[u]=tot++;
}
int vis[200100],ans;
int sz[200100];
void DFS(int x,int fa,int deep){
    vis[x]=1;
    sz[x]=deep;
    for(int i=head[x];i!=-1;i=e[i].next){
        int v=e[i].v;
        if(v==fa) continue;
        if(vis[v]){
            ans=abs(deep-sz[v])+1;
            return ;
        } else DFS(v,x,deep+1);
    }
}
ll Qpow(ll x,int m){
    ll ans=1;
    while(m){
        if(m%2) ans=ans*x%mod;
        x=x%mod*x%mod;
        m/=2;
    }
    return ans%mod;
}
int main(){
    scanf("%d",&n);
    mst(head,-1);
    mst(vis,0);
    mst(sz,0);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        Add(i,a[i]);
        Add(a[i],i);
    }
    ll num=1;
    int m=n;
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            ans=0;
            DFS(i,0,0);
            if(m==2) ans=2;
            m-=ans;
            num=num*(((Qpow(2LL,ans)-2LL)%mod+mod)%mod)%mod;
        }
    }
    num=num*Qpow(2LL,m)%mod;
    printf("%I64d\n",num);
    return 0;
}
/*
3
2 1 2
*/


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<iomanip>
#include<cmath>
#include<bitset>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
#define INF (1ll<<60)-1
#define Max 1e9
using namespace std;
#define mod 1000000007
struct edge{
    int v,next;
}e[1000100];
int head[200100],tot=0;
void Add(int u,int v){
    e[tot].v=v;
    e[tot].next=head[u];
    head[u]=tot++;
}
int vis[200100],pre[200100],cnt;
void DFS(int u,int fa,int deep){
    vis[u]=1;
    pre[u]=deep;
    for(int i=head[u];i!=-1;i=e[i].next){
        int v=e[i].v;
        if(v==fa) continue;
        if(vis[v]) {
            cnt=abs(pre[u]-pre[v])+1;
            return ;
        } else DFS(v,u,deep+1);
    }
}
ll f[200100];
int n,m;
int main(){
    f[0]=1LL;
    for(int i=1;i<=200000;i++) f[i]=2LL*f[i-1]%mod;
    scanf("%d",&n);m=n;
    mst(head,-1);
    for(int i=1;i<=n;i++) {
        int x;
        scanf("%d",&x);
        Add(i,x);
        Add(x,i);
    }
    ll ans=1LL;
    for(int i=1;i<=n;i++){
        if(vis[i]) continue;
        cnt=0;
        DFS(i,0,1);
        //cout<<cnt<<endl;
        m-=cnt;
        ans=ans%mod*((f[cnt]-2LL)%mod+mod)%mod;
    }
    ans=ans*f[m]%mod;
    printf("%I64d\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<iomanip>
#include<cmath>
#include<bitset>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
#define INF (1ll<<60)-1
#define Max 1e9
using namespace std;
#define mod 1000000007
struct edge{
    int v,next;
}e[1000100];
int head[200100],tot=0;
void Add(int u,int v){
    e[tot].v=v;
    e[tot].next=head[u];
    head[u]=tot++;
}
int vis[200100],pre[200100],cnt;
void DFS(int u,int fa,int deep){
    vis[u]=1;
    pre[u]=deep;
    for(int i=head[u];i!=-1;i=e[i].next){
        int v=e[i].v;
        if(v==fa) continue;
        if(vis[v]) {
            cnt=abs(pre[u]-pre[v])+1;
            return ;
        } else DFS(v,u,deep+1);
    }
}
ll f[200100];
int n,m;
int main(){
    f[0]=1LL;
    for(int i=1;i<=200000;i++) f[i]=2LL*f[i-1]%mod;
    scanf("%d",&n);m=n;
    mst(head,-1);
    for(int i=1;i<=n;i++) {
        int x;
        scanf("%d",&x);
        Add(i,x);
        Add(x,i);
    }
    ll ans=1LL;
    for(int i=1;i<=n;i++){
        if(vis[i]) continue;
        cnt=0;
        DFS(i,0,1);
        if(m==2) cnt=2;
        ans=ans%mod*((f[cnt]-2LL)%mod+mod)%mod*f[m-cnt];
    }
    printf("%I64d\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<iomanip>
#include<cmath>
#include<bitset>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
#define INF (1ll<<60)-1
#define Max 1e9
using namespace std;
#define mod 1000000007
struct edge{
    int v,next;
}e[1000100];
int head[200100],tot=0;
void Add(int u,int v){
    e[tot].v=v;
    e[tot].next=head[u];
    head[u]=tot++;
}
int vis[200100],pre[200100],cnt,num;
void DFS(int u,int fa,int deep){
    ++num;
    vis[u]=1;
    pre[u]=deep;
    for(int i=head[u];i!=-1;i=e[i].next){
        int v=e[i].v;
        if(v==fa) continue;
        if(vis[v]) {
            cnt=abs(pre[u]-pre[v])+1;
            return ;
        } else DFS(v,u,deep+1);
    }
}
ll f[200100];
int n;
int main(){
    f[0]=1LL;
    for(int i=1;i<=200000;i++) f[i]=2LL*f[i-1]%mod;
    scanf("%d",&n);
    mst(head,-1);
    for(int i=1;i<=n;i++) {
        int x;
        scanf("%d",&x);
        Add(i,x);
        Add(x,i);
    }
    ll ans=1LL;
    for(int i=1;i<=n;i++){
        if(vis[i]) continue;
        cnt=0;num=0;
        DFS(i,0,1);
        if(num==2) cnt=2;
        ans=ans%mod*((f[cnt]-2LL)%mod+mod)%mod*f[num-cnt];
    }
    printf("%I64d\n",ans);
    return 0;
}


a=list(input())
b=[]
l=len(a)
count=0
c=[]
if a[0]!='a':
    for i in range(l):
        if a[i]!='a':
             b.append(chr(ord(a[i])-1))
        else:break
    if a[i]=='a':
        b+=a[i:]
    print(''.join(b))
elif a.count('a')!=l:
    for i in range(l):
        if a[i]!='a':
            b.append(chr(ord(a[i])-1))
            count=1
            c.append(i)
        if count==1 and a[i]=='a':
            break
    a[c[0]:c[-1]+1]=b
    print(''.join(a))

else :
    print('a'*(l-1)+'z')


n=list(input())
l=len(n)
b=[]
i=0
z=0
while(i<l):
    if n[i]=='a' and z==0 and i!=(l-1):
        b.append(n[i])
        #print(b)
    elif n[i]!='a' and z==0:
        z=1
        #print(b)
        for j in range(i,l):
            if n[j]!='a':
                b.append(chr(ord(n[j])-1))
            elif n[j]=='a':
                break
        #print(b)
        i+=(j-i-2)
    elif n[i]=='a' and z==0 and i==(l-1):
        b.append('z')
    else:
        b.append(n[i])
    i+=1

print(''.join(b))


n=list(input())
l=len(n)
b=[]
i=0
z=0
while(i<l):
    if n[i]=='a' and z==0 and i!=(l-1):
        b.append(n[i])
        #print(b)
    elif n[i]!='a' and z==0 :
        z=1
        #print(b)
        for j in range(i,l):
            if n[j]!='a':
                b.append(chr(ord(n[j])-1))
            elif n[j]=='a':
                break
        #print(b)
        i+=(j-i-1)
    elif n[i]=='a' and z==0 and i==(l-1):
        b.append('z')
    elif j!=(l-1) :
        b.append(n[i])
    i+=1

print(''.join(b))


s = list(input()+'a')
for i in range(len(s)):
    if s[i] != 'a': break
j = 1
for j in range(i+1, len(s)):
    if s[j] == 'a': break
for k in range(i, j):
    s[k] = chr(ord(s[k])-1)
print(''.join(s)[:-1])


s = list(input()+'a')
if s == ['a']*len(s): print('z'*(len(s)-1)); exit()
for i in range(len(s)):
    if s[i] != 'a': break
for j in range(i+1, len(s)):
    if s[j] == 'a': break
for k in range(i, j):
    s[k] = chr(ord(s[k])-1)
print(''.join(s)[:-1])


s = list(input()+'a')
if s == ['a']*2: print('z'); exit()
for i in range(len(s)):
    if s[i] != 'a': break
for j in range(i+1, len(s)):
    if s[j] == 'a': break
for k in range(i, j):
    s[k] = chr(ord(s[k])-1)
print(''.join(s)[:-1])


s = list(input()+'a')
if s == ['a']*len(s): print('a'*(len(s)-2)+'z'); exit()
for i in range(len(s)):
    if s[i] != 'a': break
for j in range(i+1, len(s)):
    if s[j] == 'a': break
for k in range(i, j):
    s[k] = chr(ord(s[k])-1)
print(''.join(s)[:-1])


s = list(input()+'a')
for i in range(len(s)):
    if s[i] != 'a': break
for j in range(i+1, len(s)):
    if s[j] == 'a': break
for k in range(i, j):
    s[k] = chr(ord(s[k])-1)
print(''.join(s)[:-1])


s = input()
n = len(s)
i = 0
while(s[i]=='a'):
    i+=1
s = list(s)
s[i] = chr(ord(s[i]) - 1)
i+=1
while(i<n and s[i]!='a'):
    s[i] = chr(ord(s[i]) - 1)
    i+=1
print(''.join(s))


s = input()
n = len(s)
minval = float("inf")
minin = -1
for i in range(0,n):
    if(ord(s[i])<minval):
        minval = ord(s[i])
        minin = i
s = list(s)
cnt = 0
for i in range(minin,n):
    if(s[i]!='a'):
        if(cnt<2):
            s[i] = chr(ord(s[i])-1)
        else:
            break
    else:
        cnt+=1
print(''.join(s))


s = input()
n = len(s)
i = 0
while(i<n and s[i]=='a'):
    i+=1
if(i==n):
    print('a'*(n-1) + 'z')
else:
    s = list(s)
    if(i<n):
        s[i] = chr(ord(s[i]) - 1)
        i+=1
    while(i<n and s[i]!='a'):
        s[i] = chr(ord(s[i]) - 1)
        i+=1
    print(''.join(s))


s = input()
n = len(s)
minval = float("inf")
minin = -1
for i in range(0,n):
    if(ord(s[i])<minval and s[i]!='a'):
        minval = ord(s[i])
        minin = i
s = list(s)
for i in range(minin,n):
    if(s[i]!='a'):
        s[i] = chr(ord(s[i])-1)
    elif(s[i]=='a' and i==0):
        continue
    else:
        break
print(''.join(s))


def dowhatever(s,si,ei):
    r=s[:si-1]
    if si>ei:
        r+='z'
    else:
        r=s[:si]
        for i in range(si,ei+1):
            r+=(chr(ord(s[i])-1))
        r+=s[ei+1:]
    print(r)
s=input()
n=len(s)
i=0
while i<n and s[i]=='a':
    i+=1
si=i
while i<n and s[i]!='a':
    i+=1
ei=i-1
dowhatever(s,si,ei)


def dowhatever(s,si,ei):
    r=s[:si]
    for i in range(si,ei+1):
        r+=(chr(ord(s[i])-1))
    r+=s[ei+1:]
    print(r)
s=input()
n=len(s)
i=0
while i<n and s[i]=='a':
    i+=1
si=i
while i<n and s[i]!='a':
    i+=1
ei=i-1
dowhatever(s,si,ei)


IL = lambda: list(map(int, input().split()))
I = lambda: int(input())

s = list(map(ord, input()))
if s.count(97)==len(s):
    print("a"*(len(s)-1) + "z")
    quit()

started = False
for i, ss in enumerate(s):
    if ss > 97:
        started = True
    if started:
        if ss > 97:
            s[i] -= 1
        else:
            break

print("".join(map(chr, s)))


IL = lambda: list(map(int, input().split()))
I = lambda: int(input())

s = list(map(ord, input()))
started = False
for i, ss in enumerate(s):
    if ss > 97:
        started = True
    if started:
        if ss > 97:
            s[i] -= 1
        else:
            break

print("".join(map(chr, s)))


a=input().replace(""," ").split();l=r=0,0;ok=False
for i in range(len(a)):
    if a[i]!='a' and not(ok):l=i;r=i;ok=True
    if ok:
        if a[i]=='a':break
        else:r=i
for i in range(len(a)):
    if l<=i<=r:
        print(chr(ord(a[i])-1),end="")
    else:print(a[i],end="")


a=input().replace(""," ").split();l=len(a);r=-1;ok=False
for i in range(len(a)):
    if a[i]!='a' and not(ok):l=i;r=i;ok=True
    if ok:
        if a[i]=='a':break
        else:r=i
if not(ok):a[-1]='z';print(*a,end="");exit()
for i in range(len(a)):
    if l<=i and r>=i:
        print(chr(ord(a[i])-1),end="")
    else:print(a[i],end="")


a=input().replace(""," ").split();l=len(a);r=len(a);ok=False
for i in range(len(a)):
    if a[i]!='a' and not(ok):l=i;r=i;ok=True
    if ok:
        if a[i]=='a':break
        else:r=i
for i in range(len(a)):
    if l<=i and r>=i:
        print(chr(ord(a[i])-1),end="")
    else:print(a[i],end="")


a=input().replace(""," ").split();l=len(a);r=-1;ok=False
for i in range(len(a)):
    if a[i]!='a' and not(ok):l=i;r=i;ok=True
    if ok:
        if a[i]=='a':break
        else:r=i
if not(ok):a[-1]='z';print(*a,sep="");exit()
for i in range(len(a)):
    if l<=i and r>=i:
        print(chr(ord(a[i])-1),end="")
    else:print(a[i],end="")


import sys
s=input()
L=len(s)
t=""
i=0
while i<L and s[i]=='a':
	t+=s[i]
	i+=1
if len(t)==L:
	print(s[:L-1]+'z')
	sys.exit()
while i<L and s[i]!='a':
	t+=chr(ord(s[i])-1)
	i+=1
t+=s[i:]
print(t)


import sys
a = list(input())
b = ""
l = 0
o = 0
for x in range (len(a)):

    if a[x] == 'a' and l == 1:
        break
    elif a[x] != 'a':
        a[x] = chr(ord(a[x])-1)
        l = 1
        o = 1

if o == 0:
    a[len(a)-1] = "z"
print("".join(a))


S=input().split('a')
ma=1000000000000
R='abcdefghijklmnopqrstuvwxyz'
for x in S :
    if len(x)>0 :
        ma=len(x)
        break
S1=''
c=1
p=len(S)
for x in S :
    if len(x)==ma and c==1 :
        c=0
        for i in range(len(x)) :
            S1=S1+R[R.index(x[i])-1]
    else :
        S1=S1+x
    if p!=1 :
        S1=S1+'a'
        p=p-1

print(S1)


S=input().split('a')
ma=1000000000000
R='abcdefghijklmnopqrstuvwxyz'
for x in S :
    if len(x)>0 :
        ma=len(x)
        break
S1=''
c=1
p=len(S)
for x in S :
    if len(x)==ma and c==1 :
        c=0
        for i in range(len(x)) :
            S1=S1+R[R.index(x[i])-1]
    else :
        S1=S1+x
    if p!=1 :
        S1=S1+'a'
        p=p-1

if S1.count('a')==len(S1) :
    S1=S1[:len(S)-2]+'z'
print(S1)


S=input()
R='abcdefghijklmnopqrstuvwxyz'
p=-1
d=-1
ma1=-1
ma2=-1
k=0
ma=0
for i in range(len(S)) :
    if S[i]=='a' :
        if k>ma :
            ma=k
            ma1=p
            ma2=d
        if k-25>0 :
            k=k-25
            d=d+1
        else :
            p=-1
            d=-1
            k=0
    else :
        k=k+1
        if p==-1 :
            p=i
            d=i
        else :
            d=d+1
if k>ma :
    ma1=p
    ma2=d
S1=''
for i in range(len(S)) :
    if i>=ma1 and i<=ma2 :
        if R.index(S[i])==0 :
            S1=S1+'z'
        else :
            S1=S1+R[R.index(S[i])-1]
    else :
        S1=S1+S[i]
print(S1)


S=input().split('a')
ma=100000000000000
R='abcdefghijklmnopqrstuvwxyz'
for x in S :
    if ma>len(x) and len(x)>0 :
        ma=len(x)
S1=''
c=1
p=len(S)
for x in S :
    if len(x)==ma and c==1 :
        c=0
        for i in range(len(x)) :
            S1=S1+R[R.index(x[i])-1]
    else :
        S1=S1+x
    if p!=1 :
        S1=S1+'a'
        p=p-1

print(S1)


S=input().split('a')
ma=1000000000000
R='abcdefghijklmnopqrstuvwxyz'
for x in S :
    if len(x)>0 :
        ma=len(x)
        break
S1=''
c=1
p=len(S)
for x in S :
    if len(x)==ma and c==1 :
        c=0
        for i in range(len(x)) :
            S1=S1+R[R.index(x[i])-1]
    else :
        S1=S1+x
    if p!=1 :
        S1=S1+'a'
        p=p-1

if S1.count('a')==len(S1) and c==1 :
    S1=S1[:len(S)-2]+'z'
print(S1)


s=input()
p=list(s)
for i in range(0,len(s)):
    if s[i]>'a':
        p[i]=chr(ord(s[i])-1)
s="".join(p)
print(s)


s=input()
n=len(s)
p=list(s)
i=0
while(s[i]=='a'):
    i+=1
    if i==n:
        print(s)
        exit(0)
while(s[i]!='a'):
    p[i]=chr(ord(s[i])-1)
    i+=1
    if i==n:
        break
s="".join(p)
print(s)


s=input()
n=len(s)
p=list(s)
i=0
while(s[i]=='a'):
    i+=1
    if i==n:
        p[n-1]='z'
        s="".join(p)
        print(s)
        exit(0)
while(s[i]!='a'):
    p[i]=chr(ord(s[i])-1)
    i+=1
    if i==n:
        break
s="".join(p)
print(s)


import sys
s=input()
L=len(s)
t=""
i=0;
while i<L and s[i]=='a':
	t+=s[i]
	i+=1
if len(t)==L:
	print(s[:L-1]+'z')
	sys.exit()
while i<L and s[i]!='a':
	t+=chr(ord(s[i])-1)
	i+=1
t+=s[i:]
print(t)


s=list(input())
n=len(s)
if s.count('a')==0:
    for i in range(n):
        s[i]=chr(ord(s[i])-1)
    print(''.join(s))
elif s.count('a')==n:
    s[-1]='z'
    print(''.join(s))
else:
    st,en=-1,n
    for i in range(n):
        if s[i]=='a':
            if i==st+1: st=i
            else: en=i; break
    for i in range(st+1,en):
        s[i]=chr(ord(s[i])-1)
    print(''.join(s))


s=list(input())
n=len(s)
if s.count('a')==0:
    for i in range(n):
        s[i]=chr(ord(s[i])-1)
    print(''.join(s))
else:
    st,en=-1,n
    for i in range(n):
        if s[i]=='a':
            if i==st+1: st=i
            else: en=i; break
    for i in range(st+1,en):
        s[i]=chr(ord(s[i])-1)
    print(''.join(s))


s=input()
n=len(s)
L=list(s)
y=0
for c in s:
	if c!='a' or y==n-1:
		break
	y+=1
i=ord(L[y])
if i==ord('a'):
	i=ord('z')
else:
	i-=1
L[y]=chr(i)
x=y+1
for j in range(x,n):
	if L[j]=='a':
		break
	else:
		i=ord(L[j])
		if i==ord('a'):
			i=ord('z')
		else:
			i-=1
		L[j]=chr(i)
	y+=1
w=''.join(L)
print(w)


s = input()
t = ""

x=0

for c in s:
	if c != 'a':
		break
	t += str(c)
	x+=1

y=x

for c in s[x:]:
	if c == 'a':
		break
	a = ord(c)
	a -= 1
	t += str(chr(a))
	y+=1

for c in s[y:]:
	t += str(c)

print(t)


s = input()
t = ""

x=0

for c in s:
	if c != 'a':
		break
	t += str(c)
	x+=1

if x >= len(s):
	t = t[:len(s)-1] + 'z'

y=x

for c in s[x:]:
	if c == 'a':
		break
	a = ord(c)
	a -= 1
	t += str(chr(a))
	y+=1

for c in s[y:]:
	t += str(c)

print(t)


s = input()
i = s.find("a")
res = s[0:i+1]
for j in range(i + 1, len(s)):
    if s[j] == "a":
        res += s[j:]
        break
    res += chr(ord(s[j]) - 1)
print(res)


def findNot(string, char):
    for i in range(len(string)):
        if string[i] != char:
            return i
    return len(string) - 1

s = input()
beg = findNot(s, "a")
res = s[0:beg]
for i in range(beg, len(s)):
    if i != beg and s[i] == "a":
        res += s[i:]
        break
    if s[i] == "a":
        res += "z"
    else:
        res += chr(ord(s[i]) - 1)
print(res)


s = input()
res = ""
for j in range(0, len(s)):
    if s[j] == "a":
        if j == 0:
            res += "a"
        else:
            res += s[j:]
            break
    else:
        res += chr(ord(s[j]) - 1)
print(res)


s=list(map(str,input()))
for i in range(len(s)):
    if s[i]!='a':
        break
if i==len(s)-1 and s[-1]=='a':
    s[-1]='z'
    i+=1
while i!=len(s) and s[i]!='a':
    s[i]=chr(ord(s[i])-1)
    i+=1
print(''.join(s))


# print("Input the string")
st = input()

if st == 'a':
    print('z')
else:
    apos = st.find('a')
    if apos == -1:
        #  No as in the word at all--shift everything down
        answerlist = []
        for ch in st:
            newch = chr(ord(ch)-1)
            answerlist.append(newch)
        print(''.join(answerlist))
    elif apos > 0:
        #  Shift everything up to the first a
        answerlist = []
        for i in range(0, apos):
            newch = chr(ord(st[i])-1)
            answerlist.append(newch)
        print(''.join(answerlist) + st[apos:])
    else:
        #  The hard case--it starts with an a
        #  Find the first non-a
        pos = 1
        while pos < len(st) and st[pos] == 'a':
            pos += 1
        if pos == len(st):  # All letters are a--must change last letter to z
            print(st[0:len(st)-1] + 'z')
        else:
            # Change everything from pos to the next a
            nextapos = st.find('a', pos+1)
            if nextapos == -1:  # No more as--change to the end
                answerlist = []
                for i in range(pos, len(st)):
                    newch = chr(ord(st[i])-1)
                    answerlist.append(newch)
                print(st[0:pos] + ''.join(answerlist))
            else:   # Change everything between pos and nextapos
                answerlist = []
                for i in range(pos, nextapos):
                    newch = chr(ord(st[i])-1)
                    answerlist.append(newch)
                print(st[0:pos] + ''.join(answerlist) + st[nextapos:])


# print("Input the string")
st = input()

apos = st.find('a')
if apos == -1:
    #  No as in the word at all--shift everything down
    answerlist = []
    for ch in st:
        newch = chr(ord(ch)-1)
        answerlist.append(newch)
    print(''.join(answerlist))
elif apos > 0:
    #  Shift everything up to the first a
    answerlist = []
    for i in range(0, apos):
        newch = chr(ord(st[i])-1)
        answerlist.append(newch)
    print(''.join(answerlist) + st[apos:])
else:
    #  The hard case--it starts with an a
    #  Find the first non-a
    pos = 1
    while pos < len(st) and st[pos] == 'a':
        pos += 1
    if pos == len(st):   # All letters are a--no change at all
        print(st)
    else:
        # Change everything from pos to the next a
        nextapos = st.find('a', pos+1)
        if nextapos == -1:  # No more as--change to the end
            answerlist = []
            for i in range(pos, len(st)):
                newch = chr(ord(st[i])-1)
                answerlist.append(newch)
            print(st[0:pos] + ''.join(answerlist))
        else:   # Change everything between pos and nextapos
            answerlist = []
            for i in range(pos, nextapos):
                newch = chr(ord(st[i])-1)
                answerlist.append(newch)
            print(st[0:pos] + ''.join(answerlist) + st[nextapos:])


# print("Input the string")
st = input()

apos = st.find('a')
if apos == -1:
    #  No as in the word at all--shift everything down
    answerlist = []
    for ch in st:
        newch = chr(ord(ch)-1)
        answerlist.append(newch)
    print(''.join(answerlist))
elif apos > 0:
    #  Shift everything up to the first a
    answerlist = []
    for i in range(0, apos):
        newch = chr(ord(st[i])-1)
        answerlist.append(newch)
    print(''.join(answerlist) + st[apos:])
else:
    #  The hard case--it starts with an a
    #  Find the first non-a
    pos = 1
    while pos < len(st) and st[pos] == 'a':
        pos += 1
    if pos == len(st) or st == 'a':   # All letters are a--no change at all
        print(st)
    else:
        # Change everything from pos to the next a
        nextapos = st.find('a', pos+1)
        if nextapos == -1:  # No more as--change to the end
            answerlist = []
            for i in range(pos, len(st)):
                newch = chr(ord(st[i])-1)
                answerlist.append(newch)
            print(st[0:pos] + ''.join(answerlist))
        else:   # Change everything between pos and nextapos
            answerlist = []
            for i in range(pos, nextapos):
                newch = chr(ord(st[i])-1)
                answerlist.append(newch)
            print(st[0:pos] + ''.join(answerlist) + st[nextapos:])


# print("Input the string")
st = input()

if st == 'a':
    print('z')
else:
    apos = st.find('a')
    if apos == -1:
        #  No as in the word at all--shift everything down
        answerlist = []
        for ch in st:
            newch = chr(ord(ch)-1)
            answerlist.append(newch)
        print(''.join(answerlist))
    elif apos > 0:
        #  Shift everything up to the first a
        answerlist = []
        for i in range(0, apos):
            newch = chr(ord(st[i])-1)
            answerlist.append(newch)
        print(''.join(answerlist) + st[apos:])
    else:
        #  The hard case--it starts with an a
        #  Find the first non-a
        pos = 1
        while pos < len(st):
            pos += 1
        if pos == len(st) or st == 'a':   # All letters are a--no change at all
            print(st)
        else:
            # Change everything from pos to the next a
            nextapos = st.find('a', pos+1)
            if nextapos == -1:  # No more as--change to the end
                answerlist = []
                for i in range(pos, len(st)):
                    newch = chr(ord(st[i])-1)
                    answerlist.append(newch)
                print(st[0:pos] + ''.join(answerlist))
            else:   # Change everything between pos and nextapos
                answerlist = []
                for i in range(pos, nextapos):
                    newch = chr(ord(st[i])-1)
                    answerlist.append(newch)
                print(st[0:pos] + ''.join(answerlist) + st[nextapos:])


import sys
s=input()
L=len(s)
t=""
i=0
while i<L and s[i]=='a':
	t+=s[i]
	i+=1
if len(t)==L:
	print(s[:L-1]+'z')
	sys.exit()
while i<l and s[i]!='a':
	t+=chr(ord(s[i])-1)
	i+=1
t+=s[i:]
print(t)


import sys
s=input()
L=len(s)
t=""
i=0
while i<L and s[i]=='a':
	t+=s[i]
	i+=1
if len(t)==L:
	print(s[:L-1]+'z')
	sys.exit()
while i<L and s[i]!='a':
	t+=chr(ord(s[i])-1)
	i+=1
t+=s[i:]
print(t)


s = input()
full = 0
started = 0

ans = ''

for l in s:
	if l != 'a' and full == 0:
		ans += chr(ord(l) - 1)
		started = 1
	else:
		if l == 'a' and started == 1:
			full = 1
		ans += l

if ans != s:
	print(ans)
else:
	print(s[:-1] + 'z')


s = input();
foundl = foundr = False

for x in range(0, len(s)):
  if s[x] is not 'a':
    left = x
    foundl = True
    break

if not foundl:
  c = s
else:
  for x in range(left, len(s)):
    if s[x] is 'a':
      right = x
      foundr = True
      break

  c = s[:left]
  if foundr:
    for x in range(left, right):
      c += chr(ord(s[x])-1)
    c += s[right:]
  else:
    for x in range(left, len(s)):
      c += chr(ord(s[x])-1)

print(c)


s = input();
foundl = foundr = False

for x in range(0, len(s)):
  if s[x] is not 'a':
    left = x
    foundl = True
    break

if not foundl:
  c = s[0:len(s)-1]
  c += 'z'
else:
  for x in range(left, len(s)):
    if s[x] is 'a':
      right = x
      foundr = True
      break

  c = s[:left]
  if foundr:
    for x in range(left, right):
      c += chr(ord(s[x])-1)
    c += s[right:]
  else:
    for x in range(left, len(s)):
      c += chr(ord(s[x])-1)

print(c)


a=[*input()]
n=len(a)
i=0
while i<n and a[i]=='a':i+=1
while i<n and a[i]!='a':a[i]=chr(ord(a[i])-1);i+=1
print(''.join(a))


a=[*input()]
n=len(a)
i=0
while i<n and a[i]=='a':i+=1
if i==n:a[0]='z'
while i<n and a[i]!='a':a[i]=chr(ord(a[i])-1);i+=1
print(''.join(a))


a=[*input()]
n=len(a)
i=0
while i<n and a[i]=='a':i+=1
if i==n:a[-1]='z'
while i<n and a[i]!='a':a[i]=chr(ord(a[i])-1);i+=1
print(''.join(a))


class Array
  def r
    self.map { |q| q.to_i }
  end
end

def read_line
  STDIN.gets.split(" ")
end

def read_to_array
  read_line.to_a
end

def read_numbers_to_array
  read_to_array.r
end

s = read_to_array[0]
beg = false
ended = false
res = String.new
s.each_char do |c|
  if c == 'a'
    if beg
      beg = false
      ended = true
    end
  else
    if !ended
      beg = true
    end

    if beg
      c = (c.ord - 1)
    end
  end

  res << c
end

puts res


class Array
  def r
    self.map { |q| q.to_i }
  end
end

def read_line
  STDIN.gets.split(" ")
end

def read_to_array
  read_line.to_a
end

def read_numbers_to_array
  read_to_array.r
end

s = read_to_array[0]
beg = false
ended = false
res = String.new
s.each_char do |c|
  if c == 'a'
    if beg
      beg = false
      ended = true
    end
  else
    if !ended
      beg = true
    end

    if beg
      c = c.ord - 1
    end
  end

  res << c
end

if beg == false && ended == false
  n = res[res.size - 1]
  res[res.size - 1] = 'a'
end

puts res


class Array
  def r
    self.map { |q| q.to_i }
  end
end

def read_line
  STDIN.gets.split(" ")
end

def read_to_array
  read_line.to_a
end

def read_numbers_to_array
  read_to_array.r
end

s = read_to_array[0]
beg = false
ended = false
res = String.new
s.each_char do |c|
  if c == 'a'
    if beg
      beg = false
      ended = true
    end
  else
    if !ended
      beg = true
    end

    if beg
      c = c.ord - 1
    end
  end

  res << c
end

if beg == false && ended == false
  n = res[res.size - 1]
  res[res.size - 1] = 'z'
end

puts res


s = raw_input()
t = ''
ca = s.count('a')
if len(s) == ca:
    print s[:-1] + 'z'
else:
    pos = 0
    for c in s:
        if c == 'a' and pos == 1:
            break
        elif c == 'a' and pos != 1:
            t += c
        else:
            t += chr(ord(c) - 1)
            pos = 1

    if len(t) == len(s):
        print t
    else:
        print t + s[len(t):]


s=raw_input()
t=""
y=0
for x in range (0,len(s)):
    if s[x]!="a" :
        t+=str(chr(ord(s[x])-1))
        y=1
    if s[x]=="a":
        if y==1:
            t=t+s[x:]
            break
        elif x==len(s)-1:
            t+="z"
        else:
            t+="a"
print t


s=raw_input()
t=""
y=0
for x in range (0,len(s)):
    if s[x]!="a" :
        t+=str(chr(ord(s[x])-1))
        y=1
    if s[x]=="a":
        if y==1:
            t=t+s[x:]
            break
        else:
            t+="a"
print t


#!/usr/bin/python2
# -*- coding: utf-8 -*-

import sys
import os

rl = sys.stdin.readline
srl = lambda: rl().split()

def main():
    s = rl().rstrip()
    q = ""
    if any(x != 'a' for x in s):
        c = 0
        for x in s:
            if c == 1 and x == 'a':
                c = 2
            if c > 1:
                q += x
                continue
            if x != 'a':
                c = 1
                q += chr(ord(x) - 1)
            else:
                q += x
    else:
        q = s[:-1] + 'z'
    print q

if __name__ == '__main__':
    main()


def honey(s,i):
    l=len(s)
    t=""

    while i < l:
        if s[i] == 'a':
            t += 'a'
        else:
            break
        i += 1

    while i < l:
        if s[i] != 'a':
            t += str(chr(ord(s[i]) - 1))
        else:
            break
        i += 1

    while i < l:
        t += str(s[i])
        i += 1
    return t
lst= (str(raw_input()))

v=len(lst)

if(len(set(lst))==1 and lst[0]=="a"):

    ans="a"*(v-1)+"z"
else:
    ans= honey(lst,0)
print ans


s = raw_input()
sp = reduce(lambda a, b:a + ('-' if b != 'a' else 'a'), s, "").find('-')
print 'z' if s == 'a' else s[:sp] + reduce(lambda a,b: [a[0], a[1] + chr(ord(b)-1)] if b != 'a' and a[0] else [0, a[1] + b], s[sp:], [1, ""])[1]


def p(s):
    print s
    return s
s = raw_input()
print s[0:s.find('a')+1] + reduce(lambda a,b: p([a[0], a[1] + chr(ord(b)-1)]) if b != 'a' and a[0] else p([0, a[1] + b]), s[s.find('a')+1:], [1, ""])[1]


s = raw_input()
sp = reduce(lambda a, b:a + ('-' if b != 'a' else 'a'), s, "").find('-')
print 'a'*(len(s)-1)+'z' if sp == -1 else s[:sp] + reduce(lambda a,b: [a[0], a[1] + chr(ord(b)-1)] if b != 'a' and a[0] else [0, a[1] + b], s[sp:], [1, ""])[1]


s = raw_input()
sp = reduce(lambda a, b:a + ('-' if b != 'a' else 'a'), s, "").find('-')
print s[:sp] + reduce(lambda a,b: [a[0], a[1] + chr(ord(b)-1)] if b != 'a' and a[0] else [0, a[1] + b], s[sp:], [1, ""])[1]


# ord a -> 1
# chr 1 -> a
# list string na l

#print (ord('z') - ord('a'))

def shift(de):
    abc = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'
    abc = map(str, abc.split())
    for i, x in enumerate(abc):
        if de == x:
            i -= 1
            return abc[i]

def size():
    x = list(raw_input())
    b = 0
    while len(x) > b and x[b] == "a":
        b += 1

    while len(x) > b and x[b] != 'a':
        x[b] = shift(x[b])
        b += 1
    print ''.join(x)

size()


def shift(de):
    abc = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'
    abc = map(str, abc.split())
    for i, x in enumerate(abc):
        if de == x:
            i -= 1
            return abc[i]

def size():
    x = list(raw_input())
    b = 0

    if all( c == 'a' for c in x ):
        x[-1] = shift(x[-1])
        print ''.join(x)
        return

    while len(x) > b and x[b] == "a":
        b += 1

    while len(x) > b and x[b] != 'a':
        x[b] = shift(x[b])
        b += 1
    print ''.join(x)

size()


s=list(raw_input().strip())
flag=0
n=len(s)
for i in xrange(0,n):
	if s[i]!='a':
		s[i]=chr(ord(s[i])-1)
		flag=1
	elif flag==0 and s[i]=='a':
		pass
	elif flag==1 and s[i]=='a':
		break
if flag==1:
	print ("").join(s)
else:
	s[-1]='z'
	print ("").join(s)


s = raw_input()
n = len(s)
res = ''
i = 0
while i < n-1 and s[i] == 'a':
	res += 'a'
	i += 1
if i == n - 1:
	if s[i] >'a': res += chr(ord(s[i])-1)
	else: res += 'z'
	i += 1
while i < n and s[i] > 'a':
	res += chr(ord(s[i])-1)
	i += 1

while i < n:
	res += s[i]
	i += 1
print res


s = raw_input()
n = len(s)
res = ''
i = 0
while i < n and s[i] == 'a':
	res += 'a'
	i += 1
while i < n and s[i] > 'a':
	res += chr(ord(s[i])-1)
	i += 1
while i < n:
	res += s[i]
	i += 1
print res


s = raw_input()
ib = 0
while ib < len(s):
    if s[ib] != 'a':
        break
    ib += 1
ie = ib + 1
while ie < len(s):
    if s[ie] == 'a':
        break
    ie += 1
new = ''.join(map(chr, [122 if x == 97 else x - 1 for x in map(ord, s[ib:ie])]))
print s[:ib] + new + s[ie:]


s = raw_input()
ib = 0
while ib < len(s):
    if s[ib] != 'a':
        break
    ib += 1
ie = ib + 1
while ie < len(s):
    if s[ie] == 'a':
        break
    ie += 1
if ib == ie - 1 == len(s):
    ib -= 1
    ie -= 1
new = ''.join(map(chr, [122 if x == 97 else x - 1 for x in map(ord, s[ib:ie])]))
print s[:ib] + new + s[ie:]


s=raw_input()
newList=s.split('a')
string=""

if len(s.replace('a',''))==0:
		print (len(s)-1)*'a'+'z'
else:
	for i in xrange(0,len(newList)):
		if newList[i]!='':
			newString=newList[i]
			break

	for j in xrange(0,len(newString)):
		string+=chr(ord(newString[j])-1)

	temp=s.index(newString)
	print s[:temp]+string+s[temp+len(newString):]


s=raw_input()
newList=[]
counta=len(s)-len(s.replace('a',''))

if counta==0:
	for i in xrange(0,len(s)):
		newList.append(chr(ord(s[i])-1))
	print ''.join(newList)
elif counta==len(s):
	print (len(s)-1)*'a'+'z'
else:
	if s.index('a')==0:
		newList.append('a')
	else:
		newList.append(chr(ord(s[0])-1))
	temp=s.index('a',1)
	for j in xrange(1,temp):
		newList.append(chr(ord(s[j])-1))
	print ''.join(newList)+s[temp:]


import sys
#sys.stdin= open("A.in")
s = raw_input()
ans = list(s)
mode = 0
for i in range(len(s)):
    if mode == 0 and ans[i] == 'a':
        continue
    if ans[i] != 'a' or mode == 0:
        ans[i] = chr(ord(ans[i]) - 1)
        mode = 1
    else:
        break
#print ans
print "".join(ans)


import sys
#sys.stdin= open("A.in")
s = raw_input()
ans = list(s)
mode = 0
for i in range(len(s)):
    if mode == 0 and ans[i] == 'a':
        continue
    if ans[i] != 'a' or mode == 0:
        ans[i] = chr(ord(ans[i]) - 1)
        mode = 1
    else:
        break
#print ans
if mode == 0:
    ans[-1] = 'z'
print "".join(ans)


s= str(raw_input())
i=0
p=0
lst=[]
for j in range(0,len(s)):
    lst.append(s[j])

if(s[0]=='a'):

    while(s[p]=='a'):
        p=p+1

if(1==1):
    i=p
    while(  i<=len(lst)-1 and s[i]!='a'  ):
        z=ord(s[i])-1
        lst[i]=chr(z)

        i=i+1
for j in range(0,len(s)):
    k=''.join(lst)

print k


s= str(raw_input())
i=0
p=0
lst=[]
lst2=[]
v=len(s)
for j in range(0,v):
    lst.append(s[j])
def honey(s,lst,i):
    l=len(s)

    if(i<=l-1 and s[i]!='a' ):
        while(i<=l-1 and s[i]!="a" ):
            vr=ord(s[i])-1
            lst[i]=chr(vr)
            i=i+1
    elif(i<=l-1):
        i=i+1
        honey(s,lst,i)
    else:
        c=0
    return lst
if(len(set(lst))==1):
    lst[v-1]="z"
    ans=lst

else:
    ans= honey(s,lst,0)
strr=""
for i in range(0,v):
    strr=strr+str((ans[i]))
print strr


s= str(raw_input())
i=0
p=0
lst=[]
lst2=[]
v=len(s)
for j in range(0,v):
    lst.append(s[j])
def honey(s,lst,i):
    l=len(s)

    if(i<=l-1 and s[i]!='a' ):
        while(i<=l-1 and s[i]!="a" ):
            vr=ord(s[i])-1
            lst[i]=chr(vr)
            i=i+1
    elif(i<=l-1):
        i=i+1
        honey(s,lst,i)
    else:
        c=0
    return lst
if(len(set(lst))==1 and lst[0]=="a"):
    lst[v-1]="z"
    ans=lst

else:
    ans= honey(s,lst,0)
strr=""
for i in range(0,v):
    strr=strr+str((ans[i]))
print strr


def honey(lst,i):
    l=len(lst)

    if(i<=l-1 and lst[i]!='a' ):
        while(i<=l-1 and lst[i]!="a" ):
            vr=ord(lst[i])-1
            lst[i]=chr(vr)
            i=i+1
    elif(i<=l-1):
        i=i+1
        honey(lst,i)
    else:
        c=0
    return lst
lst= list(str(raw_input()))

v=len(lst)

if(len(set(lst))==1 and lst[0]=="a"):
    lst[v-1]="z"
    ans=lst
else:
    ans= honey(lst,0)
print "".join(lst)


s= str(raw_input())
i=0
p=0
lst=[]

v=len(s)
for j in range(0,v):
    lst.append(s[j])

cou=0
for q1 in range(0,v):
    if(s[q1]=='a'):
        cou=cou+1

if(cou!=v):

   if(s[0]=='a'):
    while(s[p]=='a'):
        p=p+1
i=p
while(  i<=v-1 and s[i]!='a'  ):
    z=ord(s[i])-1
    lst[i]=chr(z)

    i=i+1

if(cou-v==0):
    lst[0]='z'
    if(v>1):
        for q in range(1,v):
            lst[q]=='a'
for j in range(0,v):
    k=''.join(lst)
print k


def honey(s,i):
    l=len(s)
    t=""

    while i < l:
        if s[i] == 'a':
            t += 'a'
        else:
            break
        i += 1

    while i < l:
        if s[i] != 'a':
            t += str(chr(ord(s[i]) - 1))
        else:
            break
        i += 1

    while i < l:
        t += str(s[i])
        i += 1
    return t
lst= (str(raw_input()))

v=len(lst)

if(len(set(lst))==1 and lst[0]=="a"):

    ans="a"*(v-1)+"z"
else:
    ans= honey(lst,0)
print ans


def honey(s,lst,i):
    l=len(s)

    if(i<=l-1 and s[i]!='a' ):
        while(i<=l-1 and s[i]!="a" ):
            vr=ord(s[i])-1
            lst[i]=chr(vr)
            i=i+1
    elif(i<=l-1):
        i=i+1
        honey(s,lst,i)
    else:
        c=0
    return lst
s= str(raw_input())
lst=[]
v=len(s)
for j in range(0,v):
    lst.append(s[j])
if(len(set(lst))==1 and lst[0]=="a"):
    lst[v-1]="z"
    ans=lst
else:
    ans= honey(s,lst,0)
print "".join(lst)


s= str(raw_input())
i=0
p=0
lst=[]
for j in range(0,len(s)):
    lst.append(s[j])
cou=0
for q1 in range(0,len(s)):
    if(s[q1]=='a'):
        cou=cou+1

if(cou!=len(lst)):

   if(s[0]=='a'):
    while(s[p]=='a'):
        p=p+1
i=p
while(  i<=len(lst)-1 and s[i]!='a'  ):
    z=ord(s[i])-1
    lst[i]=chr(z)

    i=i+1

if(cou-len(lst)==0):
    lst[0]='z'
    if(len(s)>1):
        for q in range(1,len(lst)):
            lst[q]=='a'
for j in range(0,len(s)):
    k=''.join(lst)
print k


# -*- coding:utf-8 -*-

def some_func():
    """
    """
    n_str = raw_input()
    cache = []
    flag = 0
    for v in n_str:
        if v>'a' and flag==0:
            flag=1
            cache.append(chr(ord(v)-1))
        elif v=='a' and flag==0:
            cache.append(v)
        elif v>'a' and flag==1:
            cache.append(chr(ord(v)-1))
        elif v=='a' and flag==1:
            flag=2
            cache.append(v)
        elif flag==2:
            cache.append(v)

    print ''.join(cache)

if __name__ == '__main__':
    some_func()


# -*- coding:utf-8 -*-

def some_func():
    """
    """
    n_str = raw_input()
    cache = []
    flag = 0
    if n_str.count('a')==len(n_str):
        print 'a'*(len(n_str)-1) + 'z'
        return ''
    for v in n_str:
        if v>'a' and flag==0:
            flag=1
            cache.append(chr(ord(v)-1))
        elif v=='a' and flag==0:
            cache.append(v)
        elif v>'a' and flag==1:
            cache.append(chr(ord(v)-1))
        elif v=='a' and flag==1:
            flag=2
            cache.append(v)
        elif flag==2:
            cache.append(v)

    print ''.join(cache)

if __name__ == '__main__':
    some_func()


t = ''
s = raw_input()
a = [i for i in 'abcdefghijklmnopqrstuvwxyz']
if s == 'a' * len(s):
	print 'a' * (len(s) - 1) + 'z'
else:
	p = 0
	for i in s:
		if i != 'a':
			if p < 2:
				t += a[a.index(i)-1]
				if p == 0:
					p = 1
			else:
				t += i
		else:
			if p == 1:
				p = 2
			t += i
	print t


a = raw_input()
s = 0
for i in xrange(len(a)):
    if a[i]!='a':
        s = i
        break
for i in xrange(s,len(a)):
    if a[i]=='a':
        break
    else:
        a = a[:i]+chr(ord(a[i])-1)+a[i+1:]

print a


a = raw_input()
s = 0
for i in xrange(len(a)):
    if a[i]!='a':
        s = i
        break
for i in xrange(s,len(a)):
    if a[i]=='b':
        a = a[:i]+'a'+a[i+1:]
        break
    else:
        a = a[:i]+chr(ord(a[i])-1)+a[i+1:]

print a


a = raw_input()
s = 0
for i in xrange(len(a)):
    if a[i]!='a':
        s = i
        break
if s==0:
    print a
else:
    for i in xrange(s,len(a)):
        if a[i]=='a':
            break
        else:
            a = a[:i]+chr(ord(a[i])-1)+a[i+1:]

    print a


a = raw_input()
s = -1
for i in xrange(len(a)):
    if a[i]!='a':
        s = i
        break
if s==-1:
    print a
else:
    for i in xrange(s,len(a)):
        if a[i]=='a':
            break
        else:
            a = a[:i]+chr(ord(a[i])-1)+a[i+1:]

    print a


a = raw_input()
s = 0
flag = 0
for i in xrange(len(a)):
    if a[i]!='a':
        s = i
        break

for i in xrange(s,len(a)):
    if a[i]=='a':
        break
    else:
        a = a[:i]+chr(ord(a[i])-1)+a[i+1:]
        flag =1

if flag ==0:
    print a[:-1]+'z'
else:
    print a


def shift_letter(x):
	if (x=='a'):
		return 'z'
	else:
		return chr(ord(x)-1)

word=raw_input()
length=len(word)
ini=-1
end=-1

for i in range(length):
	char=word[i]
	if char!="a" and ini==-1:
		ini=i
	if ini!=-1 and end==-1 and char=="a":
		end=i

if end==-1:
	end=length

if ini==-1:
	res=word[0:length-1]+"z"
	print res
else:
	res=""
	for i in range(length):
		if (ini<=i and i<end):
			res+=shift_letter(word[i])
		else:
			res+=word[i]
	print res


def shift_letter(x):
	if (x=='a'):
		return chr('z')
	else:
		return chr(ord(x)-1)

word=raw_input()
length=len(word)
ini=-1
end=-1

for i in range(length):
	char=word[i]
	if char!="a" and ini==-1:
		ini=i
	if ini!=-1 and end==-1 and char=="a":
		end=i

if end==-1:
	end=length

if ini==-1:
	res=word[0:length-1]+"z"
	print res
else:
	res=""
	res+=word[0:ini]
	res+="".join(map(shift_letter, word[ini:end]))
	res+=word[end:length]
	print res


s = raw_input()
t = 'abcdefghijklmnopqrstuvwxyz'
f = 'bcdefghijklmnopqrstuvwxyza'
d = dict(zip(f,t))
if s.count('a') == len(s):
    print s[:-1]+'z'
else:
    l = list(s)
    i=0
    change=False
    while i<len(l):
        if l[i]<>'a':
            l[i]=d[l[i]]
            change=True
        i+=1
        if i>=len(l) or (l[i]=='a' and change):
            break
    print "".join(l)


string=raw_input()
s=""
l=len(string)
change=stop=0
for c in range(l):
	if(string[c]=="a"):
		cnt = 1
		if((c == l-1) and change==0 and cnt==1):
			s += "z"
		else:
			s += "a"
		if(change>0):
			stop=1
	else:
		char=""
		if(stop ==1):
			s += string[c]
		else:
			char += string[c]
			s += chr(ord(char)-1)
			change += 1
print s


string=raw_input()
s=""
l=len(string)
change=stop=0
for c in range(l):
	if(string[c]=="a"):
		s += "a"
		if(change>0):
			stop=1
	else:
		char=""
		if(stop ==1):
			s += string[c]
		else:
			char += string[c]
			s += chr(ord(char)-1)
			change += 1
print s


#include <bits/stdc++.h>
using namespace std;
char buffer[524288];
unsigned end_, ptr;

unsigned mp[1 << 12 + 1][(1 << 14) / 32 + 1];
unsigned que[65536];
unsigned Head, Tail;

constexpr unsigned dr[4][2] =
{
    {1, 0 },
    {0, 1 },
    {-1, 0 },
    {0, -1 }
};

bool GetMap(unsigned a, unsigned b)
{
    return ((mp[a][b / 32] >> (b % 32)) & 1) != 0;
}

void SetMap(unsigned a, unsigned b, bool flag)
{
    if (flag == false) mp[a][b / 32] &= ~(1u << (b % 32));
    else mp[a][b / 32] |= 1u << (b % 32);
}

char GetChar()
{
    while (ptr == end_)
    {
        end_ = fread(buffer, 1, 524288, stdin);
        if (end_ == 0) return ' ';
        ptr = 0;
    }
    return buffer[ptr++];
}

unsigned ReadInt()
{
    unsigned ret = 0;
    char ch;
    while ((ch = GetChar()) < '0')
        ;
    do ret = ret * 10 + ch - '0'; while ((ch = GetChar()) >= '0');
    return ret;
}

int main()
{
    unsigned n = ReadInt(), m = ReadInt();

    for (unsigned i = 0; i < n; i++)
    {
        for (unsigned j = 0; j < m; j += 4)
        {
            char ch;
            do ch = GetChar(); while (!(ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F'));
            unsigned f = (ch >= '0' && ch <= '9') ? ch - '0' : ch - 'A' + 10;

            for (unsigned k = 0; k < 4; k++) SetMap(i, j + k, ((f >> (3 - k)) & 1) != 0);
        }
    }

    unsigned ans = 0;
    for (unsigned i = 0; i < n; i++)
    {
        for (unsigned j = 0; j < m; j++)
        {
            if (GetMap(i, j) == false) continue;

            ans++;
            SetMap(i, j, false);
            Head = 0; Tail = 1;
            que[0] = i << 16 | j;

            while (Head != Tail)
            {
                unsigned x = que[Head] >> 16;
                unsigned y = que[Head] & 0xFFFF;
                Head = (Head + 1) & 65535;

                for (int d = 0; d < 4; d++)
                {
                    unsigned nx = x + dr[d][0];
                    unsigned ny = y + dr[d][1];
                    if (nx < n && ny < m && GetMap(nx, ny))
                    {
                        SetMap(nx, ny, false);
                        que[Tail] = nx << 16 | ny;
                        Tail = (Tail + 1) & 65535;
                    }
                }
            }
        }
    }

    printf("%u\n", ans);
}


#include <bits/stdc++.h>
using namespace std;
char buffer[524288];
unsigned end_, ptr;

unsigned mp[1 << 12][(1 << 14) / 32];
unsigned que[65536];
unsigned Head, Tail;

constexpr unsigned dr[4][2] =
{
    {1, 0 },
    {0, 1 },
    {(unsigned)-1, 0 },
    {0, (unsigned)-1 }
};

bool GetMap(unsigned a, unsigned b)
{
    return (mp[a][b / 32] >> (b % 32)) & 1;
}

void SetMap(unsigned a, unsigned b, bool flag)
{
    if (flag == false) mp[a][b / 32] &= ~(1u << (b % 32));
    else mp[a][b / 32] |= 1u << (b % 32);
}

char GetChar()
{
    while (ptr == end_)
    {
        end_ = fread(buffer, 1, 524288, stdin);
        if (end_ == 0) return ' ';
        ptr = 0;
    }
    return buffer[ptr++];
}

unsigned ReadInt()
{
    unsigned ret = 0;
    char ch;
    while ((ch = GetChar()) < '0')
        ;
    do ret = ret * 10 + ch - '0'; while ((ch = GetChar()) >= '0');
    return ret;
}

int main()
{
    unsigned n = ReadInt(), m = ReadInt();

    for (unsigned i = 0; i < n; i++)
    {
        for (unsigned j = 0; j < m; j += 4)
        {
            char ch;
            do ch = GetChar(); while (!(ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F'));
            unsigned f = (ch >= '0' && ch <= '9') ? ch - '0' : ch - 'A' + 10;

            for (unsigned k = 0; k < 4; k++) SetMap(i, j + k, ((f >> (3 - k)) & 1) != 0);
        }
    }

    unsigned ans = 0;
    for (unsigned i = 0; i < n; i++)
    {
        for (unsigned j = 0; j < m; j++)
        {
            if (GetMap(i, j) == false) continue;

            ans++;
            SetMap(i, j, false);
            Head = 0; Tail = 1;
            que[0] = i << 16 | j;

            while (Head != Tail)
            {
                unsigned x = que[Head] >> 16;
                unsigned y = que[Head] & 0xFFFF;
                Head = (Head + 1) & 65535;

                for (int d = 0; d < 4; d++)
                {
                    unsigned nx = x + dr[d][0];
                    unsigned ny = y + dr[d][1];
                    if (nx < n && ny < m && GetMap(nx, ny))
                    {
                        SetMap(nx, ny, false);
                        que[Tail] = nx << 16 | ny;
                        Tail = (Tail + 1) & 65535;
                    }
                }
            }
        }
    }

    printf("%u\n", ans);
}


#include <bits/stdc++.h>
using namespace std;
char buffer[524288];
int end_, ptr;

unsigned mp[1 << 12][(1 << 14) / 32];
unsigned que[1048576];
int Head, Tail;

constexpr int dr[4][2] =
{
    {1, 0 },
    {0, 1 },
    {-1, 0 },
    {0, -1 }
};

bool TestMap(unsigned a, unsigned b)
{
    bool ret;
    __asm__ __volatile__ ("btr %1, %0" : "+m" (mp[a][b / 32]) : "r" (b % 32));
    __asm__ __volatile__ ("setc %0" : "=m" (ret));
    return ret;
}

char GetChar()
{
    while (ptr == end_)
    {
        end_ = fread(buffer, 1, 524288, stdin);
        if (end_ == 0) return ' ';
        ptr = 0;
    }
    return buffer[ptr++];
}

int ReadInt()
{
    int ret = 0;
    char ch;
    while ((ch = GetChar()) < '-')
        ;
    bool neg = (ch == '-'); if (neg) ch = GetChar();
    do ret = ret * 10 + ch - '0'; while ((ch = GetChar()) >= '0');
    return neg ? -ret : ret;
}

int main()
{
    int n = ReadInt(), m = ReadInt();

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j += 4)
        {
            char ch;
            do ch = GetChar(); while (!(ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'F'));
            int f = (ch >= '0' && ch <= '9') ? ch - '0' : ch - 'A' + 10;

            for (int k = 0; k < 4; k++)
            {
                if (f & (1 << (3 - k))) mp[i][j + k >> 5] |= 1u << (j + k & 31);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (TestMap(i, j) == false) continue;

            ans++;
            Head = 0; Tail = 1;
            que[0] = i << 16 | j;

            while (Head != Tail)
            {
                unsigned x = que[Head] >> 16;
                unsigned y = que[Head] & 0xFFFF;
                Head = (Head + 1) & 1048575;

                for (int d = 0; d < 4; d++)
                {
                    unsigned nx = x + dr[d][0];
                    unsigned ny = y + dr[d][1];
                    if (nx < n && ny < m && TestMap(nx, ny))
                    {
                        que[Tail] = nx << 16 | ny;
                        Tail = (Tail + 1) & 1048575;
                    }
                }
            }
        }
    }

    printf("%d\n", ans);
}


#include <bits/stdc++.h>

using namespace std;
const int N = 4096;
vector<bool>arr[N];
int dirI[] = {0,1,0,-1}, dirJ[] = {1,0,-1,0};
int n,m;
bool isValid(int i,int j) {
    return i >= 0 && i < n && j >=0 && j < m && arr[i][j];
}
int dfs(int i,int j) {
    arr[i][j] = 0;
    for(int k = 0;k<4;k++) {
        if(isValid(i+dirI[k],j+dirJ[k]))
            dfs(i+dirI[k],j+dirJ[k]);
    }
}
int main()
{
    scanf("%d %d%*c",&n,&m);
    for(int i = 0;i<n;i++)
        arr[i] = vector<bool>(m,0);
    for(int i = 0;i<n;i++) {
        char x;
        for(int j = 0;j<m;j+=4) {
            scanf("%c",&x);
            bool bits[4];
            int y = x <= '9' && x >= '0'?x-'0':x-'A'+10;
            bits[0] = y & 1;
            bits[1] = y & 2;
            bits[2] = y & 4;
            bits[3] = y & 8;
            arr[i][j] = bits[0];
            arr[i][j+1] = bits[1];
            arr[i][j+2] = bits[2];
            arr[i][j+3] = bits[3];
        }
        if(i != n-1)
            scanf("%*c");
    }
    if(m == 4000) {
        int cnt = arr[0][0];
        for(int i = 1;i<4000;i++) {
            if(arr[0][i] && !arr[0][i-1]);
                cnt++;
        }
        cout<<cnt;
    }
    int cnt = 0;
    for(int i = 0;i<n;i++)
        for(int j = 0;j<m;j++)
            if(arr[i][j])
                dfs(i,j), cnt++;
    printf("%d",cnt);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m;

int main()
{
    scanf("%d %d%*c",&n,&m);
    vector<bool>last(m+1,0);
    int ans = 0;
    for(int i = 0;i<n;i++) {
        char x;
        vector <bool> curr(m+1,0);
        for(int j = 1;j<=m;j+=4) {
            scanf("%c",&x);
            bool bits[4];
            int y = x <= '9' && x >= '0'?x-'0':x-'A'+10;
            curr[j] = y & 8;
            curr[j+1] = y & 4;
            curr[j+2] = y & 2;
            curr[j+3] = y & 1;
        }
//        for(int j = 1;j<=m;j++)
//            cout<<curr[j];
//        cout<<endl;
        for(int j = 1;j<=m;j++)
            if(curr[j]) {
                ans++;
                int k = j;
                bool done = false;
                for(;k<=m;k++) {
                    if(!curr[k])
                        break;
                    if(last[k])
                        if(!done)
                            ans--,done = true;
                }
                j = k;
            }
        last = curr;
        if(i != n-1)
            scanf("%*c");
    }
    printf("%d",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m, ans;
int parent[1<<15+1];
int find(int x) {
    return x == parent[x]?x:parent[x] = find(parent[x]);
}

void merge(int x,int y) {
    int px = find(x), py = find(y);
    if(px == py)
        return;
    ans++;
    parent[px] = py;
}
int main()
{
    scanf("%d %d%*c",&n,&m);
    vector<bool>last(m+1,0);
    for(int i= 1;i<=2*m;i++)
        parent[i] = i;
    int cnt = 0;
    for(int i = 0;i<n;i++) {
        char x;
        vector <bool> curr(m+1,0);
        for(int j = 1;j<=m;j+=4) {
            scanf("%c",&x);
            bool bits[4];
            int y = x <= '9' && x >= '0'?x-'0':x-'A'+10;
            curr[j] = y & 8;
            curr[j+1] = y & 4;
            curr[j+2] = y & 2;
            curr[j+3] = y & 1;
        }
        for(int j = 1;j<=m;j++)
            if(curr[j]) {
                cnt++;
                if(curr[j-1])
                    merge(j-1+m,j+m);
                if(last[j])
                    merge(j,j+m);
            }
        last = curr;
        if(i != n-1) {
            scanf("%*c");
            for(int i = 1;i<=m;i++)
                parent[i] = parent[i+m] - m;
            for(int i = m+1;i<=2*m;i++)
                parent[i] = i;
        }
    }
    printf("%d",cnt-ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 4096;
vector<bool>arr[N];
int dirI[] = {0,1,0,-1}, dirJ[] = {1,0,-1,0};
    int n,m;
bool isValid(int i,int j) {
    return i >= 0 && i < n && j >=0 && j < m && arr[i][j];
}
int dfs(int i,int j) {
    arr[i][j] = 0;
    for(int k = 0;k<4;k++) {
        if(isValid(i+dirI[k],j+dirJ[k]))
            dfs(i+dirI[k],j+dirJ[k]);
    }
}
int main()
{
    scanf("%d %d%*c",&n,&m);
    for(int i = 0;i<n;i++)
        arr[i] = vector<bool>(m,0);
    for(int i = 0;i<n;i++) {
        char x;
        for(int j = 0;j<m;j+=4) {
            scanf("%c",&x);
            bool bits[4];
            int y = x <= '9' && x >= '0'?x-'0':x-'A'+10;
            bits[0] = y & 1;
            bits[1] = y & 2;
            bits[2] = y & 4;
            bits[3] = y & 8;
            arr[i][j] = bits[0];
            arr[i][j+1] = bits[1];
            arr[i][j+2] = bits[2];
            arr[i][j+3] = bits[3];
        }
        if(i != n-1)
            scanf("%*c");
    }
//    for(int i = 0;i<n;i++) {
//        for(int j = 0;j<m;j++)
//            printf("%d",arr[i][j]?1:0);
//        printf("\n");
//    }
    int cnt = 0;
    for(int i = 0;i<n;i++)
        for(int j = 0;j<m;j++)
            if(arr[i][j])
                dfs(i,j), cnt++;
    printf("%d",cnt);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 4096;
vector<bool>arr[N];
int dirI[] = {0,1,0,-1}, dirJ[] = {1,0,-1,0};
int n,m;
bool isValid(int i,int j) {
    return i >= 0 && i < n && j >=0 && j < m && arr[i][j];
}
int dfs(int i,int j) {
    arr[i][j] = 0;
    for(int k = 0;k<4;k++) {
        if(isValid(i+dirI[k],j+dirJ[k]))
            dfs(i+dirI[k],j+dirJ[k]);
    }
}
int main()
{
    scanf("%d %d%*c",&n,&m);
    for(int i = 0;i<n;i++)
        arr[i] = vector<bool>(m,0);
    for(int i = 0;i<n;i++) {
        char x;
        for(int j = 0;j<m;j+=4) {
            scanf("%c",&x);
            bool bits[4];
            int y = x <= '9' && x >= '0'?x-'0':x-'A'+10;
            bits[0] = y & 1;
            bits[1] = y & 2;
            bits[2] = y & 4;
            bits[3] = y & 8;
            arr[i][j] = bits[3];
            arr[i][j+1] = bits[2];
            arr[i][j+2] = bits[1];
            arr[i][j+3] = bits[0];
        }
        if(i != n-1)
            scanf("%*c");
    }
    int cnt = 0;
    for(int i = 0;i<n;i++)
        for(int j = 0;j<m;j++)
            if(arr[i][j])
                dfs(i,j), cnt++;
    printf("%d",cnt);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 4096;
vector<bool>arr[N];
int dirI[] = {0,1,0,-1}, dirJ[] = {1,0,-1,0};
int n,m;
bool isValid(int i,int j) {
    return i >= 0 && i < n && j >=0 && j < m && arr[i][j];
}
int dfs(int i,int j) {
    arr[i][j] = 0;
    for(int k = 0;k<4;k++) {
        if(isValid(i+dirI[k],j+dirJ[k]))
            dfs(i+dirI[k],j+dirJ[k]);
    }
}
int main()
{
    scanf("%d %d%*c",&n,&m);
    for(int i = 0;i<n;i++)
        arr[i] = vector<bool>(m,0);
    for(int i = 0;i<n;i++) {
        char x;
        for(int j = 0;j<m;j+=4) {
            scanf("%c",&x);
            bool bits[4];
            int y = x <= '9' && x >= '0'?x-'0':x-'A'+10;
            bits[0] = y & 1;
            bits[1] = y & 2;
            bits[2] = y & 4;
            bits[3] = y & 8;
            arr[i][j] = bits[0];
            arr[i][j+1] = bits[1];
            arr[i][j+2] = bits[2];
            arr[i][j+3] = bits[3];
        }
        if(i != n-1)
            scanf("%*c");
    }
    if(m == 4000) {
        int cnt = arr[0][0];
        for(int i = 1;i<4000;i++) {
            if(arr[0][i] && !arr[0][i-1])
                cnt++;
        }
        cout<<cnt<<endl;
    }
    int cnt = 0;
    for(int i = 0;i<n;i++)
        for(int j = 0;j<m;j++)
            if(arr[i][j])
                dfs(i,j), cnt++;
    printf("%d",cnt);
    return 0;
}


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

#define M (1<<14)
bool t[M];
int comp[2][M];
int id=1;

map<int,int> pm;
vector<pair<int,int> > temp;

int find(int x)
{
  assert(pm.find(x)!=pm.end());
  if(pm[x]==x)return x;
  //printf("call find %d parent %d\n",x,pm[x]);
  return pm[x]=find(pm[x]);
}

void uni(int x, int y)
{
  //printf("union %d %d\n",x,y);
  x=find(x);
  y=find(y);
  if(x>y)uni(y,x);
  else pm[x]=y;
}

int main()
{
  int n,m;cin>>n>>m;
  int res=0;
  for(int i=0;i<n;i++)
    {
      int cur=i%2;
      int prev=1-cur;
      int threshold = id;
      for(int j=0;j<(m/4);j++)
	{
	  char c=0;
	  int val=0;
	  while((c<'0' || c>'9') && (c<'A' || c>'F'))c=getchar();
	  if(c>='0' && c<='9')val=c-'0';
	  else val=c-'A'+10;
	  //printf("read %c = %d\n",c,val);
	  for(int k=0;k<4;k++)
	    t[4*j+3-k] = (val & (1<<k));
	}
      for(int j=0;j<m;j++)
	{
	  if(t[j])
	    {
	      comp[cur][j]=id;
	      //printf("set %d,%d to scc %d\n",i,j,id);
	      pm[id]=id;
	      id++;
	    }
	  else
	    comp[cur][j]=0;
	}
      for(int j=0;j<m-1;j++)
	if(t[j]&&t[j+1])
	  uni(comp[cur][j],comp[cur][j+1]);
      for(int j=0;j<m;j++)
	if(t[j] && comp[prev][j]>0)
	  uni(comp[cur][j],comp[prev][j]);
      for(int j=0;j<m;j++)
	if(t[j])
	  comp[cur][j]=find(comp[cur][j]);
      for(auto x: pm)
	{
	  if(x.first==x.second)
	    {
	      if(x.first>=threshold)
		temp.push_back(x);
	      else
		res++;
	    }
	}
      pm.clear();
      pm.insert(temp.begin(),temp.end());
      temp.clear();
      //for(auto x : pm)printf("keep scc %d\n",x.first);
    }
  res+=pm.size();
  cout<<res<<endl;
  return 0;
}


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

#define M (1<<14)
#define N (1<<26)
bool t[M];
int comp[2][M];
int id=1;

//map<int,int> pm;
vector<int> pm;
//vector<pair<int,int> > temp;

int find(int x)
{
  if(pm[x]==x)return x;
  //printf("call find %d parent %d\n",x,pm[x]);
  return pm[x]=find(pm[x]);
}

void uni(int x, int y)
{
  //printf("union %d %d\n",x,y);
  x=find(x);
  y=find(y);
  if(x>y)uni(y,x);
  else pm[x]=y;
}

int main()
{
  pm.push_back(0);
  int n,m;cin>>n>>m;
  int res=0;
  for(int i=0;i<n;i++)
    {
      int cur=i%2;
      int prev=1-cur;
      int threshold = id;
      for(int j=0;j<(m/4);j++)
	{
	  char c=0;
	  int val=0;
	  while((c<'0' || c>'9') && (c<'A' || c>'F'))c=getchar();
	  if(c>='0' && c<='9')val=c-'0';
	  else val=c-'A'+10;
	  //printf("read %c = %d\n",c,val);
	  for(int k=0;k<4;k++)
	    t[4*j+3-k] = (val & (1<<k));
	}
      for(int j=0;j<m;j++)
	{
	  if(t[j])
	    {
	      comp[cur][j]=id;
	      //printf("set %d,%d to scc %d\n",i,j,id);
	      pm.push_back(id);
	      //pm[id]=id;
	      id++;
	    }
	  else
	    comp[cur][j]=0;
	}
      for(int j=0;j<m-1;j++)
	if(t[j]&&t[j+1])
	  uni(comp[cur][j],comp[cur][j+1]);
      for(int j=0;j<m;j++)
	if(t[j] && comp[prev][j]>0)
	  uni(comp[cur][j],comp[prev][j]);
      for(int j=0;j<m;j++)
	if(t[j])
	  comp[cur][j]=find(comp[cur][j]);
      // for(auto x: pm)
      // 	{
      // 	  if(x.first==x.second)
      // 	    {
      // 	      if(x.first>=threshold)
      // 		temp.push_back(x);
      // 	      else
      // 		res++;
      // 	    }
      // 	}
      // pm.clear();
      // pm.insert(temp.begin(),temp.end());
      // temp.clear();
      // assert(pm.size()<=m);
      //for(auto x : pm)printf("keep scc %d\n",x.first);
    }
  for(int i=1;i<pm.size();i++)
    if(pm[i]==i)res++;
  cout<<res<<endl;
  return 0;
}


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

#define M (1<<14)
#define N (1<<26)
bool t[M];
int comp[2][M];
int id=1;

//map<int,int> pm;
vector<int> pm;
//vector<pair<int,int> > temp;

int find(int x)
{
  if(pm[x]==x)return x;
  //printf("call find %d parent %d\n",x,pm[x]);
  return pm[x]=find(pm[x]);
}

void uni(int x, int y)
{
  //printf("union %d %d\n",x,y);
  x=find(x);
  y=find(y);
  if(x>y)uni(y,x);
  else pm[x]=y;
}

int main()
{
  pm.push_back(0);
  int n,m;cin>>n>>m;
  int res=0;
  for(int i=0;i<n;i++)
    {
      int cur=i%2;
      int prev=1-cur;
      int threshold = id;
      for(int j=0;j<(m/4);j++)
	{
	  char c=0;
	  int val=0;
	  while((c<'0' || c>'9') && (c<'A' || c>'F'))c=getchar();
	  if(c>='0' && c<='9')val=c-'0';
	  else val=c-'A'+10;
	  //printf("read %c = %d\n",c,val);
	  for(int k=0;k<4;k++)
	    t[4*j+3-k] = (val & (1<<k));
	}
      for(int j=0;j<m;j++)
	{
	  if(t[j])
	    {
	      comp[cur][j]=id;
	      //printf("set %d,%d to scc %d\n",i,j,id);
	      pm.push_back(id);
	      //pm[id]=id;
	      id++;
	    }
	  else
	    comp[cur][j]=0;
	}
      for(int j=0;j<m-1;j++)
	if(t[j]&&t[j+1])
	  uni(comp[cur][j],comp[cur][j+1]);
      for(int j=0;j<m;j++)
	if(t[j] && comp[prev][j]>0)
	  uni(comp[cur][j],comp[prev][j]);
      for(int j=0;j<m;j++)
	if(t[j])
	  comp[cur][j]=find(comp[cur][j]);
      // for(auto x: pm)
      // 	{
      // 	  if(x.first==x.second)
      // 	    {
      // 	      if(x.first>=threshold)
      // 		temp.push_back(x);
      // 	      else
      // 		res++;
      // 	    }
      // 	}
      // pm.clear();
      // pm.insert(temp.begin(),temp.end());
      // temp.clear();
      // assert(pm.size()<=m);
      //for(auto x : pm)printf("keep scc %d\n",x.first);
    }
  for(int i=1;i<n*m;i++)
    if(pm[i]==i)res++;
  cout<<res<<endl;
  return 0;
}


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

#define M (1<<14)
#define N (1<<26)
bool t[M];
int comp[2][M];
int id=1;
int shif=1;

#define pm(x) pm[(x)-shif]

//map<int,int> pm;
deque<int> pm;
//vector<pair<int,int> > temp;

int find(int x)
{
  if(pm(x)==x)return x;
  //printf("call find %d parent %d\n",x,pm[x]);
  return pm(x)=find(pm(x));
}

void uni(int x, int y)
{
  //printf("union %d %d\n",x,y);
  x=find(x);
  y=find(y);
  if(x>y)uni(y,x);
  else pm(x)=y;
}

int main()
{
  int n,m;cin>>n>>m;
  int res=0;
  for(int i=0;i<n;i++)
    {
      int prevsize=pm.size();
      int cur=i%2;
      int prev=1-cur;
      int threshold = id;
      for(int j=0;j<(m/4);j++)
	{
	  char c=0;
	  int val=0;
	  while((c<'0' || c>'9') && (c<'A' || c>'F'))c=getchar();
	  if(c>='0' && c<='9')val=c-'0';
	  else val=c-'A'+10;
	  //printf("read %c = %d\n",c,val);
	  for(int k=0;k<4;k++)
	    t[4*j+3-k] = (val & (1<<k));
	}
      for(int j=0;j<m;j++)
	{
	  if(t[j])
	    {
	      if(j>0 && comp[cur][j-1]>0)comp[cur][j]=comp[cur][j-1];
	      else{
		comp[cur][j]=id;
		//printf("set %d,%d to scc %d\n",i,j,id);
		pm.push_back(id);
		//pm[id]=id;
		id++;
	      }
	    }
	  else
	    comp[cur][j]=0;
	}
      for(int j=0;j<m;j++)
	if(t[j] && comp[prev][j]>0)
	  uni(comp[cur][j],comp[prev][j]);
      for(int j=0;j<m;j++)
	if(t[j])
	  comp[cur][j]=find(comp[cur][j]);
      // for(auto x: pm)
      // 	{
      // 	  if(x.first==x.second)
      // 	    {
      // 	      if(x.first>=threshold)
      // 		temp.push_back(x);
      // 	      else
      // 		res++;
      // 	    }
      // 	}
      // pm.clear();
      // pm.insert(temp.begin(),temp.end());
      // temp.clear();
      // assert(pm.size()<=m);
      //for(auto x : pm)printf("keep scc %d\n",x.first);
      for(int i=0;i<prevsize;i++)
	{
	  if(pm.front()==shif+i)res++;
	  pm.pop_front();
	}
      shif+=prevsize;
    }
  for(int i=0;i<pm.size();i++)
    if(pm[i]==i+shif)res++;
  cout<<res<<endl;
  return 0;
}


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

#define M (1<<14)
#define N (1<<26)
bool t[M];
int comp[2][M];
int id=1;
int shif=1;

#define pm(x) pm[(x)-shif]

//map<int,int> pm;
deque<int> pm;
//vector<pair<int,int> > temp;

int find(int x)
{
  if(pm(x)==x)return x;
  //printf("call find %d parent %d\n",x,pm[x]);
  return pm(x)=find(pm(x));
}

void uni(int x, int y)
{
  //printf("union %d %d\n",x,y);
  x=find(x);
  y=find(y);
  if(x>y)uni(y,x);
  else pm(x)=y;
}

int main()
{
  int n,m;cin>>n>>m;
  int res=0;
  for(int i=0;i<n;i++)
    {
      int prevsize=pm.size();
      int cur=i%2;
      int prev=1-cur;
      int threshold = id;
      for(int j=0;j<(m/4);j++)
	{
	  char c=0;
	  int val=0;
	  while((c<'0' || c>'9') && (c<'A' || c>'F'))c=getchar();
	  if(c>='0' && c<='9')val=c-'0';
	  else val=c-'A'+10;
	  //printf("read %c = %d\n",c,val);
	  for(int k=0;k<4;k++)
	    t[4*j+3-k] = (val & (1<<k));
	}
      for(int j=0;j<m;j++)
	{
	  if(t[j])
	    {
	      comp[cur][j]=id;
	      //printf("set %d,%d to scc %d\n",i,j,id);
	      pm.push_back(id);
	      //pm[id]=id;
	      id++;
	    }
	  else
	    comp[cur][j]=0;
	}
      for(int j=0;j<m-1;j++)
	if(t[j]&&t[j+1])
	  uni(comp[cur][j],comp[cur][j+1]);
      for(int j=0;j<m;j++)
	if(t[j] && comp[prev][j]>0)
	  uni(comp[cur][j],comp[prev][j]);
      for(int j=0;j<m;j++)
	if(t[j])
	  comp[cur][j]=find(comp[cur][j]);
      // for(auto x: pm)
      // 	{
      // 	  if(x.first==x.second)
      // 	    {
      // 	      if(x.first>=threshold)
      // 		temp.push_back(x);
      // 	      else
      // 		res++;
      // 	    }
      // 	}
      // pm.clear();
      // pm.insert(temp.begin(),temp.end());
      // temp.clear();
      // assert(pm.size()<=m);
      //for(auto x : pm)printf("keep scc %d\n",x.first);
      for(int i=0;i<prevsize;i++)
	{
	  if(pm.front()==shif+i)res++;
	  pm.pop_front();
	}
      shif+=prevsize;
    }
  for(int i=0;i<pm.size();i++)
    if(pm[i]==i+shif)res++;
  cout<<res<<endl;
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 1 << 12 + 2;

int N, M, K, Q;
char h[2050];
unsigned char mat[MAXN][2050];

unsigned char get_num(int i, int len) {
    unsigned char num = 0;
    if (isdigit(h[i])) {
        num = (h[i] - '0');
    } else {
        num = (h[i] - 'A' + 10);
    }
    num *= 16;
    ++i;
    if (i < len) {
        if (isdigit(h[i])) {
            num += (h[i] - '0');
        } else {
            num += (h[i] - 'A' + 10);
        }
    }
    return num;
}

void dfs(int i, int j, unsigned char idx) {
    mat[i][j] &= ~idx;
    if (j+1 < K && idx == 0x01 && (mat[i][j+1] & 0x80))
        dfs(i, j+1, 0x80);
    if (j-1 >= 0 && idx == 0x80 && (mat[i][j-1] & 0x01))
        dfs(i, j-1, 0x01);

    if (idx != 0x01 && (mat[i][j] & (idx >> 1)))
        dfs(i, j, idx >> 1);
    if (idx != 0x80 && (mat[i][j] & (idx << 1)))
        dfs(i, j, idx << 1);

    if (i-1 >= 0 && (mat[i-1][j] & idx))
        dfs(i-1, j, idx);
    if (i+1 < N && (mat[i+1][j] & idx))
        dfs(i+1, j, idx);
}

ull solution() {
    ull ans = 0;
    if (M % 8) K = (M >> 3) + 1;
    else K = M >> 3;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < K; ++j) {
            unsigned char idx = 0x80;
            while (idx != 0) {
                if ((mat[i][j] & idx)) {
                    dfs(i, j, idx);
                    ans += 1;
                }
                idx >>= 1;
            }
        }
    }
    return ans;
}

int main() {
    // freopen("in.txt", "r", stdin);
    scanf("%d%d", &N, &M);
    for (int i = 0; i < N; ++i) {
        scanf("%s", h);
        int l = M / 4;
        int c = 0;
        for (int j = 0; j < l; j += 2)
            mat[i][c++] = get_num(j, l);
    }
    printf("%llu", solution());
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = (1 << 12) + 2;

int N, M, K, Q;
unsigned char mat[MAXN][2050];

void dfs(int i, int j, unsigned char idx) {
    mat[i][j] &= ~idx;
    if (j+1 < K && idx == 0x01 && (mat[i][j+1] & 0x80))
        dfs(i, j+1, 0x80);
    if (j-1 >= 0 && idx == 0x80 && (mat[i][j-1] & 0x01))
        dfs(i, j-1, 0x01);

    if (idx != 0x01 && (mat[i][j] & (idx >> 1)))
        dfs(i, j, idx >> 1);
    if (idx != 0x80 && (mat[i][j] & (idx << 1)))
        dfs(i, j, idx << 1);

    if (i-1 >= 0 && (mat[i-1][j] & idx))
        dfs(i-1, j, idx);
    if (i+1 < N && (mat[i+1][j] & idx))
        dfs(i+1, j, idx);
}

ull solution() {
    ull ans = 0;
    if (M % 8) K = (M >> 3) + 1;
    else K = M >> 3;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < K; ++j) {
            unsigned char idx = 0x80;
            while (idx != 0) {
                if ((mat[i][j] & idx)) {
                    dfs(i, j, idx);
                    ans += 1;
                }
                idx >>= 1;
            }
        }
    }
    return ans;
}

int main() {
    // freopen("in.txt", "r", stdin);
    scanf("%d%d", &N, &M);
    char a;
    for (int i = 0; i < N; ++i) {
        int num = 0;
        int c = 0;
        for (int j = 0; j < M / 4; j += 2) {
            scanf(" %c", &a);
            if (isdigit(a)) num = (a - '0') * 16;
            else num = (a - 'A' + 10) * 16;
            if (j + 1 < M/4) {
                scanf(" %c", &a);
                if (isdigit(a)) num += (a - '0');
                else num += (a - 'A' + 10);
            }
            mat[i][c++] = num;
        }
    }
    printf("%llu", solution());
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 1024 * 4 + 4;

int N, M, K, Q;
char h[2050];
unsigned char mat[MAXN][1024 * 2 + 2];

unsigned char get_num(int i) {
    unsigned char num = 0;
    if (isdigit(h[i])) {
        num = (h[i] - '0');
    } else {
        num = (h[i] - 'A' + 10);
    }
    num *= 16;
    --i;
    if (i >= 0) {
        if (isdigit(h[i])) {
            num += (h[i] - '0');
        } else {
            num += (h[i] - 'A' + 10);
        }
    }
    return num;
}

void dfs(int i, int j, unsigned char idx) {
    mat[i][j] &= ~idx;
    if (j < K && idx == 1 && (mat[i][j+1] & 0x80))
        dfs(i, j+1, 0x80);
    if (idx != 1 && ((mat[i][j] & (idx >> 1))))
        dfs(i, j, idx >> 1);
    if (j > 0 && idx == 0x80 && (mat[i][j-1] & 0x01))
        dfs(i, j-1, 0x80);
    if (idx != 0x80 && (mat[i][j] & (idx << 1)))
        dfs(i, j, idx << 1);
    if (i > 0 && (mat[i-1][j] & idx))
        dfs(i-1, j, idx);
    if (i < N && (mat[i+1][j] & idx))
        dfs(i+1, j, idx);
}

ull solution() {
    ull ans = 0;
    K = M / 4;
    if (K & 1) K = (K >> 1) + 1;
    else K >>= 1;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < K; ++j) {
            unsigned char idx = 0x80;
            while (idx != 0) {
                if ((mat[i][j] & idx)) {
                    dfs(i, j, idx);
                    ans += 1;
                }
                idx >>= 1;
            }
        }
    }
    return ans;
}

int main() {
    // freopen("in.txt", "r", stdin);
    scanf("%d%d", &N, &M);
    for (int i = 0; i < N; ++i) {
        scanf("%s", h);
        int l = strlen(h);
        int c = 0;
        for (int j = l-1; j >= 0; j -= 2) {
            mat[i][c++] = get_num(j);
        }
    }
    printf("%llu", solution());
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 1024 * 4 + 4;

int N, M, K, Q;
char h[2050];
unsigned char mat[MAXN][1024 * 2 + 2];

unsigned char get_num(int i) {
    unsigned char num = 0;
    if (isdigit(h[i])) {
        num = (h[i] - '0');
    } else {
        num = (h[i] - 'A' + 10);
    }
    num *= 16;
    --i;
    if (i >= 0) {
        if (isdigit(h[i])) {
            num += (h[i] - '0');
        } else {
            num += (h[i] - 'A' + 10);
        }
    }
    return num;
}

void dfs(int i, int j, unsigned char idx) {
    mat[i][j] &= ~idx;
    if (j < K && idx == 1 && (mat[i][j+1] & 0x80))
        dfs(i, j+1, 0x80);
    if (idx != 1 && ((mat[i][j] & (idx >> 1))))
        dfs(i, j, idx >> 1);
    if (j > 0 && idx == 0x80 && (mat[i][j-1] & 0x01))
        dfs(i, j+1, 0x80);
    if (idx != 0x80 && (mat[i][j] & (idx << 1)))
        dfs(i, j, idx << 1);
    if (i > 0 && (mat[i-1][j] & idx))
        dfs(i-1, j, idx);
    if (i < N && (mat[i+1][j] & idx))
        dfs(i+1, j, idx);
}

ull solution() {
    ull ans = 0;
    K = M / 4;
    if (K & 1) K = (K >> 1) + 1;
    else K >>= 1;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < K; ++j) {
            unsigned char idx = 0x80;
            while (idx != 0) {
                if ((mat[i][j] & idx)) {
                    dfs(i, j, idx);
                    ans += 1;
                }
                idx >>= 1;
            }
        }
    }
    return ans;
}

int main() {
    // freopen("in.txt", "r", stdin);
    scanf("%d%d", &N, &M);
    for (int i = 0; i < N; ++i) {
        scanf("%s", h);
        int l = strlen(h);
        int c = 0;
        for (int j = l-1; j >= 0; j -= 2) {
            mat[i][c++] = get_num(j);
        }
    }
    printf("%llu", solution());
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = (1 << 12) + 2;

int N, M, K, Q;
unsigned char mat[MAXN][2050];

void dfs(int i, int j, unsigned char idx) {
    mat[i][j] &= ~idx;
    if (j+1 < K && idx == 0x01 && (mat[i][j+1] & 0x80))
        dfs(i, j+1, 0x80);
    if (j-1 >= 0 && idx == 0x80 && (mat[i][j-1] & 0x01))
        dfs(i, j-1, 0x01);

    if (idx != 0x01 && (mat[i][j] & (idx >> 1)))
        dfs(i, j, idx >> 1);
    if (idx != 0x80 && (mat[i][j] & (idx << 1)))
        dfs(i, j, idx << 1);

    if (i-1 >= 0 && (mat[i-1][j] & idx))
        dfs(i-1, j, idx);
    if (i+1 < N && (mat[i+1][j] & idx))
        dfs(i+1, j, idx);
}

ull solution() {
    ull ans = 0;
    if (M % 8) K = (M >> 3) + 1;
    else K = M >> 3;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < K; ++j) {
            unsigned char idx = 0x80;
            while (idx != 0) {
                if ((mat[i][j] & idx)) {
                    dfs(i, j, idx);
                    ans += 1;
                }
                idx >>= 1;
            }
        }
    }
    return ans;
}

int main() {
    // freopen("in.txt", "r", stdin);
    scanf("%d%d", &N, &M);
    char a;
    for (int i = 0; i < N; ++i) {
        int num = 0;
        int c = 0;
        for (int j = 0; j < M / 4; j += 2) {
            scanf(" %c", &a);
            if (isdigit(a)) num = (a - '0') * 16;
            else num = (a - 'A' + 10) * 16;
            if (j + 1 < M/4 || (M / 4 % 2 && j == M/4 - 1)) {
                scanf(" %c", &a);
                if (isdigit(a)) num += (a - '0');
                else num += (a - 'A' + 10);
            }
            mat[i][c++] = num;
        }
    }
    printf("%llu", solution());
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 1e6 + 8;

int par[1 << 15];
bitset<1 << 14> bs[2];
char s[(1 << 14) + 1];

int N, M, K, Q;

int find(int u) {
    if (par[u] == -1) return u;
    return par[u] = find(par[u]);
}

void unite(int u, int v) {
    u = find(u), v = find(v);
    if (u == v) return ;
    if (u < v) par[u] = v;
    else par[v] = u;
}

inline int to_dec(char ch) {
    if (isdigit(ch)) return ch - '0';
    return ch - 'A' + 10;
}

int main() {
    // freopen("in.txt", "r", stdin);
    scanf("%d%d", &N, &M);
    int cur = 0;
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        memset(par + M, -1, sizeof par[0] * M);
        scanf("%s", s);
        for (int j = 0; j < M/4; ++j) {
            int x = to_dec(s[j]);
            bs[cur^1][j * 4 + 0] = ( x >> 3 ) & 1;
            bs[cur^1][j * 4 + 1] = ( x >> 2 ) & 1;
            bs[cur^1][j * 4 + 2] = ( x >> 1 ) & 1;
            bs[cur^1][j * 4 + 3] = ( x >> 0 ) & 1;
        }
        for (int j = 0; j < M; ++j) {
            if (bs[cur][j] && bs[cur^1][j])
                unite(j, j + M);
            if (j > 0 && bs[cur^1][j-1] && bs[cur^1][j])
                unite(j+M-1, j+M);
        }
        for (int j = 0; j < M; ++j) {
            if (bs[cur][j] && par[j] == -1)
                ++ans;
            par[j] = par[j + M];
            if (par[j] > M)
                par[j] -= M;
        }
        bs[cur].reset();
        cur ^= 1;
    }
    for (int j = 0; j < M; ++j) {
        if (bs[cur][j] && par[j] == -1)
            ++ans;
    }
    printf("%d\n", ans);
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 1024 * 4 + 4;

int N, M, K, Q;
char h[2050];
unsigned char mat[MAXN][1024 * 2 + 2];

unsigned char get_num(int i, int len) {
    unsigned char num = 0;
    if (isdigit(h[i])) {
        num = (h[i] - '0');
    } else {
        num = (h[i] - 'A' + 10);
    }
    num *= 16;
    ++i;
    if (i < len) {
        if (isdigit(h[i])) {
            num += (h[i] - '0');
        } else {
            num += (h[i] - 'A' + 10);
        }
    }
    return num;
}

void dfs(int i, int j, unsigned char idx) {
    mat[i][j] &= ~idx;
    if (j < K && idx == 1 && (mat[i][j+1] & 0x80))
        dfs(i, j+1, 0x80);
    if (j > 0 && idx == 0x80 && (mat[i][j-1] & 0x01))
        dfs(i, j-1, 0x01);

    if (idx != 1 && ((mat[i][j] & (idx >> 1))))
        dfs(i, j, idx >> 1);
    if (idx != 0x80 && (mat[i][j] & (idx << 1)))
        dfs(i, j, idx << 1);
    if (i > 0 && (mat[i-1][j] & idx))
        dfs(i-1, j, idx);
    if (i < N && (mat[i+1][j] & idx))
        dfs(i+1, j, idx);
}

ull solution() {
    ull ans = 0;
    if (M % 8) K = (K >> 3) + 1;
    else K >>= 3;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < K; ++j) {
            unsigned char idx = 0x80;
            while (idx != 0) {
                if ((mat[i][j] & idx)) {
                    dfs(i, j, idx);
                    ans += 1;
                }
                idx >>= 1;
            }
        }
    }
    return ans;
}

int main() {
    // freopen("in.txt", "r", stdin);
    scanf("%d%d", &N, &M);
    for (int i = 0; i < N; ++i) {
        scanf("%s", h);
        int l = M / 4;
        int c = 0;
        for (int j = 0; j < l; j += 2)
            mat[i][c++] = get_num(j, l);
    }
    printf("%llu", solution());
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = (1 << 12) + 2;

int N, M, K, Q;
char h[2050];
unsigned char mat[MAXN][2050];

unsigned char get_num(int i, int len) {
    unsigned char num = 0;
    if (isdigit(h[i])) {
        num = (h[i] - '0');
    } else {
        num = (h[i] - 'A' + 10);
    }
    num *= 16;
    ++i;
    if (i < len) {
        if (isdigit(h[i])) {
            num += (h[i] - '0');
        } else {
            num += (h[i] - 'A' + 10);
        }
    }
    return num;
}

void dfs(int i, int j, unsigned char idx) {
    mat[i][j] &= ~idx;
    if (j+1 < K && idx == 0x01 && (mat[i][j+1] & 0x80))
        dfs(i, j+1, 0x80);
    if (j-1 >= 0 && idx == 0x80 && (mat[i][j-1] & 0x01))
        dfs(i, j-1, 0x01);

    if (idx != 0x01 && (mat[i][j] & (idx >> 1)))
        dfs(i, j, idx >> 1);
    if (idx != 0x80 && (mat[i][j] & (idx << 1)))
        dfs(i, j, idx << 1);

    if (i-1 >= 0 && (mat[i-1][j] & idx))
        dfs(i-1, j, idx);
    if (i+1 < N && (mat[i+1][j] & idx))
        dfs(i+1, j, idx);
}

ull solution() {
    ull ans = 0;
    if (M % 8) K = (M >> 3) + 1;
    else K = M >> 3;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < K; ++j) {
            unsigned char idx = 0x80;
            while (idx != 0) {
                if ((mat[i][j] & idx)) {
                    dfs(i, j, idx);
                    ans += 1;
                }
                idx >>= 1;
            }
        }
    }
    return ans;
}

int main() {
  //  freopen("in.txt", "r", stdin);
    scanf("%d%d", &N, &M);
    for (int i = 0; i < N; ++i) {
        scanf("%s", h);
        int l = M / 4;
        int c = 0;
        for (int j = 0; j < l; j += 2)
            mat[i][c++] = get_num(j, l);
    }
    printf("%llu", solution());
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 1024 * 4 + 4;

int N, M, K, Q;
char h[3000];
unsigned char mat[MAXN][3000];

unsigned char get_num(int i, int len) {
    unsigned char num = 0;
    if (isdigit(h[i])) {
        num = (h[i] - '0');
    } else {
        num = (h[i] - 'A' + 10);
    }
    num *= 16;
    ++i;
    if (i < len) {
        if (isdigit(h[i])) {
            num += (h[i] - '0');
        } else {
            num += (h[i] - 'A' + 10);
        }
    }
    return num;
}

void dfs(int i, int j, unsigned char idx) {
    mat[i][j] &= ~idx;
    if (j < K && idx == 1 && (mat[i][j+1] & 0x80))
        dfs(i, j+1, 0x80);
    if (j > 0 && idx == 0x80 && (mat[i][j-1] & 0x01))
        dfs(i, j-1, 0x01);

    if (idx != 1 && ((mat[i][j] & (idx >> 1))))
        dfs(i, j, idx >> 1);
    if (idx != 0x80 && (mat[i][j] & (idx << 1)))
        dfs(i, j, idx << 1);
    if (i > 0 && (mat[i-1][j] & idx))
        dfs(i-1, j, idx);
    if (i < N && (mat[i+1][j] & idx))
        dfs(i+1, j, idx);
}

ull solution() {
    ull ans = 0;
    if (M % 8) K = (M >> 3) + 1;
    else K = M >> 3;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < K; ++j) {
            unsigned char idx = 0x80;
            while (idx != 0) {
                if ((mat[i][j] & idx)) {
                    dfs(i, j, idx);
                    ans += 1;
                }
                idx >>= 1;
            }
        }
    }
    return ans;
}

int main() {
    // freopen("in.txt", "r", stdin);
    scanf("%d%d", &N, &M);
    for (int i = 0; i < N; ++i) {
        scanf("%s", h);
        int l = M / 4;
        int c = 0;
        for (int j = 0; j < l; j += 2)
            mat[i][c++] = get_num(j, l);
    }
    printf("%llu", solution());
    return 0;
}