{"problem":{"name":"D. Seating of Students","description":{"content":"Students went into a class to write a test and sat in some way. The teacher thought: \"Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF904D"},"statements":[{"statement_type":"Markdown","content":"Students went into a class to write a test and sat in some way. The teacher thought: \"Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating.\"\n\nThe class can be represented as a matrix with _n_ rows and _m_ columns with a student in each cell. Two students are neighbors if cells in which they sit have a common side.\n\nLet's enumerate students from 1 to _n_·_m_ in order of rows. So a student who initially sits in the cell in row _i_ and column _j_ has a number (_i_ - 1)·_m_ + _j_. You have to find a matrix with _n_ rows and _m_ columns in which all numbers from 1 to _n_·_m_ appear exactly once and adjacent numbers in the original matrix are not adjacent in it, or determine that there is no such matrix.\n\n## Input\n\nThe only line contains two integers _n_ and _m_ (1 ≤ _n_, _m_ ≤ 105; _n_·_m_ ≤ 105) — the number of rows and the number of columns in the required matrix.\n\n## Output\n\nIf there is no such matrix, output \"_NO_\" (without quotes).\n\nOtherwise in the first line output \"_YES_\" (without quotes), and in the next _n_ lines output _m_ integers which form the required matrix.\n\n[samples]\n\n## Note\n\nIn the first test case the matrix initially looks like this:\n\n1 2 3 4\n5 6 7 8\n\nIt's easy to see that there are no two students that are adjacent in both matrices.\n\nIn the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors.","is_translate":false,"language":"English"}],"meta":{"iden":"CF904D","tags":["constructive algorithms"],"sample_group":[["2 4","YES\n5 4 7 2 \n3 6 1 8"],["2 1","NO"]],"created_at":"2026-03-03 11:00:39"}}