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 Berdychiv's expansion to accommodate 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 exchange information about the routes they have taken. This exchange continues at the monastery, the ultimate destination.
It is known that the location of the monastery is such that the distance from it to the farthest settlement is minimal among all possible maximum distances from any settlement to any other.
Given information about the roads traveled, determine the distance from the monastery to the most distant settlement from which the pilgrims have arrived.
The first line contains the number of settlements (2 \leq N \leq 5 \times 10^4), from which pilgrims have come. The next N - 1 lines each contain three integers: , , (1 \leq a, b \leq N, a \neq b, 0 < S \leq 2 \times 10^9), indicating there is a road of length between settlements and .
It is guaranteed that any settlement can be reached from any other (possibly not directly).
Output a single number: the distance from the monastery to the most distant settlement.
Example 1