#include <iostream>

#define M 1000001
#define P 78498
#define Mod 1000000007
using namespace std;

int main() {

	int cnt[M]={0},ans[M]={0};
	int two[200001];
	long long int over;
	two[0]=1;
	int n,x,k,i,j;
	cin >> n;

	for (i=0;i<M;i++) {
		cnt[i]=0;
		ans[i]=0;
	}

	for (i=0;i<n;i++) {
		cin >> x;
		cnt[x]++;
	}

	for (i=2;i<M;i++) {
		for (j=2*i;j<M;j+=i) {
			cnt[i]+=cnt[j];
		}
	}

	for (i=1;i<M;i++) {
		two[i]=2*two[i-1];
		two[i]%=Mod;
	}
	for (i=M-1;i>1;i--) {
		over=cnt[i];
		if (over==0) continue;
		over*=two[cnt[i]-1];
		over%=Mod;
		ans[i]=over;
		for (j=i*2;j<M;j+=i) {
			ans[i]-=ans[j];
			ans[i]%=Mod;
		}
	}
	long long int res=0;
	for (i=2;i<M;i++) {
		res+= (long long int) (i)*ans[i];
		res%=Mod;
	}
	cout << res << '\n';

	return 0;
}


#include <iostream>
#include <vector>

#define M 1000005
#define P 78498
#define Mod 1000000007
using namespace std;

int main() {

	vector <int> cnt(M,0);
	vector <int> ans(M,0);

	int two[200005];
	long long int over;
	two[0]=1;
	int n,x,k,i,j;
	cin >> n;

	for (i=0;i<M;i++) {
		cnt[i]=0;
		ans[i]=0;
	}

	for (i=0;i<n;i++) {
		cin >> x;
		cnt[x]++;
	}

	for (i=2;i<M;i++) {
		for (j=2*i;j<M;j+=i) {
			cnt[i]+=cnt[j];
		}
	}

	for (i=1;i<M;i++) {
		two[i]=2*two[i-1];
		two[i]%=Mod;
	}
	for (i=M-1;i>1;i--) {
		over=cnt[i];
		if (over==0) continue;
		over*=two[cnt[i]-1];
		over%=Mod;
		ans[i]=over;
		for (j=i*2;j<M;j+=i) {
			ans[i]-=ans[j];
			ans[i]%=Mod;
		}
	}
	long long int res=0;
	for (i=2;i<M;i++) {
		over=i;
		over*=ans[i];
		over%=Mod;
		res+=over;
		res%=Mod;
	}
	cout << res << '\n';

	return 0;
}


#include <iostream>

#define M 100001
#define P 78498
#define Mod 1000000007
using namespace std;

int main() {

	int cnt[M]={0},ans[M]={0};
	int two[200001];
	long long int over;
	two[0]=1;
	int n,x,k,i,j;
	cin >> n;

	for (i=0;i<M;i++) {
		cnt[i]=0;
		ans[i]=0;
	}

	for (i=0;i<n;i++) {
		cin >> x;
		cnt[x]++;
	}

	for (i=2;i<M;i++) {
		for (j=2*i;j<M;j+=i) {
			cnt[i]+=cnt[j];
		}
	}

	for (i=1;i<M;i++) {
		two[i]=2*two[i-1];
		two[i]%=Mod;
	}
	for (i=M-1;i>1;i--) {
		over=cnt[i];
		if (over==0) continue;
		over*=two[cnt[i]-1];
		over%=Mod;
		ans[i]=over;
		for (j=i*2;j<M;j+=i) {
			ans[i]-=ans[j];
			ans[i]%=Mod;
		}
	}
	long long int res=0;
	for (i=2;i<M;i++) {
		res+= (long long int) (i)*ans[i];
		res%=Mod;
	}
	cout << res << '\n';

	return 0;
}


#include <iostream>
#include <vector>

#define M 1000001
#define P 78498
#define N 100001
#define Mod 1000000007
using namespace std;

int cnt[M]={0},ans[M]={0};
int two[200001];

int main() {

	int n,x,i,j;
	long long int over=0;

	two[0]=1;
	for (i=1;i<N;i++) {
		two[i]=2*two[i-1];
		two[i]%=Mod;
	}
	cin >> n;
	for (i=0;i<n;i++) {
		cin >> x;
		cnt[x]++;
	}

	for (i=2;i<M;i++) {
		for (j=2*i;j<M;j+=i) {
			cnt[i]+=cnt[j];
		}
	}

	for (i=M-1;i>1;i--) {
		over=cnt[i];
		if (over==0) continue;
		over*=two[cnt[i]-1];
		over%=Mod;
		ans[i]=over;
		for (j=2*i;j<M;j+=i) {
			ans[i]-=ans[j];
			ans[i]%=Mod;
		}
	}
	long long int res=0;
	for (i=2;i<M;i++) {
		over=i;
		over*=ans[i];
		over%=Mod;
		res+=over;
		res%=Mod;
	}
	res=(res+Mod)%Mod;
	cout << res << '\n';

	return 0;
}


#include <iostream>
#include <vector>

#define M 1000001
#define P 78498
#define Mod 1000000007
using namespace std;

int main() {

	vector <int> cnt(M,0);
	vector <int> ans(M,0);

	int two[200001];
	long long int over;
	two[0]=1;
	int n,x,k,i,j;
	cin >> n;

	for (i=0;i<M;i++) {
		cnt[i]=0;
		ans[i]=0;
	}

	for (i=0;i<n;i++) {
		cin >> x;
		cnt[x]++;
	}

	for (i=2;i<M;i++) {
		for (j=2*i;j<M;j+=i) {
			cnt[i]+=cnt[j];
		}
	}

	for (i=1;i<M;i++) {
		two[i]=2*two[i-1];
		two[i]%=Mod;
	}
	for (i=M-1;i>1;i--) {
		over=cnt[i];
		if (over==0) continue;
		over*=two[cnt[i]-1];
		over%=Mod;
		ans[i]=over;
		for (j=i*2;j<M;j+=i) {
			ans[i]-=ans[j];
			ans[i]%=Mod;
		}
	}
	long long int res=0;
	for (i=2;i<M;i++) {
		over=i;
		over*=ans[i];
		over%=Mod;
		res+=over;
		res%=Mod;
	}
	cout << res << '\n';

	return 0;
}


#include <iostream>
#include <vector>

#define M 1000001
#define P 78498
#define N 200001
#define Mod 1000000007
using namespace std;

int cnt[M]={0},ans[M]={0};
int two[200001];

int main() {

	int n,x,i,j;
	long long int over=0;

	two[0]=1;
	for (i=1;i<N;i++) {
		two[i]=2*two[i-1];
		two[i]%=Mod;
	}
	cin >> n;
	for (i=0;i<n;i++) {
		cin >> x;
		cnt[x]++;
	}

	for (i=2;i<M;i++) {
		for (j=2*i;j<M;j+=i) {
			cnt[i]+=cnt[j];
		}
	}

	for (i=M-1;i>1;i--) {
		over=cnt[i];
		if (over==0) continue;
		over*=two[cnt[i]-1];
		over%=Mod;
		ans[i]=over;
		for (j=2*i;j<M;j+=i) {
			ans[i]-=ans[j];
			ans[i]%=Mod;
		}
	}
	long long int res=0;
	for (i=2;i<M;i++) {
		over=i;
		over*=ans[i];
		over%=Mod;
		res+=over;
		res%=Mod;
	}
	res=(res+Mod)%Mod;
	cout << res << '\n';

	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000001

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
int divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=1; i<MX; i++)
    {
        if(a[i]==0)
            continue;
        for(j=i; j<MX; j+=i)
        {
            if(a[j]!=0)
                divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

ll calcAns(int i)
{
    //cout<<i<<endl;
    int c = divisors[i];
    //cout<<"       "<<c<<endl;
    ans[i] = (power[c-1]*c)%MOD;
    //cout<<"       "<<ans[i]<<endl;
    for(int j=i+i; j<MX; j+=i)
    {
        ans[i] = (ans[i]-ans[j]+MOD)%MOD;
    }
    //cout<<"        "<<ans[i]<<endl;
    parallelAns[i] = (ans[i]*i)%MOD;
    //cout<<"        "<<parallelAns[i]<<endl;
    return parallelAns[i];
}

int main()
{
    int n;
    ri(n);
    int i,x;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    for(i=MX-1; i>1; i--)
    {
        if(a[i])
            answer = (answer + calcAns(i))%MOD;
    }
    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

long long bigmod(long long p,long long e){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % MOD;
        p = (p * p) % MOD;
    } return ret;
}

//***********************************************************************//
ll a[MX];
ll divisors[MX];
ll ans[MX];

int main()
{
    int n;
    cin>>n;
    int x;
    ll i;

    for(i=0; i<n; i++)
    {
        cin>>x;
        a[x]++;
    }

    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }

    ll answer = 0, c;

    ans[MX-1] = 0;

    for(i=MX-2; i>1; i--)
    {
        c = divisors[i];

        ans[i] = (c*bigMod(2,c-1));
        ans[i] %= MOD;

        for(j=2LL*i; j<MX; j+=i)
        {
            ans[i] = (ans[i]-ans[j])%MOD;
        }
    }
    for(i=2; i<MX; i++)
    {
        answer = (answer + ans[i]*1LL*i)%MOD;
    }

    cout<<answer<<endl;

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000005

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
ll divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

ll calcAns(int i)
{
    //cout<<i<<endl;
    ll c = divisors[i];
    //cout<<"       "<<c<<endl;
    ans[i] = (power[c-1]*c)%MOD;
    //cout<<"       "<<ans[i]<<endl;
    for(int j=2*i; j<MX; j+=i)
    {
        ans[i] = (ans[i]-ans[j])%MOD;
        if(ans[i] < 0)
            ans[i] += MOD;
    }

    //cout<<"        "<<ans[i]<<endl;
    parallelAns[i] = (ans[i]*i)%MOD;
    //cout<<"        "<<parallelAns[i]<<endl;
    return parallelAns[i];
}

int main()
{
    int n;
    ri(n);
    int i,x;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    for(i=MX-1; i>1; i--)
    {
        answer = (answer + calcAns(i))%MOD;
    }
    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000005

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
ll divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }
    power[0] = 1LL;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

ll calcAns(int i)
{
    //cout<<i<<endl;
    ll c = divisors[i];
    //cout<<"       "<<c<<endl;
    ans[i] = (power[c-1]*c)%MOD;
    //cout<<"       "<<ans[i]<<endl;
    for(int j=2*i; j<MX; j+=i)
    {
        ans[i] = (ans[i] - ans[j])%MOD;
        if(ans[i] < MOD)
            ans[i] += MOD;
    }

    //cout<<"        "<<ans[i]<<endl;
    parallelAns[i] = (ans[i]*i)%MOD;
    //cout<<"        "<<parallelAns[i]<<endl;
    return parallelAns[i];
}

int main()
{
    int n;
    ri(n);
    int i,x;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    for(i=MX-1; i>1; i--)
    {
        answer = (answer + calcAns(i))%MOD;
    }
    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

long long bigmod(long long p,long long e){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % MOD;
        p = (p * p) % MOD;
    } return ret;
}

//***********************************************************************//
ll a[MX];
ll divisors[MX];
ll ans[MX];

int main()
{
    int n;
    cin>>n;
    int x;
    ll i;

    for(i=0; i<n; i++)
    {
        cin>>x;
        a[x]++;
    }

    int j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }

    ll answer = 0, c;

    ans[MX-1] = 0;

    for(i=MX-2; i>1; i--)
    {
        c = divisors[i];

        ans[i] = (c*bigMod(2,c-1));
        ans[i] %= MOD;

        for(j=2LL*i; j<MX; j+=i)
        {
            ans[i] = (ans[i]-ans[j])%MOD;
        }
    }
    for(i=2; i<MX; i++)
    {
        answer = (answer + ans[i]*1LL*i)%MOD;
    }

    cout<<answer<<endl;

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1LL;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
ll divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

int main()
{
    int n;
    ri(n);
    int x;
    ll i;

    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    ll c;
    int j;

    for(i=MX-2; i>1; i--)
    {
        c = divisors[i];

        if(c == 0)
        {
            ans[i] = 0;
            continue;
        }
        ans[i] = (c*bigMod(2,c-1))%MOD;

        for(j=2*i; j<MX; j+=i)
        {
            ans[i] = (ans[i]-ans[j])%MOD;
        }
    }
    for(i=2; i<MX; i++)
    {
        answer = (answer + (ans[i]*i)%MOD)%MOD;
    }

    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000005

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
int divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=1; i<MX; i++)
    {
        if(a[i]==0)
            continue;
        for(j=i; j<MX; j+=i)
        {
            if(a[j]!=0)
                divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

ll calcAns(int i)
{
    //cout<<i<<endl;
    int c = divisors[i];
    //cout<<"       "<<c<<endl;
    ans[i] = (power[c-1]*c)%MOD;
    //cout<<"       "<<ans[i]<<endl;
    ll t = 0;
    for(int j=2*i; j<MX; j+=i)
    {
        t =  (t + ans[j])%MOD;
    }
    ans[i] = (ans[i] - t)%MOD;
    //cout<<"        "<<ans[i]<<endl;
    parallelAns[i] = (ans[i]*i)%MOD;
    //cout<<"        "<<parallelAns[i]<<endl;
    return parallelAns[i];
}

int main()
{
    int n;
    ri(n);
    int i,x;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    for(i=MX-1; i>1; i--)
    {
        if(a[i])
            answer = (answer + calcAns(i))%MOD;
    }
    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000005

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
ll divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=1; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

ll calcAns(int i)
{
    //cout<<i<<endl;
    ll c = divisors[i];
    //cout<<"       "<<c<<endl;
    ans[i] = (power[c-1]*c)%MOD;
    //cout<<"       "<<ans[i]<<endl;
    for(int j=2*i; j<MX; j+=i)
    {
        ans[i] = (ans[i] - ans[j])%MOD;
    }

    //cout<<"        "<<ans[i]<<endl;
    parallelAns[i] = (ans[i]*i)%MOD;
    //cout<<"        "<<parallelAns[i]<<endl;
    return parallelAns[i];
}

int main()
{
    int n;
    ri(n);
    int i,x;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    for(i=MX-1; i>1; i--)
    {
        answer = (answer + calcAns(i))%MOD;
    }
    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000005

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1LL;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
ll divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

ll calcAns(int i)
{
    //cout<<i<<endl;
    ll c = divisors[i];
    if(c==0)
    return 0;
    //cout<<"       "<<c<<endl;
    ans[i] = (power[c-1]*c)%MOD;
    //cout<<"       "<<ans[i]<<endl;
    for(int j=2*i; j<MX; j+=i)
    {
        ans[i] = (ans[i]-ans[j])%MOD;
        if(ans[i] < 0)
            ans[i] += MOD;
    }

    //cout<<"        "<<ans[i]<<endl;
    parallelAns[i] = (ans[i]*i)%MOD;
    //cout<<"        "<<parallelAns[i]<<endl;
    return parallelAns[i];
}

int main()
{
    int n;
    ri(n);
    int i,x;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    for(i=MX-1; i>1; i--)
    {
        answer = (answer + calcAns(i))%MOD;
    }
    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1LL;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
ll a[MX];
ll divisors[MX];
ll ans[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }

}

int main()
{
    int n;
    cin>>n;
    int x;
    ll i;

    for(i=0; i<n; i++)
    {
        cin>>x;
        a[x]++;
    }

    pre();

    ll answer = 0;

    ll c;
    int j;

    ans[MX-1] = 0;

    for(i=MX-2; i>1; i--)
    {
        c = divisors[i];

        ans[i] = (c*bigMod(2,c-1));
        ans[i] = ans[i]%MOD;

        for(j=2*i; j<MX; j+=i)
        {
            ans[i] = (ans[i]-ans[j])%MOD;
        }
    }
    for(i=2; i<MX; i++)
    {
        answer = (answer + ans[i]*1LL*i)%MOD;
    }

    cout<<answer<<endl;

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1LL;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
ll divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

int main()
{
    int n;
    ri(n);
    int x;
    ll i;

    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    ll c;
    int j;

    ans[MX-1] = 0;

    for(i=MX-2; i>1; i--)
    {
        c = divisors[i];

        if(c == 0)
        {
            ans[i] = 0;
            continue;
        }
        ans[i] = (c*bigMod(2,c-1))%MOD;

        for(j=2*i; j<MX; j+=i)
        {
            ans[i] = (ans[i]-ans[j])%MOD;
        }
    }
    for(i=2; i<MX; i++)
    {
        answer = (answer + (ans[i]*i)%MOD)%MOD;
    }

    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1LL;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
ll a[MX];
ll divisors[MX];
ll ans[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }

}

int main()
{
    int n;
    cin>>n;
    int x;
    ll i;

    for(i=0; i<n; i++)
    {
        cin>>x;
        a[x]++;
    }

    pre();

    ll answer = 0;

    ll c;
    int j;

    ans[MX-1] = 0;

    for(i=MX-2; i>1; i--)
    {
        c = divisors[i];

        ans[i] = (c*bigMod(2,c-1));
        ans[i] = ans[i]%MOD;

        for(j=2*i; j<MX; j+=i)
        {
            ans[i] = (ans[i]-ans[j])%MOD;
        }
    }
    for(i=2; i<MX; i++)
    {
        answer = (answer + (ans[i]*i)%MOD)%MOD;
    }

    cout<<answer<<endl;

    return 0;
}


/// HK 108 Times
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std ;
#define ll long long
#define pb push_back
typedef pair <int,int>  PII ;
typedef pair < ll, ll > PLL ;
#define all(x) (x).begin() , (x).end()
#define F first
#define S second
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout)
#define FAST ios_base::sync_with_stdio(false)
#define ll long long
#define MOD 1000000007
#define endl '\n'

// Order Statistic Tree

/* Special functions:

        find_by_order(k) --> returns iterator to the elements
                            //that has k elements less in the set

        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/
const int mod = 1e9 + 7 ;
typedef tree<
int,					// type long long
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
 ll modinverse(ll a,ll M){return bigmod(a,M-2,M);}
ll bigmod(ll base, ll pow)
{
    if(pow == 0) return (1 % mod);
    ll x = bigmod(base, pow/2 );
    x = ( x * x ) % mod;
    if(pow % 2 == 1)
         x = (x * base) % mod;
    return x;
}
const int MX = 1e6 + 100;
ll cnt[MX], ans[MX] ;
ll has[MX];
int main()
{
//clock_t z = clock() ;
    FAST;
    cin.tie(0);
    int n;
    cin >> n;

    for(int i = 0; i < n;i++)
    {
        ll tmp ;
        cin >> tmp ;
        has[tmp]++;
    }
    for(int i = 2; i < MX; i++)
    {
        for(int j = i; j < MX; j += i)
        {
            cnt[i] += has[j] ;
        }
    }
    ans[MX-1] = 0;
    for(int i = MX -2; i > 1; i--)
    {
        ans[i] = (cnt[i]) * bigmod(2,cnt[i]-1) ;
        ans[i] %= MOD ;
        for(int j = i*2; j < MX; j += i )
        {
            ans[i] = (ans[i] - ans[j]) % MOD ;
        }
    }
    ll e = 0;
    for(int i = 2; i < MX; i++)
        e = (e + ans[i]* 1LL * i) % MOD ;
    cout << e << endl;
// printf("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000005

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
int divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=1; i<MX; i++)
    {
       // if(a[i]==0)
           // continue;
        for(j=i; j<MX; j+=i)
        {
            //if(a[j]!=0)
                divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

ll calcAns(int i)
{
    //cout<<i<<endl;
    int c = divisors[i];
    //cout<<"       "<<c<<endl;
    ans[i] = (power[c-1]*c)%MOD;
    //cout<<"       "<<ans[i]<<endl;
    ll t = 0;
    for(int j=2*i; j<MX; j+=i)
    {
        t =  (t + ans[j])%MOD;
    }
    ans[i] = (ans[i] - t)%MOD;
    //cout<<"        "<<ans[i]<<endl;
    parallelAns[i] = (ans[i]*i)%MOD;
    //cout<<"        "<<parallelAns[i]<<endl;
    return parallelAns[i];
}

int main()
{
    int n;
    ri(n);
    int i,x;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    for(i=MX-1; i>1; i--)
    {
        //if(a[i])
            answer = (answer + calcAns(i))%MOD;
    }
    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1LL;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
ll divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

ll calcAns(ll i)
{
    //cout<<i<<endl;
    ll c = divisors[i];
    if(c==0)
        return 0;
    //cout<<"       "<<c<<endl;
    ans[i] = (power[c-1]*c)%MOD;
    //cout<<"       "<<ans[i]<<endl;
    for(ll j=2*i; j<MX; j+=i)
    {
        ans[i] = (ans[i]-ans[j])%MOD;
        if(ans[i] < 0)
            ans[i] += MOD;
    }

    //cout<<"        "<<ans[i]<<endl;
    parallelAns[i] = (ans[i]*i)%MOD;
    //cout<<"        "<<parallelAns[i]<<endl;
    return parallelAns[i];
}

int main()
{
    int n;
    ri(n);
    int i,x;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    for(i=MX-2; i>1; i--)
    {
        answer = (answer + calcAns(i))%MOD;
    }
    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1LL;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
ll divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

int main()
{
    int n;
    ri(n);
    int x;
    ll i;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    ll c;
    int j;

    for(i=MX-2; i>1; i--)
    {
        c = divisors[i];

        if(c == 0)
        {
            ans[i] = 0;
            continue;
        }
        ans[i] = (c*bigMod(2,c-1))%MOD;

        for(j=2*i; j<MX; j+=i)
        {
            ans[i] = (ans[i]-ans[j])%MOD;
        }

    }
    for(i=2; i<MX; i++)
    {
        answer = (answer + (ans[i]*i)%MOD)%MOD;
    }

    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000005

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
int divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=1; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            if(a[j])
                divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

ll calcAns(int i)
{
    //cout<<i<<endl;
    int c = divisors[i];
    //cout<<"       "<<c<<endl;
    ans[i] = (power[c-1]*c)%MOD;
    //cout<<"       "<<ans[i]<<endl;
    ll t = 0;
    for(int j=2*i; j<MX; j+=i)
    {
        t =  (t + ans[j])%MOD;
    }
    ans[i] = (ans[i] - t)%MOD;
    //cout<<"        "<<ans[i]<<endl;
    parallelAns[i] = (ans[i]*i)%MOD;
    //cout<<"        "<<parallelAns[i]<<endl;
    return parallelAns[i];
}

int main()
{
    int n;
    ri(n);
    int i,x;
    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    for(i=MX-1; i>1; i--)
    {
        //if(a[i])
            answer = (answer + calcAns(i))%MOD;
    }
    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1LL;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
int a[MX];
ll divisors[MX];
ll power[MX],ans[MX],parallelAns[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }
    power[0] = 1;
    for(i=1; i<MX; i++)
    {
        power[i] = (power[i-1] * 2)%MOD;
    }
}

int main()
{
    int n;
    ri(n);
    int x;
    ll i;

    for(i=0; i<n; i++)
    {
        ri(x);
        a[x]++;
    }

    pre();

    ll answer = 0;

    ll c;
    int j;

    for(i=MX-2; i>1; i--)
    {
        c = divisors[i];

        if(c == 0)
        {
            ans[i] = 0;
            continue;
        }
        ans[i] = (c*power[c-1])%MOD;

        for(j=2*i; j<MX; j+=i)
        {
            ans[i] = (ans[i]-ans[j])%MOD;
        }
    }
    for(i=2; i<MX; i++)
    {
        answer = (answer + (ans[i]*i)%MOD)%MOD;
    }

    pl(answer);

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll unsigned long long
#define pii pair<int,int>
#define pb push_back

#define ri(n) scanf("%d",&n)
#define pi(n) printf("%d",n)
#define rl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)

#define MOD 1000000007
#define MX 1000100

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//find_by_order(k) --> returns iterator to the kth largest element counting from 0
//order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item

int setBit(int n,int p)
{
    return n|(1<<p);
}
bool checkBit(int n,int p)
{
    return (bool)(n&(1<<p));
}
int fx[]= {0,-1,0,1,1,-1,-1,1};
int fy[]= {1,0,-1,0,1,-1,1,-1};

ll bigMod(ll x,ll n)
{
    if(n==0)
        return 1LL;
    ll t = bigMod(x,n/2);
    t = ((t%MOD)*(t%MOD))%MOD;
    if(n%2)
    {
        t = ((x%MOD)*(t%MOD))%MOD;
    }
    return t;
}

//***********************************************************************//
ll a[MX];
ll divisors[MX];
ll ans[MX];

void pre()
{
    int i,j;
    for(i=2; i<MX; i++)
    {
        for(j=i; j<MX; j+=i)
        {
            divisors[i]+=a[j];
        }
    }

}

int main()
{
    int n;
    cin>>x
    int x;
    ll i;

    for(i=0; i<n; i++)
    {
        cin>>x;
        a[x]++;
    }

    pre();

    ll answer = 0;

    ll c;
    int j;

    ans[MX-1] = 0;

    for(i=MX-2; i>1; i--)
    {
        c = divisors[i];

        ans[i] = (c*bigMod(2,c-1));
        ans[i] = ans[i]%MOD;

        for(j=2*i; j<MX; j+=i)
        {
            ans[i] = (ans[i]-ans[j])%MOD;
        }
    }
    for(i=2; i<MX; i++)
    {
        answer = (answer + (ans[i]*i)%MOD)%MOD;
    }

    cout<<answer<<endl;

    return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;
int main(){
    int n;
    cin>>n;
    cin.ignore();
    string command;
    string line;
    string destination;
    string current;
    for(int i = 0; i<n ; i++){
        getline(cin,line);
        stringstream ss(line);
        ss>>command;
        if(command == "pwd"){
            if(current.length() == 0){
                cout<<"/"<<endl;
            } else{
                cout<<current<<endl;
            }
        } else if(command== "cd"){
            ss>>destination;
            for(int i = 0 ; i < destination.length() ; i++){
                if(destination[i] == '.'){
                    int j= current.length() -2;
                    while(current[j] != '/'){
                        current.erase(current.begin()+j);
                        j--;
                    }
                    current.erase(current.begin()+j);
                    i++;
                } else{
                    current+=destination[i];
                    if(i == destination.length() - 1){
                        current+="/";
                    }
                }
            }
        }
        for(int k = 0 ; k<current.length() ; k++){
                if(k != current.length()+1){
                    if(current[k] == '/' && current[k+1] == '/'){
                        current.erase(current.begin()+k);
                    }
                }
            }
    }
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n, i;
	cin >> n;
	string str;

	for(i = 0; i < n; i++)
	{
		cin >> str;
		cout << endl;
	}

	for(int i = 0; i< n ; i++)
	{
	if(str[i] != '/')
		cout << "/" << "\n";
	string ans;
	bool flag = false;
	for(int i = 0; i < str.size(); i++)
	{
		if(flag)
		{
		 ans = ans + str[i - 1];
		}

		if(str[i] == '/' and flag == false)
		{
			flag = true;
		}
	}

	cout << ans << "\n";
}

}


#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n, i;
	cin >> n;
	string str;

	for(i = 0; i < n; i++)
	{
		cin >> str;
		cout << endl;
	}

	for(int i = 0; i< n ; i++)
	{

	string ans;
	bool flag = false;
	for(int i = 0; i < str.size(); i++)
	{
		if(flag)
		{
		 ans = ans + str[i - 1];
		}

		if(str[i] == '/' and flag == false)
		{
			flag = true;
		}
	}

	cout << ans << "\n";
}

}


#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int n;
    string command, parameter;
    vector<string> path;
    cin >> n;
    while (n--)
    {
        cin >> command;
        if (command.compare("pwd") == 0)
        {
            cout << "/";
            for (size_t i = 0; i < path.size(); ++i)
            {
                cout << path[i] << "/";
            }
            cout << endl;
        }
        else
        {
            cin >> parameter;
            size_t pos = 0;
            if (parameter[0] == '/')
            {
                path.clear();
                pos = 1;
            }
            while (true)
            {
                size_t next_pos = parameter.find('/', pos);
                if (next_pos != string::npos)
                {
                    string dir = parameter.substr(pos, next_pos - pos);
                    if (dir.compare("..") != 0)
                    {
                        path.push_back(dir);
                    }
                    else
                    {
                        if (!path.empty())
                        {
                            path.pop_back();
                        }
                    }
                    pos = next_pos + 1;
                }
                else
                {
                    string dir = parameter.substr(pos, string::npos);
                    if (dir.compare("..") != 0)
                    {
                        path.push_back(dir);
                    }
                    else
                    {
                        if (!path.empty())
                        {
                            path.pop_back();
                        }
                    }
                    break;
                }
            }
        }
    }
    return 0;
}


/****************************************************************************************************************
                                            Mahnur Rahman Mahin(Trooper)
                                           Mail:mahnurrahman14@gamil.com
                                                 Vjudge:2018331043
******************************************************************************************************************/
#include <iostream>
#include <stdio.h>
#include <list>
#include <string.h>
#include <algorithm>
#include <iterator>
#include <vector>
#include <bits/stdc++.h>
                                            /**"Why so serious?!!!"**/
#define debug cout<<"Why So Serious?!!!"<<endl
#define dg1 cout<<"Fear  cuts deeper than swords"<<endl
/**                "A wise man once said: If you are good at something don't do it for free"
                                                                                --Joker(Heath Ledger).             */
using namespace std;
//int adj[1000][1000],p,o,W,H;
char s[1000000],s1[1000000];//hel[1000000];
//int neigh[1000][1000],input[1000][1000],ans[1000][1000];
double input1[1000000],input2[1000000];
long long int dp1[1000000],dp2[1000];
list<char> hel;
list<string> dirs;
void solve(){
    long long  int cnt1=0,cnt2=0,cnt3=0,cnt4=0,i,length,value,l,m,n,j,flag=0,temp,temp2,ans=0,ans1=0,ans2=0;
    char k;
    string tes;
    long long  int a,b,c;
    dirs.push_back("/");
    scanf("%lld",&length);
    for (l=0;l<length ;l++ )
    {
        scanf("%s",&s);
        //cout<<"debug"<<dirs.back()<<endl;
        /*for (i=0;i<dirs.size() ;i++ )
        {
            cout<<"debug"<<dirs.back()<<endl;
        }*/
        if(strcmp(s,"pwd")==0){
                tes=dirs.back();
            cout<<tes<<endl;
        }
        else if(strcmp(s,"cd")==0){
            scanf("%s",&s1);
            value=strlen(s1);
            if(s1[0]=='/'){
                dirs.clear();
                dirs.push_back("/");
                for (i=0;i<value ;i++ )
                {
                    if(s1[i]=='/'){
                        string ss;
                    //strcpy(sss,hel);
                    n=hel.size();
                        for (j=0;j<n ;j++ )
                        {
                            //ss[j]=hel.front();
                            ss.push_back(hel.front());
                            //cout<<ss<<" "<<ss.size()<<endl;
                            hel.pop_front();
                           // debug;
                        }
                        dirs.push_back(ss);
                        //cout<<"debug"<<dirs.back()<<endl;
                        hel.clear();
                        continue;
                    }
                    if(s1[i]=='.'){
                        dirs.pop_back();
                        i++;
                        i++;
                         continue;
                    }
                    hel.push_back(s1[i]);
                    //hel[cnt1++]=s1[i];
                }
                 if(hel.size()!=0){
                string ss;
                    //strcpy(sss,hel);
                     n=hel.size();
                        for (j=0;j<n ;j++ )
                        {
                             ss.push_back(hel.front());
                            hel.pop_front();
                        }
                        dirs.push_back(ss);
                        hel.clear();
                 }
            }
            else {
                for (i=0;i<value ;i++ )
                {
                    if(s1[i]=='/'){
                        string ss;
                    //strcpy(sss,hel);
                     n=hel.size();
                        for (j=0;j<n ;j++ )
                        {
                            ss.push_back(hel.front());
                            hel.pop_front();
                        }
                        dirs.push_back(ss);
                       // cout<<"debug"<<dirs.back()<<endl;
                        hel.clear();
                        continue;
                    }
                    if(s1[i]=='.'){
                        dirs.pop_back();
                        i++;
                        i++;
                        continue;
                    }
                    hel.push_back(s1[i]);
                    //hel[cnt1++]=s1[i];
                }
                if(hel.size()!=0){
               string ss;
                    //strcpy(sss,hel);
                     n=hel.size();
                        for (j=0;j<n ;j++ )
                        {
                            ss.push_back(hel.front());
                            hel.pop_front();
                        }
                        dirs.push_back(ss);
                        hel.clear();
                }
            }
        }
    }
    return;

}
int main(){
    long long int T;
    //scanf("%lld",&T);
    T=1;
    while(T--)solve();
    return 0;
}
/**
7
pwd
cd /home/vasya
pwd
cd ..
pwd
cd vasya/../petya
pwd

*/


/****************************************************************************************************************
                                            Mahnur Rahman Mahin(Trooper)
                                           Mail:mahnurrahman14@gamil.com
                                                 Vjudge:2018331043
******************************************************************************************************************/
#include <iostream>
#include <stdio.h>
#include <list>
#include <string.h>
#include <algorithm>
#include <iterator>
#include <vector>
#include <bits/stdc++.h>
                                            /**"Why so serious?!!!"**/
#define debug cout<<"Why So Serious?!!!"<<endl
#define dg1 cout<<"Fear  cuts deeper than swords"<<endl
/**                "A wise man once said: If you are good at something don't do it for free"
                                                                                --Joker(Heath Ledger).             */
using namespace std;
//int adj[1000][1000],p,o,W,H;
char s[1000000],s1[1000000];//hel[1000000];
//int neigh[1000][1000],input[1000][1000],ans[1000][1000];
double input1[1000000],input2[1000000];
long long int dp1[1000000],dp2[1000];
list<char> hel;
list<string> dirs;
void solve(){
    long long  int cnt1=0,cnt2=0,cnt3=0,cnt4=0,i,length,value,l,m,n,j,flag=0,temp,temp2,ans=0,ans1=0,ans2=0;
    char k;
    string tes;
    long long  int a,b,c;
    dirs.push_back("/");
    scanf("%lld",&length);
    for (l=0;l<length ;l++ )
    {
        scanf("%s",&s);
        //cout<<"debug"<<dirs.back()<<endl;
        /*for (i=0;i<dirs.size() ;i++ )
        {
            cout<<"debug"<<dirs.back()<<endl;
        }*/
        if(strcmp(s,"pwd")==0){
                tes=dirs.back();
                list<string> test;
                test=dirs;
                for (i=0;i<dirs.size() ;i++ )
                {
                   cout<<test.front();
                   //debug;
                   if(i!=0)printf("/");

                test.pop_front();
                }
                printf("\n");

        }
        else if(strcmp(s,"cd")==0){
            scanf("%s",&s1);
            value=strlen(s1);
            if(s1[0]=='/'){
                dirs.clear();
                dirs.push_back("/");
                for (i=0;i<value ;i++ )
                {
                    if(s1[i]=='/'){
                        string ss;
                    //strcpy(sss,hel);
                    n=hel.size();
                        for (j=0;j<n ;j++ )
                        {
                            //ss[j]=hel.front();
                            ss.push_back(hel.front());
                            //cout<<ss<<" "<<ss.size()<<endl;
                            hel.pop_front();
                           // debug;
                        }
                        if(ss.size()!=0)
                        dirs.push_back(ss);
                        //cout<<"debug"<<dirs.back()<<endl;
                        hel.clear();
                        continue;
                    }
                    if(s1[i]=='.'){
                        dirs.pop_back();
                        i++;
                        i++;
                         continue;
                    }
                    hel.push_back(s1[i]);
                    //hel[cnt1++]=s1[i];
                }
                 if(hel.size()!=0){
                string ss;
                    //strcpy(sss,hel);
                     n=hel.size();
                        for (j=0;j<n ;j++ )
                        {
                             ss.push_back(hel.front());
                            hel.pop_front();
                        }
                        if(ss.size()!=0)
                        dirs.push_back(ss);
                        hel.clear();
                 }
            }
            else {
                for (i=0;i<value ;i++ )
                {
                    if(s1[i]=='/'){
                        string ss;
                    //strcpy(sss,hel);
                     n=hel.size();
                        for (j=0;j<n ;j++ )
                        {
                            ss.push_back(hel.front());
                            hel.pop_front();
                        }
                        if(ss.size()!=0)
                        dirs.push_back(ss);
                       // cout<<"debug"<<dirs.back()<<endl;
                        hel.clear();
                        continue;
                    }
                    if(s1[i]=='.'){
                        dirs.pop_back();
                        i++;
                        i++;
                        continue;
                    }
                    hel.push_back(s1[i]);
                    //hel[cnt1++]=s1[i];
                }
                if(hel.size()!=0){
               string ss;
                    //strcpy(sss,hel);
                     n=hel.size();
                        for (j=0;j<n ;j++ )
                        {
                            ss.push_back(hel.front());
                            hel.pop_front();
                        }
                        if(ss.size()!=0)
                        dirs.push_back(ss);
                        hel.clear();
                }
            }
        }
    }
    return;

}
int main(){
    long long int T;
    //scanf("%lld",&T);
    T=1;
    while(T--)solve();
    return 0;
}
/**
7
pwd
cd /home/vasya
pwd
cd ..
pwd
cd vasya/../petya
pwd

*/


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

#define ll long long
#define ull unsigned long long

using namespace std;

vector<string> Stack;

void pwd(){
    cout << '/';
    if (!Stack.empty()){
        for (auto &s : Stack){
            cout << s << '/';
        }
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    string str, str2;
    string::size_type pos, pos2;
    for (int i = 0; i < n; ++i) {
        cin >> str;
        if (str == "cd"){
            cin >> str;
            pos = 0;
            if (str[0] == '/'){
                pos = 1;
                Stack.clear();
            }
            while (true){
                pos2 = str.find('/', pos + 1);
                if (pos2 != string::npos){
                    str2 = str.substr(pos, pos2 - pos);
                } else{
                    str2 = str.substr(pos, str.size() - pos);
                }

                if (str2 == ".."){
                    Stack.pop_back();
                } else{
                    Stack.emplace_back(str2);
                }

                if (pos2 == string::npos)
                    break;

                pos = pos2 + 1;
            }
        } else pwd();
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stack>

#define ll long long
#define ull unsigned long long

using namespace std;

stack<string> Stack;

void pwdrec(stack<string> s2) {
    if (s2.size() == 0){
        return;
    }
    string &str = s2.top();
    s2.pop();
    pwdrec(s2);
    cout << '/' << str;
}

void pwd(){
    if (Stack.empty()){
        cout << '/' << endl;
        return;
    }
    stack<string> S2 = Stack;
    pwdrec(S2);
    cout << '/' << endl;
}

int main() {
    int n;
    cin >> n;
    string str, str2;
    string::size_type pos, pos2;
    for (int i = 0; i < n; ++i) {
        cin >> str;
        if (str == "cd"){
            cin >> str;
            pos = str.find('/', 0);
            if (pos == string::npos){
                if (str == ".."){
                    Stack.pop();
                } else{
                    Stack.push(str);
                }
                continue;
            } else if (pos == 0){
                while (!Stack.empty()) Stack.pop();
            } else {
                str2 = str.substr(0, pos);
                if (str2 == ".."){
                    Stack.pop();
                } else{
                    Stack.push(str2);
                }
            }
            pos2 = str.find('/', pos + 1);
            if (pos2 == string::npos){
                Stack.push(str.substr(1, str.size() - 1));
                cout << endl;
                continue;
            } else{
                while (true){
                    str2 = str.substr(pos + 1, pos2 - pos - 1);
                    if (str2 == ".."){
                        Stack.pop();
                    } else{
                        Stack.push(str2);
                    }
                    pos = pos2;
                    pos2 = str.find('/', pos2 + 1);
                    if (pos2 == string::npos){
                        str2 = str.substr(pos+1, str.size() - pos - 1);
                        if (str2 == ".."){
                            Stack.pop();
                        } else{
                            Stack.push(str2);
                        }
                        break;
                    }
                }
            }
        } else if (str == "pwd") {
            pwd();
        }
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stack>

#define ll long long
#define ull unsigned long long

using namespace std;

stack<string> Stack;

void pwdrec(stack<string> s2) {
    if (s2.size() == 0){
        return;
    }
    string &str = s2.top();
    s2.pop();
    pwdrec(s2);
    cout << '/' << str;
}

void pwd(){
    if (Stack.empty()){
        cout << '/' << endl;
        return;
    }
    stack<string> S2 = Stack;
    pwdrec(S2);
    cout << '/' << endl;
}

int main() {
    int n;
    cin >> n;
    string str, str2;
    string::size_type pos, pos2;
    for (int i = 0; i < n; ++i) {
        cin >> str;
        if (str == "cd"){
            cin >> str;
            pos = 0;
            if (str[0] == '/'){
                pos = 1;
                while (!Stack.empty())
                    Stack.pop();
            }
            while (true){
                pos2 = str.find('/', pos + 1);
                if (pos2 != string::npos){
                    str2 = str.substr(pos, pos2 - pos);
                } else{
                    str2 = str.substr(pos, str.size() - pos);
                }

                if (str2 == ".."){
                    Stack.pop();
                } else{
                    Stack.push(str2);
                }

                if (pos2 == string::npos)
                    break;

                pos = pos2 + 1;
            }
        } else pwd();
    }
}


#include <bits/stdc++.h>

using namespace std;

int T;
string s, res;
vector <string> v;

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> T;
	while(T--) {
		cin >> s, res = "";
		if(s == "pwd") {
			cout << "/";
			for(auto x : v)
				cout << x << "/";
			cout << endl;
			continue;
		}
		cin >> s;
		if(s[0] == '/')
			v.clear();
		for(int i = 0; i < s.size(); i++) {
			if(s[i] == '/') {
				if(res == "..")
					v.pop_back();
				else if(res.size())
					v.push_back(res);
				res = "";
			}
			else
				res += s[i];
		}
		if(res == "..")
			v.pop_back();
		else if(res.size())
			v.push_back(res);
	}
}


#include <bits/stdc++.h>

using namespace std;

int T;
string s, res;
vector <string> v;

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> T;
	while(T--) {
		cin >> s, res = "";
		if(s == "pwd") {
			cout << "/";
			for(auto x : v)
				cout << x << "/";
			cout << endl;
			continue;
		}
		cin >> s;
		for(int i = 0; i < s.size(); i++) {
			if(s[i] == '/') {
				if(res == "..")
					v.pop_back();
				else if(res.size())
					v.push_back(res);
				res = "";
			}
			else
				res += s[i];
		}
		if(res == "..")
			v.pop_back();
		else if(res.size())
			v.push_back(res);
	}
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    int n;
    cin >> n;
    vector<string> A;
    rep(j, 0, n)
    {
        string x;
        cin >> x;
        if (x[0] == 'p')
        {
            // cout << A << endl;
            cout << '/';
            rep(i, 0, A.size())
            {
                cout << A[i] << '/';
            }
            cout << endl;
        }
        else
        {
            string g;
            cin >> g;
            string gg;
            rep(i, 0, g.size())
            {
                if (g[i] != '.' && g[i] != '/')
                {
                    gg.pb(g[i]);
                }
                else if (g[i] == '/')
                {
                    if (gg.size() != 0)
                    {
                        A.pb(gg);
                    }
                    gg = "";
                }
                else
                {
                    if (g[i - 1] == '.' && g[i] == '.')
                    {
                        A.Pb();
                    }
                }
            }
            if (gg.size() != 0)
            {
                A.pb(gg);
            }
        }
    }
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    int n;
    cin >> n;
    vector<string> A;
    rep(j, 0, n)
    {
        string x;
        cin >> x;
        if (x[0] == 'p')
        {
            // cout << A << endl;
            cout << '/';
            rep(i, 0, A.size())
            {
                cout << A[i] << '/';
            }
            cout << endl;
        }
        else
        {
            string g;
            cin >> g;
            string gg;
            if(g[0]=='/'){
                A.resize(0);
            }
            rep(i, 0, g.size())
            {
                if (g[i] != '.' && g[i] != '/')
                {
                    gg.pb(g[i]);
                }
                else if (g[i] == '/')
                {
                    if (gg.size() != 0)
                    {
                        A.pb(gg);
                    }
                    gg = "";
                }
                else
                {
                    if (g[i - 1] == '.' && g[i] == '.')
                    {
                        A.Pb();
                    }
                }
            }
            if (gg.size() != 0)
            {
                A.pb(gg);
            }
        }
    }
}


/*
 _  __    _   _   _ ____ _____
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |
| . \  / ___ \ |_| |___) || |
|_|\_\/_/   \_\___/|____/ |_|
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    int n;
    cin >> n;
    vector<string> A;
    rep(j, 0, n)
    {
        string x;
        cin >> x;
        if (x[0] == 'p')
        {
            // cout << A << endl;
            cout << '/';
            rep(i, 0, A.size())
            {
                cout << A[i] << '/';
            }
            cout << endl;
        }
        else
        {
            string g;
            cin >> g;
            string gg;
            rep(i, 1, g.size())
            {
                if (g[i] != '.' && g[i] != '/')
                {
                    gg.pb(g[i]);
                }
                else if (g[i] == '/')
                {
                    if (gg.size() != 0)
                    {
                        A.pb(gg);
                    }
                    gg = "";
                }
                else
                {
                    if (g[i - 1] == '.' && g[i] == '.')
                    {
                        A.Pb();
                    }
                }
            }
            if (gg.size() != 0)
            {
                A.pb(gg);
            }
        }
    }
}


#include <vector>
#include <iostream>
#include <string>

int numberOfCommands;
std::string command, dir;
std::vector<std::string> current_dir;

void next(std::string&& next_path) {
  if (next_path == "..")
    current_dir.pop_back();
  else if (next_path != "")
    current_dir.emplace_back(next_path);
}

int main(int argc, char const* argv[]) {

  std::cin >> numberOfCommands;
  for (auto cnt = 0; cnt < numberOfCommands; cnt++) {
    std::cin >> command;
    if (command == "cd") {
      std::cin >> dir;
      if (dir == "/") {
        current_dir.resize(0);
        continue;
      }
      int current_pos = 0;
      while (true) {
        int next_pos = dir.find('/', current_pos);
        if (next_pos == std::string::npos) break;
        next(dir.substr(current_pos, next_pos - current_pos));
        current_pos = next_pos + 1;
      }
      next(dir.substr(current_pos));
    } else {
      for(auto& path: current_dir)
        std::cout << "/" << path;
      std::cout << "/" << std::endl;
    }
  }
  /* code */
  return 0;
}


#include <vector>
#include <iostream>
#include <string>

int numberOfCommands;
std::string command, dir;
std::vector<std::string> current_dir;

void next(std::string&& next_path) {
  if (next_path == "..")
    current_dir.pop_back();
  else
    current_dir.emplace_back(next_path);
}

int main(int argc, char const* argv[]) {

  std::cin >> numberOfCommands;
  for (auto cnt = 0; cnt < numberOfCommands; cnt++) {
    std::cin >> command;
    if (command == "cd") {
      std::cin >> dir;
      if (dir[0] == '/') {
        current_dir.resize(0);
        dir.erase(0, 1);
      }
      int current_pos = 0;
      while (current_pos < dir.length()) {
        int next_pos = dir.find('/', current_pos);
        if (next_pos == std::string::npos) break;
        next(dir.substr(current_pos, next_pos - current_pos));
        current_pos = next_pos + 1;
      }
      if(dir.length() > 0) next(dir.substr(current_pos));
    } else {
      for(auto& path: current_dir)
        std::cout << "/" << path;
      std::cout << "/" << std::endl;
    }
  }
  /* code */
  return 0;
}


#include <filesystem>
#include <iostream>
#include <string>

namespace fs = std::filesystem;

int numberOfCommands;
std::string command, dir;

void next(fs::path& current_dir, std::string&& next_path) {
  if (next_path == "..")
    current_dir = current_dir.parent_path();
  else
    current_dir /= next_path;
}

int main(int argc, char const* argv[]) {
  fs::path current_dir = "/";

  std::cin >> numberOfCommands;
  for (auto cnt = 0; cnt < numberOfCommands; cnt++) {
    std::cin >> command;
    if (command == "cd") {
      std::cin >> dir;
      if (dir == "/") {
        current_dir = "/";
        continue;
      }
      int current_pos = 0;
      while (true) {
        int next_pos = dir.find('/', current_pos);
        if (next_pos == std::string::npos) break;
        next(current_dir, dir.substr(current_pos, next_pos - current_pos));
        current_pos = next_pos + 1;
      }
      next(current_dir, dir.substr(current_pos));
    } else {
      if (current_dir.relative_path() == "")
        std::cout << "/" << std::endl;
      else
        std::cout << fs::absolute(current_dir).string() << "/" << std::endl;
    }
  }
  /* code */
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef vector<ll> vi;
// push_back insert lower_bound upper_bound erase
#define F(a) for ( ll i = 0; i < (ll)(a); ++i )
// INF for (int) = ( 1<<30 ), for (long long) = ( 1LL<<62LL )

int main() {
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    string path="/";
    regex e("(.*)/[^/]+/\\.\\.(.*)");
    F(N){
        string s;cin>>s;
        if(s=="pwd"){
            if(path.size()==1){
                cout<<path<<endl;
            }else{
                cout<<path<<"/"<<endl;
            }
        }else{
            cin>>s;
            if(s[0]=='/'){
                path=s;
            }else{
                path+="/";
                path+=s;
                while(regex_search(path,e)){
                    path=regex_replace(path,e,"$1$2");
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef vector<ll> vi;
// push_back insert lower_bound upper_bound erase
#define F(a) for ( ll i = 0; i < (ll)(a); ++i )
// INF for (int) = ( 1<<30 ), for (long long) = ( 1LL<<62LL )

int main() {
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    string path="/";
    regex e("(.*)/[^/]+/\\.\\.(.*)");
    F(N){
        string s;cin>>s;
        if(s=="pwd"){
            cout<<path<<endl;
        }else{
            cin>>s;
            if(s[0]=='/'){
                path=s;
            }else{
                path+="/";
                path+=s;
                while(regex_search(path,e)){
                    path=regex_replace(path,e,"$1$2");
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef vector<ll> vi;
// push_back insert lower_bound upper_bound erase
#define F(a) for ( ll i = 0; i < (ll)(a); ++i )
// INF for (int) = ( 1<<30 ), for (long long) = ( 1LL<<62LL )

int main() {
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    string path="/";
    regex e("^(.*)/[^/\\.]+/\\.\\.(.*)$");
    F(N){
        string s;cin>>s;
        if(s=="pwd"){
            cout<<path<<endl;
        }else{
            cin>>s;
            if(s[0]=='/'){
                path=s;
            }else{
                path+=s;
            }
            path+="/";
            while(regex_search(path,e)){
                path=regex_replace(path,e,"$1$2");
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef vector<ll> vi;
// push_back insert lower_bound upper_bound erase
#define F(a) for ( ll i = 0; i < (ll)(a); ++i )
// INF for (int) = ( 1<<30 ), for (long long) = ( 1LL<<62LL )

int main() {
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    string path="/";
    regex e("(.*)/[^/]+/\\.\\.(.*)");
    F(N){
        string s;cin>>s;
        if(s=="pwd"){
            if(path.size()==1){
                cout<<path<<endl;
            }else{
                cout<<path<<"/"<<endl;
            }
        }else{
            cin>>s;
            if(s[0]=='/'){
                path=s;
            }else{
                path+="/";
                path+=s;
            }
            while(regex_search(path,e)){
                path=regex_replace(path,e,"$1$2");
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef vector<ll> vi;
// push_back insert lower_bound upper_bound erase
#define F(a) for ( ll i = 0; i < (ll)(a); ++i )
// INF for (int) = ( 1<<30 ), for (long long) = ( 1LL<<62LL )

int main() {
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    string path="/";
    regex e("(.*)/[^/]+/\\.\\.(.*)");
    F(N){
        string s;cin>>s;
        if(s=="pwd"){
            cout<<path<<endl;
        }else{
            cin>>s;
            if(s[0]=='/'){
                path=s;
            }else{
                path+=s;
            }
            path+="/";
            while(regex_search(path,e)){
                path=regex_replace(path,e,"$1$2");
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
int main() {
	int n ; cin >> n ;
	string te , kt , result ;
	vector<string>ve ;
	for(int i =  0 ; i < n ; i++ ) {
		cin >> kt ;
		if(kt == "pwd") {
			cout <<"/";
			int size = ve.size() ;
			for(int i = 0 ; i < size ; i++ ) {
				cout <<ve[i]<<"/";
			}
			cout << endl;
		}else {
			cin >> te ;
			for(int i = 0 ; i < te.length() ;i++) {
				if(i == te.length()) break ;
				if(i == 0 && te[0] =='/')
				{
					ve.clear() ;
				}
				if(te[i]=='.' && te[i+1] =='.') {
					ve.pop_back() ;
				}
				else if (te[i] !='/' && te[i]!='.' && te[i+1]  !='.') {
					result+=te[i];
				}
				else if(te[i] =='/' && result[0] !='\0') {
					ve.push_back(result) ;
					result.clear() ;
				}
			}
			if(result[0] !='\0'){
				ve.push_back(result) ;
				result.clear() ;
			}
		}
	}
}


#include<bits/stdc++.h>
#define fora(i,a,b) for(int i = a; i < b  i++ )
using namespace std ;
typedef long long ll ;
struct ban{
    ll soluong ,  khachhang ;
};
bool cmp(ban a , ban b){
    if(a.soluong < b.soluong){
        return a.soluong > b.soluong ;
    }
    else if(a.soluong == b.soluong){
        return a.soluong > b.soluong ;
    }
}
bool check1 (ll n){
    if(n >= 2 && n <= 9 ) return false ;
    if (n == 10 ) return true ;
    int h = n%10 ;
    n/=10;
    while(n != 0){
        if(h == (n%10) && h == 1){
            return false ;
        }
        n/=10;
    }
    return true ;
}
int main(){
    ll n ; cin >> n ;
    string res ;
    int count = 0 ;

///string k[100001] ;
    for(int i = 0 ; i < n ; i++ ) {
        string k ; cin >> k ;
        if(k =="pwd" ){
            if(res.length() == 0) {
                cout <<"/"<<endl;
            }else {
               cout << res <<"/" << endl;
               // cout << endl;
            }
        }else {
            string k1 ; cin >> k1 ;
            if(k1 =="..") {
                if(res.length() == 0 ){
                    continue ;
                }else {
                   string h ="/";
                        for(int j = 1 ; j < res.length()  ; j++) {
                            if(res[j] =='/'){
                                break ;
                            }
                            h+= res[j] ;
                        }
                   //cout << h << endl;
                   res = h ;
                }
            }
            else if (k1.find("../")!= -1 ){
                string h1  ;
                for(int j = k1.length()-1; j>=0 ; j-- ){
                     if(k1[j] =='/'){
                        h1+=k1[j];
                        break;
                     }
                     h1+=k1[j] ;
                }
                reverse(h1.begin(),h1.end()) ;
               // cout << h1 << endl;
                res +=  h1;
            }
            else {
                res = k1 ;
               // cout << res << endl;
            }

        }
    }
}


#include<bits/stdc++.h>
#define fora(i,a,b) for(int i = a; i < b  i++ )
using namespace std ;
typedef long long ll ;
int main(){
    ll n ; cin >> n ;
    string res ;
    int count = 0 ;

///string k[100001] ;
    for(int i = 0 ; i < n ; i++ ) {
        string k ; cin >> k ;
        if(k =="pwd" ){
            if(res.length() == 0) {
                cout <<"/"<<endl;
            }else {
               cout << res <<"/" << endl;
               // cout << endl;
            }
        }else {
            string k1 ; cin >> k1 ;
             if (k1.find("..")!= -1 ){
                    if(res.length() == 0 ){
                    continue ;
                    }

                    string h ="/";
                            for(int j = 1 ; j < res.length()  ; j++) {
                                if(res[j] =='/'){
                                    break ;
                                }
                                h+= res[j] ;
                            }
                       //cout << h << endl;
                       res = h ;

                string h1  ;
                for(int j = k1.length()-1; j>=0 ; j-- ){
                     if(k1[j] =='.'){
                        break;
                     }
                     h1+=k1[j] ;
                }
                reverse(h1.begin(),h1.end()) ;
               // cout << h1 << endl;
                res +=  h1;
            }
            else {
                res = k1 ;
               // cout << res << endl;
            }

        }
    }
}


#include <bits/stdc++.h>

using namespace std;

deque<string> tree;

void f(string s){
    s = s.substr(3);
    if(s[0] == '/'){
        tree.clear();
    }

    s += '/';
    string dir = "";
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '/'){
            if(dir == ".."){
                tree.pop_back();
            }
            else if(dir != ""){
                // 4cout << dir << endl;
                tree.push_back(dir);
            }
            dir = "";
        } else{
            dir += s[i];
        }
    }
}

int main()
{

    int n;
    cin >> n;
    string tmp;
    getline(cin, tmp);

    for(int i = 1; i <= n; i++){
        getline(cin, tmp);
        if(tmp == "pwd"){
            for(auto it : tree){ cout << "/" << it; }
            cout << endl;
        } else{
            f(tmp);
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

deque<string> tree;

void f(string s){
    s = s.substr(3);
    if(s[0] == '/'){
        tree.clear();
    }

    s += '/';
    string dir = "";
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '/'){
            if(dir == ".."){
                tree.pop_back();
            }
            else if(dir != ""){
                // 4cout << dir << endl;
                tree.push_back(dir);
            }
            dir = "";
        } else{
            dir += s[i];
        }
    }
}

int main()
{

    int n;
    cin >> n;
    string tmp;
    getline(cin, tmp);

    for(int i = 1; i <= n; i++){
        getline(cin, tmp);
        if(tmp == "pwd"){
            for(auto it : tree){ cout << "/" << it; }
            cout << "/\n";
        } else{
            f(tmp);
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

deque<string> tree;

void f(string s){
    s = s.substr(3);
    if(s[0] == '/'){
        tree.clear();
    }

    s += '/';
    string dir = "";
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '/'){
            if(dir == ".."){
                tree.pop_back();
            }
            else if(dir != ""){
                // 4cout << dir << endl;
                tree.push_back(dir);
            }
            dir = "";
        } else{
            dir += s[i];
        }
    }
}

int main()
{

    int n;
    cin >> n;
    string tmp;
    getline(cin, tmp);

    for(int i = 1; i <= n; i++){
        getline(cin, tmp);
        if(tmp == "pwd"){
            if(tree.size() == 0){
                cout << "/\n";
                continue;
            }
            for(auto it : tree){ cout << "/" << it; }
            cout << endl;
        } else{
            f(tmp);
        }
    }
}


#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long double ld;

#define sync                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int base = 1e9;
const int MAX = 1e5;
const double EPS = 1e-9;
const double PI = acos(-1.);

vector<string> cut(string s){
    int n=s.size();
    vector<string> res;
    string cur="";
    for (int i=0;i<n;i++){
        if (s[i]=='/'){
            res.pb(cur);
            cur="";
        }
        else cur+=s[i];
    }
    res.pb(cur);
    return res;
}

main() {
    string p="/";
    int t;
    cin>>t;
    vector<string> dirs;
    for (int r=0;r<t;r++){
        string com;
        cin>>com;
        if (com=="pwd"){
            cout<<p<<endl;
            continue;
        }
        string s;
        cin>>s;
        if (s[0]=='/'){
            p="/";
            s.erase(0,1);
        }

        dirs = cut(s);
        for (int i=0;i<dirs.size();i++){
            if (dirs[i]==".."){
                p.pop_back();
                while (p[p.size()-1]!='/')
                    p.pop_back();
            }
            else{
                p+=dirs[i]+"/";
            }
        }
        if (p[p.size()-1]!='/') p+="/";
    }
}


#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long double ld;

#define sync                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int base = 1e9;
const int MAX = 1e5;
const double EPS = 1e-9;
const double PI = acos(-1.);

vector<string> cut(string s){
    int n=s.size();
    vector<string> res;
    string cur="";
    for (int i=0;i<n;i++){
        if (s[i]=='/'){
            res.pb(cur);
            cur="";
        }
        else cur+=s[i];
    }
    res.pb(cur);
    return res;
}

main() {
    string p="/";
    int t;
    cin>>t;
    vector<string> dirs;
    for (int r=0;r<t;r++){
        string com;
        cin>>com;
        if (com=="pwd"){
            cout<<p<<endl;
            continue;
        }
        string s;
        cin>>s;
        if (s[0]=='/'){
            p=s+"/";
            continue;
        }
        dirs = cut(s);
        for (int i=0;i<dirs.size();i++){
            if (dirs[i]==".."){
                p.pop_back();
                while (p[p.size()-1]!='/')
                    p.pop_back();
            }
            else{
                p+=dirs[i]+"/";
            }
        }
    }
}


#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long double ld;

#define sync                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int base = 1e9;
const int MAX = 1e5;
const double EPS = 1e-9;
const double PI = acos(-1.);

vector<string> cut(string s){
    int n=s.size();
    vector<string> res;
    string cur="";
    for (int i=0;i<n;i++){
        if (s[i]=='/'){
            res.pb(cur);
            cur="";
        }
        else cur+=s[i];
    }
    res.pb(cur);
    return res;
}

main() {
    string p="/";
    int t;
    cin>>t;
    vector<string> dirs;
    for (int r=0;r<t;r++){
        string com;
        cin>>com;
        if (com=="pwd"){
            cout<<p<<endl;
            continue;
        }
        string s;
        cin>>s;
        if (s[0]=='/'){
            p="/";
        }
        s.erase(0,1);
        dirs = cut(s);
        for (int i=0;i<dirs.size();i++){
            if (dirs[i]==".."){
                p.pop_back();
                while (p[p.size()-1]!='/')
                    p.pop_back();
            }
            else{
                p+=dirs[i]+"/";
            }
        }
    }
}


#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <list>

#define umap unordered_map
#define uset unordered_set

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

const ll M = 100000000;

// Here could be your advertisement =)

// https://codeforces.com/problemset/problem/559/B

int n;

vector<string> path;

inline void input(){
    std::ios_base::sync_with_stdio(false);

    cin >> n;
}

inline void print_path(){
    if(!path.size())
        cout << '/';
    for(auto el : path) cout << '/' << el;
    cout << endl;
}

inline void add_to_path(string s){
    if(s == "..")
        path.pop_back();
    else path.push_back(s);
}

inline void parse(string &s){
    if(s[0] == '/')
        s = s.substr(1);
    int p = -1;
    while(1){
        int t = s.find('/', p + 1);

        if(t == string::npos){
            add_to_path(s.substr(p + 1));
            return;
        }
        else{
            add_to_path(s.substr(p + 1, t - p - 1));
        }
        p = t;
    }
}

inline void do_stuff(){
    string s;
    for(int i = 0; i < n; i++){
        cin >> s;
        if(s == "cd"){
            cin >> s;
            parse(s);
        }
        else print_path();
    }
}

inline void output(){

}

int main(){
    input();
    do_stuff();
    output();
    return 0;
}


#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <list>

#define umap unordered_map
#define uset unordered_set

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

const ll M = 100000000;

// Here could be your advertisement =)

// https://codeforces.com/problemset/problem/559/B

int n;

vector<string> path;

inline void input(){
    std::ios_base::sync_with_stdio(false);

    cin >> n;
}

inline void print_path(){
    cout << '/';
    for(auto el : path) cout << el << '/';
    cout << endl;
}

inline void add_to_path(string s){
    if(s == "..")
        path.pop_back();
    else path.push_back(s);
}

inline void parse(string &s){
    if(s[0] == '/'){
        path.clear();
        s = s.substr(1);
    }
    int p = -1;
    while(1){
        int t = s.find('/', p + 1);

        if(t == string::npos){
            add_to_path(s.substr(p + 1));
            return;
        }
        else{
            add_to_path(s.substr(p + 1, t - p - 1));
        }
        p = t;
    }
}

inline void do_stuff(){
    string s;
    for(int i = 0; i < n; i++){
        cin >> s;
        if(s == "cd"){
            cin >> s;
            parse(s);
        }
        else print_path();
    }
}

inline void output(){

}

int main(){
    input();
    do_stuff();
    output();
    return 0;
}


#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <list>

#define umap unordered_map
#define uset unordered_set

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

const ll M = 100000000;

// Here could be your advertisement =)

// https://codeforces.com/problemset/problem/559/B

int n;

vector<string> path;

inline void input(){
    std::ios_base::sync_with_stdio(false);

    cin >> n;
}

inline void print_path(){
    cout << '/';
    for(auto el : path) cout << el << '/';
    cout << endl;
}

inline void add_to_path(string s){
    if(s == "..")
        path.pop_back();
    else path.push_back(s);
}

inline void parse(string &s){
    if(s[0] == '/')
        s = s.substr(1);
    int p = -1;
    while(1){
        int t = s.find('/', p + 1);

        if(t == string::npos){
            add_to_path(s.substr(p + 1));
            return;
        }
        else{
            add_to_path(s.substr(p + 1, t - p - 1));
        }
        p = t;
    }
}

inline void do_stuff(){
    string s;
    for(int i = 0; i < n; i++){
        cin >> s;
        if(s == "cd"){
            cin >> s;
            parse(s);
        }
        else print_path();
    }
}

inline void output(){

}

int main(){
    input();
    do_stuff();
    output();
    return 0;
}