#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(false);

	ll n, i, j;

	//scan(n);
	cin >> n;
	string s[n];
	string ans[n];

	for(i=0; i<n; i++)
		cin >> s[i];

	ll size = siz(s[n-1]), currsize;

	for(i=0; i<size; i++)
		ans[n-1].eb(s[n-1][i]);

	for(i=n-2; i>=0; i--){

		size = siz(ans[i+1]);

		currsize = siz(s[i]);

		bool flag=false;
		ans[i]="";
		for(j=0; j<size && j<currsize; j++){
			//trace5(i, size, currsize, ans[i+1][j], s[i][j]);

			if(ans[i+1][j] > s[i][j]){
				flag=true;
				break;
			}

			if(ans[i+1][j] < s[i][j]){

				break;
			}

			ans[i] += s[i][j];
		}
		if(flag){
			for(; j<currsize; j++)
				ans[i]+=s[i][j];
		}
		ans[i]+='\0';
	}

	for(i=0; i<n; i++){
		size = siz(ans[i]);

		for(j=0; j<size; j++)
			cout << ans[i][j];

		cout << endl;
	}

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;

int main(){
	ll n, i, j;
	scan(n);

	string s[n];
	vector<char> ans[n];

	for(i=0; i<n; i++)
		cin >> s[i];

	ll size = siz(s[n-1]), currsize;

	for(i=0; i<size; i++)
		ans[n-1].eb(s[n-1][i]);

	for(i=n-2; i>=0; i--){

		size = siz(ans[i+1]);

		currsize = siz(s[i]);

		bool flag=false;

		for(j=0; j<size && j<currsize; j++){
			//trace5(i, size, currsize, ans[i+1][j], s[i][j]);

			if(ans[i+1][j] > s[i][j]){
				flag=true;
				break;
			}

			if(ans[i+1][j] < s[i][j]){

				break;
			}

			ans[i].eb(s[i][j]);
		}
		if(flag){
			for(; j<currsize; j++)
				ans[i].eb(s[i][j]);
		}
	}

	for(i=0; i<n; i++){
		size = siz(ans[i]);

		for(j=0; j<size; j++)
			cout << ans[i][j];

		cout << endl;
	}

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;

typedef pair < int , int > ii;

const int mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(false);

	ll n, i, j;

	//scan(n);
	cin >> n;
	string s[n];
	string ans[n];

	for(i=0; i<n; i++)
		cin >> s[i];

	ll size = siz(s[n-1]), currsize;
	ans[n-1]="";
	for(i=0; i<size; i++)
		ans[n-1]+=s[n-1][i];
	ans[n-1]+='\0';
	for(i=n-2; i>=0; i--){

		size = siz(ans[i+1]);

		currsize = siz(s[i]);

		bool flag=false;
		ans[i]="";
		for(j=0; j<size && j<currsize; j++){
			//trace5(i, size, currsize, ans[i+1][j], s[i][j]);

			if(ans[i+1][j] > s[i][j]){
				flag=true;
				break;
			}

			if(ans[i+1][j] < s[i][j]){

				break;
			}

			ans[i] += s[i][j];
		}
		if(flag){
			for(; j<currsize; j++)
				ans[i]+=s[i][j];
		}
		ans[i]+='\0';
	}

	for(i=0; i<n; i++){
		//size = siz(ans[i]);

		//for(j=0; j<size; j++)
		//	cout << ans[i][j];
		cout << ans[i];
		cout << endl;
	}

	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;

const int maxn=500000*2;

int n;
int a[maxn];
int l[maxn],r[maxn];
char s[maxn],ch[maxn];
int main()
{
    // freopen("H:\\123.txt","r",stdin);
     while(scanf("%d",&n)!=EOF){
        int len,now=0;
        for(int i=1;i<=n;i++){
            scanf("%s",s);
            len=strlen(s);
            l[i]=now+1;
            r[i]=now+len;
            for(int j=0;j<len;j++){
               ch[++now]=s[j];
            }
        }
        for(int i=n;i>=2;i--){
            if(r[i]==l[i]){
              r[i-1]=l[i-1];
              continue;
            }
            int u=l[i],v=l[i-1];
            while(ch[u]==ch[v]&&u<=r[i]&&v<=r[i-1]){
                u++,v++;
            }
            if(ch[u]>ch[v] ||(ch[u]==ch[v]&&v==r[i-1]) ){

            }else{
              r[i-1]=v-1;
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=l[i];j<=r[i];j++){
                printf("%c",ch[j]);
            }
            printf("\n");
        }
      //  printf("%s %d %d %d\n",ch+1,'#','a','z');
     }
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;

const int maxn=500000*3;

int n;
int a[maxn];
int l[maxn],r[maxn];
char s[maxn],ch[maxn];
int main()
{
     //freopen("H:\\123.txt","r",stdin);
     while(scanf("%d",&n)!=EOF){
        int len,now=0;
        for(int i=1;i<=n;i++){
            scanf("%s",s);
            len=strlen(s);
            l[i]=now+1;
            r[i]=now+len;
            for(int j=0;j<len;j++){
               ch[++now]=s[j];
            }
        }
        for(int i=n;i>=2;i--){
            if(r[i]==l[i]){
              r[i-1]=l[i-1];
              continue;
            }
            int u=l[i],v=l[i-1];
            while(ch[u]==ch[v]&&u<=r[i]&&v<=r[i-1]){
                u++,v++;
            }
            if(ch[u]>ch[v] ||(ch[u]==ch[v]&&v==r[i-1]) ){

            }else{

              r[i-1]=v-1;
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=l[i];j<=r[i];j++){
                printf("%c",ch[j]);
            }
            printf("\n");
        }
       // printf("%s %d %d %d %d\n",ch+1,'#','a','z',' ');
     }
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;

const int maxn=500000*3;

int n;
int a[maxn];
int l[maxn],r[maxn];
char s[maxn],ch[maxn];
int main()
{
    // freopen("H:\\123.txt","r",stdin);
     while(scanf("%d",&n)!=EOF){
        int len,now=0;
        for(int i=1;i<=n;i++){
            scanf("%s",s);
            len=strlen(s);
            l[i]=now+1;
            r[i]=now+len;
            for(int j=0;j<len;j++){
               ch[++now]=s[j];
            }
        }
        for(int i=n;i>=2;i--){
            if(r[i]==l[i]){
              r[i-1]=l[i-1];
              continue;
            }
            int u=l[i],v=l[i-1];
            while(ch[u]==ch[v]&&u<=r[i]&&v<=r[i-1]){
                u++,v++;
            }
            if(ch[u]>ch[v] ||(ch[u]==ch[v]&&v==r[i-1]) ){

            }else{

              r[i-1]=v-1;
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=l[i];j<=r[i];j++){
                printf("%c",ch[j]);
            }
            printf("\n");
        }
       // printf("%s %d %d %d %d\n",ch+1,'#','a','z',' ');
     }
    return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;

const int maxn=500000*3;

int n;
int a[maxn];
int l[maxn],r[maxn];
char s[maxn],ch[maxn];
int main()
{
   //  freopen("H:\\123.txt","r",stdin);
     while(scanf("%d",&n)!=EOF){
        int len,now=0;
        for(int i=1;i<=n;i++){
            scanf("%s",s);
            len=strlen(s);
            l[i]=now+1;
            r[i]=now+len;
            for(int j=0;j<len;j++){
               ch[++now]=s[j];
            }
        }
        for(int i=n;i>=2;i--){
            if(r[i]==l[i]){
              r[i-1]=l[i-1];
              continue;
            }
            int u=l[i],v=l[i-1];
            while(ch[u]==ch[v]&&u<=r[i]&&v<=r[i-1]){
                u++,v++;
            }
            if(ch[u]>ch[v] ||(ch[u]==ch[v]&&v==r[i-1]) ){

            }else{

              r[i-1]=v-1;
              ch[r[i-1]+1]='#';
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=l[i];j<=r[i];j++){
                printf("%c",ch[j]);
            }
            printf("\n");
        }
       // printf("%s %d %d %d %d\n",ch+1,'#','a','z',' ');
     }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define mst(a,b) memset(a,b,sizeof(a))
#define F(i,a,b) for(int i=a;i<=b;++i)
#define ___ freopen("d:\\acm\\input.txt","r",stdin);
using namespace std;
typedef long long ll;

const int N=5e5+7;
char str[N*2];
int st[N],len[N],n,ed;

char find(int i,int j)
{
	return str[st[i]+j];
}

inline void output(int s)
{
	int now=s;
	while(1)
	{
		if(!str[now])return;
		putchar(str[now++]);
	}
}

int main(){
	scanf("%d",&n);
	F(i,1,n)
	{
		st[i]=ed;
		scanf("%s",str+ed);
		len[i]=strlen(str+ed);
		ed+=len[i]+1;
	}
	for(int i=n-1;i>0;i--)
	{
		F(j,1,len[i]-1)
		{
			int tmp=find(i+1,j)-find(i,j);
			if(tmp<0&&find(i+1,j-1)==find(i,j-1))
			{
				str[st[i]+j]=0;
				break;
			}if(tmp>0)break;
		}
	}
	F(i,1,n)output(st[i]),puts("");
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define mst(a,b) memset(a,b,sizeof(a))
#define F(i,a,b) for(int i=a;i<=b;++i)
#define ___ freopen("d:\\acm\\input.txt","r",stdin);
using namespace std;
typedef long long ll;

const int N=5e5+7;
char str[N*3];
int st[N],len[N],n,ed;

char find(int i,int j)
{
	return str[st[i]+j];
}

inline void output(int s)
{
	int now=s;
	while(1)
	{
		if(!str[now])return;
		putchar(str[now++]);
	}
}

int main(){
	scanf("%d",&n);
	F(i,1,n)
	{
		st[i]=ed;
		scanf("%s",str+ed);
		len[i]=strlen(str+ed);
		ed+=len[i]+1;
	}
	for(int i=n-1;i>0;i--)
	{
		F(j,1,len[i]-1)
		{
			int tmp=find(i+1,j)-find(i,j);
			if(tmp<0)
			{
				str[st[i]+j]=0;
				break;
			}if(tmp>0)break;
		}
	}
	F(i,1,n)output(st[i]),puts("");
	return 0;
}


#include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
typedef long long ll;

const int N=5e5+7;
char str[N*3];
int st[N],len[N],n,ed;

char find(int i,int j){return str[st[i]+j];}

inline void output(int s)
{
	int now=s;
	while(1)
	{
		if(!str[now])return;
		printf("%c",str[now++]);
	}
}

int main(){
	scanf("%d",&n);
	F(i,1,n)
	{
		st[i]=ed;
		scanf("%s",str+ed);
		len[i]=strlen(str+ed);
		ed+=len[i]+1;
	}
	for(int i=n-1;i>0;i--)
	{
		F(j,1,len[i]-1)
		{
			int tmp=find(i+1,j)-find(i,j);
			if(tmp<0)
			{
				str[st[i]+j]=0;
				break;
			}if(tmp>0)break;
		}
	}
	F(i,1,n)output(st[i]),puts("");
	return 0;
}


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"

using namespace std;

const int maxn = 1e6;

typedef long long LL;

struct FYJ{
	string str;
	string ans;
}fyj[maxn];

int main(){
	int n;
	int k;
	while( ~scanf("%d",&n) ){
		for( int i = 0 ; i < n ; i++ ){
			cin>>fyj[i].str;
		}
		fyj[n-1].ans = fyj[n-1].str;
		for( int i = n-2 ; i >= 0 ; i-- ){
			if( fyj[i+1].ans > fyj[i].str ){
				fyj[i].ans = fyj[i].str;
				continue;
			}
			LL m = fyj[i].str.length();
			k = m;
			LL n = fyj[i+1].str.length();
			LL mi = min( m , n );
			int j;
			for( j = 0 ; j < mi ; j++ ){
				if( fyj[i].str[j] > fyj[i+1].str[j] ){
					k = j;
					break;
				}
			}
			if( k > n ) k = n;
			fyj[i].ans = fyj[i].str.substr(0,k);
		}
		for( int i = 0 ; i < n ; i++ ){
			cout<<fyj[i].ans<<endl;
		}
	}
	return 0;
}


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"

using namespace std;

const int maxn = 1e6;

typedef long long LL;

struct FYJ{
	string str;
	string ans;
}fyj[maxn];

int main(){
	int n;
	int k;
	while( ~scanf("%d",&n) ){
		for( int i = 0 ; i < n ; i++ ){
			cin>>fyj[i].str;
		}
		fyj[n-1].ans = fyj[n-1].str;
		for( int i = n-2 ; i >= 0 ; i-- ){
			if( fyj[i+1].ans > fyj[i].str ){
				fyj[i].ans = fyj[i].str;
				continue;
			}
			LL m = fyj[i].str.length();
			k = m;
			LL n = fyj[i+1].str.length();
			LL mi = min( m , n );
			int j;
			for( j = 0 ; j < mi ; j++ ){
				if( fyj[i].str[j] > fyj[i+1].ans[j] ){
					k = j;
					break;
				}
			}
			if( k > n ) k = n;
			fyj[i].ans = fyj[i].str.substr(0,k);
		}
		for( int i = 0 ; i < n ; i++ ){
			cout<<fyj[i].ans<<endl;
		}
	}
	return 0;
}


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"

using namespace std;

const int maxn = 1e6;

typedef long long LL;

struct FYJ{
	string str;
	string ans;
}fyj[maxn];

int main(){
	int n;
	int k;
	while( ~scanf("%d",&n) ){
		for( int i = 0 ; i < n ; i++ ){
			cin>>fyj[i].str;
		}
		fyj[n-1].ans = fyj[n-1].str;
		for( int i = n-2 ; i >= 0 ; i-- ){
			if( fyj[i+1].ans > fyj[i].str ){
				fyj[i].ans = fyj[i].str;
				continue;
			}
			LL m = fyj[i].str.length();
			LL n = fyj[i+1].str.length();
			LL mi = min( m , n );
			int j;
			for( j = 0 ; j < mi ; j++ ){
				if( fyj[i].str[j] > fyj[i+1].str[j] ){
					k = j;
					break;
				}
			}
			if( k > n ) k = n;
			fyj[i].ans = fyj[i].str.substr(0,k);
		}
		for( int i = 0 ; i < n ; i++ ){
			cout<<fyj[i].ans<<endl;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
//#define DEBUG
using namespace std;
int n;
char* s[500005];
char tmp[500005];
int main()
{
	#ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	cin>>n;
	for(int i = 0;i < n;i ++){
		cin>>tmp;
		s[i] = new char[strlen(tmp+2)];
		strcpy(s[i],tmp);
	}
	for(int i = n-2;i >=0; i --){
		if(strcmp(s[i],s[i + 1]) > 0){
			for(int j = 0;; j++){
				if(s[i][j] != s[i+1][j]){
					s[i][j] = 0;
					break;
				}
			}
		}
	}
	for(int i = 0;i < n ;i ++){
		cout<<s[i]<<endl;
	}
	return 0;
};


#include <cstdio>
#include <cstring>
#include <iostream>
//#define DEBUG
using namespace std;
int n;
char* s[500005];
char tmp[500005];
int main()
{
	#ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	cin>>n;
	for(int i = 0;i < n;i ++){
		cin>>tmp;
		s[i] = new char[strlen(tmp)+2];
		strcpy(s[i],tmp);
	}
	for(int i = n-2;i >=0; i --){
		if(strcmp(s[i],s[i + 1]) > 0){
			for(int j = 0;; j++){
				if(s[i][j] != s[i+1][j]){
					s[i][j] = 0;
					break;
				}
			}
		}
	}
	for(int i = 0;i < n ;i ++){
		cout<<s[i]<<endl;
	}
	return 0;
};


#include <cstdio>
#include <cstring>
#include <iostream>
//#define DEBUG
using namespace std;
int n;
char* s[500005];
char tmp[500005];
int main()
{
	#ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	cin>>n;
	for(int i = 0;i < n;i ++){
		cin>>tmp;
		s[i] = new char[strlen(tmp+2)];
		strcpy(s[i],tmp);
	}
	for(int i = n-2;i >=0; i --){
		if(strcmp(s[i],s[i + 1]) > 0){
			for(int j = 0;;j ++){
				if(s[i][j]&&s[i+1][j]){
						if(s[i][j] > s[i+1][j]){
						s[i][j] = 0;
						break;
					}
				}else{
					s[i][j] = 0;
					break;
				}
			}
		}
	}
	for(int i = 0;i < n ;i ++){
		cout<<s[i]<<endl;
	}
	return 0;
};


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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<string>a;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		a.push_back(s);
	}
	for(int i = (int)a.size() - 1; i > 0; i--)
	{
		if((int)a[i - 1].size() < (int)a[i].size() || a[i - 1] <= a[i])
			continue;
		a[i] = a[i].substr(0, (int)(a[i-1].size() + 1));
		while(a[i - 1] > a[i]){
			a[i-1].pop_back();
		}
	}
	for(int i = 0; i < n; i++){
		cout << a[i] << endl;
	}

}


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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<string>a;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		a.push_back(s);
	}
	for(int i = (int)a.size() - 1; i > 0; i--)
	{
		while(a[i - 1] > a[i]){
			a[i-1].pop_back();
		}
	}
	for(int i = 0; i < n; i++){
		cout << a[i] << endl;
	}

}


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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<string>a;
	vector<int>sz(n);
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		a.push_back(s);
		sz[i] = (int)s.size();
	}
	for(int i = n - 1; i > 0; i--)
	{
		string f = a[i].substr(0, sz[i]);
		string b = a[i - 1].substr(0, sz[i - 1]);
		if(f < b)
		{
			int L = min(sz[i], sz[i - 1]);
			for(int j = 0; j < L && f[j] >= b[j]; j++)
			{
				sz[i - 1] = j + 1;
			}
		}
	}
	for(int i = 0; i < n; i++){
		a[i] = a[i].substr(0, sz[i]);
		cout << a[i] << endl;
	}

}


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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<string>a;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		a.push_back(s);
	}
	for(int i = (int)a.size() - 1; i > 0; i--)
	{
		a[i] = a[i].substr(0, (int)(a[i-1].size() + 1));
		while(a[i - 1] > a[i]){
			a[i-1].pop_back();
		}
	}
	for(int i = 0; i < n; i++){
		cout << a[i] << endl;
	}

}


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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<string>a;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		a.push_back(s);
	}
	for(int i = (int)a.size() - 1; i > 0; i--)
	{
		if(a[i - 1] < a[i])
			continue;
		a[i] = a[i].substr(0, (int)(a[i-1].size() + 1));
		while(a[i - 1] > a[i]){
			a[i-1].pop_back();
		}
	}
	for(int i = 0; i < n; i++){
		cout << a[i] << endl;
	}

}


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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<string>a;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		a.push_back(s);
	}
	for(int i = (int)a.size() - 1; i > 0; i--)
	{
		if(a[i - 1] <= a[i])
			continue;
		a[i] = a[i].substr(0, (int)(a[i-1].size() + 1));
		while(a[i - 1] > a[i]){
			a[i-1].pop_back();
		}
	}
	for(int i = 0; i < n; i++){
		cout << a[i] << endl;
	}

}


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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<string>a;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		a.push_back(s);
	}
	if(n == 76065)
		assert(0);
	for(int i = (int)a.size() - 1; i > 0; i--)
	{
		while(a[i - 1] > a[i]){
			a[i-1].pop_back();
		}
	}
	for(int i = 0; i < n; i++){
		cout << a[i] << endl;
	}

}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<algorithm>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
using namespace std;
typedef long long LL;
const int N = 100005;
const auto INF = 0x3f3f3f3f;
string str[500005];
int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        cin>>str[i];
    for(int i=n; i>=1; i--) {
        if(i==1)
            break;
        if(str[i]>=str[i-1])
            continue;
        while(str[i-1].length()>1) {
            str[i-1].erase(str[i-1].length()-1, 1);
            if(str[i]>=str[i-1])
                break;
        }
    }
    for(int i=1; i<=n; i++)
        cout<<str[i]<<endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<algorithm>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
using namespace std;
typedef long long LL;
const int N = 100005;
const auto INF = 0x3f3f3f3f;
string str[500005];
int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        cin>>str[i];
    for(int i=1; i<=n; i++) {
        for(int j=i-1; j>=1; j--) {
            if(str[i]>=str[j])
                continue;
            while(1) {
                str[j] = str[j].substr(0,str[j].length() - 1);
                if(str[i]>=str[j])
                    break;
            }
        }
    }
    for(int i=1; i<=n; i++)
        cout<<str[i]<<endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<algorithm>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
using namespace std;
typedef long long LL;
const int N = 100005;
const auto INF = 0x3f3f3f3f;
string str[500005];
int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++) {
        cin>>str[i];
    }
    for(int i=n; i>=1; i--) {
        if(i==1)
            break;
        int lena = (int)str[i].length(), lenb = (int)str[i-1].length();
        bool flag = false;
        for(int j=0; j<min(lena, lenb); j++) {
            if(str[i][j]<str[i-1][j]) {
                flag = true;
                str[i-1] = str[i-1].substr(0, j);
                break;
            } else if(str[i][j]>str[i-1][j]) {
                flag = true;
                break;
            }
        }
        if(!flag && lenb>lena) {
            str[i-1] = str[i-1].substr(0, lena);
        }
    }
    for(int i=1; i<=n; i++) {

        cout<<str[i]<<endl;
    }
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<algorithm>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
using namespace std;
typedef long long LL;
const int N = 100005;
const auto INF = 0x3f3f3f3f;
string str[500005];
int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        cin>>str[i];
    for(int i=n; i>=1; i--) {
        if(i==1)
            break;
        if(str[i]>=str[i-1])
            continue;
        while(str[i-1].length()>1) {
            str[i-1] = str[i-1].substr(0,str[i-1].length() - 1);
            if(str[i]>=str[i-1])
                break;
        }
    }
    for(int i=1; i<=n; i++)
        cout<<str[i]<<endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<algorithm>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
using namespace std;
typedef long long LL;
const int N = 100005;
const auto INF = 0x3f3f3f3f;
string str[500005];
char ch[500005];
int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++) {
        scanf("%s", ch);
        str[i] = (string) ch;
    }
    for(int i=n; i>=1; i--) {
        if(i==1)
            break;
        if(str[i]>=str[i-1])
            continue;
        while(str[i-1].length()>1) {
            str[i-1].erase(str[i-1].length()-1, 1);
            if(str[i]>=str[i-1])
                break;
        }
    }
    for(int i=1; i<=n; i++) {

        cout<<str[i]<<endl;
    }
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<algorithm>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
using namespace std;
typedef long long LL;
const int N = 100005;
const auto INF = 0x3f3f3f3f;
string str[500005];
int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        cin>>str[i];
    for(int i=1; i<=n; i++) {
        for(int j=i-1; j>=1; j--) {
            if(str[i]>=str[j])
                break;
            while(str[j].length()>1) {
                str[j] = str[j].substr(0,str[j].length() - 1);
                if(str[i]>=str[j])
                    break;
            }
        }
    }
    for(int i=1; i<=n; i++)
        cout<<str[i]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fio ios_base::sync_with_stdio(0)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define ll pair<lli,lli>
#define vl vector<lli>
#define vvl vector<vl >
#define vll vector<ll >
#define vvll vector<vll >
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define MAX 200005
#define EPS 1e-12

int main(){
	fio;
	lli n,ind;
	cin>>n;
	vector<string> str(n+1);
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	for(int i=n-1;i>=1;i--){
		ind=str[i].length();
		while(str[i].substr(0,ind)>str[i+1]){
			ind--;
		}
		str[i]=str[i].substr(0,ind);
	}
	for(int i=1;i<=n;i++)
		cout<<str[i]<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fio ios_base::sync_with_stdio(0)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define ll pair<lli,lli>
#define vl vector<lli>
#define vvl vector<vl >
#define vll vector<ll >
#define vvll vector<vll >
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define MAX 200005
#define EPS 1e-12

int main(){
	fio;
	lli n,ind;
	cin>>n;
	vector<string> str(n+1);
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	for(int i=n-1;i>=1;i--){
		if(str[i+1]=="#")
			str[i]="#";
		else{
			int x=0,y=0;
			while(x<str[i].length() && y<str[i+1].length()){
				if(str[i][x]==str[i+1][y]){
					x++;
					y++;
				}else{
					break;
				}
			}
			if(x==str[i].length()){

			}else if(y==str[i+1].length()){
				str[i]=str[i].substr(0,x);
			}else{
				if(str[i][x]<=str[i+1][x]){

				}else{
					str[i]=str[i].substr(0,x);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
		cout<<str[i]<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fio ios_base::sync_with_stdio(0)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define ll pair<lli,lli>
#define vl vector<lli>
#define vvl vector<vl >
#define vll vector<ll >
#define vvll vector<vll >
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define MAX 200005
#define EPS 1e-12

int main(){
	fio;
	lli n,x,y;
	cin>>n;
	vector<string> str(n+1);
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	for(int i=n-1;i>=1;i--){
		if(str[i+1]=="#")
			str[i]="#";
		else{
			x=0;y=0;
			while(x<str[i].length() && y<str[i+1].length()){
				if(str[i][x]==str[i+1][y]){
					x++;
					y++;
				}else{
					break;
				}
			}
			if(y==str[i+1].length() || (x!=str[i].length() && y!=str[i+1].length() && str[i][x]>str[i+1][x]))
				str[i]=str[i].substr(0,x);
		}
	}
	for(int i=1;i<=n;i++)
		cout<<str[i]<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fio ios_base::sync_with_stdio(0)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define ll pair<lli,lli>
#define vl vector<lli>
#define vvl vector<vl >
#define vll vector<ll >
#define vvll vector<vll >
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define MAX 200005
#define EPS 1e-12

int main(){
	fio;
	lli n,ind;
	cin>>n;
	vector<string> str(n+1);
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	for(int i=n-1;i>=1;i--){
		ind=str[i].length();
		string temp=str[i];
		while(temp>str[i+1]){
			ind--;
			temp=str[i].substr(0,ind);
		}
		str[i]=str[i].substr(0,ind);
	}
	for(int i=1;i<=n;i++)
		cout<<str[i]<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fio ios_base::sync_with_stdio(0)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define ll pair<lli,lli>
#define vl vector<lli>
#define vvl vector<vl >
#define vll vector<ll >
#define vvll vector<vll >
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define MAX 200005
#define EPS 1e-12

int main(){
	fio;
	lli n,x,y;
	cin>>n;
	vector<string> str(n+1);
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	for(int i=n-1;i>=1;i--){
		if(str[i+1]=="#")
			str[i]="#";
		else{
			x=0;y=0;
			while(x<str[i].length() && y<str[i+1].length()){
				if(str[i][x]==str[i+1][y]){
					x++;
					y++;
				}else{
					break;
				}
			}
			if(x==str[i].length()){

			}else if(y==str[i+1].length()){
				str[i]=str[i].substr(0,x);
			}else{
				if(str[i][x]<=str[i+1][x]){

				}else{
					str[i]=str[i].substr(0,x);
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
		cout<<str[i]<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fio ios_base::sync_with_stdio(0)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define ll pair<lli,lli>
#define vl vector<lli>
#define vvl vector<vl >
#define vll vector<ll >
#define vvll vector<vll >
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define MAX 200005
#define EPS 1e-12

int main(){
	fio;
	lli n,ind;
	cin>>n;
	vector<string> str(n+1);
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	for(int i=n-1;i>=1;i--){
		if(str[i+1]=="#")
			str[i]="#";
		else{
			ind=str[i].length();
			while(str[i].substr(0,ind)>str[i+1]){
				ind--;
			}
			str[i]=str[i].substr(0,ind);
		}
	}
	for(int i=1;i<=n;i++)
		cout<<str[i]<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fio ios_base::sync_with_stdio(0)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define ll pair<lli,lli>
#define vl vector<lli>
#define vvl vector<vl >
#define vll vector<ll >
#define vvll vector<vll >
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define MAX 200005
#define EPS 1e-12

int main(){
	lli n;
	cin>>n;
	vector<string> str(n+1);
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	for(int i=n-1;i>=1;i--){
		lli ind=str[i].length();
		string temp=str[i];
		while(temp>str[i+1]){
			ind--;
			temp=str[i].substr(0,ind);
		}
		str[i]=str[i].substr(0,ind);
	}
	for(int i=1;i<=n;i++)
		cout<<str[i]<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fio ios_base::sync_with_stdio(0)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define ll pair<lli,lli>
#define vl vector<lli>
#define vvl vector<vl >
#define vll vector<ll >
#define vvll vector<vll >
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define MAX 200005
#define EPS 1e-12

int main(){
	fio;
	lli n,ind;
	cin>>n;
	vector<string> str(n+1);
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	for(int i=n-1;i>=1;i--){
		ind=str[i].length();
		while(str[i]>str[i+1]){
			ind--;
			str[i]=str[i].substr(0,ind);
		}
	}
	for(int i=1;i<=n;i++)
		cout<<str[i]<<"\n";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam, j;
    for(int i = n-1; i > 0; i--){
        if(v.at(i-1) > v.at(i)){
          tam = v.at(i-1).size();
          if(tam > v.at(i).size() ){
            j = v.at(i).size();
            while(v.at(i-1).substr(0,j) > v.at(i)){j--;}
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }else{
            j = tam-1;
            while(v.at(i-1).substr(0,j) > v.at(i)){j--;}
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }
        }
    }

    for(int i = 0; i < n; i++){
        cout << v.at(i) << endl;
    }
// ' ' < 'z'
}


#include<bits/stdc++.h>

using namespace std;

//se antes > depois
int bs(string antes, string depois){
  int tam = antes.size();

  //parar qnd com char na pos search eh maior
  //e com char na pos search-1 eh <=
  int search = tam - 1;

  int hi, lo;
  hi = search;
  lo = 1;
  while(hi >= lo){
    search = (hi+lo)/2;

    // printf("hi = %d  lo = %d  search = %d\n", hi,lo,search);
    // cout << antes.substr(0,search) << " " << antes.substr(0,search-1) << " " << depois << endl;

    if(antes.substr(0,search) > depois && antes.substr(0,search-1) > depois){
      hi = search;
    }else if(antes.substr(0,search) <= depois && antes.substr(0,search-1) <= depois){
      lo = search+1;
    }else if((antes.substr(0,search) > depois && antes.substr(0,search-1) <= depois) || hi == lo)
      break;
  }

  return search-1;
}

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam, j;
    for(int i = n-1; i > 0; i--){
        if(v.at(i-1) > v.at(i)){
          if(tam > v.at(i).size() ){
            v.at(i-1).erase(v.at(i-1).begin()+bs(v.at(i-1), v.at(i)),v.at(i-1).end());
          }else{
            j = tam-1;
            while(v.at(i-1).substr(0,j) > v.at(i)){j--;}
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }
        }
    }

    for(int i = 0; i < n; i++){
        cout << v.at(i) << endl;
    }
// ' ' < 'z'
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam, j;
    for(int i = n-1; i > 0; i--){
        tam = v.at(i-1).size();

        if(tam > v.at(i).size()){
          for(j = v.at(i).size(); v.at(i-1) > v.at(i); j--){
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }
        }else{
          for(j = tam-1; v.at(i-1) > v.at(i); j--){
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }
        }
    }

    char c;
    for(int i = 0; i < n; i++){
        cout << v.at(i) << endl;
    }
// ' ' < 'z'
}


#include<bits/stdc++.h>

using namespace std;

//se antes > depois
int bs(string antes, string depois){
  //parar qnd com char na pos search eh maior
  //e com char na pos search-1 eh <=
  int hi, lo,search;
  hi = antes.size();
  lo = 1;
  while(hi >= lo){
    search = (hi+lo)/2;

    // printf("hi = %d  lo = %d  search = %d\n", hi,lo,search);
    // cout << antes.substr(0,search) << " " << antes.substr(0,search-1) << " " << depois << endl;

    if(antes.substr(0,search) > depois && antes.substr(0,search-1) > depois){
      hi = search-1;
    }else if(antes.substr(0,search) <= depois && antes.substr(0,search-1) <= depois){
      lo = search+1;
    }else if((antes.substr(0,search) > depois && antes.substr(0,search-1) <= depois))
      break;
  }

  return search-1;
}

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam, j;
    for(int i = n-1; i > 0; i--){
        if(v.at(i-1) > v.at(i)){
          if(tam > v.at(i).size() ){
            v.at(i-1).erase(v.at(i-1).begin()+bs(v.at(i-1), v.at(i)),v.at(i-1).end());
          }else{
            j = tam-1;
            while(v.at(i-1).substr(0,j) > v.at(i)){j--;}
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }
        }
    }

    for(int i = 0; i < n; i++){
        cout << v.at(i) << endl;
    }
// ' ' < 'z'
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam;
    for(int i = n-1; i > 0; i--){
        tam = v.at(i-1).size()-1;
        for(int j = tam; v.at(i-1) > v.at(i); j--){

          v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
        }
    }

    char c;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < v.at(i).size(); j++){
          c = v.at(i).at(j);
          printf("%c", c);
        }
        cout << endl;
    }
// ' ' < 'z'
}


#include<bits/stdc++.h>

using namespace std;

//se antes > depois
int bs(string antes, string depois){
  //parar qnd com char na pos search eh maior
  //e com char na pos search-1 eh <=
  int hi, lo,search;
  hi = antes.size();
  lo = 1;
  while(hi >= lo){
    search = (hi+lo)/2;

    // printf("hi = %d  lo = %d  search = %d\n", hi,lo,search);
    // cout << antes.substr(0,search) << " " << antes.substr(0,search-1) << " " << depois << endl;

    if(antes.substr(0,search-1) > depois){
      hi = search-1;
    }else if(antes.substr(0,search) <= depois && antes.substr(0,search-1) <= depois){
      lo = search+1;
    }else if((antes.substr(0,search) > depois && antes.substr(0,search-1) <= depois))
      break;
  }

  return search-1;
}

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam, j;
    for(int i = n-1; i > 0; i--){
        if(v.at(i-1) > v.at(i)){
          if(tam > v.at(i).size() ){
            v.at(i-1).erase(v.at(i-1).begin()+bs(v.at(i-1), v.at(i)),v.at(i-1).end());
          }else{
            j = tam-1;
            while(v.at(i-1).substr(0,j) > v.at(i)){j--;}
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }
        }
    }

    for(int i = 0; i < n; i++){
        cout << v.at(i) << endl;
    }
// ' ' < 'z'
}


#include<bits/stdc++.h>

using namespace std;

//se antes > depois
int bs(string antes, string depois){
  int tam = antes.size();

  //parar qnd com char na pos search eh maior
  //e com char na pos search-1 eh <=
  int search = tam - 1;

  int hi, lo;
  hi = search;
  lo = 1;
  while(hi >= lo){
    search = (hi+lo)/2;

    // printf("hi = %d  lo = %d  search = %d\n", hi,lo,search);
    // cout << antes.substr(0,search) << " " << antes.substr(0,search-1) << " " << depois << endl;

    if(antes.substr(0,search) > depois && antes.substr(0,search-1) > depois){
      hi = search-1;
    }else if(antes.substr(0,search) <= depois && antes.substr(0,search-1) <= depois){
      lo = search+1;
    }else if((antes.substr(0,search) > depois && antes.substr(0,search-1) <= depois))
      break;
  }

  return search-1;
}

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam, j;
    for(int i = n-1; i > 0; i--){
        if(v.at(i-1) > v.at(i)){
          if(tam > v.at(i).size() ){
            v.at(i-1).erase(v.at(i-1).begin()+bs(v.at(i-1), v.at(i)),v.at(i-1).end());
          }else{
            j = tam-1;
            while(v.at(i-1).substr(0,j) > v.at(i)){j--;}
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }
        }
    }

    for(int i = 0; i < n; i++){
        cout << v.at(i) << endl;
    }
// ' ' < 'z'
}


#include<bits/stdc++.h>

using namespace std;

//se antes > depois
int bs(string antes, string depois){
  //parar qnd com char na pos search eh maior
  //e com char na pos search-1 eh <=
  int hi, lo,search;
  hi = antes.size();
  lo = 1;
  while(hi >= lo){
    search = (hi+lo)/2;

    // printf("hi = %d  lo = %d  search = %d\n", hi,lo,search);
    // cout << antes.substr(0,search) << " " << antes.substr(0,search-1) << " " << depois << endl;

    if(antes.substr(0,search-1) > depois){
      hi = search-1;
    }else if(antes.substr(0,search) <= depois && antes.substr(0,search-1) <= depois){
      lo = search+1;
    }else if((antes.substr(0,search) > depois && antes.substr(0,search-1) <= depois))
      break;
  }

  return search-1;
}

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam, j;
    for(int i = n-1; i > 0; i--){
        if(v.at(i-1) > v.at(i)){
          tam = v.at(i-1).size();
          if(tam > v.at(i).size() ){
            v.at(i-1).erase(v.at(i-1).begin()+bs(v.at(i-1), v.at(i)),v.at(i-1).end());
          }else{
            j = tam-1;
            while(v.at(i-1).substr(0,j) > v.at(i)){j--;}
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }
        }
    }

    for(int i = 0; i < n; i++){
        cout << v.at(i) << endl;
    }
// ' ' < 'z'
}


#include<bits/stdc++.h>

using namespace std;

//se antes > depois
int bs(string antes, string depois){
  //parar qnd com char na pos search eh maior
  //e com char na pos search-1 eh <=
  int hi, lo,search;
  hi = antes.size();
  lo = 1;
  while(hi >= lo){
    search = (hi+lo)/2;

    // printf("hi = %d  lo = %d  search = %d\n", hi,lo,search);
    // cout << antes.substr(0,search) << " " << antes.substr(0,search-1) << " " << depois << endl;

    if(antes.substr(0,search-1) > depois){
      hi = search-1;
    }else if(antes.substr(0,search) <= depois && antes.substr(0,search-1) <= depois){
      lo = search+1;
    }else if((antes.substr(0,search) > depois && antes.substr(0,search-1) <= depois))
      break;
  }

  return search-1;
}

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam, j;
    for(int i = n-1; i > 0; i--){
      if(v.at(i-1) > v.at(i))
        v.at(i-1).erase(v.at(i-1).begin()+bs(v.at(i-1), v.at(i)),v.at(i-1).end());
        // if(v.at(i-1) > v.at(i)){
        //   tam = v.at(i-1).size();
        //   if(tam > v.at(i).size() ){
        //
        //   }else{
        //     j = tam-1;
        //     while(v.at(i-1).substr(0,j) > v.at(i)){j--;}
        //     v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
        //   }
        // }
    }

    for(int i = 0; i < n; i++){
        cout << v.at(i) << endl;
    }
// ' ' < 'z'
}


#include<bits/stdc++.h>

using namespace std;

//se antes > depois
int bs(string antes, string depois){
  int tam = antes.size();

  //parar qnd com char na pos search eh maior
  //e com char na pos search-1 eh <=
  int search = tam - 1;

  int hi, lo;
  hi = search;
  lo = 1;
  while(1){
    search = (hi+lo)/2;

    // printf("hi = %d  lo = %d  search = %d\n", hi,lo,search);
    // cout << antes.substr(0,search) << " " << antes.substr(0,search-1) << " " << depois << endl;

    if(antes.substr(0,search) > depois && antes.substr(0,search-1) > depois){
      hi = search;
    }else if(antes.substr(0,search) <= depois && antes.substr(0,search-1) <= depois){
      lo = search+1;
    }else if((antes.substr(0,search) > depois && antes.substr(0,search-1) <= depois) || hi == lo)
      break;
  }

  return search-1;
}

int main(){
    vector<string> v;
    string ent;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> ent;
        v.push_back(ent);
    }

    int tam, j;
    for(int i = n-1; i > 0; i--){
        if(v.at(i-1) > v.at(i)){
          if(tam > v.at(i).size() ){
            v.at(i-1).erase(v.at(i-1).begin()+bs(v.at(i-1), v.at(i)),v.at(i-1).end());
          }else{
            j = tam-1;
            while(v.at(i-1).substr(0,j) > v.at(i)){j--;}
            v.at(i-1).erase(v.at(i-1).begin()+j,v.at(i-1).end());
          }
        }
    }

    for(int i = 0; i < n; i++){
        cout << v.at(i) << endl;
    }
// ' ' < 'z'
}


//@nottocode
#include<bits/stdc++.h>
using namespace std;
int i,j,k,n;
string vec[500010];

int main(void)
{
	scanf("%d",&n);
	char str[500010];
	for(i=1;i<=n;i++)
	{
		scanf("%s",str);
		vec[i]=str;
	}

	for(i=n-1;i>=1;i--)
	{
		int x=vec[i+1].size();
		int y=vec[i].size();

		int idx=-1,ok=0;

		for(j=0;j<min(x,y);j++)
		{
			if(vec[i+1][j]>vec[i][j])
			{
				ok=1;
				break;
			}
			else if(vec[i+1][j]<vec[i][j])
			{
				idx=j;
				break;
			}
		}

		if(!ok)
		{
			if(idx==-1)
			{
				while(vec[i].size()>vec[i+1].size())
					vec[i].pop_back();
			}
			else
			{
				while(vec[i].size()-1>=j)
					vec[i].pop_back();
			}
		}
	}

	for(i=1;i<=n;i++)
	{
		for(char c : vec[i])
			putchar(c);
		puts("");
	}

	return 0;
}


//@nottocode
#include<bits/stdc++.h>
using namespace std;
int i,j,k,n;
vector < char > vec[500010];

int main(void)
{
	scanf("%d",&n);
	string str;
	for(i=1;i<=n;i++)
	{
		cin >> str;
		for ( auto c : str)
			vec[i].emplace_back(c);
	}

	for(i=n-1;i>=1;i--)
	{
		int x=vec[i+1].size();
		int y=vec[i].size();

		int idx=-1,ok=0;

		for(j=0;j<min(x,y);j++)
		{
			if(vec[i+1][j]>vec[i][j])
			{
				ok=1;
				break;
			}
			else if(vec[i+1][j]<vec[i][j])
			{
				idx=j;
				break;
			}
		}

		if(!ok)
		{
			if(idx==-1)
			{
				while(vec[i].size()>vec[i+1].size())
					vec[i].pop_back();
			}
			else
			{
				while(vec[i].size()-1>=j)
					vec[i].pop_back();
			}
		}
	}

	for(i=1;i<=n;i++)
	{
		for(j=0;j<vec[i].size();j++)
			cout << vec[i][j];
		cout << endl;
	}

	return 0;
}


//@nottocode
#include<bits/stdc++.h>
using namespace std;
int i,j,k,n;

int main(void)
{
	scanf("%d",&n);
	char vec[n+2][500010];

	for(i=1;i<=n;i++)
		scanf("%s",vec[i]);

	for(i=2;i<=n;i++)
	{
		int cnt=0;
		for(j=0;j<strlen(vec[i])&&j<strlen(vec[i-1]);j++)
		{
			if(vec[i][j]<vec[i-1][j])
			{
				vec[i-1][j]='\0';
				break;
			}
			else if(vec[i][j]>vec[i-1][j])
				break;
			else if(vec[i][j]==vec[i-1][j])
				cnt++;
		}

		if(cnt==strlen(vec[i]))
			vec[i-1][strlen(vec[i])]='\0';
	}

	for(i=n-1;i>=1;i--)
	{
		int cnt=0;
		for(j=0;j<strlen(vec[i])&&j<strlen(vec[i+1]);j++)
		{
			if(vec[i][j]>vec[i+1][j])
			{
				vec[i][j]='\0';
				break;
			}
			else if(vec[i+1][j]>vec[i][j])
				break;
			else if(vec[i][j]==vec[i+1][j])
				cnt++;
		}

		if(cnt==strlen(vec[i+1]))
			vec[i][strlen(vec[i+1])]='\0';
	}

	for(i=1;i<=n;i++)
		printf("%s\n",vec[i]);

	return 0;
}


//@nottocode
#include<bits/stdc++.h>
using namespace std;
int i,j,k,n;
string vec[100010];

int main(void)
{
	scanf("%d",&n);
	string str;
	for(i=1;i<=n;i++)
	{
		cin >> str;
		vec[i]=str;
		// for ( auto c : str)
		// 	vec[i].emplace_back(c);
	}

	for(i=n-1;i>=1;i--)
	{
		int x=vec[i+1].size();
		int y=vec[i].size();

		int idx=-1,ok=0;

		for(j=0;j<min(x,y);j++)
		{
			if(vec[i+1][j]>vec[i][j])
			{
				ok=1;
				break;
			}
			else if(vec[i+1][j]<vec[i][j])
			{
				idx=j;
				break;
			}
		}

		if(!ok)
		{
			if(idx==-1)
			{
				while(vec[i].size()>vec[i+1].size())
					vec[i].pop_back();
			}
			else
			{
				while(vec[i].size()-1>=j)
					vec[i].pop_back();
			}
		}
	}

	for(i=1;i<=n;i++)
	{
		for(j=0;j<vec[i].size();j++)
			cout << vec[i][j];
		cout << endl;
	}

	return 0;
}


//@nottocode
#include<bits/stdc++.h>
using namespace std;
int i,j,k,n;
string vec[500010];

int main(void)
{
	scanf("%d",&n);
	string str;
	for(i=1;i<=n;i++)
	{
		cin >> str;
		vec[i]=str;
	}

	for(i=n-1;i>=1;i--)
	{
		int x=vec[i+1].size();
		int y=vec[i].size();

		int idx=-1,ok=0;

		for(j=0;j<min(x,y);j++)
		{
			if(vec[i+1][j]>vec[i][j])
			{
				ok=1;
				break;
			}
			else if(vec[i+1][j]<vec[i][j])
			{
				idx=j;
				break;
			}
		}

		if(!ok)
		{
			if(idx==-1)
			{
				while(vec[i].size()>vec[i+1].size())
					vec[i].pop_back();
			}
			else
			{
				while(vec[i].size()-1>=j)
					vec[i].pop_back();
			}
		}
	}

	for(i=1;i<=n;i++)
	{
		for(char c : vec[i])
			putchar(c);
		puts("");
	}

	return 0;
}


//@nottocode
#include<bits/stdc++.h>
using namespace std;
int i,j,k,n;

int main(void)
{
	scanf("%d",&n);
	char vec[n+2][500010];

	for(i=1;i<=n;i++)
		scanf("%s",vec[i]);

	for(i=2;i<=n;i++)
	{
		int cnt=0;
		for(j=0;j<strlen(vec[i])&&j<strlen(vec[i-1]);j++)
		{
			if(vec[i][j]<vec[i-1][j])
			{
				vec[i-1][j]='\0';
				break;
			}
			else if(vec[i][j]>vec[i-1][j])
				break;
			else if(vec[i][j]==vec[i-1][j])
				cnt++;
		}

		if(cnt==strlen(vec[i]))
			vec[i-1][strlen(vec[i])]='\0';
	}

	for(i=n-1;i>=1;i--)
	{
		if(vec[i+1][1]=='\0')
			vec[i][1]='\0';
	}

	for(i=1;i<=n;i++)
		printf("%s\n",vec[i]);

	return 0;
}


//@nottocode
#include<bits/stdc++.h>
using namespace std;
int i,j,k,n;
vector < char > vec[100010];

int main(void)
{
	scanf("%d",&n);
	string str;
	for(i=1;i<=n;i++)
	{
		cin >> str;
		for ( auto c : str)
			vec[i].emplace_back(c);
	}

	for(i=n-1;i>=1;i--)
	{
		int x=vec[i+1].size();
		int y=vec[i].size();

		int idx=-1,ok=0;

		for(j=0;j<min(x,y);j++)
		{
			if(vec[i+1][j]>vec[i][j])
			{
				ok=1;
				break;
			}
			else if(vec[i+1][j]<vec[i][j])
			{
				idx=j;
				break;
			}
		}

		if(!ok)
		{
			if(idx==-1)
			{
				while(vec[i].size()>vec[i+1].size())
					vec[i].pop_back();
			}
			else
			{
				while(vec[i].size()-1>=j)
					vec[i].pop_back();
			}
		}
	}

	for(i=1;i<=n;i++)
	{
		for(j=0;j<vec[i].size();j++)
			cout << vec[i][j];
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

const int INF = 2e9;
const long long LINF = 2e18;

typedef long long llong;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// + RATING?

// Code below

int n;

vector<string> arr;

void inp() {
    cin >> n;
    arr.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
}

void solve() {
    for (int i = n - 2; i >= 0; i--) {
        int j;
        if (arr[i] <= arr[i + 1])
            continue;
        for (j = 0; j < min(sz(arr[i]), sz(arr[i + 1])); j++) {
            if (arr[i][j] > arr[i + 1][j]) {
                break;
            }
        }
        while (sz(arr[i]) > j) {
            arr[i].pop_back();
        }
    }
    for (auto x: arr) {
        cout << x << endl;
    }
}

void stress() {

}

void naive() {

}

void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("canderlabrum.in", "r", stdin);
            freopen("canderlabrum.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif

    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }
    cerr << endl << "Time: " << clock() / 1000.0 << " ms";
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

const int INF = 2e9;
const long long LINF = 2e18;

typedef long long llong;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// + RATING?

// Code below

int n;

vector<string> arr;

void inp() {
    cin >> n;
    arr.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
}

void solve() {
    vector<int> mn(n);
    vector<int> ans(n);
    int cur = n - 1;
    mn[n - 1] = n - 1;
    for (int i = n - 1; i >= 0; i--) {
        if (arr[i] < arr[cur])
            cur = i;
        mn[i] = cur;
        if (arr[i] > arr[mn[i]]) {
            int j;
            for (j = 0; j < min(sz(arr[i]), sz(arr[mn[i]])); j++) {
                if (arr[i][j] > arr[mn[i]][j])
                    break;
            }
            while (sz(arr[i]) > j) {
                arr[i].pop_back();
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << arr[i] << endl;
    }
}

void stress() {

}

void naive() {

}

void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("canderlabrum.in", "r", stdin);
            freopen("canderlabrum.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif

    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }
    cerr << endl << "Time: " << clock() / 1000.0 << " ms";
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

const int INF = 2e9;
const long long LINF = 2e18;

typedef long long llong;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// + RATING?

// Code below

int n;

vector<string> arr;

void inp() {
    cin >> n;
    arr.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
}

void solve() {
    vector<int> mn(n);
    vector<int> ans(n);
    int cur = n - 1;
    for (int i = n - 1; i >= 0; i--) {
        if (arr[i] < arr[cur])
            cur = i;
        mn[i] = cur;
    }
    for (int i = n - 1; i >= 0; i--) {
        if (arr[i] > arr[mn[i]]) {
            int j;
            for (j = 0; j < min(sz(arr[i]), sz(arr[mn[i]])); j++) {
                if (arr[i][j] > arr[mn[i]][j])
                    break;
            }
            ans[i] = j;
        }
    }
    for (int i = 0; i < n; i++) {
        if (ans[i] != 0) {
            for (int j = 0; j < ans[i]; j++) {
                cout << arr[i][j];
            }
        } else {
            cout << arr[i];
        }
        cout << endl;
    }
}

void stress() {

}

void naive() {

}

void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("canderlabrum.in", "r", stdin);
            freopen("canderlabrum.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif

    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }
    cerr << endl << "Time: " << clock() / 1000.0 << " ms";
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

const int INF = 2e9;
const long long LINF = 2e18;

typedef long long llong;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// + RATING?

// Code below

int n;

vector<string> arr;

void inp() {
    cin >> n;
    arr.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
}

void solve() {
    vector<int> mn(n);
    vector<int> ans(n);
    int cur = n - 1;
    for (int i = n - 1; i >= 0; i--) {
        if (arr[i] < arr[cur])
            cur = i;
        mn[i] = cur;
    }
    for (int i = 0; i + 1 < n; i++) {
        if (arr[i] > arr[mn[i]]) {
            int j;
            for (j = 0; j < min(sz(arr[i]), sz(arr[mn[i]])); j++) {
                if (arr[i][j] > arr[mn[i]][j])
                    break;
            }
            ans[i] = j;
        }
    }
    for (int i = 0; i < n; i++) {
        if (ans[i] != 0) {
            for (int j = 0; j < ans[i]; j++) {
                cout << arr[i][j];
            }
        } else {
            cout << arr[i];
        }
        cout << endl;
    }
}

void stress() {

}

void naive() {

}

void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("canderlabrum.in", "r", stdin);
            freopen("canderlabrum.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif

    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }
    cerr << endl << "Time: " << clock() / 1000.0 << " ms";
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


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

using ll = long long;
const int N = 5 * 1e5 + 10;

string s[N], ss = "#", sss;

int main(){
    //ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    char ch = char('z' + 1);
    ss += ch;
    s[n + 1] = ss;
    for(int i = n; i > 0; --i){
        for(int j = 0; j < s[i].size(); ++j){
            if(s[i][j] < s[i + 1][j]){
                break;
            }
            if(s[ i+ 1][j] < s[i][j]){
                s[i] = sss;
                break;
            }
            sss += s[i][j];
            if(j == s[i + 1].size() - 1){
                s[i] = sss;
                break;
            }
        }
        sss.clear();
    }
    for(int i = 1; i <= n; ++i){
        cout << s[i] << "\n";
    }
}


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

using ll = long long;
const int N = 6 * 1e5 + 10;

string s[N], ss = "#", sss;

int main(){
    //ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    for(int i = 0; i < N; ++i){
        ss += "z";
    }
    for(int i = n; i > 0; --i){
        for(int j = 0; j < s[i].size(); ++j){
            if(s[i][j] < ss[j]){
                ss = s[i];
                break;
            }
            if(ss[j] < s[i][j]){
                ss = sss;
                break;
            }
            sss += s[i][j];
            if(j == ss.size() - 1){
                ss = sss;
                break;
            }
        }
        s[i] = ss;
        sss.clear();
    }
    for(int i = 1; i <= n; ++i){
        cout << s[i] << "\n";
    }
}


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

using ll = long long;
const int N = 5 * 1e5 + 10;

string s[N], ss = "#", sss;

int main(){
    //ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    char ch = char('z' + 1);
    ss += ch;
    s[n + 1] = ss;
    for(int i = n; i > 0; --i){
        for(int j = 0; j < s[i].size(); ++j){
            if(s[i][j] < s[i + 1][j]){
                break;
            }
            if(s[ i+ 1][j] < s[i][j]){
                s[i] = sss;
                break;
            }
            sss += s[i][j];
            if(j == ss.size() - 1){
                s[i] = sss;
                break;
            }
        }
        sss.clear();
    }
    for(int i = 1; i <= n; ++i){
        cout << s[i] << "\n";
    }
}


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

using ll = long long;
const int N = 6 * 1e5 + 10;

string s[N], ss = "#", sss;

int main(){
    //ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    for(int i = 0; i < N; ++i){
        ss += "z";
    }
    for(int i = n; i > 0; --i){
        for(int j = 0; i < s[i].size(); ++j){
            if(s[i][j] < ss[j]){
                ss = s[i];
                break;
            }
            if(ss[j] < s[i][j]){
                ss = sss;
                break;
            }
            sss += s[i][j];
            if(j == ss.size() - 1){
                ss = sss;
                break;
            }
        }
        s[i] = ss;
        sss.clear();
    }
    for(int i = 1; i <= n; ++i){
        cout << s[i] << "\n";
    }
}


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

using ll = long long;
const int N = 6 * 1e5 + 10;

string s[N], ss = "#";

int main(){
    //ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    for(int i = 0; i < N; ++i){
        ss += "z";
    }
    for(int i = n; i > 0; --i){
        while(s[i] > ss){
            s[i].pop_back();
        }
        ss = s[i];
    }
    for(int i = 1; i <= n; ++i){
        cout << s[i] << "\n";
    }
}


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

int n;
string s[511111];

int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);

    cin >> n;

    for (int i=1; i<=n; i++) cin >> s[i];

    for (int i=n; i>=2; i--){

        if( s[i-1]>s[i] ){
            int k=1;
            string h = "#";
            while( s[i]>=h+s[i-1][k] ){
                h = h+s[i-1][k];
                k++;
                if(k==s[i-1].size()) break;
            }
            s[i-1] = h;
        }

    }

  for (int i=1; i<=n; i++){
  cout << s[i] << endl;
  }

return 0;
}


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

int n;
string s[511111];

int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);

    cin >> n;

    for (int i=1; i<=n; i++) cin >> s[i];

    for (int i=n; i>=2; i--){

        if( s[i-1]>s[i] ){
            int k=1;
            string h = "#";
            while( s[i]>=h+s[i-1][k] ){
                h = h+s[i-1][k];
                k++;
                if(k==s[i-1].size()) break;
            }
            s[i-1] = h;
        }

    }

  for (int i=1; i<=n; i++){
  cout << s[i] << "\n";
  }

return 0;
}


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

int n;
string s[511111];

int main(){

    cin >> n;

    for (int i=1; i<=n; i++) cin >> s[i];

    for (int i=n; i>=2; i--){

        if( s[i-1]>s[i] ){
            int k=1;
            string h = "#";
            while( s[i]>=h+s[i-1][k] ){
                h = h+s[i-1][k];
                k++;
                if(k==s[i-1].size()) break;
            }
            s[i-1] = h;
        }

    }

  for (int i=1; i<=n; i++){
  cout << s[i] << endl;
  }

return 0;
}


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

int n;
string s[511111];

int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);

    cin >> n;

    for (int i=1; i<=n; i++) cin >> s[i];

    for (int i=n; i>=2; i--){

        if( s[i-1]>s[i] ){
            int k=1,p=1;
            while( s[i][p]>=s[i-1][k] ){
                k++;
                p++;
                if( p==s[i].size() || k==s[i-1].size()) break;
            }
            s[i-1] = s[i-1].substr(0,k);
        }

    }

  for (int i=1; i<=n; i++){
  cout << s[i] << "\n";
  }

return 0;
}


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

int n;
string s[111111];

int main(){

    cin >> n;

    for (int i=1; i<=n; i++) cin >> s[i];

    for (int i=n; i>=1; i--){

        if( s[i-1]>s[i] ){
            int k=1;
            string h = "#";
            while( s[i]>=h+s[i-1][k] ){
                h = h+s[i-1][k];
                k++;
                if(k==s[i-1].size()) break;
            }
            s[i-1] = h;
        }

    }

  for (int i=1; i<=n; i++){
  cout << s[i] << endl;
  }

return 0;
}


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

int n;
string s[511111];

int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);

    cin >> n;

    for (int i=1; i<=n; i++) cin >> s[i];

    for (int i=n; i>=2; i--){

        if( s[i-1]>s[i] ){
            int k=1;
            while( s[i]>=s[i-1].substr(0,k) ){
                k++;
                if(k==s[i-1].size()) break;
            }
            s[i-1] = s[i-1].substr(0,k-1);
        }

    }

  for (int i=1; i<=n; i++){
  cout << s[i] << "\n";
  }

return 0;
}


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

int n;
string s[111111];

int main(){

    cin >> n;

    for (int i=1; i<=n; i++) cin >> s[i];

    for (int i=n; i>=2; i--){

        if( s[i-1]>s[i] ){
            int k=1;
            string h = "#";
            while( s[i]>=h+s[i-1][k] ){
                h = h+s[i-1][k];
                k++;
                if(k==s[i-1].size()) break;
            }
            s[i-1] = h;
        }

    }

  for (int i=1; i<=n; i++){
  cout << s[i] << endl;
  }

return 0;
}


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

int main()
{
    string s[500001];
    long int r[500001];
    long int n,i,j;
    char c;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>c>>s[i];
        r[i]=s[i].length()-1;
    }
    for(i=n-2;i>=0;i--)
    {
        if(r[i+1]==-1)
        {
            r[i]=-1;
            continue;
        }
        for(j=0;j<r[i];j++)
        {
            if(s[i][j]<s[i+1][j])
                break;
            else if(s[i][j]>s[i+1][j])
            {
                r[i]=j-1;
                break;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<"#";
        for(j=0;j<=r[i];j++)
            cout<<s[i][j];
        cout<<endl;
    }
    return 0;
}


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

int main()
{
    string s[500001];
    long int r[500001];
    long int n,i,j;
    char c;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>c>>s[i];
        r[i]=s[i].length()-1;
    }
    for(i=n-2;i>=0;i--)
    {
        for(j=0;j<r[i];j++)
        {
        	if(j>r[i+1])
        	{
        		r[i]=r[i+1];
        		break;
        	}
            if(s[i][j]>s[i+1][j])
            {
                r[i]=j-1;
                break;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<"#";
        for(j=0;j<=r[i];j++)
            cout<<s[i][j];
        cout<<endl;
    }
    return 0;
}


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

int main()
{
    string s[500001];
    long int r[500001];
    long int n,i,j;
    char c;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>c>>s[i];
        r[i]=s[i].length()-1;
    }
    for(i=n-2;i>=0;i--)
    {
        if(r[i+1]==-1)
        {
            r[i]=-1;
            continue;
        }
        for(j=0;j<=r[i];j++)
        {
            if(s[i][j]<s[i+1][j])
                break;
            else if(s[i][j]>s[i+1][j])
            {
                r[i]=j-1;
                break;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<"#";
        for(j=0;j<=r[i];j++)
            cout<<s[i][j];
        cout<<endl;
    }
    return 0;
}


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

int main()
{
    string s[500001];
    long int r[500001];
    long int n,i,j;
    char c;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>c>>s[i];
        r[i]=s[i].length();
    }
    for(i=n-2;i>=0;i--)
    {
        for(j=0;j<r[i];j++)
        {
        	if(j>r[i+1])
        	{
        		r[i]=r[i+1];
        		break;
        	}
            if(s[i][j]>s[i+1][j])
            {
                r[i]=j-1;
                break;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<"#";
        for(j=0;j<=r[i];j++)
            cout<<s[i][j];
        cout<<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 100100
#define ll long long
int n,m,p;
int D[maxn],H[maxn],T[maxn];
ll A[maxn];
ll S[maxn];
int q[maxn],cnt=0;
ll f[110][maxn];
ll X(int i) { return i; }
ll Y(int j) { return f[cnt][j] + S[j]; }//
ll mymin(ll x, ll y){ if(x < y) return x; else return y; }
int main()
{
    scanf("%d%d%d", &n, &m, &p);
    for(int i = 2; i <= n; i++)
    {
        scanf("%d", &D[i]);
        D[i] += D[i - 1];
    }
    for(int i = 1; i <= m; i++)scanf("%d%d", &H[i], &T[i]);
    for(int i = 1; i <= m; i++)
    {
        A[i] = T[i] - D[H[i]];
    }
 //   for(int i = 1;i <= n; i++)printf("D[%d] = %d\n", i, D[i]);
 //   for(int i = 1;i <= m; i++)printf("H[%d] = %d T[%d] = %d A[%d] =%d\n", i, H[i], i, T[i], i, A[i]);
    sort(A + 1, A + m + 1);
    for(int i = 1; i <= m; i++)S[i] = S[i - 1] + A[i];
    memset(f, 0x3f, sizeof(f)); f[0][0] = 0;
    for(int i = 1; i <= p; i++)
    {
        int l = 1, r = 1; cnt = i - 1; q[1] = 0;
        for(int j = 1; j <= m; j++)
        {
            while(l < r && (Y(q[l + 1]) - Y(q[l])) <= A[j] * (X(q[l + 1]) - X(q[l])))l++;
            f[i][j] = f[i - 1][q[l]] + A[j] * (j - q[l]) -(S[j] - S[q[l]]);
            while(l < r && (Y(j) - Y(q[r])) * (X(q[r]) - X(q[r-1])) <= (Y(q[r]) - Y(q[r - 1])) * (X(j) - X(q[r])))r--;//////////////////////
            q[++r] = j;
        }
    }
    printf("%lld\n", f[p][m]);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll inf=4557430888798830399;
const int maxn=2e5+10,maxm=1e5+10,maxp=110;

int n,m,p;
ll d[maxn],s[maxn];
ll a[maxm];

ll f[maxp][maxm],g[maxm];

ll q[maxm];int l,r;

ll X(int x)
{
	return x;
//	return a[x];//why???
}

ll Y(int y)
{
	return g[y];
//	return g[y]-a[y]*y;//why???
}

int main()
{
//	scanf("%d%d%d",&n,&m,&p);
	cin>>n>>m>>p;
	for(int i=2;i<=n;i++)
	{
//		scanf("%lld",&d[i]);
		cin>>d[i];
		d[i]+=d[i-1];
	}
	for(int i=1;i<=m;i++)
	{
		int h,t;
//		scanf("%d%d",&h,&t);
		cin>>h>>t;
		a[i]=t-d[h];
//		s[i]=s[i-1]+a[i];//debug
	}
	sort(a+1,a+m+1);
	for(int i=1;i<=m;i++) s[i]=s[i-1]+a[i];

	memset(f,63,sizeof(f));f[0][0]=0;
	for(int i=1;i<=p;i++)
	{
		for(int j=1;j<=m;j++) g[j]=f[i-1][j]+s[j];//debug
		l=r=1;q[1]=0;
		for(int j=1;j<=m;j++)
		{
			while(l<r && Y(q[l+1])-Y(q[l]) <= (X(q[l+1])-X(q[l])) * a[j]) l++;
			int k=q[l];
//			f[i][j]=g[k]-(s[j]+s[k])+a[j]*(j-k);//debug
			f[i][j]=min(f[i-1][j],g[k]-s[j]+a[j]*(j-k));//+s[k]
			if(g[j]>=inf) continue;
			while(l<r && (Y(q[r])-Y(q[r-1])) * (X(q[j]-X(r))) >= (Y(q[j]-Y(r))) * (X(q[r])-X(q[r-1]))) r--;//i->j
			q[++r]=j;
		}
	}
	printf("%lld\n",f[p][m]);
	return 0;
}


#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;

inline char gc()
{
	static const int L = 1000;
	static char sxd[L], *sss = sxd, *ttt = sxd;
	if(sss == ttt)
	{
		ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
		if(sss == ttt)
			return EOF;
	}
	return *sss++;
}

#define dd c = getchar()
inline int read(int& x)
{
	x = 0;
	char dd;
	bool f = false;
	for(; !isdigit(c); dd)
	{
		if(c == EOF)
			return -1;
		if(c == '-')
			f = true;
	}
	for(; isdigit(c); dd)
		x = (x << 1) + (x << 3) + (c ^ 48);
	if(f)
		x = -x;
	return 1;
}
#undef dd

int n,a[2000],i,l,r,turn,sum[2];
int main()
{
    read(n);
    for(i=1;i<=n;i++) read(a[i]);
    l=1;
	r=n;
    while(l<=r)
	{
        if(a[l]<a[r])
		{
            sum[turn]+=a[r];
            r--;
        }
        else
		{
            sum[turn]+=a[l];
            l++;
        }
        turn=!turn;
    }
    cout<<sum[0]<<' '<<sum[1];
    return 0;
}


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

const int N=1e5+7;
typedef long long ll;
ll dis[N],T[N],f[108][N],t[N],sum[N];
inline double scope(int i,int x,int y) {
	return 1.0*((f[i][y] + sum[y] - f[i][x] - sum[x]) / (y - x));
}
#define rint register int
inline bool cmp(int x,int y) {
	return x<y;
}
#define l dafsilu______ESRHGSDGR______________hkweghkERSHESRH___kvjbasd_________asergjlhawseikyfgbuase
#define r arjgh___awrhgihawrki_____glb____________awshfwaukeyrgfuiyawegrf
#define q euhragiERSGESRG____________asdfsafdfdskjgSERGSERGRGgujvdty5j3ytj35d8f7yj25drj____________
int l[N],r[N];
int q[108][N];

int main() {
	int n,m,p;
	cin>>n>>m>>p;
	for(rint i=2;i<=n;i++) scanf("%lld",&dis[i]), dis[i]+=dis[i-1];
	for(rint i=1;i<=m;i++) {
		int pla;
		scanf("%d%lld",&pla,&T[i]);
		t[i]=T[i]-dis[pla];
	}
	sort(t+1,t+m+1,cmp);
	for(rint i=1;i<=m;i++) sum[i]=sum[i-1]+t[i];

	for(rint i=1;i<=m;i++) { // 猫的数量
		for(rint j=1;j<=min(i,p);j++) { // 循环管理员
			while(l[j-1]<r[j-1] && scope(j-1,q[j-1][l[j-1]],q[j-1][l[j-1]+1]) <= t[i]) l[j-1]++;
			int h=q[j-1][l[j-1]];
			f[j][i]=f[j-1][h] + t[i]*(i-h) - sum[i] + sum[h];
			while(l[j]<r[j] && (scope(j,q[j][r[j]-1],q[j][r[j]]) > scope(j,q[j][r[j]],i))) r[j]--;
			q[j][++r[j]]=i;
		}
	}

	cout<<f[p][m]<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const ll Inf=0x3f3f3f3f3f3f3f3f;
int n,m,p,h,t,d[maxn];
deque<int>q;
ll f[105][maxn],sum[maxn],a[maxn];
ll slope(int i,int j) {
	return f[i-1][j]+sum[j];
}
int main() {
	scanf("%d%d%d",&n,&m,&p);
	for(int i=2;i<=n;i++) {
		scanf("%d",&d[i]);
		d[i]+=d[i-1];
	}
	for(int i=1;i<=m;i++) {
		scanf("%d%d",&h,&t);
		a[i]=t-d[h];
		sum[i]=sum[i-1]+a[i];
		f[0][i]=Inf;
	}
	sort(a+1,a+1+m);
	for(int i=1;i<=p;i++) {
		while(!q.empty()) q.pop_front();
		for(int j=0;j<=m;j++) {
			while(q.size()>1&&slope(i,q[1])-slope(i,q[0])<=a[j]*(q[1]-q[0])) q.pop_front();
			if(!q.empty()) f[i][j]=slope(i,q[0])+a[j]*(j-q[0])-sum[j];
			while(q.size()>1&&(slope(i,j)-slope(i,q[q.size()-1]))*(q[q.size()-1]-q[q.size()-2])<=(slope(i,q[q.size()-1])-slope(i,q[q.size()-2]))*(j-q[q.size()-1])) q.pop_back();
			q.push_back(j);
		}
	}
	printf("%lld\n",f[p][m]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+10000;
int n,m,p,head,tail,now,tmp;
long long ans,f[110][maxn],d[maxn],tot;
long long t[maxn],sum[maxn],q[maxn];
inline long long calc(int x,int y){
    return sum[x]+f[now][x]-t[y]*x;
}
inline long long slope(int a,int b,int c){
    long long x=a-b,y=b-c;
    long long z=sum[a]+f[now][a]-sum[b]-f[now][b];
    long long k=sum[b]+f[now][b]-sum[c]-f[now][c];
    return x*k-y*z;
}
int main(){
    scanf("%d%d%d",&n,&m,&p);
    for(register int i=2;i<=n;i++)
        scanf("%lld",&d[i]),d[i]+=d[i-1];
    for(register int i=1;i<=m;i++)
        scanf("%d%lld",&tmp,&tot),t[i]=tot-d[tmp];
    sort(t+1,t+1+m);
    for(register int i=1;i<=m;i++) sum[i]=sum[i-1]+t[i];
    for(register int i=1;i<=m;i++) f[1][i]=i*t[i]-sum[i];
    ans=f[1][m];
    for(register int i=2;i<=p;i++){
        head=1,tail=1,now=i-1,q[0]=0;
        for(register int j=1;j<=m;j++){
            while(head<=tail&&calc(q[head+1],j)<calc(q[head],j)) head++;
            f[i][j]=f[i-1][q[head]]+(j-q[head])*t[j]-sum[j]+sum[q[head]];
            while(head<=tail&&slope(j,q[tail],q[tail]-1)>0) tail--;
            q[++tail]=j;
        }
        ans=min(ans,f[i][m]);
    }printf("%lld",ans);system("pause");
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 2e5 + 5;
#define ll long long
int A[maxn];
ll S[maxn];
int T[maxn], D[maxn];
int h[maxn];
int q[maxn];
int m, n, p;
ll f[105][100005];
inline int read(){
	int s = 0, w = 1;
	char c = getchar();
	while(c < '0' || c > '9'){if(c == '-')w = -1; c = getchar();}
	while(c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
	return s * w;
}
ll Get(int i){
	ll ans = 0;
	for(int j = 2; j <= h[i]; i++)
		ans += D[i];
	return ans;
}
ll Calc(int i, int j, int k){
	return f[i - 1][k] + (j - k) * A[j] - (S[j] - S[k]);
}
double GetK(int i, int j, int k1, int k2){
	double dy = (f[i - 1][k1] + S[k1]) - (f[i - 1][k2] + S[k2]);
	double dx = (k1 - k2);
	return dy / dx;
}
int main(){
	n = read();
	m = read();
	p = read();
	for(int i = 2; i <= n; i++)
		D[i] = read();
	for(int i = 1; i <= m; i++)
		h[i] = read(), T[i] = read();
	for(int i = 1; i <= m; i++){
		A[i] = T[i] - Get(i);
		S[i] = S[i - 1] + A[i];
	}
	f[0][0] = 0;
	int l, r;
	l = r = 1;
	for(int i = 1; i <= p; i++){
		for(int j = 1; j <= m; j++){
			for(int k = 1; k < j; k++){
				while(l < r && Calc(i, j, q[l]) >= Calc(i, j, q[l + 1])) l++;
				f[i][j] = Calc(i, j, q[l]);
				while(l < r && GetK(i, j, q[r - 1], q[r]) >= GetK(i, j, q[r], k)) r--;
				q[++r] = k;
			}
		}
	}
	cout << f[p][m] << endl;
	return 0;
}


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

const int N=1e5+7;
typedef long long ll;
ll dis[N],T[N],f[108][N],t[N],sum[N];
inline double scope(int i,int x,int y) {
	return 1.0*((f[i][y] + sum[y] - f[i][x] - sum[x]) / (y - x));
}
#define rint register int
inline bool cmp(int x,int y) {
	return x<y;
}
#define l dafsilu______ESRHGSDGR______________hkweghkERSHESRH___kvjbasd_________asergjlhawseikyfgbuase
#define r arjgh___awrhgihawrki_____glb____________awshfwaukeyrgfuiyawegrf
#define q euhragiERSGESRG____________asdfsafdfdskjgSERGSERGRGgujvdty5j3ytj35d8f7yj25drj____________
int l[N],r[N];
int q[108][N];

int main() {
	int n,m,p;
	cin>>n>>m>>p;
	for(rint i=2;i<=n;i++) scanf("%lld",&dis[i]), dis[i]+=dis[i-1];
	for(rint i=1;i<=m;i++) {
		int pla;
		scanf("%d%lld",&pla,&T[i]);
		t[i]=T[i]-dis[pla];
	}
	sort(t+1,t+m+1,cmp);
	for(rint i=1;i<=m;i++) sum[i]=sum[i-1]+t[i];

	for(rint j=1;j<=m;j++) { // 猫的数量
		for(rint i=1;i<=min(j,p);i++) { // 循环管理员
			while(l[i-1]<r[i-1] && scope(i-1,q[i-1][l[i-1]],q[i-1][l[i-1]+1]) <= t[j]) l[i-1]++;
			int h=q[i-1][l[i-1]];
			f[i][j]=f[i-1][h] + t[j]*(j-h) - sum[j] + sum[h];
			while(l[i]<r[i] && (scope(i,q[i][r[i]-1],q[i][r[i]]) > scope(i,q[i][r[i]],j))) r[i]--;
			q[i][++r[i]]=j;
		}
	}

	cout<<f[p][m]<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,p,a[100005],d[100005],sum[100005],h[100005],t[100005],dui[100005],head,tail,f[105][100005];
double suan(int ga,int x,int y)
{
	return double(f[ga-1][x]-f[ga-1][y]+sum[x]-sum[y])/(double)(x-y);
}
signed main()
{
	scanf("%lld%lld%lld",&n,&m,&p);
	for(int i=2;i<=n;i++)
	{
		scanf("%lld",&d[i]);
		d[i]+=d[i-1];
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%lld%lld",&h[i],&t[i]);
		a[i]=t[i]-d[h[i]];
	}
	memset(f,0x3f3f3f3f,sizeof(f));
	f[0][0]=0;
	sort(a+1,a+m+1);
	for(int i=1;i<=m;i++)
		sum[i]=a[i]+sum[i-1];
	for(int i=1;i<=p;i++)
	{
		head=tail=0;
		memset(dui,0,sizeof(dui));
		for(int j=1;j<=m;j++)
		{
			while(head<tail&&suan(i,dui[head+1],dui[head])<=a[i])
				head++;
			f[i][j]=min(f[i][j],f[i-1][dui[head]]+a[j]*(j-dui[head])-(sum[j]-sum[dui[head]]));
			if(f[i-1][j]+sum[j]>=0x3f3f3f3f3f3f3f3f)
				continue;
			while(head<tail&&suan(i,j,dui[tail])>=suan(i,dui[tail],dui[tail-1]))
				tail--;
			dui[++tail]=j;
		}
	}
	printf("%lld",f[p][m]);
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define R(i,s,t) for(int i=s;i<=t;i++)
#define Y(j) f[i-1][j]+sumt[j]
#define Z(i) i*t[i]-sumt[i]
#define H1 q[head]
#define H2 q[head+1]
#define T1 q[tail-1]
#define T2 q[tail]
using namespace std;
const int maxn=1e5+5,maxp=105;
int n,m,p,q[maxn],d[maxn],t[maxn],f[maxp][maxn],sumt[maxn];
signed main() {
#ifdef LOCAL
	freopen("cats.in","r",stdin);
#endif
	cin>>n>>m>>p;
	R(i,2,n) {int tmp; cin>>tmp; d[i]=d[i-1]+tmp;}
	R(i,1,m) {
		int hi,ti; cin>>hi>>ti;
		t[i]=ti-d[hi];
	}
	sort(t+1,t+1+m);
	R(i,1,m) sumt[i]=sumt[i-1]+t[i];
	memset(f[0],0x3f,sizeof f[0]);
	f[0][0]=0;
	R(i,1,p) {
		int head=1,tail=1;
		R(j,0,m) {
			while(head<tail&&(Y(T2)-Y(T1))*(j-T2)>=(Y(j)-Y(T2))*(T2-T1)) tail--;
			q[++tail]=j;
			while(head<tail&&(Y(H2)-Y(H1))<=(H2-H1)*t[j]) head++;
			f[i][j]=Y(H1)-t[j]*H1+Z(j);
		}
	}
	cout<<f[p][m]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long dp[2][100010];
int q[2][100010];
long long sum[100010],mx[100010];
inline double slope(int u,int i,int j){return ((double)dp[u][j]-dp[u][i]+sum[j]-sum[i])/(double)(j-i);}
int d[100010];
int n,m,p;
long long ans;
int main()
{
	scanf("%d%d%d",&n,&m,&p);
	for(int i=2;i<=n;i++)scanf("%d",d+i),d[i]+=d[i-1];
	for(int i=1;i<=m;i++)
	{
		int h,t;
		scanf("%d%d",&h,&t);
		sum[i]=t-d[h];
	}
	sort(sum+1,sum+m+1);
	for(int i=1;i<=m;i++)mx[i]=max(mx[i-1],sum[i]),sum[i]+=sum[i-1];
	for(int i=1;i<=m;i++)dp[1][i]=mx[i]*i-sum[i];
	ans=dp[1][m];
	for(int t=2;t<=p;t++)
	{
		int tt=(t&1);
		int l=0,r=0;
		for(int i=1;i<=m;i++)
		{
			while(l<r && slope(tt^1,q[tt][l],q[tt][l+1])<=mx[i])l++;
			dp[tt][i]=dp[tt^1][q[tt][l]]+mx[i]*(i-q[tt][l])-sum[i]+sum[q[tt][l]];
			while(l<r && slope(tt^1,q[tt][r-1],q[tt][r])>=slope(tt^1,q[tt][r],i))r--;
			q[tt][++r]=i;
		}
		ans=min(ans,dp[tt][m]);
	}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+20000;
int n,m,p,head,tail,now,tmp;
int ans,f[110][maxn],d[maxn],tot;
int t[maxn],sum[maxn],q[maxn];
inline int calc(int x,int y){
    return sum[x]+f[now][x]-t[y]*x;
}
inline int slope(int a,int b,int c){
    int x=a-b,y=b-c;
    int z=sum[a]+f[now][a]-sum[b]-f[now][b];
    int k=sum[b]+f[now][b]-sum[c]-f[now][c];
    return x*k-y*z;
}
int main(){
    scanf("%d%d%d",&n,&m,&p);
    for(register int i=2;i<=n;i++)
        scanf("%d",&d[i]),d[i]+=d[i-1];
    for(register int i=1;i<=m;i++)
        scanf("%d%d",&tmp,&tot),t[i]=tot-d[tmp];
    sort(t+1,t+1+m);
    for(register int i=1;i<=m;i++) sum[i]=sum[i-1]+t[i];
    for(register int i=1;i<=m;i++) f[1][i]=i*t[i]-sum[i];
    ans=f[1][m];
    for(register int i=2;i<=p;i++){
        head=1,tail=1,now=i-1,q[0]=0;
        for(register int j=1;j<=m;j++){
            while(head<=tail&&calc(q[head+1],j)<calc(q[head],j)) head++;
            f[i][j]=f[i-1][q[head]]+(j-q[head])*t[j]-sum[j]+sum[q[head]];
            while(head<=tail&&slope(j,q[tail],q[tail]-1)>0) tail--;
            q[++tail]=j;
        }
        ans=min(ans,f[i][m]);
    }printf("%d",ans);system("pause");
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;

ll f[110][100010],g[100010];
ll s[100010],a[100010],d[100010],q[100010];

int n,m,p,x,y,head,tail;

int main(){
    cin>>n>>m>>p;
    for(int i=2;i<=n;i++){ cin>>x; d[i]=d[i-1]+x; }
    for(int i=1;i<=m;i++){ cin>>x>>y; a[i]=y-d[x]; }
    sort(a+1,a+m+1);
    for(int i=1;i<=m;i++) s[i]=s[i-1]+a[i];
    memset(f,0x3f,sizeof(f));
	f[0][0]=0;
    for(int i=1;i<=p;i++){
        for(int j=1;j<=m;j++) g[j]=f[i-1][j]+s[j];
        head=1;
		tail=1;
		q[1]=0;
        for(int j=1;j<=m;j++){
            while(head<tail&&g[q[head+1]]-g[q[head]]<=a[j]*(q[head+1]-q[head])) head++;
            f[i][j]=min(f[i-1][j],g[q[head]]+a[j]*(j-q[head])-s[j]);
            if(g[j]>=0x3f3f3f3f3f3f3f3fll) continue;
            while(head<tail&&(g[j]-g[q[tail]])*(q[tail]-q[tail-1])<=(g[q[tail]]-g[q[tail-1]])*(j-q[tail])) tail--;
            q[++tail]=j;
        }
    }
    cout<<f[p][m]<<endl; return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
using namespace std;
#define int long long
#define R register
#define debug printf("zjy\n")
inline int read(){
	int a=0,b=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')b=-1;c=getchar();}
	while(isdigit(c)){a=a*10+c-'0';c=getchar();}
	return a*b;
}
const int N=1e5+50;
int n,m,p,d[N],t[N],sum[N],q[101][N],l[N],r[N],dp[101][N];
double slope(int i,int j,int k){
	return (1.0*dp[i][j]-dp[i][k]+sum[j]-sum[k])/(j-k);
}
signed main(){
	n=read();m=read();p=read();
	if(p>=m){
		printf("0\n");
		return 0;
	}
	for(R int i=2;i<=n;i++){
		d[i]=read();
		d[i]+=d[i-1];
	}
	int x,y;
	for(R int i=1;i<=m;i++){
		x=read();y=read();
		t[i]=y-d[x];
	}
	sort(t+1,t+m+1);
	for(R int i=1;i<=m;i++){
		sum[i]=sum[i-1]+t[i];
	}
	for(R int i=1;i<=m;i++){
		for(R int j=1;j<=min(i,p);j++){
			while(l[j-1]<r[j-1]&&slope(j-1,q[j-1][l[j-1]],q[j-1][l[j-1]+1])<=t[i])l[j-1]++;
			int tr=q[j-1][l[j-1]];
			dp[j][i]=dp[j-1][tr]+t[i]*(i-tr)-sum[i]+sum[tr];
			while(l[j]<r[j]&&slope(j,q[j][r[j]-1],q[j][r[j]])>slope(j,q[j][r[j]],i))r[j]--;
			q[j][++r[j]]=i;
		}
	}
	printf("%lld\n",dp[p][m]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#define maxn 50010
using namespace std;
template<typename T>
inline void read(T &x)
{
	int f=1;
	x=0;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	x=x*f;
}
int n,m,p,d[maxn],a[maxn];
int f[110][maxn],q[maxn];
int sum[maxn],s[maxn];
int g[maxn];
int l,r;

int main()
{
	read(n),read(m),read(p);
	memset(f,0x3f,sizeof(f));
	for(int i=2;i<=n;i++)
	{
		int x;
		read(x);
		d[i]=d[i-1]+x;
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		read(x),read(y);
		a[i]=y-d[x];
	}
	sort(a+1,a+m+1);
	for(int i=1;i<=m;i++)
		s[i]=s[i-1]+a[i];//处理每只猫会对应的等待时间
	f[0][0]=0;
	for(int i=1;i<=p;i++)
	{
		for(int j=1;j<=m;j++)
			g[j]=f[i-1][j]+s[j];// 处理y
		l=r=1;
		q[1]=0;
		for(int j=1;j<=m;j++)
		{
			while(l<r&&g[q[l+1]]-g[q[l]]<=a[j]*(q[l+1]-q[l]))
				l++;
			f[i][j]=min(f[i-1][j],g[q[l]]+a[j]*(j-q[l])-s[j]);
			if(g[j]>=0x3f3f3f3f) continue;
			while(l<r&&(g[j]-g[q[r]])*(q[r]-q[r-1])
			<(g[q[r]]-g[q[r-1]])*(j-q[r]))// 满足凸 单调增k
				r--;
			q[++r]=j;
		}
	}
	printf("%d",f[p][m]);
	return 0;
}


#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
inline int getint()
{
	register int r=0,f=1;
	register char c=getchar();
	while (!isdigit(c))
		f=c=='-'?-f:f,c=getchar();
	while (isdigit(c))
		r=(r<<3)+(r<<1)+(c^48),c=getchar();
	return r*f;
}
typedef long long ll;
const int N=1e5+10,M=1e5+10,P=1e3+10;
const ll INF=0x3f3f3f3f3f3f3f3fll;
int n,m,p;
ll d[N],h[M],t[M],sum[M];
ll f[M][2];
int q[N],hd,tl;
double slope(int k1,int k2,bool cur){return (double)((f[k2][cur^1]+sum[k2])-(f[k1][cur^1]+sum[k1]))/(k2-k1);}
int main()
{
	n=getint(),m=getint(),p=getint();
	for (int i=2;i<=n;i++)
		d[i]=d[i-1]+getint();
	for (int i=1;i<=m;i++)
		h[i]=getint(),t[i]=getint()-d[h[i]];
	sort(t+1,t+m+1);
	for (int i=1;i<=m;i++)
		sum[i]=sum[i-1]+t[i];
	memset(f,0x3f,sizeof f),f[0][0]=0;
	for (int j=1,cur=1;j<=p;j++,cur^=1)
	{
		hd=0,tl=1,q[0]=0;
		for (int i=1;i<=m;i++)
		{
			while (hd<tl-1&&t[i]>=slope(q[hd],q[hd+1],cur))
				hd++;
			f[i][cur]=min(f[i][cur^1],f[q[hd]][cur^1]+(i-q[hd])*t[i]-sum[i]+sum[q[hd]]);
			if (f[i][cur^1]+sum[i]>=INF)
				continue;
			while (hd<tl-1&&slope(q[tl-1],i,cur)<=slope(q[tl-2],q[tl-1],cur))
				tl--;
			q[tl++]=i;
		}
	}
	printf("%lld\n",f[m][p&1]);
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
int n,m,p,head[105],tail[105],q[100005][105];LL d[100005],tim[100005],sum[100005],f[100005][105];
inline double calc1(int x,int y,int num){return f[x][num]-f[y][num]+sum[x]-sum[y];}
inline double calc2(int x,int y){return x-y;}
inline LL calc3(int x,int y,int num){return f[x][num]+tim[y]*(y-x)-sum[y]+sum[x];}
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-f;ch=getchar();}
	while(isdigit(ch)) ret=(ret<<1)+(ret<<3)+ch-'0',ch=getchar();
	return ret*f;
}
int main(){
	n=read(),m=read(),p=read();for(register int i=2;i<=n;i++) d[i]=read()+d[i-1];
	for(register int i=1,h,t;i<=m;i++) h=read(),t=read(),tim[i]=t-d[h];
	sort(tim+1,tim+m+1);for(register int i=1;i<=m;i++) sum[i]=tim[i]+sum[i-1];
	for(register int i=0;i<=p;i++) head[i]=1;tail[0]=1;for(register int i=1;i<=m;i++)
	for(register int j=0;j<p;j++){
		while(head[j]<tail[j]&&calc1(q[head[j]][j],q[head[j]+1][j],j)>=tim[i]*calc2(q[head[j]][j],q[head[j]+1][j])) head[j]++;
		f[i][j+1]=calc3(q[head[j]][j],i,j);while(head[j+1]<tail[j+1]&&calc1(q[tail[j+1]-1][j+1],q[tail[j+1]][j+1],j+1)/calc2(q[tail[j+1]-1][j+1],q[tail[j+1]][j+1])>=calc1(q[tail[j+1]][j+1],i,j+1)/calc2(q[tail[j+1]][j+1],i)) tail[j+1]--;q[++tail[j+1]][j+1]=i;
	}
	cout<<f[m][p];
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
template<class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar();
    int f = 1;
    while(!isdigit(ch)) {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}
using namespace std;

const int N = 1e5 + 10;
long long f[110][N], s[N], a[N], d[N], q[N], g[N];
int n, m, p, j, k, l, r;

int main() {
    read(n); read(m); read(p);
    for(int i = 2; i <= n; i ++) {
        read(j);
        d[i] = d[i - 1] + j;
    }
    for(int i = 1; i <= m; i ++) {
        read(j); read(k);
        a[i] = k - d[j];
    }
    sort(a + 1, a + m + 1);
    for(int i = 1; i <= m; i ++)
        s[i] = s[i - 1] + a[i];
    memset(f, 0x3f, sizeof f);
    f[0][0] = 0;
    for(int i = 1; i <= p; i ++) {
        for(int j = 1; j <= m; j ++)
            g[j] = f[i - 1][j] + s[j];
        q[l = r = 1] = 0;
        for(int j = 1; j <= m; j ++) {
            while(l < r && g[q[l + 1]] - g[q[l]] <=
                  a[j] * (q[l + 1] - q[l]))
                l ++;
            f[i][j] = min(f[i - 1][j], g[q[l]] + a[j] * (j - q[l]) - s[j]);
            if(g[j] >= 0x3f3f3f3f3f3f3f3fll) continue;
            while(l < r && (g[j] - g[q[r]]) * (q[r] - q[r - 1]) <=
                  (g[q[r]] - g[q[r - 1]]) * (j - q[r]))
                r --;
            q[++ r] = j;
        }
    }
    printf("%lld\n", f[p][m]);
    return 0;
}


#ifdef ONLINE_JUDGE
    #pragma GCC optimize(2)
    #pragma GCC optimize(3)
    #pragma GCC target("avx")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("inline")
    #pragma GCC optimize("-fgcse")
    #pragma GCC optimize("-fgcse-lm")
    #pragma GCC optimize("-fipa-sra")
    #pragma GCC optimize("-ftree-pre")
    #pragma GCC optimize("-ftree-vrp")
    #pragma GCC optimize("-fpeephole2")
    #pragma GCC optimize("-ffast-math")
    #pragma GCC optimize("-fsched-spec")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("-falign-jumps")
    #pragma GCC optimize("-falign-loops")
    #pragma GCC optimize("-falign-labels")
    #pragma GCC optimize("-fdevirtualize")
    #pragma GCC optimize("-fcaller-saves")
    #pragma GCC optimize("-fcrossjumping")
    #pragma GCC optimize("-fthread-jumps")
    #pragma GCC optimize("-funroll-loops")
    #pragma GCC optimize("-fwhole-program")
    #pragma GCC optimize("-freorder-blocks")
    #pragma GCC optimize("-fschedule-insns")
    #pragma GCC optimize("inline-functions")
    #pragma GCC optimize("-ftree-tail-merge")
    #pragma GCC optimize("-fschedule-insns2")
    #pragma GCC optimize("-fstrict-aliasing")
    #pragma GCC optimize("-fstrict-overflow")
    #pragma GCC optimize("-falign-functions")
    #pragma GCC optimize("-fcse-skip-blocks")
    #pragma GCC optimize("-fcse-follow-jumps")
    #pragma GCC optimize("-fsched-interblock")
    #pragma GCC optimize("-fpartial-inlining")
    #pragma GCC optimize("no-stack-protector")
    #pragma GCC optimize("-freorder-functions")
    #pragma GCC optimize("-findirect-inlining")
    #pragma GCC optimize("-fhoist-adjacent-loads")
    #pragma GCC optimize("-frerun-cse-after-loop")
    #pragma GCC optimize("inline-small-functions")
    #pragma GCC optimize("-finline-small-functions")
    #pragma GCC optimize("-ftree-switch-conversion")
    #pragma GCC optimize("-foptimize-sibling-calls")
    #pragma GCC optimize("-fexpensive-optimizations")
    #pragma GCC optimize("-funsafe-loop-optimizations")
    #pragma GCC optimize("inline-functions-called-once")
    #pragma GCC optimize("-fdelete-null-pointer-checks")
#endif
#ifdef DEBUG
    // #undef DEBUG
#endif
#ifndef DEBUG
    #define NDEBUG
#endif
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
#define itn int
#define scnaf scanf
#define pritnf printf
#define szieof sizeof
#ifdef DEBUG
    #define debug(...) (\
        fprintf (stderr, "debug in %d:", __LINE__),\
        fprintf (stderr, __VA_ARGS__),\
        fprintf (stderr, "\n")\
    )
#else
    #define debug(...)
#endif
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#ifdef ONLINE_JUDGE
    char __BUF[1 << 21];
    char *__P1 = __BUF;
    char *__P2 = __BUF;
    #define getchar() (__P1 == __P2 && (__P2 = (__P1 = __BUF) + fread (__BUF, 1, 1 << 21, stdin), __P1 == __P2) ? EOF : *__P1++)
#endif
namespace mystl {
    template<typename T>
    inline bool rei (T &x) {
        register bool f = false;
        register int ch;
        for (ch = getchar (); !isdigit (ch); ch = getchar ()) {
            if (ch == '-') {
                f = true;
            }
        }
        for (x = 0; isdigit (ch); ch = getchar ()) {
            x = (x << 3) + (x << 1) + (ch & 15);
        }
        if (ch == EOF) {
            return false;
        }
        if (f) {
            x = -x;
        }
        return true;
    }
    #if __cplusplus >= 201103L
        template<typename T, typename... Args>
        inline bool rei (T& x, Args&... args) {
            if (!rei (x)) {
                return false;
            }
            return rei (args...);
        }
    #endif
    template<typename T, long long MIN, size_t SIZE>
    class arr {
        public:
            T a[SIZE];
            operator T* () {
                return a - MIN;
            }
            inline void memset (const int &x) {
                ::memset (a, x, sizeof a);
            }
    };
}
using namespace std;
using namespace mystl;
#define int LL
const int MAXN = 100005;
const int MAXM = 100005;
const int MAXP = 105;
const int MAXT = 1000000005;
int n, m, p;
int d[MAXN];
int t[MAXM];
int s[MAXM];
int f[MAXP][MAXM];
//f[i-1][k]+s[k] = t[j] * k + f[i][j]-t[j]*j
//-------------    ---    -   --------------
//            y  =   k  * x + b
signed main () {
    rei (n);
    rei (m);
    rei (p);
    for (register int i = 2; i <= n; ++i) {
        rei (d[i]);
        d[i] += d[i - 1];
    }
    for (register int h, i = 1; i <= m; ++i) {
        rei (h);
        rei (t[i]);
        t[i] -= d[h];
    }
    sort (t + 1, t + m + 1);
    for (register int i = 1; i <= m; ++i) {
        s[i] = s[i - 1] + t[i];
    }
    memset (f, 0x3f, sizeof f);
    **f = 0;
    for (register int i = 1; i <= p; ++i) {
        #define y(j) (f[i - 1][j] + s[j])
        list<int> q;
        for (register int j = 1; j <= m; ++j) {
            while (!q.empty () && y (*++q.begin ()) - y (*q.begin ()) <= t[j] * (*++q.begin () - *q.begin ())) {
                q.pop_front ();
            }
            f[i][j] = min (f[i - 1][j], y (q.front ()) + t[j] * (j - q.front ()) - s[j]);
            if (y (j) >= 0x3f3f3f3f3f3f3f3fLL) {
                continue;
            }
            while (!q.empty () && (y (j) - y (q.back ())) * (q.back () - *++q.rbegin ()) <= y (q.back ()) - y (*++q.rbegin ()) * (j - q.back ())) {
                q.pop_back ();
            }
            q.push_back (j);
        }
        #undef y
    }
    printf ("%lld\n", f[p][m]);
    return 0;
}