{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eNow, Bob is playing an interesting game in which he is a general of a harmonious army. There are $n$ soldiers in this army. Each soldier should be in one of the two occupations, Mage or Warrior. There are $m$ pairs of soldiers having combination ability. There are three kinds of combination ability. If the two soldiers in a pair are both Warriors, the army power would be increased by $a$. If the two soldiers in a pair are both Mages, the army power would be increased by $c$. Otherwise the army power would be increased by $b$, and $b \u003d a / 4 + c / 3$, guaranteed that $4 | a$ and $3 | c$. Your task is to output the maximum power Bob can increase by arranging the soldiers\u0027 occupations.\u003cbr\u003e\u003cbr\u003eNote that the symbol $a | b$ means that $a$ divides $b$, e.g. , $3|12$ and $8|24$.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are multiple test cases.\u003cbr\u003e\u003cbr\u003eEach case starts with a line containing two positive integers $n(n \\leq 500)$ and $m(m \\leq 10^4)$.\u003cbr\u003e\u003cbr\u003eIn the following $m$ lines, each line contains five positive integers $u, \\; v, \\; a, \\; b, \\; c$ $(1 \\leq u, v \\leq n, u \\neq v, 1 \\leq a, c \\leq 4 \\times 10 ^6, b \u003d a / 4 + c / 3)$, denoting soldiers $u$ and $v$ have combination ability, guaranteed that the pair $(u,v)$ would not appear more than once.\u003cbr\u003e\u003cbr\u003eIt is guaranteed that the sum of $n$ in all test cases is no larger than $5 \\times 10^3$, and the sum of $m$ in all test cases is no larger than $5 \\times 10^4$."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output one line containing the maximum power Bob can increase by arranging the soldiers\u0027 occupations."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3 2\r\n1 2 8 3 3\r\n2 3 4 3 6\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e12\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}