{"problem":{"name":"A. If at first you don't succeed...","description":{"content":"Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF991A"},"statements":[{"statement_type":"Markdown","content":"Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.\n\nSome of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.\n\nBased on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?\n\n## Input\n\nThe first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \\leq A, B, C, N \\leq 100$).\n\n## Output\n\nIf a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.\n\nIf such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.\n\n[samples]\n\n## Note\n\nThe first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.\n\nIn the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.\n\nThe third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"每个学生都热切期盼着考试顺利通过的那一天。因此，Vasya 也准备庆祝，但遗憾的是，他没有通过。然而，Vasya 同班的许多同学却更成功，考试后进行了庆祝。\n\n其中一些人在 BugDonalds 餐厅庆祝，一些人在 BeaverKing 餐厅庆祝，最成功的同学甚至足够快地在两家餐厅都庆祝了。没有通过考试的学生则没有在任何一家餐厅庆祝，选择留在家中准备补考。但这很快让 Vasya 感到无聊，于是他开始在 Kilogramm 上查看庆祝照片。他发现，总共有 $A$ 名学生去了 BugDonalds，$B$ 名学生去了 BeaverKing，$C$ 名学生去了两家餐厅。Vasya 还知道，他的班级共有 $N$ 名学生。\n\n基于这些信息，Vasya 希望判断这些数据是否自相矛盾，或者如果不矛盾，他的班级中有多少学生没有通过考试。你能帮助他吗，这样他就不会浪费宝贵的备考时间了？\n\n第一行包含四个整数 — $A$、$B$、$C$ 和 $N$（$0 lt.eq A, B, C, N lt.eq 100$）。\n\n如果存在一种 $N$ 名学生的分配方式，使得 $A$ 名学生去了 BugDonalds，$B$ 名去了 BeaverKing，$C$ 名去了两家餐厅，且至少有一名学生留在家中（已知 Vasya 没有通过考试并留在家中），请输出一个整数 —— 没有通过考试的学生人数（包括 Vasya）。 \n\n如果这样的分配不存在，且 Vasya 在确定 $A$、$B$、$C$ 或 $N$ 的数值时出错（如样例 2 和 3 所示），请输出 $-1$。\n\n第一个样例描述了以下情况：$5$ 名学生只去了 BugDonalds，$5$ 名学生只去了 BeaverKing，$5$ 名学生去了两家餐厅，$5$ 名学生（包括 Vasya）没有通过考试。\n\n在第二个样例中，$2$ 名学生只去了 BugDonalds，$2$ 名学生只去了 BeaverKing，但这意味着班级中所有 $4$ 名学生都通过了考试，这与 Vasya 没有通过考试的事实相矛盾，因此这种情况不可能成立。\n\n第三个样例描述了一种情况：有 $2$ 名学生去了 BugDonalds，但班级总共只有 $1$ 名学生，这显然不可能。\n\n## Input\n\n第一行包含四个整数 — $A$、$B$、$C$ 和 $N$（$0 lt.eq A, B, C, N lt.eq 100$）。\n\n## Output\n\n如果存在一种 $N$ 名学生的分配方式，使得 $A$ 名学生去了 BugDonalds，$B$ 名去了 BeaverKing，$C$ 名去了两家餐厅，且至少有一名学生留在家中（已知 Vasya 没有通过考试并留在家中），请输出一个整数 —— 没有通过考试的学生人数（包括 Vasya）。如果这样的分配不存在，且 Vasya 在确定 $A$、$B$、$C$ 或 $N$ 的数值时出错（如样例 2 和 3 所示），请输出 $-1$。\n\n[samples]\n\n## Note\n\n第一个样例描述了以下情况：$5$ 名学生只去了 BugDonalds，$5$ 名学生只去了 BeaverKing，$5$ 名学生去了两家餐厅，$5$ 名学生（包括 Vasya）没有通过考试。在第二个样例中，$2$ 名学生只去了 BugDonalds，$2$ 名学生只去了 BeaverKing，但这意味着班级中所有 $4$ 名学生都通过了考试，这与 Vasya 没有通过考试的事实相矛盾，因此这种情况不可能成立。第三个样例描述了一种情况：有 $2$ 名学生去了 BugDonalds，但班级总共只有 $1$ 名学生，这显然不可能。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"Let $ A $: number of students who visited BugDonalds  \nLet $ B $: number of students who visited BeaverKing  \nLet $ C $: number of students who visited both restaurants  \nLet $ N $: total number of students in the group  \n\nDefine:  \n- Students who passed the exam = $ A + B - C $ (by inclusion-exclusion)  \n- Students who did not pass the exam = $ N - (A + B - C) $\n\nConstraints:  \n1. $ 0 \\leq C \\leq \\min(A, B) $ (cannot have more students in both than in either)  \n2. $ A + B - C \\leq N $ (number of students who passed cannot exceed total)  \n3. $ N - (A + B - C) \\geq 1 $ (at least Vasya did not pass; so at least one failed)  \n\nIf all constraints are satisfied, output:  \n$$\nN - (A + B - C)\n$$\n\nOtherwise, output:  \n$$\n-1\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF991A","tags":["implementation"],"sample_group":[["10 10 5 20","5"],["2 2 0 4","\\-1"],["2 2 2 1","\\-1"]],"created_at":"2026-03-03 11:00:39"}}