okay I'll try to explain it a bit deeper
Dengan - for one context, like you go out with friends,'with' here can be replaced with 'dengan/bersama'. dengan and bersama are interchangeable for this context.
Ex: Kami makan dengan seorang teman / Kami makan bersama seorang teman.
But, 'dengan' always need object. you can't say "kami makan dengan." because it has no meaning.
if you find a sentence like "kami makan bersama", that's correct BUT has different meaning. Bersama + no object, means 'together'.
Ex: Kami melompat bersama / Kami melompat bersama-sama = we jump together
* actually Indonesian don't really care about the usage of bersama/bersama-sama in daily/natural conversation. If you say "ayo pergi bersama", they will understand that you invite them to go together with you
** the slang of bersama/bersama-sama (together) is "bareng"
Dengan - also means 'by' if you talk about the way you do something
Ex: Aku belajar Bahasa Inggris dengan membaca buku = I learn English by reading books
Sama - it means same, like Roeker told you before.
But sometimes in daily conversation, Indonesian use 'sama' as a substituter of 'dengan/bersama (with)' but it sounds informal.
Ex: Dia belanja bersama temannya / Dia belanja sama temannya = she goes shopping with her friend.
*If you a beginner indonesian learner, I don't recommend you to use 'sama' as with. Natives will understand you but it's not good to be applied as language practice. Unless you want to sound natural in daily conversation
Untuk - for, like Roeker told you before.
But, in some contexts 'untuk' means 'to'.
Ex: Pemerintah membuat sebuah kebijakan baru untuk meningkatkan kualitas pangan = The government make a new policy to increase the food quality
Hope it enlightens you