WASHINGTON (BLOOMBERG) - Five months into Mr Donald Trump's tumultuous presidency, the rest of the world is getting the hang of how to deal with him.
Don't react to his tweets, play down areas of conflict where you can, and stand your ground when you need to.
Most of those tactics were deployed during last week's (July) Group of 20 (G-20) summit and while there were some tense moments, everyone left Hamburg agreeing to disagree, at least for now.
"There is a sense they are figuring this out," said Mr Mark Leonard, director of the European Council on Foreign Relations research institute.
With German Chancellor Angela Merkel and French President Emmanuel Macron in particular emboldening each other to take Mr Trump on, "they have also understood it is politically helpful for them to be seen to be standing up to Trump".
Dr Merkel acknowledged the divisions in a closing press conference as G-20 host. When asked what to do about a US President who could impose trade barriers as soon as he gets back home, she said: "I can only take things as they come."
In many ways, world leaders find themselves exactly where Republicans in the US Congress ended up on Mr Trump after several months worth of exasperating episodes - watch what he does, not what he says.
The fact the global leaders got there so much more quickly, after just a few brief interactions with Mr Trump, suggests how determined they were to solve the puzzle.
The US President was never shunned during his time in Hamburg, as sometimes seemed to be the case during his last trip to Europe for the G-7 and Nato summits in May. And the body language seemed to be better on all sides.
Mr Macron, who bragged about his first macho handshake with Mr Trump two months ago, was an almost constant presence at the US President's side, patting him on the shoulder here, engaging in small talk there.
He even helped him out where he could, supporting Mr Trump's ultimately successful bid to get a line into the final communique that supported the use of "legitimate trade defence instruments" - summit-speak for tariffs.
Russian President Vladimir Putin also offered praise after their unexpectedly long meeting on Friday (July 7), saying Mr Trump is wholly different in real life from his TV persona.
Still, G-20 leaders were tough on Mr Trump when they thought they needed to be.
French officials said they led a charge to ensure the final communique would not be fudged to mask Mr Trump's isolation on climate change. Chinese President Xi Jinping got in an early dig at America First protectionism on Friday.
And Mr Putin landed Mr Trump in political hot water back home, when he insisted the President told him he "accepted" Russia's denials that it was involved in the hacking of last year's (2016) US presidential election. The White House denied Mr Trump had said that.
Nor did Mr Trump's general good humour hold through the whole summit. In a session on trade on Friday,
Mr Trump listened "with a face like thunder" as Mr Xi responded to his claims of unfair trade, according to a Western diplomat who was present.
Still, it could have been worse. Mr Trump was routinely seen chatting with groups of smiling leaders, and was visibly more at ease than he had been in May.
G-20 delegates seem keenly aware that they need to pick their battles.
Mexican officials said they agreed ahead of time with their US counterparts not to mention the border wall that Mr Trump has promised to build between the two countries.
British Prime Minister Theresa May opted not to get into the details of their differences over free trade or other areas of potential divergence.
And Chinese officials said they have learnt not to react to every Trump tweet, looking at them as bargaining tactics.
An incident on the final day illustrated the key role that Ms Ivanka Trump is playing in the world's attempts to find an accommodation with the US President. When Mr Trump stepped out of the room during a session on Africa, his daughter took his seat as the representative of the world's most powerful country.
That moment exploded on social media, but Dr Merkel - who like other leaders, from Saudi Arabia to China has been courting Mr Trump's daughter as a way to get his ear - brushed it off, saying it was normal because Ms Trump is also a White House aide.
The bureaucratic and personal relationships built at G-7 and G-20 summits come into their own when crises develop, said Mr Simon Fraser, formerly the UK foreign ministry's top diplomat and now partner at Flint Global, a London-based consultancy.
They are also important as venues for leaders to take each other's measure, as occurred with the Trump-Putin meeting, he said.
"I think the reason their meeting went long was that they wanted to demonstrate to each other that they could handle it. It's a bit like an arm wrestling contest," Mr Fraser said.
"When these people meet there really is a lot of psychology about leadership and relationships that goes into it."
None of this can hide the tensions that are bristling over a wide range of issues. A trade war over steel may not be far away and G-20 leaders made no major concessions to Mr Trump.
There was no mention of North Korea in the final statement and questions were immediately raised about the viability of the Syrian ceasefire deal he brokered with Mr Putin.
For now, though, the leaders of the world's biggest countries were able to go home relieved that the worst did not happen. Mr Trump even directed a laudatory tweet at Dr Merkel on his way back to Washington.