#include<bits/stdc++.h>

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
struct node { int to, nxt, w; } g[N << 1];
int lst[N], gl, w[N];
void add(int z, int y, int x) {
	g[++gl] = (node) {y, lst[x], z}; lst[x] = gl;
	g[++gl] = (node) {x, lst[y], z}; lst[y] = gl;
}
int ans1;
long double ans2;
int siz[N], mx, rt, sum;
bool vis[N];
void getroot(int u, int ff) {
	siz[u] = 1;
	int s = 0;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff || vis[v]) continue;
		getroot(v, u); siz[u] += siz[v];
		s = max(s, siz[v]);
	}
	s = max(s, sum - siz[u]);
	if (s < mx) mx = s, rt = u;
}
long double sd[N], sumd, ans;
void dfs(int u, int ff, int tp, int dep) {
	ans += sqrt(dep) * dep * w[u];
	sumd += 1.5 * sqrt(dep) * w[u];
	sd[tp] += 1.5 * sqrt(dep) * w[u];
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u, tp, dep + g[i].w);
	}
}

void solve(int u) {
	vis[u] = 1; ans = sumd = 0;
	for (int i = lst[u]; i; i = g[i].nxt)
		sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);
	if (ans2 > ans) ans1 = u, ans2 = ans;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (vis[v]) continue;
		if (sumd - sd[v] < sd[v]) continue;
		mx = sum = siz[v]; getroot(v, u); solve(rt);
	}
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= n; i++) w[i] = gi<int>();
	for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());
	ans2 = 1e18;
	mx = sum = n; getroot(1, 0); solve(rt);
	printf("%d %.10Lf\n", ans1, ans2);
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register
#define double long double

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
struct node { int to, nxt, w; } g[N << 1];
int lst[N], gl, w[N];
void add(int z, int y, int x) {
	g[++gl] = (node) {y, lst[x], z}; lst[x] = gl;
	g[++gl] = (node) {x, lst[y], z}; lst[y] = gl;
}
int ans1; double ans2;
int siz[N], mx, rt, sum;
bool vis[N];
void getroot(int u, int ff) {
	siz[u] = 1;
	int s = 0;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff || vis[v]) continue;
		getroot(v, u); siz[u] += siz[v];
		s = max(s, siz[v]);
	}
	s = max(s, sum - siz[u]);
	if (s < mx) mx = s, rt = u;
}
double sd[N], sumd, ans;
void dfs(int u, int ff, int tp, int dep) {
	ans += pow(dep, 1.5) * w[u];
	sumd += 1.5 * sqrt(dep) * w[u];
	sd[tp] += 1.5 * sqrt(dep) * w[u];
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u, tp, dep + g[i].w);
	}
}

void solve(int u) {
	vis[u] = 1; ans = sumd = 0;
	for (int i = lst[u]; i; i = g[i].nxt)
		sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);
	if (ans2 > ans) ans1 = u, ans2 = ans;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (vis[v]) continue;
		if (sumd - sd[v] > sd[v]) continue;
		mx = sum = siz[v]; getroot(v, u); solve(rt);
	}
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= n; i++) w[i] = gi<int>();
	for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());
	ans2 = 1e18;
	mx = sum = n; getroot(1, 0); solve(rt);
	printf("%d %.10Lf\n", ans1, ans2);
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register
using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
struct node { int to, nxt, w; } g[N << 1];
int lst[N], gl, w[N];
void add(int z, int y, int x) {
	g[++gl] = (node) {y, lst[x], z}; lst[x] = gl;
	g[++gl] = (node) {x, lst[y], z}; lst[y] = gl;
}
int ans1;
double ans2;
int siz[N], mx, rt, sum;
bool vis[N];
void getroot(int u, int ff) {
	siz[u] = 1;
	int s = 0;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff || vis[v]) continue;
		getroot(v, u); siz[u] += siz[v];
		s = max(s, siz[v]);
	}
	s = max(s, sum - siz[u]);
	if (s < mx) mx = s, rt = u;
}
double sd[N], sumd, ans;
void dfs(int u, int ff, int tp, int dep) {
	ans += pow(dep, 1.5) * w[u];
	sumd += 1.5 * sqrt(dep) * w[u];
	sd[tp] += 1.5 * sqrt(dep) * w[u];
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u, tp, dep + g[i].w);
	}
}

void solve(int u) {
	vis[u] = 1; ans = sumd = 0;
	for (int i = lst[u]; i; i = g[i].nxt)
		sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);
	if (ans2 > ans) ans1 = u, ans2 = ans;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (vis[v]) continue;
		if (sumd - sd[v] > sd[v]) continue;
		mx = sum = siz[v]; getroot(v, u); solve(rt);
	}
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= n; i++) w[i] = gi<int>();
	for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());
	ans2 = 1e20;
	mx = sum = n; getroot(1, 0); solve(rt);
	printf("%d %.10lf\n", ans1, ans2);
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register
#define double long double

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
struct node { int to, nxt, w; } g[N << 1];
int lst[N], gl, w[N];
void add(int z, int y, int x) {
	g[++gl] = (node) {y, lst[x], z}; lst[x] = gl;
	g[++gl] = (node) {x, lst[y], z}; lst[y] = gl;
}
int ans1; double ans2;
int siz[N], mx, rt, sum;
bool vis[N];
void getroot(int u, int ff) {
	siz[u] = 1;
	int s = 0;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff || vis[v]) continue;
		getroot(v, u); siz[u] += siz[v];
		s = max(s, siz[v]);
	}
	s = max(s, sum - siz[u]);
	if (s < mx) mx = s, rt = u;
}
double sd[N], sumd, ans;
void dfs(int u, int ff, int tp, int dep) {
	ans += pow(dep, 1.5) * w[u];
	sumd += 1.5 * sqrt(dep) * w[u];
	sd[tp] += 1.5 * sqrt(dep) * w[u];
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u, tp, dep + g[i].w);
	}
}

void solve(int u) {
	vis[u] = 1; ans = sumd = 0;
	for (int i = lst[u]; i; i = g[i].nxt)
		sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);
	if (ans2 > ans) ans1 = u, ans2 = ans;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (vis[v]) continue;
		if (sumd - sd[v] < sd[v]) continue;
		mx = sum = siz[v]; getroot(v, u); solve(rt);
	}
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= n; i++) w[i] = gi<int>();
	for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());
	ans2 = 1e18;
	mx = sum = n; getroot(1, 0); solve(rt);
	printf("%d %.10Lf\n", ans1, ans2);
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
struct node { int to, nxt, w; } g[N << 1];
int lst[N], gl, w[N];
void add(int z, int y, int x) {
	g[++gl] = (node) {y, lst[x], z}; lst[x] = gl;
	g[++gl] = (node) {x, lst[y], z}; lst[y] = gl;
}
int ans1; double ans2;
int siz[N], mx, rt, sum;
bool vis[N];
void getroot(int u, int ff) {
	siz[u] = 1;
	int s = 0;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff || vis[v]) continue;
		getroot(v, u); siz[u] += siz[v];
		s = max(s, siz[v]);
	}
	s = max(s, sum - siz[u]);
	if (s < mx) mx = s, rt = u;
}
double sd[N], sumd, ans;
void dfs(int u, int ff, int tp, int dep) {
	ans += pow(dep, 1.5) * w[u];
	sumd += 1.5 * sqrt(dep) * w[u];
	sd[tp] += 1.5 * sqrt(dep) * w[u];
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u, tp, dep + g[i].w);
	}
}

void solve(int u) {
	vis[u] = 1; ans = sumd = 0;
	for (int i = lst[u]; i; i = g[i].nxt)
		sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);
	if (ans2 > ans) ans1 = u, ans2 = ans;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (vis[v]) continue;
		if (sumd - sd[v] < sd[v]) continue;
		mx = sum = siz[v]; getroot(v, u); solve(rt);
	}
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= n; i++) w[i] = gi<int>();
	for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());
	ans2 = 1e18;
	mx = sum = n; getroot(1, 0); solve(rt);
	printf("%d %.10lf\n", ans1, ans2);
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register
using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
struct node { int to, nxt, w; } g[N << 1];
int lst[N], gl, w[N];
void add(int z, int y, int x) {
	g[++gl] = (node) {y, lst[x], z}; lst[x] = gl;
	g[++gl] = (node) {x, lst[y], z}; lst[y] = gl;
}
int ans1;
double ans2;
int siz[N], mx, rt, sum;
bool vis[N];
void getroot(int u, int ff) {
	siz[u] = 1;
	int s = 0;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff || vis[v]) continue;
		getroot(v, u); siz[u] += siz[v];
		s = max(s, siz[v]);
	}
	s = max(s, sum - siz[u]);
	if (s < mx) mx = s, rt = u;
}
double sd[N], sumd, ans;
void dfs(int u, int ff, int tp, double dep) {
	ans += sqrt(dep) * dep * w[u];
	sumd += 1.5 * sqrt(dep) * w[u];
	sd[tp] += 1.5 * sqrt(dep) * w[u];
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u, tp, dep + g[i].w);
	}
}

void solve(int u) {
	vis[u] = 1; ans = sumd = 0;
	for (int i = lst[u]; i; i = g[i].nxt)
		sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);
	if (ans2 > ans) ans1 = u, ans2 = ans;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (vis[v]) continue;
		if (sumd - sd[v] > sd[v]) continue;
		mx = sum = siz[v]; getroot(v, u); solve(rt);
	}
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= n; i++) w[i] = gi<int>();
	for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());
	ans2 = 1e20;
	mx = sum = n; getroot(1, 0); solve(rt);
	printf("%d %.10lf\n", ans1, ans2);
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
struct node { int to, nxt, w; } g[N << 1];
int lst[N], gl, w[N];
void add(int z, int y, int x) {
	g[++gl] = (node) {y, lst[x], z}; lst[x] = gl;
	g[++gl] = (node) {x, lst[y], z}; lst[y] = gl;
}
int ans1;
double ans2;
int siz[N], mx, rt, sum;
bool vis[N];
void getroot(int u, int ff) {
	siz[u] = 1;
	int s = 0;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff || vis[v]) continue;
		getroot(v, u); siz[u] += siz[v];
		s = max(s, siz[v]);
	}
	s = max(s, sum - siz[u]);
	if (s < mx) mx = s, rt = u;
}
double sd[N], sumd, ans;
void dfs(int u, int ff, int tp, double dep) {
	ans += sqrt(dep) * dep * w[u];
	sumd += 1.5 * sqrt(dep) * w[u];
	sd[tp] += 1.5 * sqrt(dep) * w[u];
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u, tp, dep + g[i].w);
	}
}

void solve(int u) {
	vis[u] = 1; ans = sumd = 0;
	for (int i = lst[u]; i; i = g[i].nxt)
		sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);
	if (ans2 > ans) ans1 = u, ans2 = ans;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (vis[v]) continue;
		if (sumd - sd[v] < sd[v]) continue;
		mx = sum = siz[v]; getroot(v, u); solve(rt);
	}
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= n; i++) w[i] = gi<int>();
	for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());
	ans2 = 1e20;
	mx = sum = n; getroot(1, 0); solve(rt);
	printf("%d %.10lf\n", ans1, ans2);
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 2e5 + 10;
struct node { int to, nxt, w; } g[N << 1];
int lst[N], gl, w[N];
void add(int z, int y, int x) {
	g[++gl] = (node) {y, lst[x], z}; lst[x] = gl;
	g[++gl] = (node) {x, lst[y], z}; lst[y] = gl;
}
int ans1;
long double ans2;
int siz[N], mx, rt, sum;
bool vis[N];
void getroot(int u, int ff) {
	siz[u] = 1;
	int s = 0;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff || vis[v]) continue;
		getroot(v, u); siz[u] += siz[v];
		s = max(s, siz[v]);
	}
	s = max(s, sum - siz[u]);
	if (s < mx) mx = s, rt = u;
}
long double sd[N], sumd, ans;
void dfs(int u, int ff, int tp, long double dep) {
	ans += sqrt(dep) * dep * w[u];
	sumd += 1.5 * sqrt(dep) * w[u];
	sd[tp] += 1.5 * sqrt(dep) * w[u];
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u, tp, dep + g[i].w);
	}
}

void solve(int u) {
	vis[u] = 1; ans = sumd = 0;
	for (int i = lst[u]; i; i = g[i].nxt)
		sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);
	if (ans2 > ans) ans1 = u, ans2 = ans;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (vis[v]) continue;
		if (sumd - sd[v] < sd[v]) continue;
		mx = sum = siz[v]; getroot(v, u); solve(rt);
	}
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= n; i++) w[i] = gi<int>();
	for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());
	ans2 = 1e20;
	mx = sum = n; getroot(1, 0); solve(rt);
	printf("%d %.10Lf\n", ans1, ans2);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=200000 +117;
const int MM=100000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}

int m,n;
struct node{
	int len,to;
};
LL v[NN]={};
LL dep[NN]={};
LD d[NN]={};
LD res[NN]={};
vector<node> p[NN];
int rt;
int siz[NN]={};
int all=0;
bool fl[NN]={};
LD ans=0;
int pos=0;
void getrt(int x){
	fl[x]=1;
	siz[x]=1;
	bool ok=1;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i].to;
		if(!fl[cur]){
			getrt(cur);
			siz[x]+=siz[cur];
			if(siz[cur]>all/2)ok=0;
		}
	}
	if(all-siz[x]<=all/2&&ok)rt=x;
}
void getd(int x,int fa){
	d[x]=pow(dep[x],0.5)*v[x];
	res[x]=pow(dep[x],1.5)*v[x];
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i].to;
		if(cur!=fa){
			dep[cur]=dep[x]+p[x][i].len;
			getd(cur,x);
			d[x]+=d[cur];
			res[x]+=res[cur];
		}
	}
}
void dfs(int x){
	dep[x]=0;
	getd(x,0);
	fl[x]=1;
	if(ans>res[x])ans=res[x],pos=x;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i].to;
		if(!fl[cur]){
			if(d[x]-d[cur]<d[cur]){
				all=siz[cur];
				getrt(cur);
				dfs(rt);
				break;
			}
		}
	}
}
int main(){
	//open();
	n=read();
	ans=1e200;
	for(int i=1;i<=n;++i)v[i]=read();
	for(int i=1;i<n;++i){
		int x=read(),y=read();
		node tp;
		tp.len=read();
		tp.to=y;
		p[x].push_back(tp);
		tp.to=x;
		p[y].push_back(tp);
	}
	all=n;
	getrt(1);
	dfs(rt);
	printf("%d %.8lf\n",pos,(double)ans);
	close();
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=200000 +117;
const int MM=100000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}

int m,n;
struct node{
	int len,to;
};
LL v[NN]={};
LL dep[NN]={};
LD d[NN]={};
LD res[NN]={};
vector<node> p[NN];
int rt;
int siz[NN]={};
int all=0;
bool fl[NN]={};
LD ans=0;
int pos=0;
void getrt(int x){
	fl[x]=1;
	siz[x]=1;
	bool ok=1;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i].to;
		if(!fl[cur]){
			getrt(cur);
			siz[x]+=siz[cur];
			if(siz[cur]>all/2)ok=0;
		}
	}
	if(all-siz[x]<=all/2&&ok)rt=x;
}
void getd(int x,int fa){
	d[x]=pow(dep[x],0.5)*v[x];
	res[x]=pow(dep[x],1.5)*v[x];
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i].to;
		if(cur!=fa){
			dep[cur]=dep[x]+p[x][i].len;
			getd(cur,x);
			d[x]+=d[cur];
			res[x]+=res[cur];
		}
	}
}
void dfs(int x){
	dep[x]=0;
	getd(x,0);
	fl[x]=1;
	if(ans>res[x])ans=res[x],pos=x;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i].to;
		if(!fl[cur]){
			if(d[x]-d[cur]<d[cur]){
				all=siz[cur];
				getrt(cur);
				dfs(rt);
				break;
			}
		}
	}
}
int main(){
	//open();
	n=read();
	ans=1e200;
	for(int i=1;i<=n;++i)v[i]=read();
	for(int i=1;i<n;++i){
		int x=read(),y=read();
		node tp;
		tp.len=read();
		tp.to=y;
		p[x].push_back(tp);
		tp.to=x;
		p[y].push_back(tp);
	}
	all=n;
	getrt(1);
	dfs(rt);
	printf("%d %.8Lf\n",pos,ans);
	close();
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int i,n,a[1010],maxa=0,maxa2=0,cnt;
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>a[i];
    maxa=maxa2=a[1];
    for (i=1;i<=n;i++)
    {
        if (a[i]>maxa)
            cnt=i,maxa=a[i];
        else if (a[i]>maxa2) maxa2=a[i];
    }
    cout<<cnt<<' '<<maxa2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[10000],max=-1,k;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]>max) max=a[i];
		k=i;
	}
	cout<<k+1<<" ";
	sort(a,a+n);
	cout<<a[n-2];
}


#include<iostream>
#include<cstdio>
#include<queue>
#define N 1010
using namespace std;

int n,num[N],mx,ans,pos;

int main()
{
	int i,j,p;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&num[i]);
		if(num[i]>mx)
		{
			ans=mx;
			mx=num[i];
			pos=i;
		}
		else ans=max(ans,num[i]);
	}
	cout<<pos<<" "<<ans;
}


#include<iostream>
using namespace std;
int main()
{
    int i,n,a[1010],maxa=0,maxa2=0;
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>a[i];
    for (i=1;i<=n;i++)
    {
        if (a[i]>maxa)
            cnt=i,maxa=a[i];
        else if (a[i]>maxa2) maxa2=a[i];
    }
    cout<<cnt<<maxa2<<endl
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[10000],max,k;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]; max=a[0];
        if(a[i]>max){ max=a[i];
        k=i;}
    }
    cout<<k+1<<" ";
    sort(a,a+n);
    cout<<a[n-2];
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int b[n];
	for(int i=0;i<n;i++) b[i]=a[i];
	sort(a,a+n);
	int sec=a[n-2];
	for(int i=0;i<n;i++){
	   if(a[n-1]==b[i])
	   cout<<i+1<<" ";
    }
    cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
    int pi,t;
}p[1010];
bool cmp(const node &a,const node &b){
    return a.pi>b.pi;
}
int main(){
    int i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&p[i].pi);
        p[i].t=i+1;
    }
    sort(p,p+n,cmp);
    printf("%d %d\n",p[0].t,p[1].pi);
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    long long a[1000], n, i, z;
    cin>>n;
    z = 1;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>a[0])
            z=i;
    }
    sort(a,a+n);
    cout<<z+1<<" "<<a[n-2];
}


#include <iostream>
using namespace std;
int main()
{
    long long  n, i, j, m, t, c;
    cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    m = a[0];
    for(i=1;i<n;i++)
    {
        for(j=0;j<=i;j++)
        {
            if(a[i]>a[j])
            {
                if(a[i]>a[0])
                    c = i;
               m = a[i];
               for(t=i-1;t>=j;t--)
               {
                   a[t+1] = a[t];
               }
               a[j] = m;
               j = i;
            }
        }
    }
    cout<<c<<" "<<a[1];
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    long long a[1000], n, i, z;
    cin>>n;
    z = 1;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>a[z])
            z=i;
    }
    sort(a,a+n);
    cout<<z+1<<" "<<a[n-2];
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int cmp(int a,int b)
{
    return a>b;
}
int main(int argc, char const *argv[])
{
    int n;

    while(~scanf("%d", &n))
    {
        int a[n+1];
        int maxx=0;
        int ans;
        for (int i = 0; i < n; ++i)
        {
            scanf("%d", a+i);
            if(a[i]>maxx) {maxx=a[i];ans=i+1;}
        }
        sort(a,a+n,cmp);
        printf("%d %d\n",ans,a[1] );
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
struct pe
{
	int id;
	int money;
}ken[1001];
bool cmp(pe a,pe b)
{
	return a.money>b.money;
 }
int main()
{
	int i,j;
	int n;
	while(cin>>n)
	{
		for(i=0;i<n;i++)
		{
			cin>>ken[i].money;
			ken[i].id=i+1;
		}
		sort(ken,ken+n,cmp);
		cout<<ken[0].id<<' '<<ken[1].money<<endl;
	}
 }


#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct Competitor
{
	int index;
	int price;
};
bool cmp(Competitor a,Competitor b)
{
	return a.price >= b.price;
}
int main()
{
	int n;
	cin>>n;
	vector<Competitor> prices(n);
	for (int i = 0; i < n; i++)
	{
		cin>>prices[i].price;
		prices[i].index = i+1;
	}
	sort(prices.begin(),prices.end(),cmp);
	cout<<prices[0].index<<" "<<prices[1].price<<endl;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
#define f0(i,n) for (int i=0; i<n; i++)
int main()
{
	int n,t,index=0,price=0,max=-1;
	cin>>n;
	vector<int> prices(n);
	f0(i,n)
	{
		cin>>t;
		prices[i]=t;
		if(t>max)
		{
			index=i+1;
			max = t;
		}
	}
	int maxprice = prices[index-1],dif=10001;
	f0(i,n)
	{
		if(index!=i+1 && maxprice-prices[i]<dif)
		{
			dif=maxprice-prices[i];
			price = prices[i];
		}
	}
	cout<<index<<" "<<price<<endl;
	return 0;
}

/*
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;

#define long long long
#define f1(i,n) for (int i=1; i<=n; i++)
#define f0(i,n) for (int i=0; i<n; i++)

#define N 100005
int n, a[N], Index[N];

bool cmp(int x, int y){
return a[x]>a[y];
}

main(){
scanf("%d", &n);
f1(i,n) scanf("%d", &a[i]);
f1(i,n) Index[i]=i;
sort(Index+1, Index+n+1, cmp);
cout << Index[1] << " " << a[Index[2]] << endl;
}
*/


#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

int main()
{
    long long a;
    cin>>a;
    int b[a];
    int i=0;
    long long temp,nomber;
    while(i<a)
    {
        cin>>b[i];

        i++;
    }
    temp=b[0];
    nomber=0;
    i=1;
    while (i<a)
    {
        if(b[i]>temp)nomber=i;
        temp=b[i];
        i++;
    }
    nomber--;
    sort(b,b+a);
    cout<<nomber<<' '<<b[a-2];
}


#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

int main()
{
    long long a;
    cin>>a;
    int b[a];
    int i=0;
    int temp,nomber;
    while(i<a)
    {
        cin>>b[i];

        i++;
    }
    temp=b[0];
    nomber=0;
    i=1;
    while (i<a)
    {
        if(b[i]>temp){nomber=i;temp=b[i];}

        i++;
    }
    nomber++;
    sort(b,b+a);
    cout<<nomber<<' '<<b[a-2]<<endl<<endl;

}


#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

int main()
{
    long long a;
    cin>>a;
    int b[a];
    int i=0;
    long long temp,nomber;
    while(i<a)
    {
        cin>>b[i];

        i++;
    }
    temp=b[0];
    nomber=0;
    i=1;
    while (i<a)
    {
        if(b[i]>temp)nomber=i;
        temp=b[i];
        i++;
    }
    nomber++;
    sort(b,b+a);
    cout<<nomber<<' '<<b[a-2];
}


#include <iostream>
using namespace std;
int a[10000];
int main()
{
    int t; cin >> t;
    int m = -1,y=0,o=0;
    for (int i = 0; i < t; i++)
    {
        cin >> a[i];
        if (a[i]>m)
        {
            y = m;
            m = a[i];
            o = i+1;
        }
    }
    cout << o << " " << y << endl;
    int w; cin >> w;
    return 0;
}


#include <iostream>
using namespace std;
int a[10000];
int main()
{
    int t; cin >> t;
    int m = -1,y=0,o=0,p=-1;
    for (int i = 0; i < t; i++)
    {
        cin >> a[i];
        if (a[i]>m)
        {
            m = a[i];
            o = i+1;
        }
    }
    for (int i = 0; i < t; i++)
    {
        if (a[i]==m)
        {
             a[i]=0;
        }
    }
    for (int i = 0; i < t; i++)
    {
        if (a[i]> p)
        {
            p=a[i];
        }
    }
    cout << o << " " << p << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,x,Ms=-1e9,Mx,Sx;
  scanf("%d",&n);
  for (register int i=1; i<=n; i++)
    {
      scanf("%d",&x);
      if (x>Ms)
        {
          Mx=i; Sx=Ms; Ms=x;
        }
      if (x>Sx && x<Ms) Sx=x;
    }
  printf("%d %d",Mx,Sx);
  return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[1001],b[1001];
    scanf("%d\n",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d\n",&a[i]);
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++)
    {
        if(a[i]==b[n-1]){printf("%d ",i+1);break;}
    }
    printf("%d\n",b[n-2]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int *a=new int[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int maxn=1,max2nd=1;
    for(int i=1;i<=n;i++){
        if(a[i]>=a[maxn]){
            maxn=i;
            max2nd=maxn;
        }else if(a[i]>a[max2nd]){
            max2nd=i;
        }
    }
    cout<<maxn<<" "<<a[max2nd];
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,a[10001],k,maxn;
    cin>>n;
    for(i=1;i<=n;i++)
    {
	cin>>a[i];
    }
        maxn=a[1];
        k=1;
        for(i=2;i<=n;i++)
        if(a[i]>maxn)
		{
            maxn=a[i];
            k=i;
        }
        cout<<k<<" ";
    sort(a+1,a+n+1);
    cout<<a[n-1]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define ME 0x7f
#define FO(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout)
#define fui(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define fdi(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define fel(i,a) for(register int i=h[a];i;i=ne[i])
#define ll long long
#define MEM(a,b) memset(a,b,sizeof(a))
int n;
ll a[2000];
int ma;
template<class T>
inline T read(T &n){
	n=0;int t=1;double x=10;char ch;
	for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());(ch=='-')?t=-1:n=ch-'0';
	for(ch=getchar();isdigit(ch);ch=getchar()) n=n*10+ch-'0';
	if(ch=='.') for(ch=getchar();isdigit(ch);ch=getchar()) n+=(ch-'0')/x,x*=10;
	return (n*=t);
}
template<class T>
T write(T n){
	if(n<0) putchar('-'),n=-n;
	if(n>=10) write(n/10);putchar(n%10+'0');return n;
}
template<class T>
T writeln(T n){write(n);putchar('\n');return n;}
int main(){
	read(n);
	fui(i,1,n,1) read(a[i]);
	ma=1;fui(i,1,n,1)if(a[i]>a[ma]) ma=i;
	int p=1;
	fui(i,1,n,1)if(a[i]>p&&ma!=i) p=a[i];
	cout<<ma<<' '<<p<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x[100001],y[100001];
int main()
{
  int n,t;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>x[i];
    y[i]=i;
  }
  for(int i=1;i<=n;i++){
     for(int j=i;j<=n;j++){
       if(x[i]<x[j])
       {
          swap(x[i],x[j]);
          swap(y[i],y[j]);
       }
   }
}
  cout<<y[1]<<" "<<x[2];
  return 0;
}


#include<bits/stdc++.h>
#define zhh 1005
#define ll long long
using namespace std;
ll a[zhh];
ll n,ans,b;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main(){
	n=read();
	fu(i,1,n){
		a[i]=read();
		if(a[i]>ans){
			ans=a[i];
			b=i;
		}
	}
	sort(a+1,a+n+1);
	cout<<b<<" "<<a[2];
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[10007];
int b;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b=1;
        if(a[i]>a[i-1]&&i>=2)
            b=i;
    }
    sort(a+1,a+1+n);
    cout<<b<<" "<<a[n-1]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct A{
	int id, val;
}a[1005];
int cmp(A x, A y){
	return x.val > y.val;
}
int n;
int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n ; i ++) scanf("%d", &a[i].val), a[i].id = i;
	sort(a + 1, a + 1 + n, cmp);
	printf("%d %d",a[1].id, a[2].val);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int i,n,a[1010],maxa=0,maxa2=0,cnt;
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>a[i];
    for (i=1;i<=n;i++)
    {
        if (a[i]>maxa)
            cnt=i,maxa=a[i];
        else if (a[i]>maxa2) maxa2=a[i];
    }
    cout<<cnt<<' '<<maxa2<<endl
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[10000],max,k;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]; max=a[0];
		if(a[i]>max) max=a[i];
		k=i;
	}
	cout<<k+1<<" ";
	sort(a,a+n);
	cout<<a[n-2];
}


#include <iostream>

using namespace std;

int main()
{
    int x[100],n,t,l=1;
    cin>>n;
    for (int i=0;i<n;i++){

        cin>>x[i];
}
t=x[0];

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

        if (x[i]>t){t=x[i];l=i+1;}

}

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

        for (int j=i+1;j<n;j++){
            if (x[i]<x[j]){swap(x[i],x[j]);}
        }
}

cout<<l<<"\t"<<x[1];

}


#include <iostream>

using namespace std;

int main()
{
    int x[100],n,t,l;
    cin>>n;
    for (int i=0;i<n;i++){

        cin>>x[i];
}
t=x[0];

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

        if (x[i]>t){t=x[i];l=i+1;}
}

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

        for (int j=i+1;j<n;j++){
            if (x[i]<x[j]){swap(x[i],x[j]);}
        }
}

cout<<l<<"\t"<<x[1];

}


#include <iostream>

using namespace std;

int main()
{
    int x[100],n,t,l;
    cin>>n;
    for (int i=0;i<n;i++){

        cin>>x[i];

    }
t=x[0];

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

        if (x[i]>t){t=x[i];}
}

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

        if (x[i]==t){l=i+1;break;}
}

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

        for (int j=i+1;j<n;j++){
            if (x[i]<x[j]){swap(x[i],x[j]);}
        }
}

cout<<l<<"\t"<<x[1];

}


#include <iostream>

using namespace std;

int main()
{
    int n,t,l=1;
    cin>>n;
    int x[n-1];
    for (int i=0;i<n;i++){

        cin>>x[i];
}
t=x[0];

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

        if (x[i]>t){t=x[i];l=i+1;}

}

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

        for (int j=i+1;j<n;j++){
            if (x[i]<x[j]){swap(x[i],x[j]);}
        }
}

cout<<l<<"\t"<<x[1];

}


#include <iostream>
using namespace std;

int main () {
	string s, m, s1;
	cin >> s >> m;
	s1=s;
	for(int i=0; i<s.size(); i++) {
		if(s[i]==m[i])
			s1[i]='0';
		else
			s1[i]='1';
	}
	cout << s1;
	return 0;
}


#include <iostream>
using namespace std;

int main () {
	int n;
	cin >> n;
	int a[n+1];
	int c=1;
	cin >> a[0];
	int maxi=a[0], maxi2=a[0];
	for(int i=1; i<n; i++) {
		 cin >> a[i];
		 if(a[i] > maxi) {
		 	maxi=a[i];
		 	c=i+1;
		 }
	}

		if(maxi2==maxi)
			maxi2=a[1];
			for(int i=1; i<n; i++) {
				if(a[i]>maxi2 && a[i]!=maxi)
					maxi2=a[i];
			}
	cout <<	c << " " << maxi2;
	return 0;
}


#include <iostream>
using namespace std;

int main () {
	int n;
	cin >> n;
	int a[n];
	int c=1;
	cin >> a[0];
	int maxi=a[0], maxi2=a[0];
	for(int i=1; i<n; i++) {
		 cin >> a[i];
		 if(a[i] > maxi) {
		 	maxi2=maxi;
		 	maxi=a[i];
		 	c=i+1;
		 }
	}
	if(maxi==a[0]) {
		maxi2=a[1];
		for(int i=1; i<n; i++)
			if(a[i]>maxi2)
				maxi2=a[i];
	}
	cout <<	c << " " << maxi2;
	return 0;
}


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

using namespace std;

int main()
{int n,sum;
cin>>n;
int x[n];
   for(int i=0;i<n;i++){
    cin>>x[i];}
   for(int i=0;i<n;i++){
   sum=0;
       for(int j=0;j<n;j++){
        if(x[i]<x[j])
            {sum++; break;}
       }
       if(sum==0){cout<<++i<<" "; break;}
   }
   sort(x,x+n);

for(int i=n-1;i>=0;i--){
    if(x[i]!=x[n-1]){
        cout<<x[i]; return 0;}
}
}


#include <iostream>
#include <maps>
using namespace std;

int main()
{
    int n,s;
    cin>>n;
    int x[n];
    int sum;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){  sum=0;
            if(x[i]<x[j])
            sum++;}
            if(sum==0){
                cout<<i+1<<' '; s=i; break;}

        }

        for(int j=0;j<n;j++){
            for(int l=0;l<n;l++){
                sum=0;
                if(x[j]<x[l]&&l!=s)sum++;}
                if(sum==0&&j!=s){
                    cout<<x[j]; return 0;}
            }
       return 0; }


int main()
{
    int n,s;
    cin>>n;
    int x[n];
    int sum;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){  sum=0;
            if(x[i]<x[j])
            sum++;}
            if(sum==0){
                cout<<i+1<<' '; s=i; break;}

        }

        for(int j=0;j<n;j++){
            for(int l=0;l<n;l++){
                sum=0;
                if(x[j]<x[l]&&l!=s&&x[j]<x[l=s])sum++;}
                if(sum==0&&j!=s){
                  cout<<x[j] ; return 0;}
            }
        }


#include <iostream>

using namespace std;

int main()
{
    int n,s;
    cin>>n;
    int x[n];
    int sum;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){  sum=0;
            if(x[i]<x[j])
            sum++;}
            if(sum==0){
                cout<<i+1<<' '; s=i; break;}

        }

        for(int j=0;j<n;j++){
            for(int l=0;l<n;l++){
                sum=0;
                if(x[j]<x[l]&&l!=s)sum++;}
                if(sum==0&&j!=s){
                    cout<<x[j]; return 0;}
            }
        }


#include <iostream>

using namespace std;

int main()
{
    int n,s,sum=0;
cin>>n;
int x[n];

    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){  sum=0;
            if(x[i]<x[j])
            sum++;}
            if(sum==0){
                cout<<i+1<<' '; s=i; break;}

        }

        for(int j=0;j<n;j++){
            for(int l=0;l<n;l++){
                sum=0;
                if(x[j]<x[l]&&l!=s&&x[j]<x[s])sum++;}
                if(sum==0&&j!=s){
                  cout<<x[j] ; return 0;}
            }
            return 0;
        }


#include <iostream>

using namespace std;

int main()
{
    int n,s,sum;
cin>>n;
int x[n];

    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){  sum=0;
            if(x[i]<x[j])
            sum++;}
            if(sum==0){
                cout<<i+1<<' '; s=i; break;}

        }

        for(int j=0;j<n;j++){
            for(int l=0;l<n;l++){
                sum=0;
                if(x[j]<x[l]&&l!=s&&x[j]<x[l=s])sum++;}
                if(sum==0&&j!=s){
                  cout<<x[j] ; return 0;}
            }
            return 0;
        }


#include <iostream>

using namespace std;

int main()
{
    int n,s,sum=0;
    cin>>n;
    int x[n];

    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){  sum=0;
            if(x[i]<x[j])
            sum++;}
            if(sum==0){
                cout<<i+1<<' '; s=i; break;}

        }

        for(int j=0;j<n;j++){sum=0;
        if(j==s)continue;
            for(int l=0;l<n;l++){ if(l==s) continue;
              if(x[j]<x[l])
                {sum++;}
                 }if(sum==0&&j!=s){cout<<x[j];return 0;}

            }
        }


#include <iostream>
#include <maps>
using namespace std;

int main()
{
    int n,s;
    cin>>n;
    int x[n];
    int sum;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){  sum=0;
            if(x[i]<x[j])
            sum++;}
            if(sum==0){
                cout<<i+1<<' '; s=i; break;}

        }

        for(int j=0;j<n;j++){
            for(int l=0;l<n;l++){
                sum=0;
                if(x[j]<x[l]&&l!=s)sum++;}
                if(sum==0&&j!=s){
                    cout<<x[j]; return 0;}
            }
        }


#include <iostream>

using namespace std;

int main()
{
    int n,s,sum=0;
    cin>>n;
    int x[n];

    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){  sum=0;
            if(x[i]<x[j])
            sum++;}
            if(sum==0){
                cout<<i+1<<' '; s=i; break;}

        }

        for(int j=0;j<n;j++){sum=0;
            for(int l=0;l<n;l++){
              if(x[j]>x[l!=s])
                continue;
         else  sum++ ;
                 }if(sum==0){cout<<x[j];return 0;}

            }
        }


#include <iostream>

using namespace std;

int main()
{
    int n,s,sum;
    int x[n];
    cin>>n;

    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){  sum=0;
            if(x[i]<x[j])
            sum++;}
            if(sum==0){
                cout<<i+1<<' '; s=i; break;}

        }

        for(int j=0;j<n;j++){
            for(int l=0;l<n;l++){
                sum=0;
                if(x[j]<x[l]&&l!=s&&x[j]<x[l=s])sum++;}
                if(sum==0&&j!=s){
                  cout<<x[j] ; return 0;}
            }
            return 0;
        }


#include <iostream>
#include <string>
#include<algorithm>
using namespace std;

int main()
{
   long long int n,s=0,j;
   cin>>n;
   int*x=new int[n];
   for(int i=0;i<n;i++)
    cin>>x[i];
   for(int i=0;i<n;i++){
    if(x[i]>s)
        {s=x[i]; j=i;}

    }
    cout<<j+1<<" ";
    sort(x,x+n);
    cout<<x[n-2];
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int mx=0,pos,mx2=0;
int main(int argc, char const *argv[])
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if (x>mx){
			mx2=mx;
			mx=x;
			pos=i;
		}
		else if (x>mx2)
			mx2=x;
	}
	printf("%d %d\n",pos+1,mx2 );
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct point
{
	int x;
	int y;
}a[1000000];
int cmp(point x, point y)
{
	return x.x> y.x;
}
int main()
{
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i].x;
		a[i].y = i;
	}
	sort(a,a+n,cmp);
	printf("%d %d\n", a[0].y+1,a[1].x);
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1000+10;

struct node
{
    int idx, val;
    bool operator <(const node&t)const
    {
        return val>t.val;
    }
}p[maxn];

int main()
{
    int n;
    while(scanf("%d", &n)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d", &p[i].val);
            p[i].idx=i;
        }
        sort(p+1, p+1+n);
        cout<<p[1].idx<<' '<<p[2].val<<endl;
    }
}


#include <utility>
#include <iostream>
#include <algorithm>
const int maxn = 1007;
int n;
std::pair<int, int> arr[maxn];
int main()
{
	std::cin >> n;
	for(int i = 1; i <= n; i ++){
		std::cin >> arr[i].first;
		arr[i].second = i;
	}
	std::sort(arr + 1, arr + n + 1);
	std::cout << arr[n].second << ' ' << arr[n - 1].first << "\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[10000],max,k;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]; max=a[0];
		if(a[i]>max){ max=a[i];
		k=i;}
	}
	cout<<k+1<<" ";
	sort(a,a+n);
	cout<<a[n-2];
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int d=0;
    int j;
    char a[10005];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    d=a[0];
    for(j=1;j<n;j++){
        if(a[j]>a[j-1]){
            d=j;
        }
    }
    cout<<j+1<<" ";
    a[j]=0;
    d=a[0];
    for(j=1;j<n;j++){
        if(a[j]>a[j-1]){
            d=j;
        }
    }
    cout<<a[j]<<endl;
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <queue>
#include <stack>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef long double lld;
typedef vector<int> vi;
#define lowbit(x) (x&-x)
#define fi first
#define se second
#define fin freopen("1.txt","r",stdin);
#define fout freopen("1.txt","w",stdout);
ll mod = 1000000007;
const int maxn = 1000000;

inline int Read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n, m;

struct Node {
	int w, id;
}q[maxn + 5];

bool cmp(Node a, Node b) {
	return a.w < b.w;
}

int main() {
	int n;
	cin >> n;
	n = Read();
	for(int i = 1; i <= n; i++) {
		q[i].w = Read();
		q[i].id = i;
	}
	sort(q + 1, q + n + 1, cmp);
	printf("%d %d\n", q[n].id, q[n - 1].w);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int i,n,a[1010],maxa=0,maxa2=0,cnt=1;
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>a[i];
    maxa=a[1];
    for (i=1;i<=n;i++)
    {
        if (a[i]>maxa)
            cnt=i,maxa2=maxa,maxa=a[i];
    }
    cout<<cnt<<' '<<maxa2<<endl;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int i,n,a[1010],maxa=0,maxa2=0,cnt;
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>a[i];
    for (i=1;i<=n;i++)
    {
        if (a[i]>maxa)
            cnt=i,maxa=a[i];
        else if (a[i]>maxa2) maxa2=a[i];
    }
    cout<<cnt<<maxa2<<endl
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int b[n];
	for(int i=0;i<n;i++) b[i]=a[i];
	sort(a,a+n);
	int sec=a[n-2];
	for(int i=0;i<n;i++){
	   if(a[n-1]==b[i])
	   cout<<i<<" ";
    }
    cout<<sec;
	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
int n;
struct AC{
	int number;
	int use;
}a[1001];
int cmp(AC x,AC y)
{
	return x.use>y.use;
}
int main()
{
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)
		scanf("%d",&a[i].use),a[i].number=i;
	sort(a+1,a+n+1,cmp);
	cout<<a[1].number<<" "<<a[2].use;
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define IL inline
#define RI register int
IL void read(int &x){
    int f=1;x=0;char s=getchar();
    while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
    while(s<='9'&&s>='0'){x=x*10+s-'0';s=getchar();}
    x*=f;
}
int mxx,n,a[10086],mxxpos;
int main()
{
    read(n);
    for(RI i=1;i<=n;i++)
    {
        read(a[i]);
        if(mxx<a[i])mxx=a[i],mxxpos=i;
    }
    std::sort(a+1,a+n+1);
    printf("%d %d",mxxpos,a[n-1]);
}


#include<bits/stdc++.h>
using namespace std;
long long n,a[100002],ans,bh[100002];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i],bh[i]=i;
	for(int i=1;i<=n;i++)
	  for(int j=i+1;j<=n;j++)
	    if(a[i]<a[j])swap(a[i],a[j]),swap(bh[i],bh[j]);
	cout<<bh[1]<<' '<<a[2];
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cctype>
using namespace std;
struct node{int m,num;}a[1001];
bool cmp(const node &x,const node &y){return x.m>y.m;}
int main()
{
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++){cin>>a[i].m;a[i].num=i;}
	sort(a+1,a+1+n,cmp);
	cout<<a[1].num<<" "<<a[2].m;
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
	int id;
	int w;
}a[20001];
bool cmp(node x,node y)
{
	return x.w>y.w;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i].w),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	printf("%d %d",a[1].id,a[2].w);
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[10007];
int maxx;
int b;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b=1;
        maxx=max(a[i],maxx);
        if(a[i]>=maxx)
            b=i;
    }
    sort(a+1,a+1+n);
    cout<<b<<" "<<a[n-1]<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
struct per
{
	int id,mon;
}m[10101],t;
bool cmp(const per &a,const per &b)
{
	return a.mon>b.mon;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%d",&m[i].mon),m[i].id=i+1;
	sort(m,m+n,cmp);	cout<<m[0].id<<' '<<m[1].mon<<endl;
	return 0;
}


#include"cstdio"
#include"algorithm"
using namespace std;
struct node
{
	int id,val;
}px[1010];
int n,m,k;
bool cmp(node a1,node a2)
{
	return a1.val>a2.val;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&px[i].val),px[i].id=i;
	sort(px+1,px+1+n,cmp);
	printf("%d %d",px[1].id,px[2].val);
}


//程序名:新的C++程序
//作者:

#include<iostream>
#include<fstream>
#include<algorithm>

using namespace std;
int n,num[2005],max1=-9999,max2=-9999,xb;
int main()
{
     cin>>n;
	 for(int i=1;i<=n;i++)
	 {
		 cin>>a[i];
		 if(a[i]>max1) max1=a[i],xb=i;
		 else if(a[i]>max2) max2=a[i];
	 }
	 cout<<xb<<" "<<max2;
    return 0;
}


#include <iostream>
#include <queue>

using namespace std;

int main(){

    priority_queue<pair<int,int> > PQ;
    int n, bid, pos, pay;
    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> bid;
        PQ.push(make_pair(bid,i));
    }

    pos = PQ.top().second;
    PQ.pop();
    pay = PQ.top().first;
    cout << pos << " " << pay;

    return 0;
}


#include <iostream>

using namespace std;

int main(){

    int bids[1001];
    int n, max1=0, max2=0, pos;
    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> bids[i];
        if(bids[i] > max1){
            max2 = max1;
            max1 = bids[i];
            pos = i;
        } else if (bids[i] < max1 && bids[i] > max2){
            max2 = bids[i];
        }
    }

    cout << pos << " " << max2;

    return 0;
}


#include <iostream>

using namespace std;

int main(){

    int bids[1001];
    int n, max1=0, max2=0, index;
    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> bids[i];
        if(bids[i] > max1){
            max2 = max1;
            max1 = bids[i];
            index = i;
        } else if (bids[i] < max1 && bids[i] > max2){
            max2 = bids[i];
        }
    }

    cout << index << " " << max2;

    return 0;
}


#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define len(s) s.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define fi first
#define se second
#define all(x) x.begin(),x.end()

using namespace std;

ll gcd(ll x,ll y)
{
    if(y==0) return x;
    return gcd(y,x%y);
}
ll bigMod(ll a,ll b)
{
      if(!b) return 1;
      ll x = bigMod(a,b/2);
      ll temp = (x*x)%mod;
      if(b%2) temp = (temp*a)%mod;
      return temp;
}
ll modinv(ll a)
{
      return bigMod(a,mod-2);
}
int a,b,c=0,res=0,sum=0,f=0,ff=0,cnt=0;
string s,ss;

pair<int,int>p[300004];

int main()
{
    ios_base::sync_with_stdio(false);
    int n,m;
    int t;
     cin>>n;
     int ar[100100];
     rep(i,n)
     {
         cin>>ar[i];
     }
     int res=max_element(ar,ar+n)-ar;
     sort(ar,ar+n);

      cout<<res+1<<" "<<ar[n-2];
    return 0;
}


#include <bits/stdc++.h>

#define S scanf
#define P printf

#define LL long long int
#define ULL unsigned long long int

#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SQR(n) (n*n)
#define eps 1e-9
#define PI 2.0*acos(0.0) //#define PI acos(-1.0)
#define MEM(a,val) memset(a,val,sizeof(a))

#define all(a) a.begin(),a.end()
#define ff first
#define ss second

#define PCC cout<<"Case "<<cas++<<": ";
#define PC printf("Case %d:",cas++);
#define PCN printf("Case %d:\n",cas++);
#define NL printf("\n");

#define SET(a,i) memset(a,i,sizeof a)
#define open freopen("input.txt","r",stdin)
#define close freopen ("output.txt","w",stdout)
#define Case(a) printf("Case %d:",a)
#define caseh(a) printf("Case #%d: ",a)
#define S1(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SL1(a) scanf("%lld",&a)
#define SL2(a,b) scanf("%lld%lld",&a,&b)
#define SL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define CHR getchar()
#define PB(x) push_back(x)
#define PP pop_back()
#define PF(x) push_front(x)
#define PPF(x) pop_front()
#define PS(x) push(x)
#define SZ() size()
#define MOD 1000000007
#define INF (1<<28)
#define UB upper_bound
#define LB lower_bound
#define mxe(a,n) (*max_element(a,a+n))
#define mne(a,n) (*min_element(a,a+n))
#define SUM(a,n) (accumulate(a,a+n,0))

using namespace std;

template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> void ia (T a[],int n){for (int i=0; i<n; i++) cin >> a[i];}
template <typename T> void pa (T a[],int n){for (int i=0; i<n-1; i++) cout << a[i] << " ";cout << a[n-1] << endl;}
template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Bigmod(T b,T p,T m){ if(p==0) return 1; else if (!(p&1)) return SQR(Bigmod(b,p/2,m)) % m;else return ((b % m) * Bigmod(b,p-1,m)) % m;}
template<typename T>inline T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template<typename T>inline T Angle(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template<typename T>inline T DIFF(T a,T b) { T d = a-b;if(d<0)return -d;else return d;}
template<typename T>inline T ABS(T a) {if(a<0)return -a;else return a;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template<typename T>inline T euclide(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}

int Set(int N,int pos){ return N=N | (1<<pos);}
int Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Check(int N,int pos){return (bool)(N & (1<<pos));}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}
int cdigittoint(char ch){return ch-'0';}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}

/// ------------------------------------------------------------------------------------------------------- ///
int ar[300008];
pair<int ,int >p[300008];
int main()

   {

int a,b,c,n ,m;
int res=0,ans=0;

cin>>n>>m;
ans=n;
while(n/m)
{

    res+=(n/m);

    n=n/m+(n%m);
}
cout<<ans+res;

}


#include <bits/stdc++.h>

#define S scanf
#define P printf

#define LL long long int
#define ULL unsigned long long int

#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SQR(n) (n*n)
#define eps 1e-9
#define PI 2.0*acos(0.0) //#define PI acos(-1.0)
#define MEM(a,val) memset(a,val,sizeof(a))

#define all(a) a.begin(),a.end()
#define ff first
#define ss second

#define PCC cout<<"Case "<<cas++<<": ";
#define PC printf("Case %d:",cas++);
#define PCN printf("Case %d:\n",cas++);
#define NL printf("\n");

#define SET(a,i) memset(a,i,sizeof a)
#define open freopen("input.txt","r",stdin)
#define close freopen ("output.txt","w",stdout)
#define Case(a) printf("Case %d:",a)
#define caseh(a) printf("Case #%d: ",a)
#define S1(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SL1(a) scanf("%lld",&a)
#define SL2(a,b) scanf("%lld%lld",&a,&b)
#define SL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define CHR getchar()
#define PB(x) push_back(x)
#define PP pop_back()
#define PF(x) push_front(x)
#define PPF(x) pop_front()
#define PS(x) push(x)
#define SZ() size()
#define MOD 1000000007
#define INF (1<<28)
#define UB upper_bound
#define LB lower_bound
#define mxe(a,n) (*max_element(a,a+n))
#define mne(a,n) (*min_element(a,a+n))
#define SUM(a,n) (accumulate(a,a+n,0))

using namespace std;

template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> void ia (T a[],int n){for (int i=0; i<n; i++) cin >> a[i];}
template <typename T> void pa (T a[],int n){for (int i=0; i<n-1; i++) cout << a[i] << " ";cout << a[n-1] << endl;}
template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Bigmod(T b,T p,T m){ if(p==0) return 1; else if (!(p&1)) return SQR(Bigmod(b,p/2,m)) % m;else return ((b % m) * Bigmod(b,p-1,m)) % m;}
template<typename T>inline T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template<typename T>inline T Angle(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template<typename T>inline T DIFF(T a,T b) { T d = a-b;if(d<0)return -d;else return d;}
template<typename T>inline T ABS(T a) {if(a<0)return -a;else return a;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template<typename T>inline T euclide(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}

int Set(int N,int pos){ return N=N | (1<<pos);}
int Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Check(int N,int pos){return (bool)(N & (1<<pos));}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}
int cdigittoint(char ch){return ch-'0';}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}

/// ------------------------------------------------------------------------------------------------------- ///
int main()
{
   int a,b,c;pair<int,int>ar[100100];
   int res=0,res1=0,n,m;
   cin>>n;
   for(int i=0;i<n;i++)
   {
     //  cin>>ar[i];
     cin>>a;
     ar[i]=make_pair(a,i+1);
   }
   sort(ar,ar+n);
   cout<<ar[n-1].ss<<" "<<ar[n-2].ff<<endl;
}


#include <iostream>

using namespace std;

int main()
{
    int max=0,smax=0,maxi=0,n,num[1100];
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> num[i];
    }
    int cnt=0;
    for (int i = 0; i < n; i++)
    {
        if (num[i] > max)
        {
            cnt++;
        //  cout << smax << " " << max << " "<< i << " " <<maxi << endl;
            smax=maxi;
            max = num[i];
            maxi=i;
        }
    }
    if (cnt == 1)
    {
        max=0;
        for (int i = 1; i < n; i++)
        {
            if (num[i]>max)
            {
                max=num[i];
                smax=i;
            }
        }
    }

    cout << maxi+1 << " " << num[smax];
}


#include <iostream>

using namespace std;

int main()
{
    int max=0,smax=0,maxi=0,n,num[1100];
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> num[i];
    }
    if (n==1)
    {
        cout << num[0]<< " "<< num[0];
        return 0;
    }
    int cnt=0;
    for (int i = 0; i < n; i++)
    {
        if (num[i] > max)
        {
            cnt++;
        //  cout << smax << " " << max << " "<< i << " " <<maxi << endl;
            smax=maxi;
            max = num[i];
            maxi=i;
        }
    }
    num[maxi]=0;
        max=0;
        for (int i = 1; i < n; i++)
        {
            if (num[i]>max)
            {
                max=num[i];
                smax=i;
            }
        }

    cout << maxi+1 << " " << num[smax];
}


#include <iostream>

using namespace std;

int main()
{
    int max=0,smax=0,maxi=0,n,num[1100];
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> num[i];
    }
    int cnt=0;
    for (int i = 0; i < n; i++)
    {
        if (num[i] > max)
        {
            cnt++;
        //  cout << smax << " " << max << " "<< i << " " <<maxi << endl;
            smax=maxi;
            max = num[i];
            maxi=i;
        }
    }
    num[maxi]=0;
        max=0;
        for (int i = 1; i < n; i++)
        {
            if (num[i]>max)
            {
                max=num[i];
                smax=i;
            }
        }

    cout << maxi+1 << " " << num[smax];
}


#include <iostream>

using namespace std;

int main()
{
    int max=0,smax=0,maxi=0,n,num[1100];
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> num[i];
    }
    if (n==1)
    {
        cout << num[0]<< " "<< num[0];
        return 0;
    }
    int cnt=0;
    for (int i = 0; i < n; i++)
    {
        if (num[i] > max)
        {
            cnt++;
        //  cout << smax << " " << max << " "<< i << " " <<maxi << endl;
            smax=maxi;
            max = num[i];
            maxi=i;
        }
    }
    num[maxi]=0;
    max=0;
    for (int i = 0; i < n; i++)
    {
        if (num[i]>max)
        {
            max=num[i];
            smax=i;
        }
    }

    cout << maxi+1 << " " << num[smax];
}


#include <iostream>

using namespace std;

long long int maxi, d, a[100001], n;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++){
    cin >> a[i];
    if (a[i] > maxi){
    maxi = a[i];
    d = i;
}
    }
    cout << d << " ";
    sort (a + 1, a + n + 1);
    cout << a[n - 1];
return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

long long int maxi, d, a[100001], n;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++){
    cin >> a[i];
    if (a[i] > maxi){
    maxi = a[i];
    d = i;
}
    }
    cout << d << " ";
    sort (a + 1, a + n + 1);
    cout << a[n - 1];
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int p[10010];
int max1, max2, mp;
int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
        if (p[i] >= max1) {
            max1 = p[i];
            mp = i;
            max2 = max1;
        } else if (p[i] >= max2) {
            max2 = p[i];
        }
    }
    cout << mp << " " << max2 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int p[10010];
int max1, max2, mp;
int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
        if (p[i] >= max1) {
            max2 = max(max2, max1);
            max1 = p[i];
            mp = i;
        } else if (p[i] >= max2) {
            max2 = p[i];
        }
    }
    cout << mp << " " << max2 << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int x=0;
    int t=0;
    int n=0;
    int z=0;
    int i=0;
    int y[x];
    cin>>x;
    for(i=0;i<x;i++)
    {
        cin>>y[i];
        t=y[0];
        if(t<y[i])
        {
            n=i;
        }
        n=i;
        z=y[0];
        for(int l=0;l<x;l++)
        {if(z<y[l]&&z!=y[i-1])
        {
            z=y[l];
        }
    }
    }
cout<<n<<" "<<z<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int x=0;
    int t=0;
    int n=0;
    int z=0;
    int i=0;
    int y[x];
    cin>>x;
    for(i=0;i<x;i++)
    {
        cin>>y[i];
        t=y[0];
        if(t<y[i])
        {
            n=i;
        }
        n=i;
        z=y[0];
        for(int l=0;l<x;l++)
        {if(z<y[l]&&z!=y[i-1])
        {
            z=y[l];
        }
    }
    }
cout<<(n+1)<<" "<<z<<endl;
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int x=0,t=0,n=0,i=0,k=0,z=0;
    cin>>x;
    int y[x];
    for(i=0; i<x; i++)
    {
        cin>>y[i];
        if(t<y[i])
        {
            n=i;
            t=y[i];
        }
    }
    for(z=0; z<x; z++)
    {
        if(k<y[z]&&z!=n)
        {
            k=y[z];
        }
    }
    cout<<n+1<<" "<<k<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int x=0;
    int t=0;
    int n=0;
    int z=0;
    int i=0;
    int y[x];
    cin>>x;
    for(i=0;i<x;i++)
    {
        cin>>y[i];
        t=y[0];
        if(t<y[i])
        {
            n=i;
        }
        n=i;
        z=y[0];
        for(int l=0;l<x;l++)
        {if(z<y[l]&&z!=y[i-1])
        {
            z=y[l];
        }
    }
    }
cout<<z<<" "<<n+1<<endl;
    return 0;
}
#include <iostream>

using namespace std;

int main()
{
    int x=0;
    int t=0;
    int n=0;
    int z=0;
    int i=0;
    int y[x];
    cin>>x;
    for(i=0;i<x;i++)
    {
        cin>>y[i];
        t=y[0];
        if(t<y[i])
        {
            n=i;
        }
        n=i;
        z=y[0];
        for(int l=0;l<x;l++)
        {if(z<y[l]&&z!=y[i-1])
        {
            z=y[l];
        }
    }
    }
cout<<z<<" "<<n+1<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<cstdio>
#include<queue>
#include<stack>
#include<functional>
#define INF 999999999
#define ms(a,x) memset(a,x,sizeof(a))

using namespace std;

bool cmd(int a, int b)
{
	return a > b;
}

int main()
{
	int n, a[1001] = { 0 };
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int maxv = 0, max = 0;
	for (int i = 0; i < n; i++)
	{
		if (maxv < a[i])
		{
			maxv = a[i];
			max = i;
		}
	}
	sort(a, a + n, cmd);
	cout << max + 1 << " " << a[1];
}


#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

int n;
int a[10010];

int main(){
	//int T,n,i;
	//scanf("%d",&T);
	int i;
	int k,max;
	while(~scanf("%d",&n)){
		max=-1;
		for(i=0;i<n;++i){
			scanf("%d",&a[i]);
			if(a[i]>max){
				max=a[i];
				k=i;
			}
		}
		max=-1;
		for(i=0;i<n;++i){
			if(a[i]>max&&i!=k){
				max=a[i];
			}
		}
		printf("%d %d\n",k+1,max);
	}

	return 0;
}


#include <stdio.h>
#include <algorithm>
struct node{
    int id, val;
};
node ns[15000];
bool cmp(const node &a, const node &b){
    return a.val > b.val;
}
int main()
{
    int n;
    scanf ( "%d", &n );
    for(int i=1; i<=n; i++){
        ns[i].id= i ;
        scanf ( "%d", &ns[i].val );
    }
    std::sort(ns+1, ns+1+n, cmp);
    int ansid = ns[1].id;
    int ansval = ns[2].val;
    printf ( "%d %d\n", ansid, ansval );
    return 0;
}


// run: $exec < input
#include <iostream>

int n;

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n;
	int max = 0, second = 0, id;
	for (int i = 0, x; i < n; i++) {
		std::cin >> x;
		if (x > max) {
			second = max;
			max = x;
			id = i + 1;
		} else if (x > second) {
			second = x;
		}
	}
	std::cout << id << " " << second << "\n";
}


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

const int maxn = 1005;
int p[maxn];

int cmp(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	int m = -1;
	int id;
	for(int i = 0; i < n; i ++) {
		cin >> p[i];
		if(p[i] > m) {
			m = p[i];
			id = i + 1;
		}
	}
	sort(p, p + n, cmp);
	cout << id << " " << p[1] << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
struct node
{
	int x ;
	int num ;
};
node a[1010] ;
int cmp(node a , node b)
{
	return a.x > b.x ;
}
int main()
{
	int n ;
	cin>> n ;
	for(int i = 0 ; i < n ; i++ )
	{
		cin>> a[i].	x ;
		a[i].num = i+1 ;
	}
	sort(a , a+n , cmp) ;
	cout<< a[0].num <<' '<< a[1].x << endl;
	return 0 ;

}


#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int a[1000+10];
    for (int i=0;i<n;i++)
        scanf("%d",&a[i]);
    int max1=0,max1index=0,max2=0;
    for (int i=0;i<n;i++)
    {
        if (a[i]>max1)
        {
            max1=a[i];
            max1index=i;
        }
    }
    a[max1index]=0;
    for (int i=0;i<n;i++)
    {
        if (a[i]>max2)
            max2=a[i];
    }
    printf("%d %d\n",max1index+1,max2);
    return 0;
}


#include<stdio.h>

int main()
  {
    int n,i,vtmax,max;
    int a[1000];

    scanf("%d",&n);

    max=0;
    for(i=0;i<n;i++)
      {
        scanf("%d",&a[i]);
        if(max<a[i])
          {
            max=a[i];
            vtmax=i;
          }
      }

    max=0;
    for(i=0;i<n;i++)
      {
        if((max<a[i])&&(i!=vtmax))
          max=a[i];
      }

    printf("%d %d",vtmax+1,max);

    return 0;
  }


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

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

    static class TaskC
    {
        static int MOD = 1_000_000_000 + 7;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            String s = in.next();
            long ans = 0, tens = 0, tenPow = 1, multiple = 1;

            for (int i = s.length() - 1; i >= 0; i--)
            {
                long digit = s.charAt(i) - '0';

                ans = add(ans, mul(digit, mul(comb(i), tenPow)));
                ans = add(ans, mul(digit, tens));

                tens = add(tens, mul(tenPow, multiple));
                multiple++;
                tenPow = mul(tenPow, 10);
            }
            out.println(ans);
        }

        private long comb(int i)
        {
            return add((i * (i + 1)) / 2, 0);
        }

        private long add(long a, long b)
        {
            return ((a % MOD + b % MOD) % MOD + MOD) % MOD;
        }

        private long mul(long a, long b)
        {
            return ((a % MOD * b % MOD) % MOD + MOD) % MOD;
        }

    }
}


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

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

    static class TaskC
    {
        static int MOD = 1_000_000_000 + 7;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            String s = in.next();
            long ans = 0, tens = 0, tenPow = 1, multiple = 1;

            for (int i = s.length() - 1; i >= 0; i--)
            {
                long digit = s.charAt(i) - '0';

                ans = add(ans, mul(digit, mul(comb(i), tenPow)));
                ans = add(ans, mul(digit, tens));

                tens = add(tens, mul(tenPow, multiple));
                multiple = add(multiple, 1);
                tenPow = mul(tenPow, 10);
            }
            out.println(ans);
        }

        private long comb(int i)
        {
            return add((i * (i + 1)) / 2, 0);
        }

        private long add(long a, long b)
        {
            return ((a % MOD + b % MOD) % MOD + MOD) % MOD;
        }

        private long mul(long a, long b)
        {
            return ((a % MOD * b % MOD) % MOD + MOD) % MOD;
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class C {

    public static final long mod=(int)1e9+7;

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        char[] line = fs.next().toCharArray();
        int n = line.length;
        int[] value = new int[n];
        for(int i=0; i< n; ++i)
            value[i] = line[n-1-i] - '0';

        long total = 0;
        long tenPow = 1;
        long tenValues = 0;
        long nBiggestNumbers = n- 1;
        long multiple = 1;
        for(int i : value) {

            total = add(total, mul(i, mul(nC2(nBiggestNumbers), tenPow)));

            total = add(total, mul(i,tenValues));

            tenValues = add(tenValues, mul(tenPow, multiple));
            multiple = add(multiple,1);
            tenPow = mul(tenPow,10);
            nBiggestNumbers -= 1;
        }
        System.out.println(total);

    }
    static long nC2(long n) {
        return add(n*(n+1)/2, 0);
    }
    static long mul(long a, long b) {
        return ((a*b)%mod+mod)%mod;
    }
    static long add(long a, long b) {
        return ((a+b)%mod+mod)%mod;
    }

    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}


// package CodeForces;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class Round675C {

	public static final long mod = (long)1e9 + 7;
	public static final int max = (int)1e5 + 10;
	public static long[] pow10;
	public static long[] pow10_sum;

	public static void Pre() {
		pow10 = new long[max];
		pow10_sum = new long[max];
		pow10[0] = pow10_sum[0] = 1;
		for(int i = 1; i < max; i++) {
			pow10[i] = (pow10[i - 1] * 10L)%mod;
			pow10_sum[i] = (pow10_sum[i - 1] + pow10[i])%mod;
		}
	}

	public static long give_pow(int val) {
		if(val < 0) return 0;
		return pow10[val];
	}

	public static long give_11(int val) {
		if(val < 0) return 0;
		return pow10_sum[val];
	}

	public static void solve() {
		Pre();
		String str = s.next();
		long inv_nine = ModInverse(9, mod);
		long ans = 0;
		int n = str.length();
		for(int i = 0; i < n; i++) {
			long before = i;
			long val = (before * (before + 1))/2L;
			val %= mod;
			val *= give_pow(n - i - 1);
			val %= mod;
			long rem = n - i - 1;
			long S = give_pow((int)rem) * (long)rem;
			S %= mod;
			S -= give_11((int)rem - 1);
			if(S < 0) S += mod;
			S *= inv_nine;
			S %= mod;
			ans += ((val + S)%mod * (str.charAt(i) - '0'))%mod;
			if(ans >= mod) ans -= mod;
		}
		out.println(ans);
	}

	public static class Triplet {
		long gcd;
		long x;
		long y;

		Triplet(long gcd, long x, long y) {
			this.gcd = gcd;
			this.x = x;
			this.y = y;
		}
	}

	public static Triplet ExtendedEuclideanAlgo(long a, long b) {
		if (a == 0) {
			return new Triplet(b, 0, 1);
		}
		Triplet ans = ExtendedEuclideanAlgo(b % a, a);
		long x = ans.y - (b / a) * ans.x;
		long y = ans.x;
		return new Triplet(ans.gcd, x, y);
	}

	public static long ModInverse(long a, long m) {
		Triplet ans = ExtendedEuclideanAlgo(a, m);
		if (ans.gcd != 1) {
			throw null;
		} else {
			long result = (ans.x % m + m) % m;
			return result;
		}
	}

	public static void main(String[] args) {
		new Thread(null, null, "Thread", 1 << 27) {
			public void run() {
				try {
					out = new PrintWriter(new BufferedOutputStream(System.out));
					s = new FastReader(System.in);
					solve();
					out.close();
				} catch (Exception e) {
					e.printStackTrace();
					System.exit(1);
				}
			}
		}.start();
	}

	public static PrintWriter out;
	public static FastReader s;

	public static class FastReader {

		private InputStream stream;
		private byte[] buf = new byte[4096];
		private int curChar, snumChars;

		public FastReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (snumChars == -1) {
				throw new InputMismatchException();
			}
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException E) {
					throw new InputMismatchException();
				}
			}
			if (snumChars <= 0) {
				return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int number = 0;
			do {
				number *= 10;
				number += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return number * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			long sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long number = 0;
			do {
				number *= 10L;
				number += (long) (c - '0');
				c = read();
			} while (!isSpaceChar(c));
			return number * sgn;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextLong();
			}
			return arr;
		}

		public String next() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndofLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndofLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}

}


import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;

public class Coding {

    static long MOD = 1000000007;
    static long[] fact = new long[302];
    static long[] invFact = new long[302];
    static long[][][] segmentTree = new long[4*300000 + 11][2][2];
    static long MINVALUE = Integer.MIN_VALUE;

    public static void main(String[] args) {
        BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        //precompute();
        try {
            int t = 1;
            while (t > 0) {
                String input = bi.readLine();
                int len = input.length();
                long[][][] dp = new long[len][2][2];
                long[][][] count = new long[len][2][2];
                for(int i=0;i<len;++i) {
                    dp[i][0][0] = dp[i][0][1] = dp[i][1][0] = dp[i][1][1] = 0;
                    count[i][0][0] = count[i][0][1] = count[i][1][0] = count[i][1][1] = 0;
                }
                dp[0][0][0] = input.charAt(0) - '0';
                count[0][0][0] = 1;
                count[0][1][0] = 0;
                count[0][1][1] = 0;
                for(int i=1;i<len;++i) {
                    count[i][0][0] = 1;
                    count[i][1][0] = count[i-1][1][0] + count[i-1][1][1] + 1;
                    count[i][1][1] = count[i-1][0][0] + count[i-1][1][1];

                    dp[i][0][0] = dp[i-1][0][0]*10 + (input.charAt(i) - '0');
                    dp[i][1][0] = (dp[i-1][1][0]*10 + (input.charAt(i) - '0')*count[i-1][1][0]) + (dp[i-1][1][1]*10 + (input.charAt(i) - '0')*count[i-1][1][1])  + (input.charAt(i) - '0');
                    dp[i][1][1] = dp[i-1][0][0] + dp[i-1][1][1];
                    dp[i][0][0]%=MOD;
                    dp[i][1][0]%=MOD;
                    dp[i][1][1]%=MOD;
                    count[i][0][0]%=MOD;
                    count[i][1][0]%=MOD;
                    count[i][1][1]%=MOD;
                }
                long ans = dp[len-1][1][0] + dp[len-1][1][1];
                ans%=MOD;
                writer.append(ans +  "\n");
                writer.flush();
                 t--;
            }
            writer.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static int gcd(int a, int b) {
        if (a<b) {
            return gcd(b, a);
        }
        if (a%b==0) {
            return b;
        }
        return gcd(b, a%b);
    }

    private static void dfs(int cur, List<Integer>[] adj, int[] nodeCount, int[] maxChild,  int parent, int[] par) {
        par[cur] = parent;
        for(int i=0;i<adj[cur].size();++i) {
            int nxt = adj[cur].get(i);
            if (nxt!=parent) {
                dfs(nxt, adj, nodeCount, maxChild, cur, par);
                nodeCount[cur]+=nodeCount[nxt];
                maxChild[cur] = Math.max(maxChild[cur], nodeCount[nxt]);
            }
        }
    }

    private static int findDist(int a, int b, int[] par) {
        Map<Integer, Integer> dist = new HashMap<>();
        int count = 0;
        dist.put(a, 0);
        while (par[a]!=-1) {
            a = par[a];
            count++;
            dist.put(a, count);
        }
        count=0;
        while(!dist.containsKey(b)) {
            b = par[b];
            count++;
        }
        return count+dist.get(b);
    }

    private static int findLongestPath(int cur, int prev, List<Integer>[] adj, int[] dep) {
        int diameter = 0;
        int highest = -1, second=-1;
        for(int i=0;i<adj[cur].size();++i) {
            int nxt = adj[cur].get(i);
            if (nxt!=prev) {
                diameter = Math.max(diameter, findLongestPath(nxt, cur, adj, dep));
                if (dep[nxt]>highest) {
                    second = highest;
                    highest = dep[nxt];
                } else if (dep[nxt]>second) {
                    second = dep[nxt];
                }
            }
        }
        diameter = Math.max(diameter, highest + second + 2);
        return diameter;
    }

    static long ncr(int n, int r) {
        long num = fact[n];
        long denom = (invFact[r]*invFact[n-r])%MOD;
        //System.out.println("num is " + num + " denom is" + denom);
        return (num*denom)%MOD;
    }

    static long modExp(long a, long b, long mod) {
        //System.out.println("a is " + a + " and b is " + b);
        if (a==1) return 1;
        long ans = 1;
        while (b!=0) {
            if (b%2==1) {
                ans = (ans*a)%mod;
            }
            a = (a*a)%mod;
            b/=2;
        }
        return ans;
    }

    private static void precompute() {
        fact[0] = 1;
        invFact[0] = 1;
        for(int i=1;i<=300000;++i) {
            fact[i] = (fact[i-1]*i)%MOD;
            invFact[i] = modExp(fact[i], MOD-2, MOD);
        }
    }
}


//Utilities
import java.io.*;
import java.util.*;

public class Main {
	static char[] ch;
	static long len;
	static long res = 0;
	static long left, right, subLeft;
	static long[] tenPow = new long[100005];
	static long[] sumTen = new long[100005];
	static final int MOD = (int)1e9+7;

	public static void main(String[] args) throws IOException {
		tenPow[0] = 1; sumTen[0] = 1;
		for (int i = 1; i < 100005; i++) {
			tenPow[i] = tenPow[i-1] * 10L % MOD;
			sumTen[i] = ((i+1)*tenPow[i]%MOD+sumTen[i-1])%MOD;
		}
		ch = in.sscan().toCharArray();
		len = ch.length;
		for (int i = 0; i < len; i++) {
			left = i; right = len - i - 1;
			subLeft = left * (left + 1) / 2;
			if (left != 0) {
				res = (res + (Long.parseLong(""+ch[i]) * subLeft % MOD * tenPow[(int)len-1-i] % MOD)) % MOD;
			}
			if (right != 0) {
				res = (res + (Long.parseLong(""+ch[i]) * sumTen[(int)right-1] % MOD)) % MOD;
			}
			//out.println(res);
		}
		out.println(res);
		out.close();
	}

	static INPUT in = new INPUT(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	private static class INPUT {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar, numChars;

		public INPUT (InputStream stream) {
			this.stream = stream;
		}

		public INPUT (String file) throws IOException {
			this.stream = new FileInputStream (file);
		}

		public int cscan () throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read (buf);
			}

			if (numChars == -1)
				return numChars;

			return buf[curChar++];
		}

		public int iscan () throws IOException {
			int c = cscan (), sgn = 1;

			while (space (c))
				c = cscan ();

			if (c == '-') {
				sgn = -1;
				c = cscan ();
			}

			int res = 0;

			do {
				res = (res << 1) + (res << 3);
				res += c - '0';
				c = cscan ();
			}
			while (!space (c));

			return res * sgn;
		}

		public String sscan () throws IOException {
			int c = cscan ();

			while (space (c))
				c = cscan ();

			StringBuilder res = new StringBuilder ();

			do {
				res.appendCodePoint (c);
				c = cscan ();
			}
			while (!space (c));

			return res.toString ();
		}

		public double dscan () throws IOException {
			int c = cscan (), sgn = 1;

			while (space (c))
				c = cscan ();

			if (c == '-') {
				sgn = -1;
				c = cscan ();
			}

			double res = 0;

			while (!space (c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * UTILITIES.fast_pow (10, iscan ());

				res *= 10;
				res += c - '0';
				c = cscan ();
			}

			if (c == '.') {
				c = cscan ();
				double m = 1;

				while (!space (c)) {
					if (c == 'e' || c == 'E')
						return res * UTILITIES.fast_pow (10, iscan ());

					m /= 10;
					res += (c - '0') * m;
					c = cscan ();
				}
			}

			return res * sgn;
		}

		public long lscan () throws IOException {
			int c = cscan (), sgn = 1;

			while (space (c))
				c = cscan ();

			if (c == '-') {
				sgn = -1;
				c = cscan ();
			}

			long res = 0;

			do {
				res = (res << 1) + (res << 3);
				res += c - '0';
				c = cscan ();
			}
			while (!space (c));

			return res * sgn;
		}

		public boolean space (int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}

	public static class UTILITIES {

		static final double EPS = 10e-6;

		public static int lower_bound (int[] arr, int x) {
			int low = 0, high = arr.length, mid = -1;

			while (low < high) {
				mid = (low + high) / 2;

				if (arr[mid] >= x)
					high = mid;
				else
					low = mid + 1;
			}

			return low;
		}

		public static int upper_bound (int[] arr, int x) {
			int low = 0, high = arr.length, mid = -1;

			while (low < high) {
				mid = (low + high) / 2;

				if (arr[mid] > x)
					high = mid;
				else
					low = mid + 1;
			}

			return low;
		}

		public static int gcd (int a, int b) {
			return b == 0 ? a : gcd (b, a % b);
		}

		public static int lcm (int a, int b) {
			return a * b / gcd (a, b);
		}

		public static long fast_pow_mod (long b, long x, int mod) {
			if (x == 0) return 1;
			if (x == 1) return b;
			if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;

			return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;
		}

		public static int fast_pow (int b, int x) {
			if (x == 0) return 1;
			if (x == 1) return b;
			if (x % 2 == 0) return fast_pow (b * b, x / 2);

			return b * fast_pow (b * b, x / 2);
		}

		public static long choose (long n, long k) {
			k = Math.min (k, n - k);
			long val = 1;

			for (int i = 0; i < k; ++i)
				val = val * (n - i) / (i + 1);

			return val;
		}

		public static long permute (int n, int k) {
			if (n < k) return 0;
			long val = 1;

			for (int i = 0; i < k; ++i)
				val = (val * (n - i));

			return val;
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class CBargain {
        public void solve(int testNumber, InputReader c, OutputWriter w) {
//    	w.print("Case #"+testNumber+": ");

            char[] ch = c.readString().toCharArray();

            int n = ch.length;
            long res = 0, mod = (long) (1e9 + 7), cur_power_10 = 1, cur_sum_10 = 0;
            long tot = (n * (long) (n + 1)) / 2;
            for (int i = n - 1; i >= 0; i--) {

                tot -= (i + 1);
                res += (((tot % mod) * cur_power_10) % mod * (ch[i] - '0')) % mod;
                res += (cur_sum_10 * (ch[i] - '0')) % mod;
                res %= mod;
                cur_sum_10 += (cur_power_10 * (n - i)) % mod;
                cur_sum_10 %= mod;
                cur_power_10 *= 10;
                cur_power_10 %= mod;
            }

            w.printLine(res);

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }
}


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
Shining through the city with a little funk and soul
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class C3
   {
      static long MOD = 1000000007L;
      public static void main(String hi[]) throws Exception
      {
         long[] pow = new long[100001];
         pow[0] = 1L;
         for(int i=1; i <= 100000; i++)
            pow[i] = (pow[i-1]*10)%MOD;
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         String input = st.nextToken();
         int N = input.length();
         int[] arr = new int[N];
         for(int i=0; i < N; i++)
            arr[i] = input.charAt(i)-'0';
         if(N == 1)
         {
            System.out.println(0);
            return;
         }
         else if(N == 2)
         {
            System.out.println(arr[0]+arr[1]);
            return;
         }
         long[] suffix = new long[N];
         suffix[N-1] = arr[N-1];
         for(int i=N-2; i >= 0; i--)
         {
            suffix[i] = suffix[i+1]+(arr[i]*pow[N-1-i])%MOD;
            if(suffix[i] >= MOD)
               suffix[i] -= MOD;
         }
         long res = 0L;
         long head = 0L;
         long mult = 0L;
         for(int i=0; i < N; i++)
         {
            mult += pow[i];
            if(mult >= MOD)
               mult -= MOD;
         }
         long tail = 0L;
         for(int i=0; i < N; i++)
         {
            tail += suffix[i];
            if(tail >= MOD)
               tail -= MOD;
         }
         for(int i=0; i < N; i++)
         {
            tail -= suffix[i];
            if(tail < 0)
               tail += MOD;
            res += tail+(head*mult)%MOD;
            while(res >= MOD)
               res -= MOD;
            head = (head*10)%MOD;
            head += arr[i];
            if(head >= MOD)
               head -= MOD;
            mult -= pow[N-i-1];
            if(mult < 0)
               mult += MOD;
         }
         System.out.println(res%MOD);
      }
   }


import java.util.*;

public class _1422C {
	static int[] fact;
	static int MOD = 1000000007;
	static int[] invfact;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long ans = 0;
		long sum = 1;
		for (int i = s.length()-2; i >= 0; i--) {
			long temp = (long) ((long) (s.charAt(i) - '0') * sum) % MOD;
			ans = (long) ((long) ans + temp) % MOD;
			sum = (long) ((long) sum + (s.length()-i)*pow(10, s.length()-i-1)) % MOD;
		}
		for (int i = 0; i < s.length(); i++) {
			long add = (long) ((long) (i + 1) * i / 2) % MOD;
			add = (long) (add * (long) pow(10, s.length()-i-1)) % MOD;
			ans = (long) ((long) ans + (s.charAt(i)-'0') * add) % MOD;
		}
//		for (int i = 1; i <= s.length(); i++) {
//			long temp = ((long) count[i-1] * sum[i]) % MOD;
//			temp = ((long) temp * (s.charAt(i-1)-'0')) % MOD;
//			ans = (long) ((long) ans + temp) % MOD;
//		}
//		System.out.println(ans);
//		for (int i = 0; i < s.length(); i++) {
//			long subtract = pow(10, s.length()-i-1) % MOD;
//			subtract = (long) ((long) (s.charAt(i)-'0') * subtract) % MOD;
//			ans = (long) ((long) ans - subtract + MOD) % MOD;
//		}
		System.out.println(ans);
	}

	public static int comb(int n, int k) {
		if (n < k) {
			return 0;
		}
		long x = (long) ((long) invfact[k] * (long) invfact[n-k]) % MOD;
		x = (long) ((long) x * fact[n]) % MOD;
		return (int) x;
	}

	public static int inverse(int a) {
		int power = MOD-2;
		return (int) pow(a, power) % MOD;
	}

	public static long pow(int base, int power) {
		if (power == 0) {
			return 1;
		}
		if (power == 1) {
			return base;
		}
		long ans = 1;
		if (power % 2 == 1) {
			ans = base;
		}
		long res = pow(base, power/2);
		ans = (long) ((long) ans * res) % MOD;
		ans = (long) ((long) ans * res) % MOD;
		return (int) ans % MOD;
	}

}


import java.util.*;

public class _1422C {
	static int[] fact;
	static int MOD = 1000000007;
	static int[] invfact;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long ans = 0;
		long sum = 1;
		for (int i = s.length()-2; i >= 0; i--) {
			long temp = (long) ((long) (s.charAt(i) - '0') * sum) % MOD;
			ans = (long) ((long) ans + temp) % MOD;
			sum = (long) ((long) sum + (s.length()-i)*pow(10, s.length()-i-1)) % MOD;
		}
		for (int i = 0; i < s.length(); i++) {
			ans = (long) ((long) ans + (s.charAt(i)-'0') * (long) (i + 1) * i / 2 * pow(10, s.length()-i-1)) % MOD;
		}
//		for (int i = 1; i <= s.length(); i++) {
//			long temp = ((long) count[i-1] * sum[i]) % MOD;
//			temp = ((long) temp * (s.charAt(i-1)-'0')) % MOD;
//			ans = (long) ((long) ans + temp) % MOD;
//		}
//		System.out.println(ans);
//		for (int i = 0; i < s.length(); i++) {
//			long subtract = pow(10, s.length()-i-1) % MOD;
//			subtract = (long) ((long) (s.charAt(i)-'0') * subtract) % MOD;
//			ans = (long) ((long) ans - subtract + MOD) % MOD;
//		}
		System.out.println(ans);
	}

	public static int comb(int n, int k) {
		if (n < k) {
			return 0;
		}
		long x = (long) ((long) invfact[k] * (long) invfact[n-k]) % MOD;
		x = (long) ((long) x * fact[n]) % MOD;
		return (int) x;
	}

	public static int inverse(int a) {
		int power = MOD-2;
		return (int) pow(a, power) % MOD;
	}

	public static long pow(int base, int power) {
		if (power == 0) {
			return 1;
		}
		if (power == 1) {
			return base;
		}
		long ans = 1;
		if (power % 2 == 1) {
			ans = base;
		}
		long res = pow(base, power/2);
		ans = (long) ((long) ans * res) % MOD;
		ans = (long) ((long) ans * res) % MOD;
		return (int) ans % MOD;
	}

}