Monastery of the Discalced Carmelites
The monastery-fortress of the Discalced Carmelites was inaugurated on July 22, 1642. It was established by Janusz Tyszkiewicz, the voivode and general elder of the Kyiv region, in 1630. Tyszkiewicz donated his castle-estate in Berdychiv, along with several nearby villages, for the construction of the future church. On the day of the monastery's opening, he presented an icon of the Blessed Virgin Mary, a cherished family heirloom. Pilgrims began to flock to the monastery, prompting the expansion of Berdychiv to accommodate the influx of craftsmen and traders. The cloister (monastery-fortress) soon became a significant economic hub. Recognizing its importance in Ukraine, the King of Poland allocated funds for repairing the fortress walls, installed cannons, and eventually stationed a military garrison there.
During the "Cossack" revolution of 1648, the cloister, seen as a symbol of the forced union, became a target of widespread animosity among locals and was destroyed during the battles between B. Khmelnytsky's troops and the Polish garrison led by Tyszkiewicz. The Carmelites fled with the icon of the Mother of God to Lviv, where it remained in the Carmelite sisters' monastery for 73 years, until 1721.
In 1717, the Lublin Tribunal decreed the return of the lands and church to the monks, leading to the monastery's reconstruction and the return of the icon. Following the suppression of the "landlord uprisings" in 1831 and 1863, the Russian government initiated repressive measures against the cloister. The Carmelite schools were closed in 1832, the printing house was banned in 1844, the publication of Berdychiv calendars in Zhytomyr was prohibited in 1864 due to their political content, and the cloister itself was abolished in 1866.
On June 16, 1918, the Carmelites regained ownership of the monastery. However, in 1926, after the death of Father Teresiy Boleslav Shtobryn, the last Carmelite, the church was taken over by the state. A museum was established in the upper church and a cinema in the lower one. In 1941, a fire likely destroyed the miraculous icon. From 1970 to 1980, the Berdychiv authorities, with help from Kyiv restorers, restored the church, and in 1991, the monastery was returned to the Catholic community.
In 1997, a replica of the icon was blessed and crowned by Pope John Paul II.
"Historical and Cultural Heritage of Ukraine"
Each year, numerous pilgrims from across Ukraine and neighboring countries visit the monastery for the anniversary of the icon's coronation. During their journey, when groups meet, they share information about the routes they have taken. This exchange of information continues at the monastery, the final destination.
The monastery is strategically located such that the distance from it to the farthest point is minimized among all maximum distances from any one settlement to another.
Using the available information about the traveled roads, determine the distance from the monastery to the most distant point from which the pilgrims have arrived.
Input
The first line provides the number of settlements N (2 ≤ N ≤ 5·10^4) from which pilgrims have come. The following N-1 lines detail the road length S between settlements a and b (1 ≤ a, b ≤ N, a≠ b, 0 < S ≤ 2·10^9).
It is guaranteed that any settlement can be reached from any other (possibly indirectly).
Output
Output a single number: the distance from the monastery to the most distant settlement.