messages
listlengths 2
2
|
---|
[
{
"role": "assistant",
"content": "v1, v2 = input().split()\nt, d = input().split()\nv1 = int(v1)\nv2 = int(v2)\nt = int(t)\nd = int(d)\na = 1\nv = v1\ndistance = 0\nfor i in range(t):\n if v - v2 > (t - i - 1) * d:\n a *= - 1\n v = (t - i - 1) * d + v2\n distance += v\n v += a * d\nprint(distance)\n"
},
{
"role": "user",
"content": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class codeforces_534_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int v1 = sc.nextInt();\n int v2 = sc.nextInt();\n int t = sc.nextInt();\n int d = sc.nextInt();\n long[][] dp = new long[t - 1][1150];\n for (int i = 0; i < t - 1; i++) {\n Arrays.fill(dp[i], -(long) (1e17));\n }\n dp[0][v1] = v1;\n long sum = 0;\n for (int i = 1; i < t - 1; i++) {\n for (int j = 0; j < 1150; j++) {\n for (int x = 0; x <= d; x++) {\n if (j + x < 1150) dp[i][j] = Math.max(dp[i][j], dp[i - 1][j + x] + j);\n }\n for (int x = d; x >= 0; x--) {\n if (j - x >= 0) {\n dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - x] + j);\n }\n }\n }\n }\n long ans = Long.MIN_VALUE;\n for (int i = t - 2; i < t - 1; i++) {\n for (int j = 0; j < 1150; j++) {\n if (Math.abs(j - v2) <= d) ans = Math.max(ans, dp[i][j] + v2);\n }\n }\n System.out.println(ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, k = map(int, input().split())\nx = 0\nif k <= max(n ** 2 // 2, n ** 2 - (n ** 2 // 2)):\n print('YES')\n for i in range(n):\n for j in range(n):\n if i % 2 == j % 2 and x < k:\n print('L', end='')\n x += 1\n else:\n print('S', end='')\n print()\nelse:\n print('NO')\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_544_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int count = scan.nextInt();\n printIsland(n, count);\n }\n\n public static void printIsland(int n, int count) {\n int a = (n + 1) / 2;\n int b = n / 2;\n int max = a * a + b * b;\n if (count > max) {\n System.out.println(\"NO\");\n return;\n }\n System.out.println(\"YES\");\n for (int i = 0; i < n; i++) {\n StringBuilder sb = new StringBuilder();\n for (int j = 0; j < n; j++) {\n if ((i + j) % 2 == 0 && count > 0) {\n sb.append('L');\n count--;\n } else {\n sb.append('S');\n }\n }\n System.out.println(sb);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "k, n, w = input().split()\nif 1 <= int(k) and int(w) <= 1000:\n total = 0\n for i in range(1, int(w) + 1):\n total += i * int(k)\n if total > int(n):\n print(total - int(n))\n else:\n print(0)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_546_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long pandu, vundu, urdu, c = 0;\n pandu = sc.nextLong();\n vundu = sc.nextLong();\n urdu = sc.nextLong();\n for (int i = 1; i <= urdu; i++) {\n c += i * pandu;\n }\n if (c < vundu) {\n System.out.print(\"0\");\n } else {\n System.out.print(c - vundu);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nwhile n % 2 == 0:\n n /= 2\nif n == 1:\n print('YES')\nelse:\n print('NO')\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_55_A {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n, i = 1, k = 0, p = 1;\n boolean flag = true;\n int[] a = new int[1000];\n n = scan.nextInt();\n i = 0;\n while (k <= n) {\n i += k;\n if (i >= n) {\n while (!(i < n)) i = i - n;\n }\n ++a[i];\n ++k;\n }\n for (i = 0; i < n; ++i)\n if (a[i] == 0) {\n flag = false;\n break;\n }\n if (flag) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def rememberTheNumber(nums, i, operations, ans):\n if i >= 3:\n return\n for j in range(4):\n for k in range(j + 1, 4):\n if (nums[j] != - 1 and nums[k] != - 1):\n s = nums[j]\n nums[j] = - 1\n t = nums[k]\n if (operations[i] == '+'):\n nums[k] = s + t\n elif (operations[i] == '*'):\n nums[k] = s * t\n if (i == 2 and nums[k] < ans[0]):\n ans[0] = nums[k]\n rememberTheNumber(nums, i + 1, operations, ans)\n nums[j] = s\n nums[k] = t\n\n\nnums = list(map(int, input().split()))\noperations = list(map(str, input().split()))\nans = [10000000000000000000000000]\nrememberTheNumber(nums, 0, operations, ans)\nprint(ans[0])\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_55_B {\n static long min;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n min = Long.MAX_VALUE;\n ArrayList<Long> arr = new ArrayList<>();\n for (int i = 0; i < 4; i++) {\n arr.add(sc.nextLong());\n }\n String[] ops = new String[3];\n for (int i = 0; i < 3; i++) {\n ops[i] = sc.next();\n }\n util(arr, ops, 0);\n System.out.println(min);\n }\n\n public static void util(ArrayList<Long> arr, String[] ops, int idx) {\n if (idx == 3) {\n min = Math.min(min, arr.get(0));\n return;\n }\n for (int i = 0; i < arr.size(); i++) {\n for (int j = i + 1; j < arr.size(); j++) {\n ArrayList<Long> a = new ArrayList<>();\n for (int k = 0; k < arr.size(); k++) {\n if (k != j && k != i) {\n a.add(arr.get(k));\n }\n }\n long res;\n if (idx < 3 && ops[idx].equals(\"+\")) {\n res = arr.get(i) + arr.get(j);\n } else {\n res = arr.get(i) * arr.get(j);\n }\n a.add(res);\n util(a, ops, idx + 1);\n }\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "inp = int(input())\nlista = []\nlista = [int(x) for x in input().split()]\nfor i in range(len(lista)):\n if i == 0:\n print(f\"{lista[i+1] - lista[i]} {lista[len(lista)-1] - lista[i]}\")\n continue\n elif i == len(lista) - 1:\n print(\n f\"{lista[len(lista)-1] - lista[len(lista)-2]} {lista[len(lista)-1] - lista[0]}\")\n continue\n elif lista[i] - lista[i - 1] > lista[i + 1] - lista[i]:\n print(lista[i + 1] - lista[i], end=\" \")\n else:\n print(lista[i] - lista[i - 1], end=\" \")\n if lista[len(lista) - 1] - lista[i] > lista[i] - lista[0]:\n print(lista[len(lista) - 1] - lista[i])\n else:\n print(lista[i] - lista[0])\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_567_A {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int a = s.nextInt();\n int ar[] = new int[a];\n int max = 0, min = 0;\n for (int i = 0; i < ar.length; i++) ar[i] = s.nextInt();\n for (int i = 0; i < ar.length; i++) {\n max = Math.max(ar[i] - ar[0], ar[ar.length - 1] - ar[i]);\n if (i == 0) min = ar[i + 1] - ar[i];\n else if (i == ar.length - 1) min = ar[i] - ar[i - 1];\n else min = Math.min(ar[i] - ar[i - 1], ar[i + 1] - ar[i]);\n System.out.println(min + \" \" + max);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "t, s, q = map(int, input().split())\nans = 0\nwhile (s < t):\n s *= q\n ans += 1\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_569_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int T = in.nextInt();\n int S = in.nextInt();\n int q = in.nextInt();\n long previous = S;\n int answer = 0;\n while (previous < T) {\n answer++;\n previous *= q;\n }\n System.out.println(answer);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "N = int(input())\nA = list(map(int, input().split()))\nmn, mx = N + 1, - 1\nfor i in range(N):\n if (i + 1 != A[i]):\n mn = min(mn, i)\n mx = max(mx, i)\nif (mx == - 1):\n print('0 0')\nelse:\n A = A[: mn] + A[mn: (mx + 1)][:: - 1] + A[(mx + 1):]\n if (sorted(A) == A):\n print(mn + 1, mx + 1)\n else:\n print('0 0')\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_56_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int len = scan.nextInt();\n int a[] = new int[len];\n for (int i = 0; i < len; i++) {\n a[i] = scan.nextInt();\n }\n int l = 0;\n int r = 0;\n boolean flag = false;\n boolean isTrue = false;\n loop:\n for (int i = 0; i < len; i++) {\n if (a[i] != i + 1 && !flag) {\n l = i + 1;\n flag = true;\n continue;\n }\n if (a[i] != i + 1 && flag) {\n r = i + 1;\n if ((a[r - 1] - a[r - 2] > 0)) {\n isTrue = true;\n break loop;\n }\n }\n }\n System.out.println((!isTrue) ? l + \" \" + r : \"0\" + \" \" + \"0\");\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import math\nn = int(input())\nx = 1\nwhile math.log2(n) % 1:\n x += 1\n n -= 2 ** (int(math.log2(n)))\nprint(x)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_579_A {\n public static void main(String[] args) {\n Scanner str = new Scanner(System.in);\n int n = str.nextInt();\n String s = \"\";\n while (n > 0) {\n int x = n % 2;\n n /= 2;\n s += x + \"\";\n }\n int ans = 0;\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) == '1') {\n ans++;\n }\n }\n System.out.println(ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "a, b = map(int, input().split())\nprint(min(a, b), (max(a, b) - min(a, b)) // 2)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_581_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a, b;\n a = sc.nextInt();\n b = sc.nextInt();\n int count = 0;\n while (true) {\n if (a > 0 && b > 0) {\n count++;\n a--;\n b--;\n } else break;\n }\n int ans = a / 2 + b / 2;\n System.out.println(count + \" \" + ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\narr = list(map(int, input().strip().split()))[: n]\nans = [0] * n\nmx = arr[- 1]\nfor i in range(n - 2, - 1, - 1):\n ans[i] = max(0, mx - arr[i] + 1)\n if arr[i] > mx:\n mx = arr[i]\nprint(* ans)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_581_B {\n static TreeSet<Long> set;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int n = in.nextInt();\n long[] a = new long[n];\n for (int i = 0; i < n; i++) a[i] = in.nextLong();\n long[] dp = new long[n + 1];\n Arrays.fill(dp, -1);\n dp[n - 1] = a[n - 1];\n for (int i = n - 1; i >= 0; i--) {\n dp[i] = Math.max(dp[i + 1], a[i]);\n }\n for (int i = 0; i < n; i++) {\n if (a[i] > dp[i + 1]) pw.print(0 + \" \");\n else pw.print((dp[i + 1] - a[i] + 1) + \" \");\n }\n pw.println();\n pw.close();\n }\n\n static void debug(Object... obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def main_function():\n n = int(input())\n a = [int(i) for i in input().split(\" \")]\n current_level = 0\n counter = 0\n counter_turns = - 1\n while counter < len(a):\n counter_turns += 1\n for i in range(len(a)):\n if a[i] != - 1 and a[i] <= counter:\n counter += 1\n a[i] = - 1\n a.reverse()\n print(counter_turns)\n\n\nmain_function()\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_583_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n while (in.hasNext()) {\n int n = in.nextInt();\n int[] a = new int[n];\n int[] b = new int[n];\n int s = -1;\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n b[i] = 0;\n }\n int tem = 1;\n int q = 0;\n while (q != n) {\n s++;\n if (tem == 1) {\n for (int i = 0; i < n; i++) {\n if (a[i] <= q && b[i] == 0) {\n b[i] = 1;\n q++;\n }\n }\n tem = 0;\n } else {\n for (int i = n - 1; i >= 0; i--) {\n if (a[i] <= q && b[i] == 0) {\n b[i] = 1;\n q++;\n }\n }\n tem = 1;\n }\n }\n System.out.println(s);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nfor i in range(n, 0, - 1):\n if n % i == 0:\n n = i\n print(i, end=' ')\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_58_B {\n public static void main(String[] args) throws java.lang.Exception {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n System.out.println(n + \" \");\n int m = n;\n for (int i = n - 1; i > 0; i--) {\n if (m % i == 0) {\n System.out.println(i + \" \");\n m = i;\n }\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nr = [* map(int, input().split())]\nans = abs(r[0])\nfor i in range(1, n):\n ans += abs(r[i] - r[i - 1])\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_596_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = scan.nextInt();\n }\n long answer = Math.abs(arr[0]);\n for (int i = 1; i < n; i++) {\n answer += Math.abs(arr[i] - arr[i - 1]);\n }\n System.out.println(answer);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "t = int(input())\n\n\ndef solve(n):\n s = (1 + n) * n // 2\n t = 1\n while t <= n:\n s -= 2 * t\n t *= 2\n return s\n\n\nfor _ in range(t):\n n = int(input())\n print(solve(n))\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_598_A {\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n int q = sc.nextInt();\n while (q-- > 0) {\n int n = sc.nextInt();\n long s = 0;\n int x = (int) (Math.log(n) / Math.log(2));\n x++;\n s =\n -1 * (long) Math.pow(2, x)\n + 2\n + ((long) n * (long) (n + 1)) / 2\n - (long) Math.pow(2, x);\n System.out.println(s);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "txt = input()\ncu = 0\ncl = 0\nfor z in txt:\n if z.islower():\n cl = cl + 1\n else:\n cu = cu + 1\nif cu > cl:\n out = txt.upper()\nelse:\n out = txt.lower()\nprint(out)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_59_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String word = in.next();\n int uppercase = 0;\n int lowercase = 0;\n for (int i = 0; i < word.length(); i++) {\n char ch = word.charAt(i);\n if (Character.isUpperCase(ch)) {\n uppercase++;\n } else {\n lowercase++;\n }\n }\n if (uppercase > lowercase) System.out.println(word.toUpperCase());\n else if (lowercase > uppercase) System.out.println(word.toLowerCase());\n else System.out.println(word.toLowerCase());\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nl = [0 for _ in range(1000010)]\ndp = [0 for _ in range(1000010)]\nfor i in range(n):\n a, b = map(int, input().split())\n l[a] = b\nif l[0] > 0:\n dp[0] = 1\nmx = 0\nfor i in range(1, 1000010):\n if (l[i] == 0):\n dp[i] = dp[i - 1]\n else:\n if (l[i] >= i):\n dp[i] = 1\n else:\n dp[i] = dp[i - l[i] - 1] + 1\n if (dp[i] > mx):\n mx = dp[i]\nprint(n - mx)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_607_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int max = 0;\n int n = sc.nextInt();\n int[] beacon = new int[1000001];\n int[] dp = new int[1000001];\n for (int i = 0; i < n; i++) {\n int a = sc.nextInt();\n beacon[a] = sc.nextInt();\n }\n if (beacon[0] != 0) dp[0] = 1;\n for (int i = 1; i < 1000001; i++) {\n if (beacon[i] != 0 && beacon[i] < i) {\n dp[i] = dp[i - beacon[i] - 1] + 1;\n } else if (beacon[i] != 0) {\n dp[i] = 1;\n } else {\n dp[i] = dp[i - 1];\n }\n max = Math.max(max, dp[i]);\n }\n System.out.print(n - max);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\ninput = sys.stdin.readline\nn, s = map(int, input().split())\nc = 0\nfor _ in range(n):\n f, t = map(int, input().split())\n x = t - (s - f)\n if x > c:\n c = x\nprint(s + c)\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class codeforces_608_A {\n public static void main(String[] args) {\n FastScanner in = new FastScanner();\n Scanner sc = new Scanner(System.in);\n PrintWriter o = new PrintWriter(System.out);\n int n = sc.nextInt();\n int s = sc.nextInt();\n int max = 0;\n while (n-- > 0) {\n int f = sc.nextInt();\n int t = sc.nextInt();\n if (max < f + t) {\n max = f + t;\n }\n }\n o.println(Math.max(max, s));\n o.close();\n }\n\n static class FastScanner {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(\"\");\n\n public String next() {\n while (!st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n public String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n byte nextByte() {\n return Byte.parseByte(next());\n }\n\n short nextShort() {\n return Short.parseShort(next());\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return java.lang.Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def _input(): return map(int, input().split())\n\n\nn, m = _input()\nlst = list(_input())\nl = {}\nfor i in range(n):\n if lst[i] not in l:\n l[lst[i]] = 1\n else:\n l[lst[i]] += 1\nres = 0\nfor i in range(n):\n if l[lst[i]] > 1:\n res += n - i - l[lst[i]]\n l[lst[i]] -= 1\n else:\n res += n - i - 1\nprint(res)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_609_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n int arr[] = new int[n];\n int gen[] = new int[11];\n for (int i = 0; i < n; i++) {\n arr[i] = in.nextInt();\n gen[arr[i]]++;\n }\n long ans = 0;\n for (int i = 1; i <= m; i++) {\n for (int k = 1; k <= m; k++) {\n if (i != k) {\n ans += (long) gen[i] * gen[k];\n }\n }\n }\n System.out.println(ans / 2);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\na = list(map(int, input().split()))\nb = [0] * n\nfor i in range(n):\n b[a[i] - 1] = i\nres = 0\nfor i in range(1, n):\n res += abs(b[i] - b[i - 1])\nprint(res)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_612_B {\n public static void main(String args[]) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n int dp[] = new int[200001];\n for (int i = 0; i < n; i++) {\n dp[s.nextInt()] = i;\n }\n long ans = 0;\n for (int i = 2; i <= n; i++) {\n ans += Math.abs(dp[i] - dp[i - 1]);\n }\n System.out.println(ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "from math import prod\ninput()\na = input()\nprint(0 if a.count(\"1\") == 0 else prod(\n [i.count(\"0\") + 1 for i in a.strip(\"0 \").split('1')]))\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_617_B {\n static Scanner input = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = input.nextInt();\n List<Integer> arr = new ArrayList<>();\n for (int i = 0; i < n; i++) if (input.nextInt() == 1) arr.add(i);\n if (arr.isEmpty()) System.out.println(0);\n else {\n long result = 1;\n for (int i = 1; i < arr.size(); i++) result *= arr.get(i) - arr.get(i - 1);\n System.out.println(result);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import collections\nimport heapq\nimport sys\nimport math\nimport itertools\nimport bisect\nfrom io import BytesIO, IOBase\nimport os\n\n\ndef valid(i, j, n, m):\n if i < n and i >= 0 and j >= 0 and j < m:\n return True\n return False\n\n\ndef sumn(i, n):\n return (n - i) * (i + n) / 2\n\n\ndef sqfun(a, b, c):\n return (- b + math.sqrt(b * b - 4 * a * c)) / 2 * a\n\n\ndef value(): return tuple(map(int, input().split()))\ndef values(): return tuple(map(int, sys.stdin.readline().split()))\ndef inlst(): return [int(i) for i in input().split()]\ndef inlsts(): return [int(i) for i in sys.stdin.readline().split()]\ndef inp(): return int(input())\ndef inps(): return int(sys.stdin.readline())\ndef instr(): return input()\ndef stlst(): return [i for i in input().split()]\n\n\ndef f(s):\n r = ''\n for i in s:\n if i not in ['-', ';', '_']:\n r += i.lower()\n return r\n\n\ndef solve():\n l = []\n for i in range(3):\n l.append(f(input()))\n t = itertools.permutations(l, len(l))\n l = []\n for i in t:\n l.append(\"\".join(i))\n for i in range(inp()):\n if f(instr()) in l:\n print('ACC')\n else:\n print('WA')\n\n\nif __name__ == \"__main__\":\n solve()\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_61_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String word1 = in.nextLine().replaceAll(\"[^a-zA-Z]\", \"\").toLowerCase();\n String word2 = in.nextLine().replaceAll(\"[^a-zA-Z]\", \"\").toLowerCase();\n String word3 = in.nextLine().replaceAll(\"[^a-zA-Z]\", \"\").toLowerCase();\n String perm1 = word1 + word2 + word3;\n String perm2 = word1 + word3 + word2;\n String perm3 = word2 + word1 + word3;\n String perm4 = word2 + word3 + word1;\n String perm5 = word3 + word2 + word1;\n String perm6 = word3 + word1 + word2;\n int students = in.nextInt();\n in.nextLine();\n for (int i = 0; i < students; i++) {\n String testCase = in.nextLine().replaceAll(\"[^a-zA-Z]\", \"\").toLowerCase();\n if (testCase.equals(perm1)\n || testCase.equals(perm2)\n || testCase.equals(perm3)\n || testCase.equals(perm4)\n || testCase.equals(perm5)\n || testCase.equals(perm6)) {\n System.out.println(\"ACC\");\n } else {\n System.out.println(\"WA\");\n }\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nlst = list(map(int, input().split()))\nlst.sort()\nlst.reverse()\nod = 0\nfor i in lst:\n if (i & 1):\n od += 1\nsum = 0\nok = 0\nfor i in range(n):\n if (lst[i] % 2 == 0):\n sum += lst[i]\n else:\n if (ok or od > 1):\n sum += lst[i]\n od -= 1\n ok = not ok\nprint(sum)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_621_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n List<Long> list = new ArrayList<>();\n for (int i = 0; i < n; i++) list.add(sc.nextLong());\n List<Long> odd = new ArrayList<>();\n long sum = 0;\n for (long i : list) {\n if (i % 2 == 0) sum += i;\n else odd.add(i);\n }\n Collections.sort(odd);\n for (long i : odd) sum += i;\n if (odd.size() % 2 != 0) sum -= odd.get(0);\n System.out.println(sum);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "from cmd import IDENTCHARS\nn = int(input())\nl = 1\nr = n\nwhile (l < r):\n mid = l + (r - l) // 2\n idxcnt = mid * (mid + 1) / 2\n if (idxcnt < n):\n l = mid + 1\n else:\n r = mid\nl -= 1\nidxcnt = l * (l + 1) / 2\nprint(int(n - idxcnt))\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_622_A {\n public static final int BUFFERSIZE = 512000;\n private static Scanner sc =\n new Scanner(new BufferedReader(new InputStreamReader(System.in), BUFFERSIZE));\n private static PrintWriter out =\n new PrintWriter(new BufferedOutputStream(System.out, BUFFERSIZE));\n\n public static void solve() {\n long position = sc.nextLong();\n long nrstSeqStartIndx = 1;\n while (getValueAtIndex(nrstSeqStartIndx * 2) < position) {\n nrstSeqStartIndx *= 2;\n }\n while (getValueAtIndex(nrstSeqStartIndx + 1) <= position) nrstSeqStartIndx++;\n long startIndex = getValueAtIndex(nrstSeqStartIndx);\n out.println((position - startIndex) + 1);\n }\n\n public static long getValueAtIndex(long index) {\n return 1 + ((index - 1) * index / 2);\n }\n\n public static void main(String args[]) throws Exception {\n in.init(System.in);\n solve();\n out.close();\n }\n\n public static class in {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n static void init(InputStream input) {\n reader = new BufferedReader(new InputStreamReader(input), BUFFERSIZE);\n tokenizer = new StringTokenizer(\"\");\n }\n\n static String next() throws IOException {\n while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine());\n return tokenizer.nextToken();\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\ninput = sys.stdin.readline\nn = int(input())\na = list(map(int, input().split()))\npre = float('inf')\nans = 0\na.sort(reverse=True)\nfor j in range(n):\n ans += max(0, min(pre - 1, a[j]))\n pre = max(0, min(pre - 1, a[j]))\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class codeforces_624_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n Long[] ans = new Long[n];\n for (int i = 0; i < n; i++) {\n ans[i] = in.nextLong();\n }\n Arrays.sort(ans);\n Long count = ans[n - 1];\n for (int i = n - 2; i >= 0; i--) {\n if (ans[i] < ans[i + 1]) {\n count += ans[i];\n } else {\n while (ans[i] >= ans[i + 1]) {\n ans[i]--;\n }\n if (ans[i] > 0) {\n count += ans[i];\n }\n }\n }\n System.out.println(count);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\ncake = []\nhappiness = 0\nchocCount = 0\nnfat = 1\nfor i in range(n):\n line = str(input())\n cake.append(line)\n for j in line:\n if (j == 'C'):\n chocCount += 1\n if (chocCount > 1):\n for i in range(chocCount, chocCount - 2, - 1):\n nfat *= i\n happiness += nfat / 2\n nfat = 1\n chocCount = 0\nposCount = 0\nfor j in range(n):\n for i in range(n):\n if (cake[i][j] == 'C'):\n chocCount += 1\n if (chocCount > 1):\n for i in range(chocCount, chocCount - 2, - 1):\n nfat *= i\n happiness += nfat / 2\n nfat = 1\n chocCount = 0\nprint(int(happiness))\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_629_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int num = sc.nextInt();\n int counter = 0;\n int fine = 0;\n ArrayList<String> arr = new ArrayList<>();\n for (int i = 0; i < num; i++) {\n String s = sc.next();\n arr.add(s);\n }\n for (int i = 0; i < num; i++) {\n for (int k = 0; k < num; k++) {\n if (arr.get(k).charAt(i) == 'C') {\n counter++;\n }\n }\n fine += (counter * (counter - 1)) / 2;\n counter = 0;\n }\n for (int i = 0; i < num; i++) {\n for (int k = 0; k < num; k++) {\n if (arr.get(i).charAt(k) == 'C') {\n counter++;\n }\n }\n fine += (counter * (counter - 1)) / 2;\n counter = 0;\n }\n System.out.println(fine);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\ninput = sys.stdin.readline\nN = 368\nm = [0] * N\nf = [0] * N\nfor i in range(int(input())):\n x, a, b = input()[: - 1].split()\n a = int(a)\n b = int(b) + 1\n if x == 'M':\n m[a] += 2\n m[b] -= 2\n else:\n f[a] += 2\n f[b] -= 2\na, b, c = 0, 0, 0\nfor i in range(N):\n a += m[i]\n b += f[i]\n if min(a, b) > c:\n c = min(a, b)\nprint(c)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_629_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] FfriendPerDay = new int[367];\n int[] MfriendPerDay = new int[367];\n int answer = 0;\n for (int i = 0; i < n; i++) {\n char c = sc.next().charAt(0);\n int a = sc.nextInt();\n int b = sc.nextInt();\n for (int j = a; j <= b; j++) {\n if (c == 'M') MfriendPerDay[j]++;\n else FfriendPerDay[j]++;\n if (MfriendPerDay[j] < FfriendPerDay[j]) {\n if (MfriendPerDay[j] > answer) answer = MfriendPerDay[j];\n } else {\n if (FfriendPerDay[j] > answer) answer = FfriendPerDay[j];\n }\n }\n }\n System.out.println(answer * 2);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def main():\n input()\n pieces = tuple(zip(map(int, input().split()), input()))\n return Bob_sMaxStrength(pieces)\n\n\ndef Bob_sMaxStrength(pieces):\n pScore = sScore = pMaxScore = sMaxScore = sum(\n piece[0] for piece in pieces if piece[1] == 'B')\n for piece in pieces:\n if piece[1] == 'A':\n pScore += piece[0]\n if pScore > pMaxScore:\n pMaxScore = pScore\n else:\n pScore -= piece[0]\n for i in range(len(pieces) - 1, - 1, - 1):\n if pieces[i][1] == 'A':\n sScore += pieces[i][0]\n if sScore > sMaxScore:\n sMaxScore = sScore\n else:\n sScore -= pieces[i][0]\n if pMaxScore > sMaxScore:\n return pMaxScore\n return sMaxScore\n\n\nif __name__ == '__main__':\n print(main())\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_632_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = sc.nextInt();\n }\n String s = sc.next();\n long sum = 0;\n for (int i = 0; i < s.length(); i++) {\n char ch = s.charAt(i);\n if (ch == 'B') sum += a[i];\n }\n long ans = sum;\n long sum1 = sum;\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) == 'A') sum1 += a[i];\n else sum1 -= a[i];\n ans = Math.max(ans, sum1);\n }\n sum1 = sum;\n for (int i = s.length() - 1; i >= 0; i--) {\n if (s.charAt(i) == 'A') sum1 += a[i];\n else sum1 -= a[i];\n ans = Math.max(ans, sum1);\n }\n System.out.println(ans);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "from collections import Counter\nimport sys\ninput = sys.stdin.readline\nn = int(input())\ns = input()[: - 1].split()\nw = Counter(s)\ns = s[:: - 1]\nc, a = - 1, 0\nfor i in w:\n if w[i] == max(w.values()):\n if s.index(i) > c:\n a = i\n c = s.index(i)\nprint(a)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_637_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int n = in.nextInt();\n int ara[] = new int[n];\n Map<Integer, Integer> map = new HashMap<>();\n for (int i = 0; i < n; i++) {\n int v = in.nextInt();\n ara[i] = v;\n if (!map.containsKey(v)) {\n map.put(v, 1);\n } else {\n map.put(v, map.get(v) + 1);\n }\n }\n int max = 0;\n for (Integer i : map.values()) {\n max = Math.max(max, i);\n }\n Map<Integer, Integer> mm = new HashMap<>();\n for (int i = 0; i < n; i++) {\n if (!mm.containsKey(ara[i])) {\n mm.put(ara[i], 1);\n if (mm.get(ara[i]) == max) {\n pw.println(ara[i]);\n break;\n }\n } else {\n mm.put(ara[i], mm.get(ara[i]) + 1);\n if (mm.get(ara[i]) == max) {\n pw.println(ara[i]);\n break;\n }\n }\n }\n pw.close();\n }\n\n static void debug(Object... obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import queue\nn, b = list(map(int, input().split()))\n\n\nclass Task:\n def __init__(self, time: int, duration: int, index: int) -> None:\n super().__init__()\n self.time = time\n self.duration = duration\n self.index = index\n\n\nremaining = queue.Queue()\nrunning = False\nfinish_time = 0\n\n\ndef run_task(remaining: queue.Queue, finish_time: int):\n task_to_run = remaining.get()\n finish_time = max(finish_time, task_to_run.time) + task_to_run.duration\n result[task_to_run.index] = finish_time\n return finish_time, result\n\n\nresult = {}\nfor i in range(n):\n time, duration = list(map(int, input().split()))\n task = Task(time, duration, index=i)\n result.update({i: 0})\n if task.time > finish_time and remaining.empty():\n running = True\n finish_time = task.time + task.duration\n result[i] = finish_time\n else:\n if task.time >= finish_time and not remaining.empty():\n finish_time, result = run_task(\n remaining=remaining, finish_time=finish_time)\n if remaining.qsize() < b:\n remaining.put(task)\n else:\n result[i] = - 1\nwhile not remaining.empty():\n finish_time, result = run_task(\n remaining=remaining, finish_time=finish_time)\nfor key in result:\n print(result.get(key))\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_644_B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int b = sc.nextInt();\n long[] ans = new long[n];\n LinkedList<Long> q = new LinkedList<>();\n for (int i = 0; i < n; i++) {\n int t = sc.nextInt();\n int d = sc.nextInt();\n while (!q.isEmpty() && q.getFirst() <= t) {\n q.pollFirst();\n }\n if (q.size() <= b) {\n ans[i] = (q.isEmpty() ? t : q.getLast()) + d;\n q.add(ans[i]);\n } else {\n ans[i] = -1;\n }\n }\n for (int i = 0; i < n; ++i) {\n System.out.print(ans[i] + \" \");\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "x, y = map(int, input().split())\nprint(max(x + y - 3 + ((y - x) % 3 > 0), 0))\ndef num_inp(): return int(input())\n\n\ndef arr_inp(): return list(map(int, input().split()))\ndef sp_inp(): return map(int, input().split())\ndef str_inp(): return input()\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_651_A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int a = in.nextInt(), b = in.nextInt();\n int c = 0;\n if (a == 1 && b == 1) {\n pw.println(0);\n } else {\n while (a >= 1 || b >= 1) {\n if (a >= b) {\n b++;\n a -= 2;\n } else {\n a++;\n b -= 2;\n }\n if (a <= 0 || b <= 0) {\n c++;\n break;\n }\n c++;\n }\n pw.println(c);\n }\n pw.close();\n }\n\n static void swap(int a, int b) {\n int t = b;\n b = a;\n a = t;\n }\n\n static void debug(Object... obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nl = list(map(int, input().split()))\nl.sort()\nfor i in l:\n if i + 1 in l and i + 2 in l:\n print('YES')\n break\nelse:\n print('NO')\n"
},
{
"role": "user",
"content": "import java.io.PrintWriter;\nimport java.util.*;\nimport java.util.stream.Collectors;\n\npublic class codeforces_653_A {\n public static void main(String[] args) {\n try (Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out)) {\n int n = in.nextInt();\n List<Integer> a = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n int value = in.nextInt();\n a.add(value);\n }\n a = a.stream().distinct().sorted().collect(Collectors.toList());\n boolean found = false;\n for (int i = 0; i < a.size(); i++) {\n if (i + 1 < a.size() && i + 2 < a.size()) {\n if (a.get(i) + 1 == a.get(i + 1) && a.get(i + 1) + 1 == a.get(i + 2)) {\n found = true;\n }\n }\n }\n out.println(found ? \"YES\" : \"NO\");\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "a, at = map(int, input().split())\nb, bt = map(int, input().split())\nt1, t2 = map(int, input().split(':'))\nst = t2 + (t1 - 5) * 60\nfin = st + at\nnow = 0\nans = 0\nwhile now < fin and now < 1140:\n if now + bt > st:\n ans += 1\n now += b\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class codeforces_665_A {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n StringTokenizer st = new StringTokenizer(br.readLine());\n int a = Integer.parseInt(st.nextToken());\n int tA = Integer.parseInt(st.nextToken());\n st = new StringTokenizer(br.readLine());\n int b = Integer.parseInt(st.nextToken());\n int tB = Integer.parseInt(st.nextToken());\n String timing = br.readLine();\n int hrs = Integer.parseInt(timing.substring(0, 2));\n int mins = Integer.parseInt(timing.substring(3));\n int simDeparture = hrs * 60 + mins;\n int simArrival = simDeparture + tA;\n int counter = 0;\n for (int i = 300; i < 1440; i += b) {\n int busDeparture = i;\n int busArrival = i + tB;\n if (busDeparture >= simArrival || simDeparture >= busArrival) continue;\n counter++;\n }\n pw.println(counter);\n pw.flush();\n pw.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\nprint((n * 2 + 1) // 3)\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class codeforces_669_A {\n public static void main(String[] subhani) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n solve(n);\n }\n\n public static void solve(int n) {\n System.out.println((n / 3) * 2 + (n % 3 == 0 ? 0 : 1));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "li = []\nind = 0\nfor i in range(1, 371):\n temp = []\n p, q = i, i\n count = 0\n while p != 0:\n p //= 10\n count += 1\n if count == 1:\n li.append(i)\n if count == 2:\n temp = []\n while q != 0:\n x = q % 10\n q //= 10\n temp.append(x)\n li = li + temp[:: - 1]\n if count == 3:\n temp = []\n while q != 0:\n x = q % 10\n q //= 10\n temp.append(x)\n li = li + temp[:: - 1]\nli.pop()\nli.pop()\nn = int(input(''))\nprint(li[n - 1])\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_672_A {\n static char[] generateString() {\n StringBuilder sb = new StringBuilder();\n for (int i = 1; i <= 1000; i++) {\n sb.append(i);\n }\n return sb.toString().toCharArray();\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n System.out.println(generateString()[n - 1]);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n = int(input())\narr = list(map(int, input().split()))\nif arr[0] > 15:\n print(15)\nelse:\n for i in range(1, len(arr)):\n if arr[i] - arr[i - 1] > 15:\n print(arr[i - 1] + 15)\n break\n else:\n if arr[- 1] == 90 or arr[- 1] + 15 >= 90:\n print(90)\n else:\n print(arr[- 1] + 15)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_673_A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n ArrayList<Integer> a = new ArrayList<Integer>();\n int value;\n for (int i = 0; i < n; i++) {\n value = sc.nextInt();\n a.add(value);\n }\n int result, pos = 0, flag = 0;\n if (a.get(0) > 15) result = 15;\n else {\n for (int i = 1; i < n; i++) {\n if (a.get(i) - a.get(i - 1) > 15) {\n pos = i - 1;\n flag = 1;\n break;\n }\n }\n if (flag == 1) result = a.get(pos) + 15;\n else result = a.get(n - 1) + 15;\n }\n if (result > 90) result = 90;\n System.out.println(result);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "vamshi, z = map(int, input().split())\nprint((vamshi // z + 1) * z)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_678_A {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int k = scan.nextInt();\n n++;\n int z = 0;\n if (n % k != 0) z = k - n % k;\n System.out.println(n + z);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "def leapyear(n):\n if (n % 400 == 0 or (n % 4 == 0 and n % 100 != 0)):\n return \"y\"\n else:\n return \"n\"\n\n\nn = int(input())\nd = \"f\"\nif (n % 400 == 0 or (n % 4 == 0 and n % 100 != 0)):\n ans = \"ly\"\nelse:\n ans = \"nly\"\nwhile (True):\n if (n % 400 == 0 or (n % 4 == 0 and n % 100 != 0)):\n if (d == \"m\"):\n d = \"w\"\n n += 1\n elif (d == \"t\"):\n d = \"th\"\n n += 1\n elif (d == \"w\"):\n d = \"f\"\n n += 1\n elif (d == \"th\"):\n d = \"sa\"\n n += 1\n elif (d == \"f\"):\n d = \"s\"\n n += 1\n elif (d == \"sa\"):\n d = \"m\"\n n += 1\n elif (d == \"s\"):\n d = \"t\"\n n += 1\n else:\n if (d == \"m\"):\n d = \"t\"\n n += 1\n elif (d == \"t\"):\n d = \"w\"\n n += 1\n elif (d == \"w\"):\n d = \"th\"\n n += 1\n elif (d == \"th\"):\n d = \"f\"\n n += 1\n elif (d == \"f\"):\n d = \"sa\"\n n += 1\n elif (d == \"sa\"):\n d = \"s\"\n n += 1\n elif (d == \"s\"):\n d = \"m\"\n n += 1\n if (d == \"f\" and ans == \"ly\" and leapyear(n) == \"y\"):\n break\n elif (d == \"f\" and ans == \"nly\" and leapyear(n) == \"n\"):\n break\nprint(n)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_678_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int y = in.nextInt();\n boolean leap = check_leap(y);\n int sum = 0;\n int mod = 0;\n for (int i = y + 1; ; i++) {\n if (check_leap(i)) {\n sum += 366;\n } else {\n sum += 365;\n }\n if (sum % 7 == 0) {\n if ((check_leap(i) && leap) || (!check_leap(i) && !leap)) {\n System.out.println(i);\n return;\n } else {\n continue;\n }\n }\n }\n }\n\n static boolean check_leap(int y) {\n return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "u = input\nn, k = map(int, u().split())\nM = [int(i) for i in u().split()]\nm = 0\nfor j in range(n):\n for p in range(n):\n if (0 == M[p]):\n print(p + 1, end=' ')\n break\n for l in range(p + 1 - k):\n M[l] -= 1\n M[p] -= 1\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_67_B extends PrintWriter {\n codeforces_67_B() {\n super(System.out, true);\n }\n\n Scanner sc = new Scanner(System.in);\n\n public static void main(String[] $) {\n codeforces_67_B o = new codeforces_67_B();\n o.main();\n o.flush();\n }\n\n void main() {\n int n = sc.nextInt();\n int k = sc.nextInt();\n int[] bb = new int[n];\n for (int i = 0; i < n; i++) bb[i] = sc.nextInt();\n int[] aa = new int[n];\n int m = 0;\n for (int a = n - 1; a >= 0; a--) {\n int j = 0;\n while (bb[a] > 0) {\n if (aa[j] >= a + k) bb[a]--;\n j++;\n }\n for (int j_ = m++; j_ > j; j_--) aa[j_] = aa[j_ - 1];\n aa[j] = a;\n }\n for (int i = 0; i < n; i++) print(aa[i] + 1 + \" \");\n println();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import os\nimport sys\nimport io\nimport math\nfrom array import array\nfrom math import *\ndef I(): return [* map(int, sys.stdin.readline().split())]\ndef IS(): return input()\n\n\ndef IN(): return int(input())\ndef IF(): return float(input())\n\n\nn = IN()\nl = I()\nf = 1\nl.sort()\nc = 0\nfor i in l:\n if i > c:\n c += 1\nprint(c + 1)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_682_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int n = in.nextInt();\n ArrayList<Integer> list = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n list.add(in.nextInt());\n }\n Collections.sort(list);\n int c = 1;\n for (int i = 0; i < n; i++) {\n if (list.get(i) >= c) {\n c++;\n }\n }\n pw.println(c);\n pw.close();\n }\n\n static void debug(Object... obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import sys\ninput = sys.stdin.readline\nn = int(input())\nw = list(map(int, input().split()))\nc = 2\nfor i in w:\n if i == 1:\n print(c)\n elif i % 2 == 0:\n c = 3 - c\n print(c)\n else:\n print(c)\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_705_B {\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n static FastReader scan = new FastReader();\n\n public static void main(String[] args) {\n int t = 1;\n while (t-- > 0) {\n solve();\n }\n }\n\n public static void solve() {\n int t = scan.nextInt();\n int[] arr = new int[t];\n for (int i = 0; i < arr.length; i++) {\n arr[i] = scan.nextInt();\n }\n int prevWinner = 0;\n for (int i = 0; i < arr.length; i++) {\n if (arr[i] == 1) {\n if (prevWinner == 0) {\n prevWinner = 2;\n }\n }\n if (prevWinner == 2 || prevWinner == 0) {\n if ((arr[i] - 1) % 2 == 0) {\n System.out.println(2);\n prevWinner = 2;\n } else {\n System.out.println(1);\n prevWinner = 1;\n }\n } else {\n if ((arr[i] - 1) % 2 == 0) {\n System.out.println(1);\n prevWinner = 1;\n } else {\n System.out.println(2);\n prevWinner = 2;\n }\n }\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "import re\nn = int(input())\nans, sumL = 1, 0\nfor s in re.split(\"[.?!]\", input()):\n s = s.strip() + '.'\n L = len(s)\n if L > 1:\n if L > n:\n print(\"Impossible\")\n exit()\n if sumL + L + (sumL > 0) > n:\n ans += 1\n sumL = L\n else:\n sumL = sumL + L + (sumL > 0)\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class codeforces_70_B {\n public static void main(String[] args) throws NumberFormatException, IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n String input = br.readLine();\n int max = -1;\n int[] msgLength = new int[input.length() / 2];\n int count = 0;\n int idx = 0;\n for (int i = 0; i < input.length(); i++) {\n char c = input.charAt(i);\n if (c == '.' || c == '?' || c == '!') {\n msgLength[idx++] = ++count;\n if (count > max) max = count;\n i++;\n count = 0;\n } else count++;\n }\n if (max > n) System.out.println(\"Impossible\");\n else {\n int ans = 0;\n for (int i = 0; i < idx; i++) {\n int l = msgLength[i];\n while (i < idx - 1 && l + msgLength[i + 1] + 1 <= n) {\n l += msgLength[i + 1] + 1;\n i++;\n }\n ans++;\n }\n System.out.println(ans);\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "x, y = list(map(int, input().split()))\na = 0\nwhile x >= 0 and y >= 22 or x >= 1 and y >= 12 or x >= 2 and y >= 2:\n if a:\n if y >= 22:\n y -= 22\n elif x >= 1 and y >= 12:\n x -= 1\n y -= 12\n else:\n x -= 2\n y -= 2\n else:\n if x >= 2 and y >= 2:\n x -= 2\n y -= 2\n elif x >= 1 and y >= 12:\n x -= 1\n y -= 12\n else:\n y -= 22\n a = 1 - a\nprint(['Ciel', 'Hanako'][1 - a])\n"
},
{
"role": "user",
"content": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class codeforces_79_A {\n public static boolean canTake(int xNeeded, int xAvailable, int yNeeded, int yAvailable) {\n if (xNeeded > xAvailable) return false;\n if (yNeeded > yAvailable) return false;\n return true;\n }\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(br.readLine());\n int x = Integer.parseInt(st.nextToken());\n int y = Integer.parseInt(st.nextToken());\n int turn = 0;\n while (true) {\n if (turn % 2 == 0) {\n if (canTake(2, x, 2, y)) {\n x -= 2;\n y -= 2;\n } else if (canTake(1, x, 12, y)) {\n x -= 1;\n y -= 12;\n } else if (canTake(0, x, 22, y)) {\n y -= 22;\n } else {\n System.out.println(\"Hanako\");\n return;\n }\n } else {\n if (canTake(0, x, 22, y)) {\n y -= 22;\n } else if (canTake(1, x, 12, y)) {\n x -= 1;\n y -= 12;\n } else if (canTake(2, x, 2, y)) {\n x -= 2;\n y -= 2;\n } else {\n System.out.println(\"Ciel\");\n return;\n }\n }\n turn++;\n }\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "t, m = map(int, input().split())\nalocuente = [0] * m\nind = 1\nfor i in range(t):\n op = input().split()\n if op[0] == 'alloc':\n pos = 0\n for j in range(m):\n if alocuente[j] == 0:\n pos += 1\n if pos == int(op[1]):\n alocuente[j - int(op[1]) + 1: j + 1] = [ind] * int(op[1])\n print(ind)\n ind += 1\n break\n else:\n pos = 0\n else:\n print(\"NULL\")\n if op[0] == 'erase':\n pos = 0\n if int(op[1]) not in alocuente or int(op[1]) == 0:\n print('ILLEGAL_ERASE_ARGUMENT')\n else:\n for j in range(m):\n if int(op[1]) > 0 and alocuente[j] == int(op[1]):\n alocuente[j] = 0\n if op[0] == \"defragment\":\n cnt = 0\n cnt = alocuente.count(0)\n alocuente = [j for j in alocuente if j != 0]\n for j in range(cnt):\n alocuente.append(0)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_7_B {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int t = s.nextInt();\n int m = s.nextInt();\n int[] memory = new int[m];\n int allocIdx = 0;\n for (int j = 0; j < t; j++) {\n switch (s.next()) {\n case \"alloc\":\n int n = s.nextInt();\n int len = 0;\n boolean canAlloc = false;\n for (int i = 0; i < m; i++) {\n if (memory[i] == 0) len++;\n else len = 0;\n if (len == n) {\n canAlloc = true;\n len = i - n + 1;\n break;\n }\n }\n if (canAlloc) {\n allocIdx++;\n for (int i = len; i < len + n; i++) memory[i] = allocIdx;\n System.out.println(allocIdx);\n } else System.out.println(\"NULL\");\n break;\n case \"erase\":\n int x = s.nextInt();\n if (x <= 0) {\n System.out.println(\"ILLEGAL_ERASE_ARGUMENT\");\n break;\n }\n boolean hasErased = false;\n for (int i = 0; i < m; i++) {\n if (memory[i] == x) {\n memory[i] = 0;\n hasErased = true;\n }\n }\n if (!hasErased) System.out.println(\"ILLEGAL_ERASE_ARGUMENT\");\n break;\n case \"defragment\":\n int d = 0;\n for (int i = 0; i < m; i++) {\n if (memory[i] == 0) d++;\n else memory[i - d] = memory[i];\n }\n for (int i = m - d; i < m; i++) memory[i] = 0;\n break;\n default:\n System.out.println(\"h\");\n break;\n }\n }\n s.close();\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "l, r = [int(x) for x in input().split()]\ncurr = r\ns = 0\nwhile curr:\n s += 1\n curr //= 10\nfirst = 10 ** s\nsecond = first // 2\nans = - 1\nfor i in [l, r, first, second]:\n if i >= l and i <= r:\n curr = i\n rev = ''\n for k in str(curr):\n rev += str(9 - int(k))\n ans = max(ans, int(rev) * curr)\nprint(ans)\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_86_A {\n public static int power(Long a) {\n int res = 0;\n while (a > 0) {\n res++;\n a = a / 10;\n }\n return res;\n }\n\n public static long mult(Long a) {\n int pow = power(a);\n long max = 0;\n for (int j = 0; j < pow; ++j) {\n max = max * 10 + 9;\n }\n return a * (max - a);\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long l = in.nextLong();\n long r = in.nextLong();\n long res = 0;\n long[] maxxes = new long[10];\n long temp = 0;\n for (int i = 0; i < 10; ++i) {\n temp = temp * 10 + 9;\n maxxes[i] = temp / 2 * (temp - temp / 2);\n }\n res = Math.max(mult(l), res);\n res = Math.max(mult(r), res);\n temp = 0;\n for (int i = 0; i < 10; ++i) {\n temp = temp * 10 + 9;\n if (l <= temp / 2 && temp / 2 <= r) res = Math.max(maxxes[i], res);\n }\n System.out.println(res);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "record_of_movements = input()\nx, y = 0, 0\nd_movement = {'L': (0, - 1), 'R': (0, 1), 'U': (1, 0), 'D': (- 1, 0)}\nd = {(x, y): ''}\nbug = False\nfor move in record_of_movements:\n temp = (x, y)\n x += d_movement[move][0]\n y += d_movement[move][1]\n if (x, y) not in d:\n for step in d_movement:\n if (x + d_movement[step][0], y + d_movement[step][1]) != temp and (x + d_movement[step][0], y + d_movement[step][1]) in d:\n bug = True\n break\n else:\n bug = True\n if bug:\n break\n d[x, y] = ''\nif bug:\n print('BUG')\nelse:\n print('OK')\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_8_B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int i, j, x = 0, y = 0, k = 0, dx, dy;\n boolean flag = true;\n String s;\n char[] ch = new char[100];\n int[][] co = new int[2][101];\n s = scan.next();\n ch = s.toCharArray();\n co[0][k] = x;\n co[1][k] = y;\n ++k;\n for (i = 0; i < s.length(); ++i) {\n switch (ch[i]) {\n case 'L':\n --x;\n break;\n case 'R':\n ++x;\n break;\n case 'U':\n ++y;\n break;\n case 'D':\n --y;\n break;\n }\n co[0][k] = x;\n co[1][k] = y;\n ++k;\n }\n for (i = 0; i < k - 3; ++i) {\n for (j = i + 3; j < k; ++j) {\n dx = co[0][i] - co[0][j];\n dy = co[1][i] - co[1][j];\n if (dx < 0) dx *= (-1);\n if (dy < 0) dy *= (-1);\n if ((dx <= 1 && dy == 0) || (dy <= 1 && dx == 0)) {\n flag = false;\n break;\n }\n }\n if (!flag) break;\n }\n if (flag) System.out.println(\"OK\");\n else System.out.println(\"BUG\");\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "n, m = map(int, input().split())\ni = 1\nwhile m >= i:\n m -= i\n i = (i % n) + 1\nprint(m)\n"
},
{
"role": "user",
"content": "import java.util.*;\n\npublic class codeforces_92_A {\n public static void main(String[] args) {\n Scanner scn = new Scanner(System.in);\n int n = scn.nextInt();\n int k = scn.nextInt();\n int i = 1, req = 1;\n while (k - req >= 0) {\n if (k - req >= 0) {\n k = k - req;\n } else {\n break;\n }\n i++;\n if (i % n != 0) req = i % n;\n else req = n;\n }\n System.out.println(k);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "pya = int(input())\narre = []\nwhile pya:\n pya -= 1\n arre.append(input().lower())\noString = input()\nlowString = oString.lower()\nletter1 = input()[0].lower()\nletter2 = 'a' if letter1.lower() != 'a' else 'b'\nvalid = [0 for i in range(len(oString))]\nsetcito = set()\nfor x in arre:\n if lowString.find(x) >= 0:\n wat = 0\n while True:\n index = lowString.find(x, wat)\n if index < 0:\n break\n for i in range(index, index + len(x)):\n setcito.add(i)\n wat = index + 1\noString = list(oString)\nfor i in setcito:\n letter = letter1 if lowString[i] != letter1 else letter2\n oString[i] = letter if oString[i].islower() else letter.upper()\nfor x in oString:\n print(x, end=\"\")\nprint()\n"
},
{
"role": "user",
"content": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces_95_A extends PrintWriter {\n codeforces_95_A() {\n super(System.out, true);\n }\n\n Scanner sc = new Scanner(System.in);\n\n public static void main(String[] $) {\n codeforces_95_A o = new codeforces_95_A();\n o.main();\n o.flush();\n }\n\n int compare(char[] aa, int i, char[] bb, int j, int m) {\n while (m-- > 0) {\n char a = Character.toUpperCase(aa[i]);\n char b = Character.toUpperCase(bb[j]);\n if (a != b) return a - b;\n i++;\n j++;\n }\n return 0;\n }\n\n void main() {\n int n = sc.nextInt();\n char[][] ss = new char[n][];\n for (int i = 0; i < n; i++) ss[i] = sc.next().toCharArray();\n char[] cc = sc.next().toCharArray();\n int m = cc.length;\n char c = sc.next().charAt(0);\n char c_ = Character.toUpperCase(c);\n char a = c == 'a' ? 'b' : 'a';\n char a_ = Character.toUpperCase(a);\n boolean[] lucky = new boolean[m];\n for (int j = 0; j < m; j++)\n for (int i = 0; i < n; i++) {\n int l = ss[i].length;\n if (m - j >= l && compare(cc, j, ss[i], 0, l) == 0)\n for (int h = 0; h < l; h++) lucky[j + h] = true;\n }\n for (int j = 0; j < m; j++)\n if (lucky[j]) {\n if (Character.toLowerCase(cc[j]) == c)\n cc[j] = Character.isUpperCase(cc[j]) ? a_ : a;\n else cc[j] = Character.isUpperCase(cc[j]) ? c_ : c;\n }\n println(cc);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "l = []\nlimit = 10000000000\n\n\ndef gen(number, four, seven):\n if (number > limit):\n return\n if (number > 0 and four == seven):\n l.append(number)\n gen(number * 10 + 4, four + 1, seven)\n gen(number * 10 + 7, four, seven + 1)\n\n\ndef main():\n gen(0, 0, 0)\n l.sort()\n n = int(input())\n ans = 0\n for val in l:\n if (val >= n):\n ans = val\n break\n print(ans)\n\n\nmain()\n"
},
{
"role": "user",
"content": "import java.util.Scanner;\n\npublic class codeforces_96_B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long number = in.nextLong();\n long ans = -1, value = 0;\n int mask = 2;\n while (value < number) {\n String s = Integer.toBinaryString(mask++).substring(1);\n int zeros = 0;\n for (char c : s.toCharArray()) if (c == '0') zeros++;\n if (zeros != s.length() - zeros) continue;\n s = s.replace('0', '4');\n s = s.replace('1', '7');\n value = Long.parseLong(s);\n }\n System.out.println(value);\n }\n}\n"
}
] |
[
{
"role": "assistant",
"content": "l = input()\nl = l.split('.')\ns = list(l[0])\np = list(l[1])\ni = int(p[0])\nif s[len(s) - 1] == '9':\n print(\"GOTO Vasilisa.\")\nelif s[len(s) - 1] != '9' and i < 5:\n s = \"\".join(s)\n print(s)\nelse:\n s = \"\".join(s)\n s = str(int(s) + 1)\n print(s)\n"
},
{
"role": "user",
"content": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class codeforces_99_A {\n public static void main(String[] args) {\n char[] str = new Scanner(System.in).nextLine().toCharArray();\n int dotIndex = 0;\n for (int i = 0; i < str.length; i++)\n if (str[i] == '.') {\n dotIndex = i;\n break;\n }\n if (str[dotIndex - 1] == '9') {\n System.out.println(\"GOTO Vasilisa.\");\n } else if (Integer.parseInt(str[dotIndex + 1] + \"\") > 4) {\n String _str = \"\";\n for (int i = 0; i < dotIndex; i++) _str += str[i];\n System.out.println(new BigInteger(_str).add(new BigInteger(\"1\")).toString());\n } else {\n for (int i = 0; i < dotIndex; i++) System.out.print(str[i]);\n System.out.println();\n }\n }\n}\n"
}
] |