buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Linq; using static System.Math; namespace A { class Program { static void Main(string[] args) { var abcd = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (abcd[2] - abcd[0] <= abcd[3]) { Console.WriteLine("Yes"); } else if (Abs(abcd[0] - abcd[1]) <= abcd[3] && Abs(abcd[1] - abcd[2]) <= abcd[3]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Linq; using static System.Math; namespace A { class Program { static void Main(string[] args) { var abcd = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (Abs(abcd[2] - abcd[0]) <= abcd[3]) { Console.WriteLine("Yes"); } else if (Abs(abcd[0] - abcd[1]) <= abcd[3] && Abs(abcd[1] - abcd[2]) <= abcd[3]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 213, 63, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25]]
8
147
3
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int[] a = Input.ScanIntArray(); if (Math.Abs(a[0] - a[2]) < a[3] || (Math.Abs(a[0] - a[1]) < a[3] && Math.Abs(a[1] - a[2]) < a[3])) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int[] a = Input.ScanIntArray(); if (Math.Abs(a[0] - a[2]) <= a[3] || (Math.Abs(a[0] - a[1]) <= a[3] && Math.Abs(a[1] - a[2]) <= a[3])) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 18], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 19], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 18], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 19]]
8
655
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace At { class Program { static void Main(string[] args) { var s = ReadInts(); if (Math.Abs(s[0] - s[2]) < s[3]) WriteLine("Yes"); else { if (Math.Abs(s[0] - s[1]) <= s[3] && Math.Abs(s[1] - s[2]) <= s[3]) WriteLine("Yes"); else WriteLine("No"); } } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace At { class Program { static void Main(string[] args) { var s = ReadInts(); if (Math.Abs(s[0] - s[2]) <= s[3]) WriteLine("Yes"); else { if (Math.Abs(s[0] - s[1]) <= s[3] && Math.Abs(s[1] - s[2]) <= s[3]) WriteLine("Yes"); else WriteLine("No"); } } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
319
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]Colorful Transceivers var line = ReadLine(); int a = line[0]; int b = line[1]; int c = line[2]; int d = line[3]; if (Math.Abs(a - b) <= d | (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } static List<int> ReadLine() { var line = Console.ReadLine(); var array = line.Split(' '); return array.Select(x => int.Parse(x)).ToList(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]Colorful Transceivers var line = ReadLine(); int a = line[0]; int b = line[1]; int c = line[2]; int d = line[3]; if (Math.Abs(a - c) <= d | (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } static List<int> ReadLine() { var line = Console.ReadLine(); var array = line.Split(' '); return array.Select(x => int.Parse(x)).ToList(); } } }
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
184
2
using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Runtime.Remoting.Messaging; using System.Security.Cryptography.X509Certificates; using System.Security.Permissions; using System.Text; using static System.Console; using static System.Math; using static Ex; class AC { /*------------------------------------------------------------------*/ private int a, b, c, d; void Solve() { io.i(out a, out b, out c, out d); io.Yn((Abs(b - a) <= d && Abs(c - d) <= d) || Abs(c - a) <= d); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] args) => new AC().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Ex { #region マクロもどき public static Dictionary<T1, T2> MERGE<T1, T2>(Dictionary<T1, T2> xs, Dictionary<T1, T2> ys) => xs.Except(xs.Join(ys, z => z.Key, z => z.Key, (a, b) => a)) .Concat(ys) .ToDictionary(z => z.Key, z => z.Value); public static void LOG<T>(T x, [CallerLineNumber] int line = 0) => Error.WriteLine($"--- LOG[{line}]: {x} ---"); public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void REP(int a, int b, Action<int, int> f) => REP(a, i => REP(b, j => f(i, j))); public static void REP(int a, int b, int c, Action<int, int, int> f) => REP(a, i => REP(b, j => REP(c, k => f(i, j, k)))); public static void REPEQ(int a, int b, Action<int, int> f) => REPEQ(a, i => REPEQ(b, j => f(i, j))); public static void REPEQ(int a, int b, int c, Action<int, int, int> f) => REPEQ(a, i => REPEQ(b, j => REPEQ(c, k => f(i, j, k)))); public static T MIN<T>(params T[] xs) => xs.Min(); public static T MAX<T>(params T[] xs) => xs.Max(); public static IEnumerable<int> RANGE(int s, int e) => Enumerable.Range(s, e - s + 1); public static int LCM(int a, int b) => a * (b / GCD(a, b)); public static int GCD(int a, int b) => (a < b) ? GCD(b, a) : b == 0 ? a : GCD(b, a % b); public static int LCM(params int[] xs) => xs.Aggregate(LCM); public static int GCD(params int[] xs) => xs.Aggregate(GCD); public static long LCM(long a, long b) => a * (b / GCD(a, b)); public static long GCD(long a, long b) => (a < b) ? GCD(b, a) : b == 0L ? a : GCD(b, a % b); public static long LCM(params long[] xs) => xs.Aggregate(LCM); public static long GCD(params long[] xs) => xs.Aggregate(GCD); #endregion #region 拡張メソッド public static void Rep(this int x, Action<int> f) => REP(x, f); public static void RepEq(this int x, Action<int> f) => REPEQ(x, f); public static int ToInt(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt32(n); } public static int ToInt(this char c) => ToInt(c.ToString()); public static int ToInt(this char[] c) => ToInt(new string(c)); public static long ToLong(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt64(n); } public static long ToLong(this int x) => (long)x; public static IEnumerable<long> ToLong(this IEnumerable<int> xs) => xs.Select(x => x.ToLong()); public static long ToLong(this char c) => ToLong(c.ToString()); public static long ToLong(this char[] c) => ToLong(new string(c)); public static int ToMod(this int x, int mod = (int)(1e9 + 7)) => x % mod; public static long ToMod(this long x, long mod = (long)(1e9 + 7)) => x % mod; public static void Do<T>(this T x, Action<T> f) => f(x); public static TU Then<T, TU>(this T x, Func<T, TU> f) => f(x); public static void Fun<T>(this T[] xs, Action<int> f) => REP(xs.Length, f); public static void Fun<T>(this T[,] xxs, Action<int, int> f) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => f(i, j))); public static bool IsIn<T>(this T[] xs, int i) => 0 <= i && i < xs.Length; public static bool IsIn<T>(this T[,] xxs, int i, int j) => 0 <= i && i < xxs.GetLength(0) && 0 <= j && j < xxs.GetLength(1); public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public class IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public static IEnumerable<IndexedItem<T>> Indexed<T>( this IEnumerable<T> xs) => xs.Select((x, i) => new IndexedItem<T>(i, x)); public static Dictionary<long, int> PrimeFactor(this int x) => ((long)x).PrimeFactor(); public static Dictionary<long, int> PrimeFactor(this long n) { var ret = new Dictionary<long, int>(); for (var i = 2; i <= n; ++i) { if (!ret.ContainsKey(i)) ret[i] = 0; while (n % i == 0) { ++ret[i]; n /= i; } } return ret.Where(kp => kp.Value != 0) .ToDictionary(kp => kp.Key, kp => kp.Value); } public static void Set<T>(this T[] xs, T v) => REP(xs.Length, i => xs[i] = v); public static void Set<T>(this T[,] xxs, T v) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => xxs[i, j] = v)); public static T[] Sort<T>(this T[] xs) { Array.Sort(xs); return xs; } public static T[] SortR<T>(this T[] xs) { Array.Reverse(xs.Sort()); return xs; } public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0'); public static int RoundOff(this double v, int n) => (int) Round(v, n - 1, MidpointRounding.AwayFromZero); public static int RoundUp(this double v) => (int)Ceiling(v); public static int RoundDown(this double v) => (int)Floor(v); public static bool Odd(this int v) => (v & 1) != 0; public static bool Odd(this long v) => (v & 1) != 0; public static bool Eve(this int v) => !v.Odd(); public static bool Eve(this long v) => !v.Odd(); public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this List<T> xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this T[,] xs) => xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Write($"{xs[i, j]} ")); WriteLine(); }); public static void Prt_<T>(this T[] xs) => WriteLine(string.Join(" ", xs)); public static void Log<T>(this T x, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"--- LOG[{line}]: {x} ---"); #endif } public static void Log<T>(this T[] xs, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"^^^ LOG[{line}] ^^^"); xs.Iter(x => Error.WriteLine(x)); Error.WriteLine($"vvv LOG[{line}] vvv\n"); #endif } public static void Log<T>(this T[,] xs, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"^^^ LOG[{line}] ^^^"); xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Error.Write($"{xs[i, j]} ")); Error.WriteLine(); }); Error.WriteLine($"vvv LOG[{line}] vvv\n"); #endif } public static string Reversed(this string s) => string.Join("", s.Reverse()); public static string Repeat(this string s, int n) => string.Concat(Enumerable.Repeat(s, n).ToArray()); #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Runtime.Remoting.Messaging; using System.Security.Cryptography.X509Certificates; using System.Security.Permissions; using System.Text; using static System.Console; using static System.Math; using static Ex; class AC { /*------------------------------------------------------------------*/ private int a, b, c, d; void Solve() { io.i(out a, out b, out c, out d); io.Yn((Abs(b - a) <= d && Abs(c - b) <= d) || Abs(c - a) <= d); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] args) => new AC().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Ex { #region マクロもどき public static Dictionary<T1, T2> MERGE<T1, T2>(Dictionary<T1, T2> xs, Dictionary<T1, T2> ys) => xs.Except(xs.Join(ys, z => z.Key, z => z.Key, (a, b) => a)) .Concat(ys) .ToDictionary(z => z.Key, z => z.Value); public static void LOG<T>(T x, [CallerLineNumber] int line = 0) => Error.WriteLine($"--- LOG[{line}]: {x} ---"); public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void REP(int a, int b, Action<int, int> f) => REP(a, i => REP(b, j => f(i, j))); public static void REP(int a, int b, int c, Action<int, int, int> f) => REP(a, i => REP(b, j => REP(c, k => f(i, j, k)))); public static void REPEQ(int a, int b, Action<int, int> f) => REPEQ(a, i => REPEQ(b, j => f(i, j))); public static void REPEQ(int a, int b, int c, Action<int, int, int> f) => REPEQ(a, i => REPEQ(b, j => REPEQ(c, k => f(i, j, k)))); public static T MIN<T>(params T[] xs) => xs.Min(); public static T MAX<T>(params T[] xs) => xs.Max(); public static IEnumerable<int> RANGE(int s, int e) => Enumerable.Range(s, e - s + 1); public static int LCM(int a, int b) => a * (b / GCD(a, b)); public static int GCD(int a, int b) => (a < b) ? GCD(b, a) : b == 0 ? a : GCD(b, a % b); public static int LCM(params int[] xs) => xs.Aggregate(LCM); public static int GCD(params int[] xs) => xs.Aggregate(GCD); public static long LCM(long a, long b) => a * (b / GCD(a, b)); public static long GCD(long a, long b) => (a < b) ? GCD(b, a) : b == 0L ? a : GCD(b, a % b); public static long LCM(params long[] xs) => xs.Aggregate(LCM); public static long GCD(params long[] xs) => xs.Aggregate(GCD); #endregion #region 拡張メソッド public static void Rep(this int x, Action<int> f) => REP(x, f); public static void RepEq(this int x, Action<int> f) => REPEQ(x, f); public static int ToInt(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt32(n); } public static int ToInt(this char c) => ToInt(c.ToString()); public static int ToInt(this char[] c) => ToInt(new string(c)); public static long ToLong(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt64(n); } public static long ToLong(this int x) => (long)x; public static IEnumerable<long> ToLong(this IEnumerable<int> xs) => xs.Select(x => x.ToLong()); public static long ToLong(this char c) => ToLong(c.ToString()); public static long ToLong(this char[] c) => ToLong(new string(c)); public static int ToMod(this int x, int mod = (int)(1e9 + 7)) => x % mod; public static long ToMod(this long x, long mod = (long)(1e9 + 7)) => x % mod; public static void Do<T>(this T x, Action<T> f) => f(x); public static TU Then<T, TU>(this T x, Func<T, TU> f) => f(x); public static void Fun<T>(this T[] xs, Action<int> f) => REP(xs.Length, f); public static void Fun<T>(this T[,] xxs, Action<int, int> f) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => f(i, j))); public static bool IsIn<T>(this T[] xs, int i) => 0 <= i && i < xs.Length; public static bool IsIn<T>(this T[,] xxs, int i, int j) => 0 <= i && i < xxs.GetLength(0) && 0 <= j && j < xxs.GetLength(1); public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public class IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public static IEnumerable<IndexedItem<T>> Indexed<T>( this IEnumerable<T> xs) => xs.Select((x, i) => new IndexedItem<T>(i, x)); public static Dictionary<long, int> PrimeFactor(this int x) => ((long)x).PrimeFactor(); public static Dictionary<long, int> PrimeFactor(this long n) { var ret = new Dictionary<long, int>(); for (var i = 2; i <= n; ++i) { if (!ret.ContainsKey(i)) ret[i] = 0; while (n % i == 0) { ++ret[i]; n /= i; } } return ret.Where(kp => kp.Value != 0) .ToDictionary(kp => kp.Key, kp => kp.Value); } public static void Set<T>(this T[] xs, T v) => REP(xs.Length, i => xs[i] = v); public static void Set<T>(this T[,] xxs, T v) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => xxs[i, j] = v)); public static T[] Sort<T>(this T[] xs) { Array.Sort(xs); return xs; } public static T[] SortR<T>(this T[] xs) { Array.Reverse(xs.Sort()); return xs; } public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0'); public static int RoundOff(this double v, int n) => (int) Round(v, n - 1, MidpointRounding.AwayFromZero); public static int RoundUp(this double v) => (int)Ceiling(v); public static int RoundDown(this double v) => (int)Floor(v); public static bool Odd(this int v) => (v & 1) != 0; public static bool Odd(this long v) => (v & 1) != 0; public static bool Eve(this int v) => !v.Odd(); public static bool Eve(this long v) => !v.Odd(); public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this List<T> xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this T[,] xs) => xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Write($"{xs[i, j]} ")); WriteLine(); }); public static void Prt_<T>(this T[] xs) => WriteLine(string.Join(" ", xs)); public static void Log<T>(this T x, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"--- LOG[{line}]: {x} ---"); #endif } public static void Log<T>(this T[] xs, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"^^^ LOG[{line}] ^^^"); xs.Iter(x => Error.WriteLine(x)); Error.WriteLine($"vvv LOG[{line}] vvv\n"); #endif } public static void Log<T>(this T[,] xs, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"^^^ LOG[{line}] ^^^"); xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Error.Write($"{xs[i, j]} ")); Error.WriteLine(); }); Error.WriteLine($"vvv LOG[{line}] vvv\n"); #endif } public static string Reversed(this string s) => string.Join("", s.Reverse()); public static string Repeat(this string s, int n) => string.Concat(Enumerable.Repeat(s, n).ToArray()); #endregion }
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
3,630
2
using System; namespace ConsoleApp5 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = int.Parse(str[2]); int d = int.Parse(str[3]); if (Math.Abs(a - c) <= d || Math.Abs(a - b) <= d && Math.Abs(b - c) <= d) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
using System; namespace ConsoleApp5 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = int.Parse(str[2]); int d = int.Parse(str[3]); if (Math.Abs(a - c) <= d || Math.Abs(a - b) <= d && Math.Abs(b - c) <= d) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
150
4
using System; using static System.Math; class Program { static void Main(string[] args) { string[] abcd = Console.ReadLine().Split(' '); int a = int.Parse(abcd[0]); int b = int.Parse(abcd[1]); int c = int.Parse(abcd[2]); int d = int.Parse(abcd[3]); if (Abs(a - c) < d) { Console.WriteLine("Yes"); } else { if (Abs(a - b) <= d && Abs(b - c) <= d) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using static System.Math; class Program { static void Main(string[] args) { string[] abcd = Console.ReadLine().Split(' '); int a = int.Parse(abcd[0]); int b = int.Parse(abcd[1]); int c = int.Parse(abcd[2]); int d = int.Parse(abcd[3]); if (Abs(a - c) <= d) { Console.WriteLine("Yes"); } else { if (Abs(a - b) <= d && Abs(b - c) <= d) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
162
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var abcd = ReadLine().Split().Select(int.Parse).ToArray(); var a = abcd[0]; var b = abcd[1]; var c = abcd[2]; var d = abcd[3]; WriteLine((Math.Abs(a - b) <= d) || (Math.Abs(a - c) <= d && Math.Abs(c - b) <= d) ? "Yes" : "No"); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var abcd = ReadLine().Split().Select(int.Parse).ToArray(); var a = abcd[0]; var b = abcd[1]; var c = abcd[2]; var d = abcd[3]; WriteLine((Math.Abs(a - c) <= d) || (Math.Abs(a - b) <= d && Math.Abs(c - b) <= d) ? "Yes" : "No"); } }
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
134
4
using System; namespace b { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); var maxV = 1; for (var i = 2; i * i <= x; i++) { var y = i * i; while (y <= x) { maxV = Math.Max(maxV, y); y *= y; } } Console.WriteLine(maxV); } } }
using System; namespace b { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); var maxV = 1; for (var i = 2; i * i <= x; i++) { var y = i * i; while (y <= x) { maxV = Math.Max(maxV, y); y *= i; } } Console.WriteLine(maxV); } } }
[["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22]]
8
96
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int x = sc.NextInt(); int answer = 0; for (int b = 1; b <= 1000; b++) { for (int p = 2; p <= 1000; p++) { int tmpAnswer = (int)Math.Pow(b, p); if (tmpAnswer < x) { break; } answer = Math.Max(tmpAnswer, answer); } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int x = sc.NextInt(); int answer = 0; for (int b = 1; b <= 1000; b++) { for (int p = 2; p <= 1000; p++) { int tmpAnswer = (int)Math.Pow(b, p); if (tmpAnswer > x) { break; } answer = Math.Max(tmpAnswer, answer); } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47]]
8
423
2
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var n = int.Parse(input.ReadLine()); if (n <= 4) return 1; var r = 0; for (int i = 2; i <= n; i++) { int y = i * i; while (y < n) { r = Math.Max(r, y); y *= i; } } return r; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var n = int.Parse(input.ReadLine()); if (n < 4) return 1; var r = 0; for (int i = 2; i <= n; i++) { int y = i * i; while (y <= n) { r = Math.Max(r, y); y *= i; } } return r; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 19]]
8
201
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; private static void swap<T>(ref T v1,ref T v2) { var t = v2;v2 = v1;v1 = t; } static void Main(string[] args) { var pr = new Program(); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); pr.Solve(); Console.Out.Flush(); } void Solve() { var x = Input.num;var res = 1; for(var i=2;i<x;i++) { var v = i*i; while (v < x) { chmax(ref res, v); v *= i; } } WriteLine(res); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] grid(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>(){ sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item);return GetValue<T>(sc.Dequeue()); } public static void Next<T>(ref T val) => val = Next<T>(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1 { get; set; } public T2 v2 { get; set; } public Pair() { v1 = Input.Next<T1>(); v2 = Input.Next<T2>(); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public override bool Equals(object obj) => this == (Pair<T1, T2>)obj; public override int GetHashCode() => v1.GetHashCode() ^ v2.GetHashCode(); public static bool operator ==(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 0; public static bool operator !=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 0; public static bool operator >(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 1; public static bool operator >=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != -1; public static bool operator <(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == -1; public static bool operator <=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 1; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3 { get; set; } public Pair() : base() { v3 = Input.Next<T3>(); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; private static void swap<T>(ref T v1,ref T v2) { var t = v2;v2 = v1;v1 = t; } static void Main(string[] args) { var pr = new Program(); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); pr.Solve(); Console.Out.Flush(); } void Solve() { var x = Input.num;var res = 1; for(var i=2;i<x;i++) { var v = i*i; while (v <= x) { chmax(ref res, v); v *= i; } } WriteLine(res); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] grid(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>(){ sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item);return GetValue<T>(sc.Dequeue()); } public static void Next<T>(ref T val) => val = Next<T>(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1 { get; set; } public T2 v2 { get; set; } public Pair() { v1 = Input.Next<T1>(); v2 = Input.Next<T2>(); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public override bool Equals(object obj) => this == (Pair<T1, T2>)obj; public override int GetHashCode() => v1.GetHashCode() ^ v2.GetHashCode(); public static bool operator ==(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 0; public static bool operator !=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 0; public static bool operator >(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 1; public static bool operator >=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != -1; public static bool operator <(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == -1; public static bool operator <=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 1; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3 { get; set; } public Pair() : base() { v3 = Input.Next<T3>(); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; }
[["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 19]]
8
1,704
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); int X = int.Parse(Console.ReadLine()); int ans = 0; for (var i = 1; i <= X; i++) { if (i == 1) { ans = Math.Max(ans, i); continue; } int k = i * i; while (k < X) { ans = Math.Max(ans, k); k *= i; } } Console.WriteLine(ans); // Console.Out.Flush(); } } public class Calculation {} public class Graph {} }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); int X = int.Parse(Console.ReadLine()); int ans = 0; for (var i = 1; i <= X; i++) { if (i == 1) { ans = Math.Max(ans, i); continue; } int k = i * i; while (k <= X) { ans = Math.Max(ans, k); k *= i; } } Console.WriteLine(ans); // Console.Out.Flush(); } } public class Calculation {} public class Graph {} }
[["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 19]]
8
169
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); } class Program { static void Main() { int X = Console.ReadLine().ToInt(); int max = 1; for (int i = 2; i <= X; i++) { var cands = beki(i).TakeWhile(n => n <= X); if (cands.Any()) { max = Math.Max(max, cands.Last()); } } Console.WriteLine(max); } static IEnumerable<int> beki(int n) { while (true) { n *= n; yield return n; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); } class Program { static void Main() { int X = Console.ReadLine().ToInt(); int max = 1; for (int i = 2; i <= X; i++) { var cands = beki(i).TakeWhile(n => n <= X); if (cands.Any()) { max = Math.Max(max, cands.Last()); } } Console.WriteLine(max); } static IEnumerable<int> beki(int n) { var nCpy = n; while (true) { n *= nCpy; yield return n; } } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22]]
8
373
7
using System; class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); Console.WriteLine(solve(x)); } static long solve(int x) { long ans = 1; for (int i = 2; i <= 1000; i++) { long tmp = 1; for (int j = 2; j <= 1000; j++) { tmp = tmp * i; if (tmp > x) break; ans = Math.Max(ans, tmp); } } return ans; } }
using System; class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); Console.WriteLine(solve(x)); } static long solve(int x) { long ans = 1; for (int i = 2; i <= 1000; i++) { long tmp = i; for (int j = 2; j <= 1000; j++) { tmp = tmp * i; if (tmp > x) break; ans = Math.Max(ans, tmp); } } return ans; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
121
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Atcoderrrrrr { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); double ans = 0; for (int b = 1; b <= x; b++) { for (int p = 2; p < 1000; p++) { double obj = Math.Pow(b, p); if (obj <= x) { ans = obj; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Atcoderrrrrr { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); double ans = 0; for (int b = 1; b <= x; b++) { for (int p = 2; p < 10; p++) { double obj = Math.Pow(b, p); if (ans <= obj && obj <= x) { ans = obj; } } } Console.WriteLine(ans); } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
128
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace atcoder097_B { class Program { static void Main(string[] args) { //入力を受け取る int X = int.Parse(Console.ReadLine()); //最終的に出力する変数 int result = 0; ; // 1000までのべき定数を作成 int[] Beki = new int[350]; int cnt = 0; for (int i = 1; i < 33; i++) { for (int j = 2; j < 9; j++) { Beki[cnt] = (int)Math.Pow(i, j); cnt++; } } // X以下で最大のべき乗数を探す for (int i = X; i > 1; i--) { for (int j = 0; j < 350; j++) { if (i == Beki[j]) { result = Beki[j]; goto last; } } } last:; Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace atcoder097_B { class Program { static void Main(string[] args) { //入力を受け取る int X = int.Parse(Console.ReadLine()); //最終的に出力する変数 int result = 0; ; // 1000までのべき定数を作成 int[] Beki = new int[350]; int cnt = 0; for (int i = 1; i < 33; i++) { for (int j = 2; j < 9; j++) { Beki[cnt] = (int)Math.Pow(i, j); cnt++; } } // X以下で最大のべき乗数を探す for (int i = X; i > 0; i--) { for (int j = 0; j < 350; j++) { if (i == Beki[j]) { result = Beki[j]; goto last; } } } last:; Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
194
2
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int X = int.Parse(Console.ReadLine()); int save = 1; if (X == 1) { Console.WriteLine(1); return; } for (int i = 2; i <= Math.Sqrt(X); i++) { int a = i * i; while (a < X) { if (a == X) { Console.WriteLine(a); return; } else if (a < X) { a = a * i; } } a = a / i; //超えたとき if (a > save) { save = a; } } Console.WriteLine(save); } }
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int X = int.Parse(Console.ReadLine()); int save = 1; if (X == 1) { Console.WriteLine(1); return; } for (int i = 2; i <= Math.Sqrt(X); i++) { int a = i * i; while (a <= X) { if (a == X) { Console.WriteLine(a); return; } else if (a < X) { a = a * i; } } a = a / i; //超えたとき if (a > save) { save = a; } } Console.WriteLine(save); } }
[["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 19]]
8
152
2
using System; using System.Linq; namespace AtCoderBeginnerContest097 { class ABC097B { static void Main(string[] args) { int X = int.Parse(Console.ReadLine()); int N = (int)Math.Sqrt(X); int max = 0; for (int i = 2; i <= N; i++) { int M = (int)Math.Log((double)X + 0.1, (double)i); int l = (int)Math.Pow((double)i, (double)M); if (max < l) max = l; } Console.WriteLine(max); } } }
using System; using System.Linq; namespace AtCoderBeginnerContest097 { class ABC097B { static void Main(string[] args) { int X = int.Parse(Console.ReadLine()); int N = (int)Math.Sqrt(X); int max = 1; for (int i = 2; i <= N; i++) { int M = (int)Math.Log((double)X + 0.1, (double)i); int l = (int)Math.Pow((double)i, (double)M); if (max < l) max = l; } Console.WriteLine(max); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
136
2
using System; class Problem02 { static void Main(string[] args) { string t = Console.ReadLine(); int X = int.Parse(t); for (int i = X; i >= 1; i--) { if (beki(i) == true) { Console.WriteLine(i); break; } } } static bool beki(int x) { if (x == 1) return true; for (int i = 2; i <= x / 2; i++) { if (x % i != 0) continue; int n = x; for (int j = 2; n >= 0; j++) { n /= i; if (n == 1) return true; else if (n % i != 0) return false; } } return false; } }
using System; class Problem02 { static void Main(string[] args) { string t = Console.ReadLine(); int X = int.Parse(t); for (int i = X; i >= 1; i--) { if (beki(i) == true) { Console.WriteLine(i); break; } } } static bool beki(int x) { if (x == 1) return true; for (int i = 2; i <= x / 2; i++) { if (x % i != 0) continue; int n = x; for (int j = 2; n >= 0; j++) { n /= i; if (n == 1) return true; else if (n % i != 0) break; } } return false; } }
[["-", 8, 196, 0, 57, 75, 57, 64, 37, 0, 38], ["-", 0, 57, 75, 57, 64, 37, 0, 211, 0, 147], ["+", 8, 196, 0, 57, 75, 57, 64, 93, 0, 94]]
8
168
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC097B { class Program { static void Main(string[] args) { var X = int.Parse(Console.ReadLine()); int ans = 1; for (int i = 2; i < X; i++) { if (i * i > X) break; for (int p = 2; Math.Pow(i, p) < X; p++) { int now = (int)Math.Pow(i, p); if (now > ans) ans = now; } } Console.WriteLine(ans); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC097B { class Program { static void Main(string[] args) { var X = int.Parse(Console.ReadLine()); int ans = 1; for (int i = 2; i < X; i++) { if (i * i > X) break; for (int p = 2; Math.Pow(i, p) <= X; p++) { int now = (int)Math.Pow(i, p); if (now > ans) ans = now; } } Console.WriteLine(ans); Console.ReadKey(); } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
152
2
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { int X = intRead(); int max = 0; int t = 0; for (int i = 2; i < 1000; i++) { for (int j = 2; j < 1000; j++) { t = (int)Math.Pow(i, j); if (t > X) break; else if (t > max) max = t; } } Console.WriteLine(max); } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string strReverce(string s) { return new string(s.Reverse().ToArray()); } public static int intRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } }
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { int X = intRead(); int max = 0; int t = 0; for (int i = 1; i < 1000; i++) { for (int j = 2; j < 1000; j++) { t = (int)Math.Pow(i, j); if (t > X) break; else if (t > max) max = t; } } Console.WriteLine(max); } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string strReverce(string s) { return new string(s.Reverse().ToArray()); } public static int intRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
377
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; using static Atcoder.IO; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); Out.Flush(); } } } public class Solve { public static void Answer() { var s = ReadLine(); var k = RInt; var has = new HashSet<string>(); for (int i = 0; i < s.Length; i++) { for (int j = 1; j < Min(s.Length + 1 - i, k); j++) { has.Add(s.Substring(i, j)); } } var lis = has.ToList(); lis.Sort(); WriteLine(lis[k - 1]); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; using static Atcoder.IO; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); Out.Flush(); } } } public class Solve { public static void Answer() { var s = ReadLine(); var k = RInt; var has = new HashSet<string>(); for (int i = 0; i < s.Length; i++) { for (int j = 1; j < Min(s.Length + 1 - i, k + 1); j++) { has.Add(s.Substring(i, j)); } } var lis = has.ToList(); lis.Sort(); WriteLine(lis[k - 1]); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
583
2
// A Dynamic Programming based // C# program to find minimum // number operations to // convert str1 to str2 using System; using System.Collections.Generic; using System.Linq; class GFG { public static void Main() { var st = Console.ReadLine(); var n = int.Parse(Console.ReadLine()); // var t = Console.ReadLine().Split(' ').Select(x => // int.Parse(x)).ToArray(); Test(st, n); } static void Test(string s, int n) { List<string> ans = new List<string>(); for (int i = 0; i < s.Length; i++) { for (int j = 1; j <= s.Length - i && j <= n; j++) { var sub = s.Substring(i, j); if (sub != string.Empty) { ans.Add(sub); } } // ans.Sort(); // if (ans.Count>n) // break; } ans.Sort(); var r = ans.Distinct().ToList(); Console.Write(ans[n - 1]); } }
// A Dynamic Programming based // C# program to find minimum // number operations to // convert str1 to str2 using System; using System.Collections.Generic; using System.Linq; class GFG { public static void Main() { var st = Console.ReadLine(); var n = int.Parse(Console.ReadLine()); // var t = Console.ReadLine().Split(' ').Select(x => // int.Parse(x)).ToArray(); Test(st, n); } static void Test(string s, int n) { List<string> ans = new List<string>(); for (int i = 0; i < s.Length; i++) { for (int j = 1; j <= s.Length - i && j <= n; j++) { var sub = s.Substring(i, j); if (sub != string.Empty) { ans.Add(sub); } } // ans.Sort(); // if (ans.Count>n) // break; } ans.Sort(); var r = ans.Distinct().ToList(); Console.Write(r[n - 1]); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22]]
8
194
2
using System; using System.Collections.Generic; using System.Linq; class AtCoder { static void Main(string[] args) { Scanner cin = new Scanner(); string s = Console.ReadLine(); int K = cin.Int(); List<string> x = new List<string>(); for (int i = 1; i <= K; i++) { for (int j = 0; j < s.Length - i + 1; j++) { x.Add(s.Substring(j, i)); } } string[] ans = x.OrderBy(t => t).ToArray(); Console.WriteLine(ans[K - 1]); Console.ReadLine(); } static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } static long BinarySearch<T>(T[] array, T target) where T : IComparable<T> // 2分探索 { int min = 0; int max = array.Length - 1; while (true) { // 範囲内に見つからなかった if (max < min) return -1; // 範囲内の中央値と比較する int mid = min + (max - min) / 2; switch (target.CompareTo(array[mid])) { case -1: // 中央値より小さい max = mid - 1; break; case 1: // 中央値より大きい min = mid + 1; break; case 0: // 見つかった return mid; } } } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } }
using System; using System.Collections.Generic; using System.Linq; class AtCoder { static void Main(string[] args) { Scanner cin = new Scanner(); string s = Console.ReadLine(); int K = cin.Int(); List<string> x = new List<string>(); for (int i = 1; i <= K; i++) { for (int j = 0; j < s.Length - i + 1; j++) { x.Add(s.Substring(j, i)); } } string[] ans = x.Distinct().OrderBy(t => t).ToArray(); Console.WriteLine(ans[K - 1]); Console.ReadLine(); } static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } static long BinarySearch<T>(T[] array, T target) where T : IComparable<T> // 2分探索 { int min = 0; int max = array.Length - 1; while (true) { // 範囲内に見つからなかった if (max < min) return -1; // 範囲内の中央値と比較する int mid = min + (max - min) / 2; switch (target.CompareTo(array[mid])) { case -1: // 中央値より小さい max = mid - 1; break; case 1: // 中央値より大きい min = mid + 1; break; case 0: // 見つかった return mid; } } } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } }
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131]]
8
655
4
using System; using System.Collections.Generic; using System.Linq; namespace _97C { class Program { static void Main(string[] args) { var str = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); List<string> list = new List<string>(); HashSet<string> hash = new HashSet<string>(); for (int j = 1; j <= k; j++) { for (int i = 0; i < str.Length - j + 1; i++) { hash.Add(str.Substring(i, j)); } } list = hash.ToList(); list.Sort(); Console.WriteLine(list[k]); } } }
using System; using System.Collections.Generic; using System.Linq; namespace _97C { class Program { static void Main(string[] args) { var str = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); List<string> list = new List<string>(); HashSet<string> hash = new HashSet<string>(); for (int j = 1; j <= k; j++) { for (int i = 0; i < str.Length - j + 1; i++) { hash.Add(str.Substring(i, j)); } } list = hash.ToList(); list.Sort(); Console.WriteLine(list[k - 1]); } } }
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
161
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { // 方針 // int n = rint(); int[] a = inta(); int[] s = new int[n]; for (int i = 0; i < n; i++) { s[i] = a[i]; } Array.Sort(s); int l = s[n / 2 - 1]; int r = s[n / 2]; for (int i = 0; i < n; i++) { if (a[i] >= l) { WriteLine(r); } else { WriteLine(l); } } } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { // 方針 // int n = rint(); int[] a = inta(); int[] s = new int[n]; for (int i = 0; i < n; i++) { s[i] = a[i]; } Array.Sort(s); int l = s[n / 2 - 1]; int r = s[n / 2]; for (int i = 0; i < n; i++) { if (a[i] <= l) { WriteLine(r); } else { WriteLine(l); } } } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
1,447
2
using System; using System.Collections.Generic; using System.Linq; public class Prog { public void run() { int N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] srt = new int[N]; input.CopyTo(srt, 0); Array.Sort(srt); int bef = srt[srt.Length / 2 - 1]; int aft = srt[srt.Length / 2 + 1]; for (int i = 0; i < N; i++) { if (input[i] <= bef) { Console.WriteLine(aft); } else { Console.WriteLine(bef); } } } public static void Main() { var prog = new Prog(); prog.run(); } /* 最小公倍数 public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } */ // a<=c, b<=d; } // Split().Select(int.Parse).ToArray() // Array.ConvertAll(int.Parse) // str.IndexOf("Stage",System.StringComparison.CurrentCulture)
using System; using System.Collections.Generic; using System.Linq; public class Prog { public void run() { int N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] srt = new int[N]; input.CopyTo(srt, 0); Array.Sort(srt); int bef = srt[srt.Length / 2 - 1]; int aft = srt[srt.Length / 2]; for (int i = 0; i < N; i++) { if (input[i] <= bef) { Console.WriteLine(aft); } else { Console.WriteLine(bef); } } } public static void Main() { var prog = new Prog(); prog.run(); } /* 最小公倍数 public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } */ // a<=c, b<=d; } // Split().Select(int.Parse).ToArray() // Array.ConvertAll(int.Parse) // str.IndexOf("Stage",System.StringComparison.CurrentCulture)
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
193
2
using Asakatsu20200503.Questions; using Asakatsu20200503.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Asakatsu20200503.Questions { /// <summary> /// ABC094 /// </summary> public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var _ = inputStream.ReadInt(); var a = inputStream.ReadIntArray(); var n = a.Max(); var r = a[0]; foreach (var ai in a) { if (GetDistance(n, ai) > GetDistance(n, r)) { r = ai; } } yield return $"{n} {r}"; } int GetDistance(int n, int r) => Math.Min(n - r, r); } } namespace Asakatsu20200503 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Asakatsu20200503.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Asakatsu20200503.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using Asakatsu20200503.Questions; using Asakatsu20200503.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Asakatsu20200503.Questions { /// <summary> /// ABC094 /// </summary> public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var _ = inputStream.ReadInt(); var a = inputStream.ReadIntArray(); var n = a.Max(); var r = a[0]; foreach (var ai in a) { if (GetDistance(n, ai) >= GetDistance(n, r) && n != ai) { r = ai; } } yield return $"{n} {r}"; } int GetDistance(int n, int r) => Math.Min(n - r, r); } } namespace Asakatsu20200503 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Asakatsu20200503.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Asakatsu20200503.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
556
6
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(a); var max = a[n - 1]; var center = max / 2; var med = 0; if (n == 2) med = a[0]; else { var min = int.MaxValue; for (var i = 0; i < n; i++) { var abs = Math.Abs(a[i] - center); if (min > abs) { min = abs; med = a[i]; } } } Console.WriteLine($"{max} {med}"); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(a); var max = a[n - 1]; var center = max / 2d; var med = 0; if (n == 2) med = a[0]; else { var min = double.MaxValue; for (var i = 0; i < n; i++) { var abs = Math.Abs(a[i] - center); if (min > abs) { min = abs; med = a[i]; } } } Console.WriteLine($"{max} {med}"); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199]]
8
189
4
using System; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var n = ReadLib.ReadAsInt(); var xArr = ReadLib.ReadAsIntArray(); var xArrSorted = xArr.OrderBy(i => i).ToArray(); var bigger = xArrSorted[(n - 1) / 2 + 1]; var smaller = xArrSorted[(n - 1) / 2]; for (int i = 0; i < n; i++) { var v = 0; if (i <= smaller) { v = bigger; } else { v = smaller; } Console.WriteLine(v); } #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } /// <summary>nCr, 組み合わせ</summary> public static long Combination(int n, int r) { if (r == 0) { return 1; } // 分子 var moleculeArr = Enumerable.Range(0, Math.Min(n - r, r)).Select(i => n - i).ToArray(); var moleculeArrLength = moleculeArr.Length; // 分母 var denominatorArr = Enumerable.Range(1, Math.Max(n - r, r)).ToArray(); for (var m = 0; m < moleculeArrLength; m++) { while (true) { var mVal = moleculeArr[m]; var gcds = denominatorArr.Select(b => Gcd(mVal, b)); var maxGcd = gcds.Max(); var maxI = gcds.ToList().IndexOf(maxGcd); if (maxGcd == 1) { break; } denominatorArr[maxI] /= maxGcd; moleculeArr[m] /= maxGcd; } } return FullPower(moleculeArr); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static int Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { var mod = a % b; if (mod == 0) { break; } a = b; b = mod; } return (int)b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)value % mod; this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } }
using System; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var n = ReadLib.ReadAsInt(); var xArr = ReadLib.ReadAsIntArray(); var xArrSorted = xArr.OrderBy(i => i).ToArray(); var bigger = xArrSorted[(n - 1) / 2 + 1]; var smaller = xArrSorted[(n - 1) / 2]; for (int i = 0; i < n; i++) { var v = 0; if (xArr[i] <= smaller) { v = bigger; } else { v = smaller; } Console.WriteLine(v); } #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } /// <summary>nCr, 組み合わせ</summary> public static long Combination(int n, int r) { if (r == 0) { return 1; } // 分子 var moleculeArr = Enumerable.Range(0, Math.Min(n - r, r)).Select(i => n - i).ToArray(); var moleculeArrLength = moleculeArr.Length; // 分母 var denominatorArr = Enumerable.Range(1, Math.Max(n - r, r)).ToArray(); for (var m = 0; m < moleculeArrLength; m++) { while (true) { var mVal = moleculeArr[m]; var gcds = denominatorArr.Select(b => Gcd(mVal, b)); var maxGcd = gcds.Max(); var maxI = gcds.ToList().IndexOf(maxGcd); if (maxGcd == 1) { break; } denominatorArr[maxI] /= maxGcd; moleculeArr[m] /= maxGcd; } } return FullPower(moleculeArr); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static int Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { var mod = a % b; if (mod == 0) { break; } a = b; b = mod; } return (int)b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)value % mod; this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } }
[["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73]]
8
1,707
3
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var nums = new List<Number>(); for (int i = 0; i < N; i++) { nums.Add(new Number(i, array[i])); } var sorted = nums.OrderByDescending(x => x.Value).ToArray(); for (int i = 0; i < N; i++) { var isFormer = array[i] == sorted[(N + 1) / 2].Value; if (isFormer) { Console.WriteLine(sorted[(N + 1) / 2].Value); } else Console.WriteLine(sorted[(N + 1) / 2 - 1].Value); } } } public struct Number { public Number(int index, int value) { Index = index; Value = value; } public int Index, Value; }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var nums = new List<Number>(); for (int i = 0; i < N; i++) { nums.Add(new Number(i, array[i])); } var sorted = nums.OrderByDescending(x => x.Value).ToArray(); for (int i = 0; i < N; i++) { var isFormer = array[i] > sorted[(N + 1) / 2].Value; if (isFormer) { Console.WriteLine(sorted[(N + 1) / 2].Value); } else Console.WriteLine(sorted[(N + 1) / 2 - 1].Value); } } } public struct Number { public Number(int index, int value) { Index = index; Value = value; } public int Index, Value; }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 60], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 47]]
8
249
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { string line = Console.ReadLine(); if (line.Contains("a") && line.Contains("b") && line.Contains("c")) Console.WriteLine("Yes"); Console.WriteLine("No"); } public static long GCD(long a, long b) { if (b == 1) return a; long p = b / a; return GCD(a, b - a * p); } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { string line = Console.ReadLine(); if (line.Contains("a") && line.Contains("b") && line.Contains("c")) Console.WriteLine("Yes"); else Console.WriteLine("No"); } public static long GCD(long a, long b) { if (b == 1) return a; long p = b / a; return GCD(a, b - a * p); } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
200
1
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var hasA = false; var hasB = false; var hasC = false; foreach (var item in S) { switch (item) { case 'A': hasA = true; break; case 'B': hasB = true; break; case 'C': hasC = true; break; } } Console.WriteLine(hasA && hasB && hasC ? "Yes" : "No"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var hasA = false; var hasB = false; var hasC = false; foreach (var item in S) { switch (item) { case 'a': hasA = true; break; case 'b': hasB = true; break; case 'c': hasC = true; break; } } Console.WriteLine(hasA && hasB && hasC ? "Yes" : "No"); } } }
[["-", 8, 254, 0, 239, 0, 264, 0, 252, 0, 253], ["+", 8, 254, 0, 239, 0, 264, 0, 252, 0, 253]]
8
125
6
using System; using System.Linq; class Program { static void Main() { // int[] input = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // int input=int.Parse(Console.ReadLine()); string a = Console.ReadLine(); Console.WriteLine( a.Contains("a") && a.Contains("b") && a.Contains("c") ? "YES" : "NO"); Console.ReadLine(); } }
using System; using System.Linq; class Program { static void Main() { // int[] input = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // int input=int.Parse(Console.ReadLine()); string a = Console.ReadLine(); Console.WriteLine( a.Contains("a") && a.Contains("b") && a.Contains("c") ? "Yes" : "No"); Console.ReadLine(); } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
76
4
using System; using System.IO; class Program { static void Main(string[] args) { string S = Console.ReadLine(); if (S[0] != S[1] && S[1] != S[2] && S[2] != S[0]) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; using System.IO; class Program { static void Main(string[] args) { string S = Console.ReadLine(); if (S[0] != S[1] && S[1] != S[2] && S[2] != S[0]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
87
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int a = sc.NextInt(); int b = sc.NextInt(); int k = sc.NextInt(); List<int> answers = new List<int>(); for (int i = a; i <= b && i <= a + k; i++) { answers.Add(i); } for (int i = b; i >= a && i >= b - k; i--) { answers.Add(i); } answers = answers.Distinct().OrderBy(i => i).ToList(); foreach (var answer in answers) { Console.WriteLine(answer); } } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int a = sc.NextInt(); int b = sc.NextInt(); int k = sc.NextInt(); List<int> answers = new List<int>(); for (int i = a; i <= b && i <= a + k - 1; i++) { answers.Add(i); } for (int i = b; i >= a && i >= b - k + 1; i--) { answers.Add(i); } answers = answers.Distinct().OrderBy(i => i).ToList(); foreach (var answer in answers) { Console.WriteLine(answer); } } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["+", 0, 7, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 7, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 16, 12, 16, 17, 72]]
8
468
4
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var a = int.Parse(spl[0]); var b = int.Parse(spl[1]); var k = int.Parse(spl[2]); for (int i = a; i <= b;) { Console.WriteLine(i); i++; if (i == a + k + 1) { i = Math.Max(i, b - (k - 1)); } } return null; } static int[] ToIntArray(string strs, int n) { var ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var a = int.Parse(spl[0]); var b = int.Parse(spl[1]); var k = int.Parse(spl[2]); for (int i = a; i <= b;) { Console.WriteLine(i); i++; if (i == a + k) { i = Math.Max(i, b - (k - 1)); } } return null; } static int[] ToIntArray(string strs, int n) { var ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
302
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = inta(); var list = new List<int>(); for (int i = 0; i < n[2]; i++) { if (n[0] + i <= n[1]) { list.Add(n[0] + i); } if (n[1] - i >= n[0]) { list.Add(n[1] - i); } } var ans = new List<int>(); ans.Add(list[0]); for (int i = 1; i < list.Count; i++) { if (list[i] != list[i - 1]) ans.Add(list[i]); } ans.Sort(); WriteLine(string.Join("\n", ans)); } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = inta(); var list = new List<int>(); for (int i = 0; i < n[2]; i++) { if (n[0] + i <= n[1]) { list.Add(n[0] + i); } if (n[1] - i >= n[0]) { list.Add(n[1] - i); } } list.Sort(); var ans = new List<int>(); ans.Add(list[0]); for (int i = 1; i < list.Count; i++) { if (list[i] != list[i - 1]) ans.Add(list[i]); } ans.Sort(); WriteLine(string.Join("\n", ans)); } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
1,353
6
using System; class p { static void Main() { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int K = int.Parse(input[2]); if (K * 2 < B - A) { for (int i = A; i < A + K; i++) { Console.WriteLine(i); } for (int i = B - (K - 1); i <= B; i++) { Console.WriteLine(i); } } else { for (int i = A; i <= B; i++) { Console.WriteLine(i); } } } }
using System; class p { static void Main() { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int K = int.Parse(input[2]); if (K * 2 <= B - A) { for (int i = A; i < A + K; i++) { Console.WriteLine(i); } for (int i = B - (K - 1); i <= B; i++) { Console.WriteLine(i); } } else { for (int i = A; i <= B; i++) { Console.WriteLine(i); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
163
2
using System.Linq; using System; using System.IO; class Program { static void Main(string[] args) { var line = Console.ReadLine().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); var k = int.Parse(line[2]); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; if ((k * 2) >= b - a) { for (var i = a; i <= b; i++) sw.WriteLine(i); } else { for (var i = a; i < a + k; i++) sw.WriteLine(i); for (var i = b - k + 1; i <= b; i++) sw.WriteLine(i); } sw.Flush(); } }
using System.Linq; using System; using System.IO; class Program { static void Main(string[] args) { var line = Console.ReadLine().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); var k = int.Parse(line[2]); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; if ((k * 2) > b - a) { for (var i = a; i <= b; i++) sw.WriteLine(i); } else { for (var i = a; i < a + k; i++) sw.WriteLine(i); for (var i = b - k + 1; i <= b; i++) sw.WriteLine(i); } sw.Flush(); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
193
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static AtCoderTemplate.MyExtensions; using static AtCoderTemplate.MyInputOutputs; using static AtCoderTemplate.MyNumericFunctions; namespace AtCoderTemplate { public class Program { public static void Main(string[] args) { var ABK = ReadLongs(); var A = ABK[0]; var B = ABK[1]; var K = (int)ABK[2]; var underK = Enumerable.Range(0, K).Select(i => A + i).Where(Ai => Ai <= B); var overK = Enumerable.Range(0, K).Select(i => B - i).Where(Bi => Bi >= A); PrintColomn(underK.Concat(overK).Distinct()); } } static class MyInputOutputs { /* Input & Output*/ public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<int> ReadInts() { return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList(); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList(); } public static List<List<int>> ReadIntColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static List<List<long>> ReadLongColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static void Print<T>(T item) { Console.WriteLine(item); } public static void PrintIf<T1, T2>(bool condition, T1 trueResult, T2 falseResult) { if (condition) { Console.WriteLine(trueResult); } else { Console.WriteLine(falseResult); } } public static void PrintRow<T>(IEnumerable<T> list) { /* 横ベクトルで表示 A B C D ... */ if (!list.IsEmpty()) { Console.Write(list.First()); foreach (var item in list.Skip(1)) { Console.Write($" {item}"); } } Console.Write("\n"); } public static void PrintColomn<T>(IEnumerable<T> list) { /* 縦ベクトルで表示 A B C D ... */ foreach (var item in list) { Console.WriteLine(item); } } public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) { foreach (var row in sources) { PrintRow(row); } } } static class MyNumericFunctions { public static bool isEven(int a) { return a % 2 == 0; } public static bool isEven(long a) { return a % 2 == 0; } public static bool isOdd(int a) { return !isEven(a); } public static bool isOdd(long a) { return !isEven(a); } public static long nPk(int n, int k) { if (k > n) { return 0; } else { return Enumerable.Range(n - k + 1, k) .Aggregate((long)1, ((i, m) => i * m)); } } public static long Fact(int n) { return nPk(n, n); } public static long nCk(int n, int k) { if (k > n) { return 0; } else { return nPk(n, k) / Fact(k); } } // 最大公約数 public static long GCD(long m, long n) { if (m < n) { return GCD(n, m); } else if (n == 0) { return m; } else { return GCD(n, m % n); } } // 最小公倍数 public static long LCM(long m, long n) { if (m < n) { return LCM(n, m); } else { return (m * n) / GCD(m, n); } } } static class MyExtensions { // AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2 // はそれに対応して仕様はあるが、実装がない public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T element) { return source.Concat(Enumerable.Repeat(element, 1)); } public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T element) { return Enumerable.Repeat(element, 1).Concat(source); } // TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2 // はそれに対応していない public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source, int count) { return source.Skip(source.Count() - count); } public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int count) { return source.Take(source.Count() - count); } public static bool IsEmpty<T>(this IEnumerable<T> source) { return !source.Any(); } /// <summary> /// インデックスiの位置の要素からk個取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source, int i, int count) { return source.Take(i).Concat(source.Skip(i + count)); } /// <summary> /// インデックスiの位置の要素を取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source, int i) { return source.TakeAwayRange(i, 1); } /// <summary> /// インデックスiの位置にシーケンスを挿入する /// O(N + K) /// </summary> public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source, int i, IEnumerable<T> inserted) { return source.Take(i).Concat(inserted).Concat(source.Skip(i)); } /// <summary> /// 順列を得る /// O(N!) /// </summary> public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source, int n) { if (n == 0 || source.IsEmpty() || source.Count() < n) { return Enumerable.Empty<IEnumerable<T>>(); } else if (n == 1) { return source.Select(i => new List<T> { i }); } else { var nexts = source.Select( (x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)), selected = source.Take(i + 1).Last() }); return nexts.SelectMany( next => Perm(next.next, n - 1) .Select(item => item.Prepend(next.selected))); } } /// <summary> /// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る /// </summary> /// <para>O(N)</para> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数</param> /// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example> public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source, Func<T1, T1, TR> func) { var list = source.ToList(); return Enumerable.Range(1, list.Count - 1) .Select(i => func(list[i], list[i - 1])); } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、first) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <param name="first">func(first, source[0])のための初項</param> /// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2), /// f(f(f(0,1),2),3)]</example> public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source, TR first, Func<TR, T, TR> func) { var list = source.ToList(); var result = new List<TR> { first }; foreach (var i in Enumerable.Range(0, source.Count())) { result.Add(func(result[i], list[i])); } return result; } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、source.First()) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example> public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source, Func<T, T, T> func) { var list = source.ToList(); var result = new List<T> { list[0] }; foreach (var i in Enumerable.Range(1, source.Count() - 1)) { result.Add(func(result[i - 1], list[i])); } return result; } /// <summary> /// 昇順にソートしたインデックスを得る /// </summary> /// <para>O(N * log N)</para> public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) { return source.Select((item, i) => new { Item = item, Index = i }) .OrderBy(x => x.Item) .Select(x => x.Index); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static AtCoderTemplate.MyExtensions; using static AtCoderTemplate.MyInputOutputs; using static AtCoderTemplate.MyNumericFunctions; namespace AtCoderTemplate { public class Program { public static void Main(string[] args) { var ABK = ReadLongs(); var A = ABK[0]; var B = ABK[1]; var K = (int)ABK[2]; var underK = Enumerable.Range(0, K).Select(i => A + i).Where(Ai => Ai <= B); var overK = Enumerable.Range(0, K) .Select(i => B - i) .Reverse() .Where(Bi => Bi >= A); PrintColomn(underK.Concat(overK).Distinct()); } } static class MyInputOutputs { /* Input & Output*/ public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<int> ReadInts() { return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList(); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList(); } public static List<List<int>> ReadIntColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static List<List<long>> ReadLongColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static void Print<T>(T item) { Console.WriteLine(item); } public static void PrintIf<T1, T2>(bool condition, T1 trueResult, T2 falseResult) { if (condition) { Console.WriteLine(trueResult); } else { Console.WriteLine(falseResult); } } public static void PrintRow<T>(IEnumerable<T> list) { /* 横ベクトルで表示 A B C D ... */ if (!list.IsEmpty()) { Console.Write(list.First()); foreach (var item in list.Skip(1)) { Console.Write($" {item}"); } } Console.Write("\n"); } public static void PrintColomn<T>(IEnumerable<T> list) { /* 縦ベクトルで表示 A B C D ... */ foreach (var item in list) { Console.WriteLine(item); } } public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) { foreach (var row in sources) { PrintRow(row); } } } static class MyNumericFunctions { public static bool isEven(int a) { return a % 2 == 0; } public static bool isEven(long a) { return a % 2 == 0; } public static bool isOdd(int a) { return !isEven(a); } public static bool isOdd(long a) { return !isEven(a); } public static long nPk(int n, int k) { if (k > n) { return 0; } else { return Enumerable.Range(n - k + 1, k) .Aggregate((long)1, ((i, m) => i * m)); } } public static long Fact(int n) { return nPk(n, n); } public static long nCk(int n, int k) { if (k > n) { return 0; } else { return nPk(n, k) / Fact(k); } } // 最大公約数 public static long GCD(long m, long n) { if (m < n) { return GCD(n, m); } else if (n == 0) { return m; } else { return GCD(n, m % n); } } // 最小公倍数 public static long LCM(long m, long n) { if (m < n) { return LCM(n, m); } else { return (m * n) / GCD(m, n); } } } static class MyExtensions { // AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2 // はそれに対応して仕様はあるが、実装がない public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T element) { return source.Concat(Enumerable.Repeat(element, 1)); } public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T element) { return Enumerable.Repeat(element, 1).Concat(source); } // TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2 // はそれに対応していない public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source, int count) { return source.Skip(source.Count() - count); } public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int count) { return source.Take(source.Count() - count); } public static bool IsEmpty<T>(this IEnumerable<T> source) { return !source.Any(); } /// <summary> /// インデックスiの位置の要素からk個取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source, int i, int count) { return source.Take(i).Concat(source.Skip(i + count)); } /// <summary> /// インデックスiの位置の要素を取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source, int i) { return source.TakeAwayRange(i, 1); } /// <summary> /// インデックスiの位置にシーケンスを挿入する /// O(N + K) /// </summary> public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source, int i, IEnumerable<T> inserted) { return source.Take(i).Concat(inserted).Concat(source.Skip(i)); } /// <summary> /// 順列を得る /// O(N!) /// </summary> public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source, int n) { if (n == 0 || source.IsEmpty() || source.Count() < n) { return Enumerable.Empty<IEnumerable<T>>(); } else if (n == 1) { return source.Select(i => new List<T> { i }); } else { var nexts = source.Select( (x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)), selected = source.Take(i + 1).Last() }); return nexts.SelectMany( next => Perm(next.next, n - 1) .Select(item => item.Prepend(next.selected))); } } /// <summary> /// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る /// </summary> /// <para>O(N)</para> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数</param> /// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example> public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source, Func<T1, T1, TR> func) { var list = source.ToList(); return Enumerable.Range(1, list.Count - 1) .Select(i => func(list[i], list[i - 1])); } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、first) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <param name="first">func(first, source[0])のための初項</param> /// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2), /// f(f(f(0,1),2),3)]</example> public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source, TR first, Func<TR, T, TR> func) { var list = source.ToList(); var result = new List<TR> { first }; foreach (var i in Enumerable.Range(0, source.Count())) { result.Add(func(result[i], list[i])); } return result; } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、source.First()) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example> public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source, Func<T, T, T> func) { var list = source.ToList(); var result = new List<T> { list[0] }; foreach (var i in Enumerable.Range(1, source.Count() - 1)) { result.Add(func(result[i - 1], list[i])); } return result; } /// <summary> /// 昇順にソートしたインデックスを得る /// </summary> /// <para>O(N * log N)</para> public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) { return source.Select((item, i) => new { Item = item, Index = i }) .OrderBy(x => x.Item) .Select(x => x.Index); } } }
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131]]
8
1,846
4
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); var list = new SortedSet<int>(); for (int i = 0; i < s[2]; i++) { list.Add(s[0] + i); list.Add(s[1] - i); if (s[0] + i == s[1] - i) break; } foreach (int i in list) Console.WriteLine(i); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); var list = new SortedSet<int>(); for (int i = 0; i < s[2]; i++) { list.Add(s[0] + i); list.Add(s[1] - i); if (s[0] + i >= s[1] - i) break; } foreach (int i in list) Console.WriteLine(i); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
142
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int K = int.Parse(input[2]); List<int> list = new List<int>(); for (int i = A; i < A + K; i++) { if (i < B) list.Add(i); } for (int i = B; i >= B - K; i--) { if (i >= A) { if (!list.Contains(i)) { list.Add(i); } } } list.Sort(); foreach (int i in list) Console.WriteLine(i); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int K = int.Parse(input[2]); List<int> list = new List<int>(); for (int i = A; i < A + K; i++) { if (i <= B) list.Add(i); } for (int i = B; i > B - K; i--) { if (i >= A) { if (!list.Contains(i)) { list.Add(i); } } } list.Sort(); foreach (int i in list) Console.WriteLine(i); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47]]
8
208
4
using System; namespace AtCoder.ABC093 { class b { static void Main(string[] args) { var line = Console.ReadLine().Trim(); var spl = line.Split(' '); var A = int.Parse(spl[0]); var B = int.Parse(spl[1]); var K = int.Parse(spl[2]); if (B - A + 1 <= K) { for (var i = A; i <= B; ++i) { Console.WriteLine(i); } } else { for (var i = A; i < A + K; ++i) { Console.WriteLine(i); } for (var i = B - K + 1; i <= B; ++i) { Console.WriteLine(i); } } } } }
using System; namespace AtCoder.ABC093 { class b { static void Main(string[] args) { var line = Console.ReadLine().Trim(); var spl = line.Split(' '); var A = int.Parse(spl[0]); var B = int.Parse(spl[1]); var K = int.Parse(spl[2]); if (B - A + 1 <= K * 2) { for (var i = A; i <= B; ++i) { Console.WriteLine(i); } } else { for (var i = A; i < A + K; ++i) { Console.WriteLine(i); } for (var i = B - K + 1; i <= B; ++i) { Console.WriteLine(i); } } } } }
[["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
178
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_ABC089_A { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); int k = int.Parse(s[2]); if ((b - a) <= (k - 1)) { for (int i = a; i <= b; ++i) { Console.WriteLine(i); } } else { for (int i = a; i < a + k; ++i) { Console.WriteLine(i); } for (int i = b - k + 1; i <= b; ++i) { Console.WriteLine(i); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_ABC089_A { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); int k = int.Parse(s[2]); if ((b - a) <= (k * 2 - 1)) { for (int i = a; i <= b; ++i) { Console.WriteLine(i); } } else { for (int i = a; i < a + k; ++i) { Console.WriteLine(i); } for (int i = b - k + 1; i <= b; ++i) { Console.WriteLine(i); } } } } }
[["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 48], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203]]
8
197
2
using System; class Program { static void Main(string[] args) { // 整数の入力 string s = Console.ReadLine(); string[] sl = s.Split(' '); int A = int.Parse(sl[0]); int B = int.Parse(sl[1]); int K = int.Parse(sl[2]); for (int i = A; i <= B; i++) { if (i == A + K) { if (i < B - K + 1) i = B - K + 1; break; } Console.WriteLine(i); } } }
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string[] sl = s.Split(' '); int A = int.Parse(sl[0]); int B = int.Parse(sl[1]); int K = int.Parse(sl[2]); for (int i = A; i <= B; i++) { if (i == A + K) { if (i < B - K + 1) i = B - K + 1; } Console.WriteLine(i); } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35]]
8
134
2
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 int a, b, k; string[] input = Console.ReadLine().Split(' '); a = int.Parse(input[0]); b = int.Parse(input[1]); k = int.Parse(input[2]); for (int i = 0; i < k; i++) { Console.WriteLine(a + i); if (a + i >= b) break; } for (int i = k - 1; i >= 0; i--) { if (a + k >= b - i) continue; Console.WriteLine(b - i); } } }
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 int a, b, k; string[] input = Console.ReadLine().Split(' '); a = int.Parse(input[0]); b = int.Parse(input[1]); k = int.Parse(input[2]); for (int i = 0; i < k; i++) { Console.WriteLine(a + i); if (a + i >= b) break; } for (int i = k - 1; i >= 0; i--) { if (a + k > b - i) continue; Console.WriteLine(b - i); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47]]
8
154
2
// using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var H = line[0]; var W = line[1]; var S = new string[H]; for (var i = 0; i < H; i++) { S[i] = Console.ReadLine(); } for (var i = 1; i < H - 1; i++) { for (var j = 1; j < W - 1; j++) { if (S[i][j] == '.' && S[i - 1][j] == '.' && S[i][j + 1] == '.' && S[i + 1][j] == '.' && S[i][j - 1] == '.') { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } }
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var H = line[0]; var W = line[1]; var S = new string[H]; for (var i = 0; i < H; i++) { S[i] = Console.ReadLine(); } for (var i = 1; i < H - 1; i++) { for (var j = 1; j < W - 1; j++) { if (S[i][j] == '#' && S[i - 1][j] == '.' && S[i][j + 1] == '.' && S[i + 1][j] == '.' && S[i][j - 1] == '.') { Console.WriteLine("No"); return; } } } Console.WriteLine("Yes"); } }
[["-", 31, 16, 31, 16, 31, 16, 12, 252, 0, 253], ["+", 31, 16, 31, 16, 31, 16, 12, 252, 0, 253], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
236
6
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int H = int.Parse(str[0]); int W = int.Parse(str[1]); int[,] S = new int[H, W]; for (var i = 0; i < H; i++) { string t = Console.ReadLine(); for (var j = 0; j < W; j++) { if (t.Substring(j, 1) == "#") { S[i, j] = 1; } else { S[i, j] = 0; } } } int x = 1; for (var i = 0; i < H; i++) { for (var j = 0; j < W; j++) { int f = 0; if (S[i, j] == 1) { if (i < H - 1 && S[i + 1, j] == 1) { f = 1; } else if (i > 0 && S[i - 1, j] == 1) { f = 1; } else if (j < W - 1 && S[i, j + 1] == 1) { f = 1; } else if (j > 0 && S[i, j - 1] == 1) { f = 1; } if (f == 0) { x = 0; break; } } } if (x == 0) { break; } } string A = "NO"; if (x == 1) { A = "YES"; } Console.WriteLine(A); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int H = int.Parse(str[0]); int W = int.Parse(str[1]); int[,] S = new int[H, W]; for (var i = 0; i < H; i++) { string t = Console.ReadLine(); for (var j = 0; j < W; j++) { if (t.Substring(j, 1) == "#") { S[i, j] = 1; } else { S[i, j] = 0; } } } int x = 1; for (var i = 0; i < H; i++) { for (var j = 0; j < W; j++) { int f = 0; if (S[i, j] == 1) { if (i < H - 1 && S[i + 1, j] == 1) { f = 1; } else if (i > 0 && S[i - 1, j] == 1) { f = 1; } else if (j < W - 1 && S[i, j + 1] == 1) { f = 1; } else if (j > 0 && S[i, j - 1] == 1) { f = 1; } if (f == 0) { x = 0; break; } } } if (x == 0) { break; } } string A = "No"; if (x == 1) { A = "Yes"; } Console.WriteLine(A); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
368
4
using System; using System.Text.RegularExpressions; using System.Numerics; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { class Program { static void Main(string[] args) { List<int> values = new List<int>(); string str = Console.ReadLine(); //標準入力 string[] str2 = str.Split(' '); int a = int.Parse(str2[0]); int b = int.Parse(str2[1]); char[,] masu = new char[a + 2, b + 2]; for (int i = 0; i < b; i++) { str = Console.ReadLine(); char[] c = str.Trim().ToCharArray(); for (int i2 = 0; i2 < b; i2++) { masu[i + 1, i2 + 1] = c[i2]; } } for (int y = 1; y < b + 1; y++) { for (int x = 1; x < a + 1; x++) { if (masu[y, x] == '#') { if (masu[y - 1, x] != '#' && masu[y + 1, x] != '#' && masu[y, x - 1] != '#' && masu[y, x + 1] != '#') { Console.WriteLine("No"); return; } } } } Console.WriteLine("Yes"); } } }
using System; using System.Text.RegularExpressions; using System.Numerics; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { class Program { static void Main(string[] args) { List<int> values = new List<int>(); string str = Console.ReadLine(); //標準入力 string[] str2 = str.Split(' '); int a = int.Parse(str2[0]); int b = int.Parse(str2[1]); char[,] masu = new char[a + 2, b + 2]; for (int i = 0; i < a; i++) { str = Console.ReadLine(); char[] c = str.Trim().ToCharArray(); for (int i2 = 0; i2 < b; i2++) { masu[i + 1, i2 + 1] = c[i2]; } } for (int y = 1; y < a + 1; y++) { for (int x = 1; x < b + 1; x++) { if (masu[y, x] == '#') { if (masu[y - 1, x] != '#' && masu[y + 1, x] != '#' && masu[y, x - 1] != '#' && masu[y, x + 1] != '#') { Console.WriteLine("No"); return; } } } } Console.WriteLine("Yes"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22]]
8
326
6
using System; namespace Template { class Program { static void Main(string[] args) { // 整数の入力 // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int h = int.Parse(input[0]); int w = int.Parse(input[1]); string[] s = new string[h]; for (int i0 = 0; i0 < h; i0++) { s[i0] = Console.ReadLine(); } for (int i0 = 0; i0 < h; i0++) { for (int i1 = 0; i1 < w; i1++) { if (s[i0][i1] == '#' && !((0 < i0 && s[i0 - 1][i1] == '#') || (i0 < h && s[i0 + 1][i1] == '#') || (0 < i1 && s[i0][i1 - 1] == '#') || (i1 < w && s[i0][i1 + 1] == '#'))) { Console.WriteLine("No"); return; } } } //出力 Console.WriteLine("Yes"); } } }
using System; namespace Template { class Program { static void Main(string[] args) { // 整数の入力 // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int h = int.Parse(input[0]); int w = int.Parse(input[1]); string[] s = new string[h]; for (int i0 = 0; i0 < h; i0++) { s[i0] = Console.ReadLine(); } for (int i0 = 0; i0 < h; i0++) { for (int i1 = 0; i1 < w; i1++) { if (s[i0][i1] == '#' && !((0 < i0 && s[i0 - 1][i1] == '#') || (i0 < h - 1 && s[i0 + 1][i1] == '#') || (0 < i1 && s[i0][i1 - 1] == '#') || (i1 < w - 1 && s[i0][i1 + 1] == '#'))) { Console.WriteLine("No"); return; } } } //出力 Console.WriteLine("Yes"); } } }
[["+", 12, 23, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 12, 23, 0, 16, 31, 16, 12, 16, 12, 203]]
8
258
4
using System; using System.Linq; namespace atcoder_Beginner_Contest096_Question3 { class Program { static void Main(string[] args) { bool possible = true; var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray(); char[][] paint = new char[input1[0]][]; for (int i = 0; i < input1[1]; i++) { paint[i] = Console.ReadLine().ToCharArray(); } for (int i = 0; i < input1[1]; i++) { for (int j = 0; j < input1[0]; j++) { if (paint[i][j] == '.') continue; if (j + 1 < input1[0] && paint[i][j + 1] != '#') if (j - 1 >= 0 && paint[i][j - 1] != '#') if (i + 1 < input1[1] && paint[i + 1][j] != '#') if (i - 1 >= 0 && paint[i - 1][j] != '#') possible = false; if (!possible) break; } if (!possible) break; } Console.WriteLine(possible ? "Yes" : "No"); } } }
using System; using System.Linq; namespace atcoder_Beginner_Contest096_Question3 { class Program { static void Main(string[] args) { bool possible = true; var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray(); char[][] paint = new char[input1[0]][]; for (int i = 0; i < input1[0]; i++) { paint[i] = Console.ReadLine().ToCharArray(); } for (int i = 0; i < input1[0]; i++) { for (int j = 0; j < input1[1]; j++) { if (paint[i][j] == '.') continue; if (j + 1 < input1[1] && paint[i][j + 1] != '#') if (j - 1 >= 0 && paint[i][j - 1] != '#') if (i + 1 < input1[0] && paint[i + 1][j] != '#') if (i - 1 >= 0 && paint[i - 1][j] != '#') possible = false; if (!possible) break; } if (!possible) break; } Console.WriteLine(possible ? "Yes" : "No"); } } }
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
289
10
using System; using System.Linq; namespace AtCoder { public class ABC096C { public static void Main(string[] args) { string[] lineArgs = Console.ReadLine().Split(' '); int H = int.Parse(lineArgs[0]); int W = int.Parse(lineArgs[1]); bool[][] target = new bool [H][]; for (int index = 0; index < H; index++) { target[index] = Console.ReadLine() .ToCharArray() .Select<char, bool>(arg => arg == '#') .ToArray<bool>(); } // 独立した一つの黒がなければ大丈夫と判断 // 全ての黒について確認する bool notIndependent = false; for (int h = 0; h < H; h++) { for (int w = 0; w < W; w++) { notIndependent = false; if (target[h][w] == false) continue; if (1 <= w && target[h][w - 1]) notIndependent = true; if (w + 1 < W && target[h][w + 1]) notIndependent = true; if (1 <= h && target[h - 1][w]) notIndependent = true; if (h + 1 < H && target[h + 1][w]) notIndependent = true; if (notIndependent == false) { Console.WriteLine("NO"); goto exit; } } } Console.WriteLine("YES"); exit:; } } }
using System; using System.Linq; namespace AtCoder { public class ABC096C { public static void Main(string[] args) { string[] lineArgs = Console.ReadLine().Split(' '); int H = int.Parse(lineArgs[0]); int W = int.Parse(lineArgs[1]); bool[][] target = new bool [H][]; for (int index = 0; index < H; index++) { target[index] = Console.ReadLine() .ToCharArray() .Select<char, bool>(arg => arg == '#') .ToArray<bool>(); } // 独立した一つの黒がなければ大丈夫と判断 // 全ての黒について確認する bool notIndependent = false; for (int h = 0; h < H; h++) { for (int w = 0; w < W; w++) { notIndependent = false; if (target[h][w] == false) continue; if (1 <= w && target[h][w - 1]) notIndependent = true; if (w + 1 < W && target[h][w + 1]) notIndependent = true; if (1 <= h && target[h - 1][w]) notIndependent = true; if (h + 1 < H && target[h + 1][w]) notIndependent = true; if (notIndependent == false) { Console.WriteLine("No"); goto exit; } } } Console.WriteLine("Yes"); exit:; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
315
4
using System.Collections.Generic; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var d = new Dictionary<long, long>(); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, long.Parse); var w = 0L; d[w] = 1; for (int i = 0; i < n; i++) { w = a[i] + w; if (d.ContainsKey(w)) d[w]++; else d[w] = 1; } Console.WriteLine(getAns(d)); } public static long getAns(Dictionary<long, long> d) { var ret = 0L; foreach (var x in d) if (x.Value >= 2 && x.Value % 2 == 0) ret += (x.Value / 2) * (x.Value - 1); else if (x.Value >= 2 && x.Value % 2 != 0) ret += (x.Value - 1 / 2) * x.Value; return ret; } }
using System.Collections.Generic; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var d = new Dictionary<long, long>(); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, long.Parse); var w = 0L; d[w] = 1; for (int i = 0; i < n; i++) { w = a[i] + w; if (d.ContainsKey(w)) d[w]++; else d[w] = 1; } Console.WriteLine(getAns(d)); } public static long getAns(Dictionary<long, long> d) { var ret = 0L; foreach (var x in d) if (x.Value >= 2 && x.Value % 2 == 0) ret += (x.Value / 2) * (x.Value - 1); else if (x.Value >= 2 && x.Value % 2 != 0) ret += ((x.Value - 1) / 2) * x.Value; return ret; } }
[["+", 12, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 23, 0, 25]]
8
257
2
using System; using System.Linq; using System.Diagnostics; using System.Collections.Generic; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); char[][] map = Enumerable.Repeat(0, n) .Select(_ => Console.ReadLine().ToArray()) .ToArray(); //[x][y][深さ] bool[][][] isSame = Enumerable.Repeat(0, n) .Select( _ => Enumerable.Repeat(0, n).Select(__ => new bool[n]).ToArray()) .ToArray(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { isSame[i][j][k] = map[i][j] == map[(i + k) % n][(j + k) % n]; } } } bool[][] isAllSame = Enumerable.Repeat(0, n) .Select(_ => Enumerable.Repeat(true, n).ToArray()) .ToArray(); //スタート for (int i = 0; i < n; i++) { //串のインデックス for (int j = 0; j < n; j++) { //ズラす for (int k = 0; k < n; k++) { if (!isSame[(n + i - k) % n][k][j]) { isAllSame[i][j] = false; break; } } } } int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!isAllSame[(i + j) % n][n - (j + 1)]) goto end; } count++; end:; } Console.WriteLine(count * n); } }
using System; using System.Linq; using System.Diagnostics; using System.Collections.Generic; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); char[][] map = Enumerable.Repeat(0, n) .Select(_ => Console.ReadLine().ToArray()) .ToArray(); //[x][y][深さ] bool[][][] isSame = Enumerable.Repeat(0, n) .Select( _ => Enumerable.Repeat(0, n).Select(__ => new bool[n]).ToArray()) .ToArray(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { isSame[i][j][k] = map[i][j] == map[(i + k) % n][(n + j - k) % n]; } } } bool[][] isAllSame = Enumerable.Repeat(0, n) .Select(_ => Enumerable.Repeat(true, n).ToArray()) .ToArray(); //スタート for (int i = 0; i < n; i++) { //串のインデックス for (int j = 0; j < n; j++) { //ズラす for (int k = 0; k < n; k++) { if (!isSame[(i + k) % n][k][j]) { isAllSame[i][j] = false; break; } } } } int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!isAllSame[(i + j) % n][n - (j + 1)]) goto end; } count++; end:; } Console.WriteLine(count * n); } }
[["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["-", 0, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72]]
8
428
8
using System; namespace AtCorder { class Program { static void Main(string[] args) { var input = Console.ReadLine(); var count = 0; if (input[0] == 'c') { count++; } if (input[1] == 'c') { count++; } if (input[2] == 'c') { count++; } var result = count == 0 ? 700 : 700 + 100 * count; Console.WriteLine(result); } } }
using System; namespace AtCorder { class Program { static void Main(string[] args) { var input = Console.ReadLine(); var count = 0; if (input[0] == 'o') { count++; } if (input[1] == 'o') { count++; } if (input[2] == 'o') { count++; } var result = count == 0 ? 700 : 700 + 100 * count; Console.WriteLine(result); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253]]
8
106
6
using System; namespace A___Something_on_It { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var sum = 700; for (var i = 0; i < 3; i++) { if (s.Substring(i, 1) == "〇") { sum += 100; } } Console.WriteLine(sum); } } }
using System; namespace A___Something_on_It { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var sum = 700; for (var i = 0; i < 3; i++) { if (s.Substring(i, 1) == "o") { sum += 100; } } Console.WriteLine(sum); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222]]
8
80
2
using System; class Program { static void Main(string[] args) { string input = Console.ReadLine(); int cnt = 0; if (input[0] == 'o') cnt++; if (input[1] == 'o') cnt++; if (input[2] == 'o') cnt++; Console.WriteLine(500 + cnt * 100); } }
using System; class Program { static void Main(string[] args) { string input = Console.ReadLine(); int cnt = 0; if (input[0] == 'o') cnt++; if (input[1] == 'o') cnt++; if (input[2] == 'o') cnt++; Console.WriteLine(700 + cnt * 100); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203]]
8
85
2
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int count = 700; for (int i = 0; i < 3; i++) { if (s[i] == '○') count += 100; } Console.WriteLine(count); } }
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int count = 700; for (int i = 0; i < 3; i++) { if (s[i] == 'o') count += 100; } Console.WriteLine(count); } }
[["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253]]
8
70
2
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int count = 0; for (int i = 0; i < 3; i++) { if (s[0] == 'o') count++; } Console.WriteLine("{0}", 700 + count * 100); } }
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int count = 0; for (int i = 0; i < 3; i++) { if (s[i] == 'o') count++; } Console.WriteLine("{0}", 700 + count * 100); } }
[["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22]]
8
77
2
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; // const int M = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { Prt(sc.Str.Count(x => x == 'o') + 700); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); public override string ToString() => v1 + " " + v2; } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2); public static T sqr<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long[n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double[n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double a, double[] x) { int n = x.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i]; return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static double[][] mul(double a, double[][] A) { int n = A.Length; var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long[n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; // const int M = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { Prt(sc.Str.Count(x => x == 'o') * 100 + 700); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); public override string ToString() => v1 + " " + v2; } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2); public static T sqr<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long[n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double[n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double a, double[] x) { int n = x.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i]; return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static double[][] mul(double a, double[][] A) { int n = A.Length; var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long[n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
[["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203]]
8
4,223
2
using System; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(" "); var N = int.Parse(input[0]); double X = int.Parse(input[1]); var min = Math.Pow(10, 5); var count = 0; for (var i = 0; i < N; i++) { var m = int.Parse(Console.ReadLine()); if (m < min) min = m; X -= m; count++; } while (X > min) { X -= min; count++; } Console.WriteLine(count); } }
using System; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(" "); var N = int.Parse(input[0]); double X = int.Parse(input[1]); var min = Math.Pow(10, 5); var count = 0; for (var i = 0; i < N; i++) { var m = int.Parse(Console.ReadLine()); if (m < min) min = m; X -= m; count++; } while (X >= min) { X -= min; count++; } Console.WriteLine(count); } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20]]
8
146
2
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var n = int.Parse(spl[0]); var x = int.Parse(spl[1]); var min = int.MaxValue; for (int i = 0; i < n; i++) { var m = int.Parse(input.ReadLine()); x -= m; min = Math.Min(m, x); } return n + x / min; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var n = int.Parse(spl[0]); var x = int.Parse(spl[1]); var min = int.MaxValue; for (int i = 0; i < n; i++) { var m = int.Parse(input.ReadLine()); x -= m; min = Math.Min(min, m); } return n + x / min; } }
[["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
8
225
4
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int[] n_x = sc.intarr; int n = n_x[0]; int x = n_x[1]; int[] ms = new int[n]; for (int i = 0; i < n; i++) { ms[i] = sc.intarr[0]; } Array.Sort(ms); for (int i = 0; i < n; i++) { x -= ms[i]; } int ex = 0; while (ex * ms[0] < x - ms[0]) { ex++; } wr.wri(n + ex); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int[] n_x = sc.intarr; int n = n_x[0]; int x = n_x[1]; int[] ms = new int[n]; for (int i = 0; i < n; i++) { ms[i] = sc.intarr[0]; } Array.Sort(ms); for (int i = 0; i < n; i++) { x -= ms[i]; } int ex = 0; while (ex * ms[0] <= x - ms[0]) { ex++; } wr.wri(n + ex); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
8
352
2
using System; using System.Linq; class Program { static void Main(string[] args) { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(s); Console.WriteLine(solve(s[0], s[1], s[2])); } static int solve(int a, int b, int c) { // a < b < c int count = 0; if ((c - b) % 2 == 0 && (c - a) % 2 == 0) { count += (c - b) / 2 + (c - a) / 2 + 1; } else if (((c - b) % 2 == 0 && (c - a) % 2 == 1) || ((c - b) % 2 == 1 && (c - a) % 2 == 0)) { count += (c - b) / 2 + (c - a) / 2 + 2; } else { count += (c - b) / 2 + (c - a) / 2 + 1; } return count; } }
using System; using System.Linq; class Program { static void Main(string[] args) { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(s); Console.WriteLine(solve(s[0], s[1], s[2])); } static int solve(int a, int b, int c) { // a < b < c int count = 0; if ((c - b) % 2 == 0 && (c - a) % 2 == 0) { count += (c - b) / 2 + (c - a) / 2; } else if (((c - b) % 2 == 0 && (c - a) % 2 == 1) || ((c - b) % 2 == 1 && (c - a) % 2 == 0)) { count += (c - b) / 2 + (c - a) / 2 + 2; } else { count += (c - b) / 2 + (c - a) / 2 + 1; } return count; } }
[["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
239
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Solve(); } static void Solve() { Scan sc = new Scan(); write wr = new write(); var s = sc.intarr; int a = s[0]; int b = s[1]; int c = s[2]; long target = Math.Max(Math.Max(a, b), c); if (3 * target - (a + b + c) % 2 == 1) target++; wr.wri((3 * target - (a + b + c)) / 2); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Solve(); } static void Solve() { Scan sc = new Scan(); write wr = new write(); var s = sc.intarr; int a = s[0]; int b = s[1]; int c = s[2]; long target = Math.Max(Math.Max(a, b), c); if ((3 * target - (a + b + c)) % 2 == 1) target++; wr.wri((3 * target - (a + b + c)) / 2); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
263
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class ABC { static void Main(string[] args) { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 0; int max = Math.Max(n[0], Math.Max(n[1], n[2])); int min = Math.Min(n[0], Math.Min(n[1], n[2])); if (3 * max % 2 == (n[0] + n[1] + n[2]) % 2) ans = (3 * max - n[0] - n[1] - n[2]) / 2; else ans = (3 * max - n[0] - n[1] - n[2]) / 2 + 1; Console.WriteLine(ans); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class ABC { static void Main(string[] args) { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 0; int max = Math.Max(n[0], Math.Max(n[1], n[2])); int min = Math.Min(n[0], Math.Min(n[1], n[2])); if (3 * max % 2 == (n[0] + n[1] + n[2]) % 2) ans = (3 * max - n[0] - n[1] - n[2]) / 2; else ans = (3 * (max + 1) - n[0] - n[1] - n[2]) / 2; Console.WriteLine(ans); Console.ReadLine(); } } }
[["+", 31, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["-", 0, 57, 75, 1, 0, 11, 12, 16, 17, 72], ["-", 0, 57, 75, 1, 0, 11, 12, 16, 12, 203]]
8
226
6
using System; class Program { static void Main() { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int answer = 0; int[] numDivides = new int[3]; for (int i = 0; i < 3; i++) numDivides[i] = nums[i] % 2; if (numDivides[0] != numDivides[1] && numDivides[0] != numDivides[2]) { nums[1]++; nums[2]++; answer++; } if (numDivides[1] != numDivides[0] && numDivides[1] != numDivides[2]) { nums[0]++; nums[2]++; answer++; } if (numDivides[2] != numDivides[1] && numDivides[2] != numDivides[0]) { nums[0]++; nums[1]++; answer++; } Array.Sort(nums); answer += (nums[2] - nums[1]) / 2; answer += (nums[1] - nums[0]) / 2; Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; class Program { static void Main() { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int answer = 0; int[] numDivides = new int[3]; for (int i = 0; i < 3; i++) numDivides[i] = nums[i] % 2; if (numDivides[0] != numDivides[1] && numDivides[0] != numDivides[2]) { nums[1]++; nums[2]++; answer++; } if (numDivides[1] != numDivides[0] && numDivides[1] != numDivides[2]) { nums[0]++; nums[2]++; answer++; } if (numDivides[2] != numDivides[1] && numDivides[2] != numDivides[0]) { nums[0]++; nums[1]++; answer++; } Array.Sort(nums); answer += (nums[2] - nums[1]) / 2; answer += (nums[2] - nums[0]) / 2; Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
8
247
2
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) {   int a = 0; // a = int.Parse(Console.ReadLine()); //標準入力 string[] str = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の List<string> lt = new List<string>(str); List<int> lis = new List<int>(); for (int i = 0; i < str.Length; i++) { lis.Add(int.Parse(str[i])); } lis.Sort(); int dis0 = lis[1] - lis[0]; int dis1 = lis[2] - lis[1]; if (dis0 % 2 == 1) { dis1++; } else { } a = dis0 / 2 + dis1; Console.Write(a); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) {   int a = 0; // a = int.Parse(Console.ReadLine()); //標準入力 string[] str = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の List<string> lt = new List<string>(str); List<int> lis = new List<int>(); for (int i = 0; i < str.Length; i++) { lis.Add(int.Parse(str[i])); } lis.Sort(); int dis0 = lis[1] - lis[0]; int dis1 = lis[2] - lis[1]; if (dis0 % 2 == 1) { dis1++; dis0++; } else { } a = dis0 / 2 + dis1; Console.Write(a); } }
[["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
181
3
using System; using System.Linq; class Program { static void Main() { var count = 0; var i = "2 6 3".Split(' ').Select(x => int.Parse(x)).ToList(); var odd = i.Where(x => x % 2 == 1).Count(); var max = i.Max(); var min = i.Min(); i.RemoveAt(i.IndexOf(max)); i.RemoveAt(i.IndexOf(min)); var mid = i.Single(); if (odd == 1) { count++; if (max % 2 == 0) { max++; if (min % 2 == 0) { min++; } else { mid++; } } else { min++; mid++; } } else if (odd == 2) { count++; if (max % 2 == 1) { max++; if (min % 2 == 1) { min++; } else { mid++; } } else { min++; mid++; } } Console.WriteLine(count + (max - mid) / 2 + (max - min) / 2); } }
using System; using System.Linq; class Program { static void Main() { var count = 0; var i = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); var odd = i.Where(x => x % 2 == 1).Count(); var max = i.Max(); var min = i.Min(); i.RemoveAt(i.IndexOf(max)); i.RemoveAt(i.IndexOf(min)); var mid = i.Single(); if (odd == 1) { count++; if (max % 2 == 0) { max++; if (min % 2 == 0) { min++; } else { mid++; } } else { min++; mid++; } } else if (odd == 2) { count++; if (max % 2 == 1) { max++; if (min % 2 == 1) { min++; } else { mid++; } } else { min++; mid++; } } Console.WriteLine(count + (max - mid) / 2 + (max - min) / 2); } }
[["-", 63, 214, 205, 213, 63, 214, 205, 5, 0, 62], ["-", 63, 214, 205, 213, 63, 214, 205, 5, 0, 222], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25]]
8
253
8
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); Array.Sort(a); var ret = a[2] - a[1]; var w = a[1] - a[0]; if (w % 2 == 0) ret += w / 2; else ret += (w - 1) / 2 + 1; Console.WriteLine(ret); } }
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); Array.Sort(a); var ret = a[2] - a[1]; var w = a[1] - a[0]; if (w % 2 == 0) ret += w / 2; else ret += (w - 1) / 2 + 2; Console.WriteLine(ret); } }
[["-", 0, 57, 75, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 12, 203]]
8
119
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; class Solver { Scanner sc = new Scanner(); // public void Solve() { var Q = sc.Int; while (Q-- > 0) { long A, B; sc.Make(out A, out B); if (A == B) { WriteLine((A - 1) * 2); continue; } var r = (long)1e9; var l = 1L; while (r - l > 1) { var m = (r + l) / 2; var ok = true; //判定 ok = (m + 1) / 2 * (m - (m - 1) / 2) >= A * B; if (ok) r = m; else l = m; } WriteLine(--l); } } } #region Template public class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>()); public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>()); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Tie(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; class Solver { Scanner sc = new Scanner(); // public void Solve() { var Q = sc.Int; while (Q-- > 0) { long A, B; sc.Make(out A, out B); if (A == B) { WriteLine((A - 1) * 2); continue; } var r = (long)2e9; var l = 1L; while (r - l > 1) { var m = (r + l) / 2; var ok = true; //判定 ok = (m + 1) / 2 * (m - (m - 1) / 2) >= A * B; if (ok) r = m; else l = m; } WriteLine(--l); } } } #region Template public class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>()); public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>()); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Tie(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; } } #endregion
[["-", 0, 198, 0, 200, 0, 212, 0, 74, 51, 250], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 51, 250]]
8
1,630
2
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class D { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { int Q = GetInt(); long[] A = new long[Q]; long[] B = new long[Q]; for (int i = 0; i < Q; i++) { A[i] = GetLong(); B[i] = GetLong(); } long[] ans = new long[Q]; for (int i = 0; i < Q; i++) ans[i] = calc(A[i], B[i]); Console.WriteLine( string.Join("\n", ans.Select(x => x.ToString()).ToArray())); } private long calc(long A, long B) { if (A == B) return (2 * A - 2); if (A > B) swap(ref A, ref B); long T = A * B; long ok = 0; long ng = (long)1e9; while (Math.Abs(ng - ok) > 1) { long mid = (ng + ok) / 2; long max = ((mid + 1) / 2) * (mid + 1 - ((mid + 1) / 2)); if (max < T) ok = mid; else ng = mid; } return ok - 1; } private void swap(ref long x, ref long y) { long tmp = x; x = y; y = tmp; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class D { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { int Q = GetInt(); long[] A = new long[Q]; long[] B = new long[Q]; for (int i = 0; i < Q; i++) { A[i] = GetLong(); B[i] = GetLong(); } long[] ans = new long[Q]; for (int i = 0; i < Q; i++) ans[i] = calc(A[i], B[i]); Console.WriteLine( string.Join("\n", ans.Select(x => x.ToString()).ToArray())); } private long calc(long A, long B) { if (A == B) return (2 * A - 2); if (A > B) swap(ref A, ref B); long T = A * B; long ok = 0; long ng = (1L << 31); while (Math.Abs(ng - ok) > 1) { long mid = (ng + ok) / 2; long max = ((mid + 1) / 2) * (mid + 1 - ((mid + 1) / 2)); if (max < T) ok = mid; else ng = mid; } return ok - 1; } private void swap(ref long x, ref long y) { long tmp = x; x = y; y = tmp; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); }
[["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 31, 203], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 17, 151], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 51, 250]]
8
649
5
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var M = array.Max(); if (3 * M - array.Sum() % 2 == 0) { Console.WriteLine((3 * M - array.Sum()) / 2); } else { Console.WriteLine((3 * M + 3 - array.Sum()) / 2); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var M = array.Max(); if ((3 * M - array.Sum()) % 2 == 0) { Console.WriteLine((3 * M - array.Sum()) / 2); } else { Console.WriteLine((3 * M + 3 - array.Sum()) / 2); } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
132
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var sb = new StringBuilder(); var S = Str; if (S == "zyxwvutsrqponmlkjihgfedcba") { Write(-1); } else if (S.Length < 26) { var set = new HashSet<char>(); for (int i = 0; i < S.Length; ++i) { set.Add(S[i]); sb.Append(S[i]); } for (char j = 'a'; j <= 'z'; ++j) { if (set.Contains(j)) continue; else { sb.Append(j); Write(sb); return; } } } else { for (int i = S.Length - 1; i >= 0; --i) { var us = new HashSet<char>(); for (int j = 0; j < i; ++j) { us.Add(S[j]); } for (char c = (char)(S[i]); c <= 'z'; ++c) { if (us.Contains(c)) continue; var ss = S.Substring(0, i); ss += c; Write(ss); return; } } } } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long i, long N, long MOD = 1000000007) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long Power2(long i, long N) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i; i = i * i; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) R = N - R; for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var sb = new StringBuilder(); var S = Str; if (S == "zyxwvutsrqponmlkjihgfedcba") { Write(-1); } else if (S.Length < 26) { var set = new HashSet<char>(); for (int i = 0; i < S.Length; ++i) { set.Add(S[i]); sb.Append(S[i]); } for (char j = 'a'; j <= 'z'; ++j) { if (set.Contains(j)) continue; else { sb.Append(j); Write(sb); return; } } } else { for (int i = S.Length - 1; i >= 0; --i) { var us = new HashSet<char>(); for (int j = 0; j < i; ++j) { us.Add(S[j]); } for (char c = (char)(S[i] + 1); c <= 'z'; ++c) { if (us.Contains(c)) continue; var ss = S.Substring(0, i); ss += c; Write(ss); return; } } } } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long i, long N, long MOD = 1000000007) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long Power2(long i, long N) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i; i = i * i; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) R = N - R; for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["+", 0, 212, 0, 74, 51, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203]]
8
1,170
2
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorders { public class Program { static void Main(string[] args) { string s = Console.ReadLine(); int n = s.Length; if (n == 26) { var chars = new List<char>(); chars.Add(s[n - 1]); for (int i = n - 2; i >= 0; i--) { if (s[i] < s[i + 1]) { chars.Sort(); char next = chars.First(x => x > s[i]); string ans = s.Substring(0, i + 1) + next; Console.WriteLine(ans); return; } else { chars.Add(s[i]); } } Console.WriteLine(-1); } else { var exists = new bool [26].ToList(); for (int i = 0; i < n; i++) { exists[s[i] - 'a'] = true; } char next = (char)(exists.FindIndex(x => x == false) + 'a'); string ans = s + next; Console.WriteLine(ans); } } } }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorders { public class Program { static void Main(string[] args) { string s = Console.ReadLine(); int n = s.Length; if (n == 26) { var chars = new List<char>(); chars.Add(s[n - 1]); for (int i = n - 2; i >= 0; i--) { if (s[i] < s[i + 1]) { chars.Sort(); char next = chars.First(x => x > s[i]); string ans = s.Substring(0, i) + next; Console.WriteLine(ans); return; } else { chars.Add(s[i]); } } Console.WriteLine(-1); } else { var exists = new bool [26].ToList(); for (int i = 0; i < n; i++) { exists[s[i] - 'a'] = true; } char next = (char)(exists.FindIndex(x => x == false) + 'a'); string ans = s + next; Console.WriteLine(ans); } } } }
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
300
2
using System; using System.Collections.Generic; using System.Linq; using console = System.Console; namespace AtCoderTemplate { public class App { public static void Main(string[] args) { var p = console.ReadLine(); if (p.Count() == 26 || true) { var q = p.Skip(1).Zip(p, (a, b) => a - b); var r = p.Count() - 1 - q.Reverse().TakeWhile(i => i < 0).Count(); if (r == 0) console.WriteLine(-1); else { var s = p.Take(r).ToArray(); s[r - 1] = p.Last(c => c > s[r - 1]); console.WriteLine(string.Join("", s)); } } else console.WriteLine( p + (char)('a' + p.OrderBy(c => c).Where((c, i) => c - i == 'a').Count())); } } }
using System; using System.Collections.Generic; using System.Linq; using console = System.Console; namespace AtCoderTemplate { public class App { public static void Main(string[] args) { var p = console.ReadLine(); if (p.Count() == 26) { var q = p.Skip(1).Zip(p, (a, b) => a - b); var r = p.Count() - 1 - q.Reverse().TakeWhile(i => i < 0).Count(); if (r == 0) console.WriteLine(-1); else { var s = p.Take(r).ToArray(); s[r - 1] = p.Last(c => c > s[r - 1]); console.WriteLine(string.Join("", s)); } } else console.WriteLine( p + (char)('a' + p.OrderBy(c => c).Where((c, i) => c - i == 'a').Count())); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 211, 0, 146]]
8
237
2
using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var str = ReadLine(); HashSet<char> charHash = new HashSet<char>(); bool end = false; var current = 'a'; foreach (var item in str) { charHash.Add(item); } for (int i = current + 1; i < 'a' + 26; i++) { if (!charHash.Any(x => x == (char)i)) { WriteLine(str + ((char)i).ToString()); end = true; return; } } while (!end) { charHash.Clear(); foreach (var item in str) { charHash.Add(item); } for (int i = current + 1; i < 'a' + 26; i++) { if (!charHash.Any(x => x == (char)i)) { WriteLine(str.Substring(0, str.Length - 1) + ((char)i).ToString()); end = true; return; } } str = str.Substring(0, str.Length - 1); if (str == "") { WriteLine("-1"); end = true; return; } current = str.Last(); } } }
using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var str = ReadLine(); HashSet<char> charHash = new HashSet<char>(); bool end = false; var current = 'a'; foreach (var item in str) { charHash.Add(item); } for (int i = current; i < 'a' + 26; i++) { if (!charHash.Any(x => x == (char)i)) { WriteLine(str + ((char)i).ToString()); end = true; return; } } while (!end) { charHash.Clear(); foreach (var item in str) { charHash.Add(item); } for (int i = current + 1; i < 'a' + 26; i++) { if (!charHash.Any(x => x == (char)i)) { WriteLine(str.Substring(0, str.Length - 1) + ((char)i).ToString()); end = true; return; } } str = str.Substring(0, str.Length - 1); if (str == "") { WriteLine("-1"); end = true; return; } current = str.Last(); } } }
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
293
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var S = ReadLine(); var u = new bool[26]; for (int i = 0; i < 26; i++) { u[i] = S.Contains((char)('a' + i)); } if (S.Length != 26) { for (int i = 0; i < 26; i++) { if (!u[i]) { WriteLine(S + (char)('a' + i)); return; } } } else { var a = new List<char>(); for (int i = 25; i > 0; i--) { a.Add(S[i]); var s = S.Substring(0, i); for (int j = 0; j < a.Count; j++) { if (S.CompareTo(s + a[j]) < 0) { WriteLine(s + a[j]); return; } } } WriteLine(-1); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var S = ReadLine(); var u = new bool[26]; for (int i = 0; i < 26; i++) { u[i] = S.Contains((char)('a' + i)); } if (S.Length != 26) { for (int i = 0; i < 26; i++) { if (!u[i]) { WriteLine(S + (char)('a' + i)); return; } } } else { var a = new List<char>(); for (int i = 25; i >= 0; i--) { a.Add(S[i]); var s = S.Substring(0, i); for (int j = 0; j < a.Count; j++) { if (S.CompareTo(s + a[j]) < 0) { WriteLine(s + a[j]); return; } } } WriteLine(-1); } } }
[["-", 0, 57, 75, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 17, 20]]
8
245
2
using System; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const long mod = 1000000007; // public static int[] max; static void Main(string[] args) { char[] cs = new char[] { ' ', ',' }; // int val = int.Parse(Console.ReadLine()); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // int n = vals[0]; // string res=""; // int y = vals[0]; // int x = vals[1]; char a = 'a'; string str = Console.ReadLine(); Dictionary<char, int> dic = new Dictionary<char, int>(); if (str == "zyxwvutsrqponmlkjihgfedcba") { Console.WriteLine("-1"); return; } for (int i = 0; i < str.Length; i++) { dic.Add(str[i], 1); } if (dic.Count == 26) { // all for (int k = 25; k >= 0; k--) { for (int i = str[k] + 1; i < 'z'; i++) { if (!dic.ContainsKey((char)i)) { str = str.Remove(k); str += ((char)i).ToString(); Console.WriteLine(str); return; } } dic.Remove((char)str[k]); str = str.Remove(k); } } else { for (int i = 'a'; i <= 'z'; i++) { if (!dic.ContainsKey((char)i)) { str += ((char)i).ToString(); Console.WriteLine(str); return; } } } // deug Console.WriteLine(""); return; } // String[] -----> int[] static int[] parseAry(string[] str) { int[] nums = new int[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } // String[] -----> long[] static long[] parseAryl(string[] str) { long[] nums = new long[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } //文字列を1文字ずつString[]に入れる static string[] strAry(String str) { string[] re = new string[str.Length]; for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); } return re; } }
using System; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const long mod = 1000000007; // public static int[] max; static void Main(string[] args) { char[] cs = new char[] { ' ', ',' }; // int val = int.Parse(Console.ReadLine()); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // int n = vals[0]; // string res=""; // int y = vals[0]; // int x = vals[1]; char a = 'a'; string str = Console.ReadLine(); Dictionary<char, int> dic = new Dictionary<char, int>(); if (str == "zyxwvutsrqponmlkjihgfedcba") { Console.WriteLine("-1"); return; } for (int i = 0; i < str.Length; i++) { dic.Add(str[i], 1); } if (dic.Count == 26) { // all for (int k = 25; k >= 0; k--) { for (int i = str[k] + 1; i <= 'z'; i++) { if (!dic.ContainsKey((char)i)) { str = str.Remove(k); str += ((char)i).ToString(); Console.WriteLine(str); return; } } dic.Remove((char)str[k]); str = str.Remove(k); } } else { for (int i = 'a'; i <= 'z'; i++) { if (!dic.ContainsKey((char)i)) { str += ((char)i).ToString(); Console.WriteLine(str); return; } } } // deug Console.WriteLine(""); return; } // String[] -----> int[] static int[] parseAry(string[] str) { int[] nums = new int[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } // String[] -----> long[] static long[] parseAryl(string[] str) { long[] nums = new long[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } //文字列を1文字ずつString[]に入れる static string[] strAry(String str) { string[] re = new string[str.Length]; for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); } return re; } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
530
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC022A { class Program { static void Main(string[] args) { string S = Console.ReadLine(); int num = S.Length; string ans = ""; bool ok = false; string[] alph = new string[26] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; bool[] alem = new bool[26]; if (num != 26) { for (int i = 0; i < num; i++) { string al = S.Substring(i, 1); int numal = -1; for (int j = 0; j < 26; j++) { if (al == alph[j]) { numal = j; break; } } alem[numal] = true; } int numfal = -1; for (int i = 0; i < 26; i++) { if (!alem[i]) { numfal = i; break; } } ans = S + alph[numfal]; } else { int valnum = -1; int valchar = -1; for (int i = 0; i < 25; i++) { string pre = S.Substring(i, 1); string nex = S.Substring(i + 1, 1); int prenum = -1; int nexnum = -1; for (int j = 0; j < 26; j++) { if (pre == alph[j]) { prenum = j; } if (nex == alph[j]) { nexnum = j; } } if (prenum < nexnum) { valnum = i; valchar = prenum; } } if (valnum == -1) { ok = true; } else { for (int i = valnum + 1; i < 26; i++) { string pre = S.Substring(i, 1); int prenum = -1; for (int j = 0; j < 26; j++) { if (pre == alph[j]) { prenum = j; } } alem[prenum] = true; } int numb = -1; for (int i = 0; i < 26; i++) { if (alem[i] && valchar < i) { numb = i; break; } } ans = S.Substring(0, valchar) + alph[numb]; } } if (ok) { Console.WriteLine(-1); } else { Console.WriteLine(ans); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC022A { class Program { static void Main(string[] args) { string S = Console.ReadLine(); int num = S.Length; string ans = ""; bool ok = false; string[] alph = new string[26] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; bool[] alem = new bool[26]; if (num != 26) { for (int i = 0; i < num; i++) { string al = S.Substring(i, 1); int numal = -1; for (int j = 0; j < 26; j++) { if (al == alph[j]) { numal = j; break; } } alem[numal] = true; } int numfal = -1; for (int i = 0; i < 26; i++) { if (!alem[i]) { numfal = i; break; } } ans = S + alph[numfal]; } else { int valnum = -1; int valchar = -1; for (int i = 0; i < 25; i++) { string pre = S.Substring(i, 1); string nex = S.Substring(i + 1, 1); int prenum = -1; int nexnum = -1; for (int j = 0; j < 26; j++) { if (pre == alph[j]) { prenum = j; } if (nex == alph[j]) { nexnum = j; } } if (prenum < nexnum) { valnum = i; valchar = prenum; } } if (valnum == -1) { ok = true; } else { for (int i = valnum + 1; i < 26; i++) { string pre = S.Substring(i, 1); int prenum = -1; for (int j = 0; j < 26; j++) { if (pre == alph[j]) { prenum = j; } } alem[prenum] = true; } int numb = -1; for (int i = 0; i < 26; i++) { if (alem[i] && valchar < i) { numb = i; break; } } ans = S.Substring(0, valnum) + alph[numb]; } } if (ok) { Console.WriteLine(-1); } else { Console.WriteLine(ans); } } } }
[["-", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22]]
8
631
2
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); int n = sc.I; int[] a = sc.Ia; int[] b = sc.Ia; int max = a.Max(); bool[] bo = new bool[max + 1]; int[,] h = new int[max + 1, max + 1]; for (int i = 1; i <= max; i++) { for (int j = 1; j <= i; j++) { h[i, j] = i % j; } } long ans = 0, k = 0; while (k < n && ans != -1) { long o = 0, p = 0; for (int i = 0; i < n; i++) { if (a[i] == b[i] || bo[i]) { if (!bo[i]) { k++; bo[i] = true; } continue; } var pq = new Pq<Mo<int>>(n, true); for (int j = 1; j <= a[i]; j++) { if (h[a[i], j] >= b[i]) { pq.Push(new Mo<int>((ans & (1L << j)) == 0 ? (1L << j) : 0, h[a[i], j])); } } while (pq.cnt > 0) { Mo<int> q = pq.Top; if (q.d == b[i]) { break; } pq.Pop(); for (int j = 1; j <= q.d; j++) { if (h[q.d, j] >= b[i]) { pq.Push(new Mo<int>( q.n + ((ans & (1L << j)) == 0 ? (1L << j) : 0), h[q.d, j])); } } } if (pq.cnt == 0) { ans = -1; break; } else if (p < pq.Top.n) { p = pq.Top.n; o = i; } } ans |= p; bo[o] = true; k++; } Console.WriteLine(ans); } } public class Mo<T> : IComparable { public long n; public T d; public Mo(long n, T d) { this.n = n; this.d = d; } public int CompareTo(object obj) { Mo<T> mymo = (Mo<T>)obj; if (mymo.n > n) { return -1; } else if (mymo.n < n) { return 1; } else { return 0; } } } public class Pq<T> where T : IComparable { private T[] he; public int cnt = 0, max = 0; private Func<T, T, int> compare; public Pq(int max, bool mm) { this.max = max; he = new T[max]; if (mm) { compare = Ao; } else { compare = Do; } } public void Push(T x) { if (cnt == max) { Extend(); } int j = cnt; while (j != 0 && compare(x, he[(j - 1) >> 1]) > 0) { he[j] = he[(j - 1) >> 1]; j = (j - 1) >> 1; } he[j] = x; cnt++; } public void Pop() { cnt--; T r = he[cnt]; int j = 0; while (true) { if (j * 2 + 1 < cnt) { if (compare(he[j * 2 + 1], he[j * 2 + 2]) > 0) { j = j * 2 + 1; } else { j = j * 2 + 2; } } else if (j * 2 < cnt) { j = j * 2 + 1; } else { break; } if (compare(he[j], r) <= 0) { j = (j - 1) >> 1; break; } he[(j - 1) >> 1] = he[j]; } he[j] = r; } private int Ao(T x, T y) { return y.CompareTo(x); } private int Do(T x, T y) { return x.CompareTo(y); } public T Top { get { return he[0]; } } private void Extend() { T[] nhe = new T[max << 1]; Array.Copy(he, nhe, max); he = nhe; max <<= 1; } } public class Sc { private string[] a; private int n = -1, m = 0; public int I { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return int.Parse(a[n]); } } public long L { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return long.Parse(a[n]); } } public double D { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return double.Parse(a[n]); } } public string S { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return a[n]; } } public int[] Ia { get { if (n != -1 && n != a.Length - 1) { m = n; n = -1; return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse); } return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); int n = sc.I; int[] a = sc.Ia; int[] b = sc.Ia; int max = a.Max(); bool[] bo = new bool[n]; int[,] h = new int[max + 1, max + 1]; for (int i = 1; i <= max; i++) { for (int j = 1; j <= i; j++) { h[i, j] = i % j; } } long ans = 0, k = 0; while (k < n && ans != -1) { long o = 0, p = 0; for (int i = 0; i < n; i++) { if (a[i] == b[i] || bo[i]) { if (!bo[i]) { k++; bo[i] = true; } continue; } var pq = new Pq<Mo<int>>(n, true); for (int j = 1; j <= a[i]; j++) { if (h[a[i], j] >= b[i]) { pq.Push(new Mo<int>((ans & (1L << j)) == 0 ? (1L << j) : 0, h[a[i], j])); } } while (pq.cnt > 0) { Mo<int> q = pq.Top; if (q.d == b[i]) { break; } pq.Pop(); for (int j = 1; j <= q.d; j++) { if (h[q.d, j] >= b[i]) { pq.Push(new Mo<int>( q.n + ((ans & (1L << j)) == 0 ? (1L << j) : 0), h[q.d, j])); } } } if (pq.cnt == 0) { ans = -1; break; } else if (p < pq.Top.n) { p = pq.Top.n; o = i; } } ans |= p; bo[o] = true; k++; } Console.WriteLine(ans); } } public class Mo<T> : IComparable { public long n; public T d; public Mo(long n, T d) { this.n = n; this.d = d; } public int CompareTo(object obj) { Mo<T> mymo = (Mo<T>)obj; if (mymo.n > n) { return -1; } else if (mymo.n < n) { return 1; } else { return 0; } } } public class Pq<T> where T : IComparable { private T[] he; public int cnt = 0, max = 0; private Func<T, T, int> compare; public Pq(int max, bool mm) { this.max = max; he = new T[max]; if (mm) { compare = Ao; } else { compare = Do; } } public void Push(T x) { if (cnt == max) { Extend(); } int j = cnt; while (j != 0 && compare(x, he[(j - 1) >> 1]) > 0) { he[j] = he[(j - 1) >> 1]; j = (j - 1) >> 1; } he[j] = x; cnt++; } public void Pop() { cnt--; T r = he[cnt]; int j = 0; while (true) { if (j * 2 + 1 < cnt) { if (compare(he[j * 2 + 1], he[j * 2 + 2]) > 0) { j = j * 2 + 1; } else { j = j * 2 + 2; } } else if (j * 2 < cnt) { j = j * 2 + 1; } else { break; } if (compare(he[j], r) <= 0) { j = (j - 1) >> 1; break; } he[(j - 1) >> 1] = he[j]; } he[j] = r; } private int Ao(T x, T y) { return y.CompareTo(x); } private int Do(T x, T y) { return x.CompareTo(y); } public T Top { get { return he[0]; } } private void Extend() { T[] nhe = new T[max << 1]; Array.Copy(he, nhe, max); he = nhe; max <<= 1; } } public class Sc { private string[] a; private int n = -1, m = 0; public int I { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return int.Parse(a[n]); } } public long L { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return long.Parse(a[n]); } } public double D { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return double.Parse(a[n]); } } public string S { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return a[n]; } } public int[] Ia { get { if (n != -1 && n != a.Length - 1) { m = n; n = -1; return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse); } return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22]]
8
1,547
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC022C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] inputA = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int[] inputB = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); bool flagg = false; for (int i = 0; i < N; i++) { if (inputA[i] != inputB[i]) { flagg = true; } } if (flagg) { bool[,] dp = new bool[N, 51]; for (int i = 0; i < N; i++) { dp[i, inputB[i]] = true; } int max = -1; for (int i = 1; i <= 25; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < 51; k++) { if (dp[j, k % i]) { dp[j, k] = true; } } } bool flag = true; for (int j = 0; j < N; j++) { if (!dp[j, inputA[j]]) { flag = false; } } if (flag) { max = i; break; } } bool ok = (max == -1) ? false : true; long ans = 0; if (ok) { bool[] flags = Enumerable.Repeat(true, max).ToArray(); for (int l = max; l >= 1; l--) { dp = new bool[N, 51]; for (int i = 0; i < N; i++) { dp[i, inputB[i]] = true; } for (int i = 1; i <= max; i++) { if (i != max) { if (i == l || !flags[i - 1]) { continue; } } // Console.WriteLine(i); for (int j = 0; j < N; j++) { for (int k = 0; k < 51; k++) { if (dp[j, k % i]) { dp[j, k] = true; } } } } bool flag = true; for (int j = 0; j < N; j++) { if (!dp[j, inputA[j]]) { flag = false; } } // Console.WriteLine(flag); if (flag) { flags[l - 1] = false; } } for (int i = 0; i < max; i++) { // Console.WriteLine(flags[max - i - 1]); if (i == 0 || flags[max - i - 1]) { ans = (ans + 1) << 1; } else { ans = ans << 1; } } } if (ok) { Console.WriteLine(ans); } else { Console.WriteLine(-1); } } else { Console.WriteLine(0); } } // nが素数かどうか判定します private static int IsPrime(int n) { for (int i = 2; i < Math.Sqrt(n); i++) { if (n % i == 0) { return i; } } return -1; } //重み付きグラフ用の辺です class Edge { public int to; public int cost; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC022C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] inputA = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int[] inputB = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); bool flagg = false; for (int i = 0; i < N; i++) { if (inputA[i] != inputB[i]) { flagg = true; } } if (flagg) { bool[,] dp = new bool[N, 51]; for (int i = 0; i < N; i++) { dp[i, inputB[i]] = true; } int max = -1; // for (int i = 1; i <= 25; i++) { for (int i = 1; i <= 50; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < 51; k++) { if (dp[j, k % i]) { dp[j, k] = true; } } } bool flag = true; for (int j = 0; j < N; j++) { if (!dp[j, inputA[j]]) { flag = false; } } if (flag) { max = i; break; } } bool ok = (max == -1) ? false : true; long ans = 0; if (ok) { bool[] flags = Enumerable.Repeat(true, max).ToArray(); for (int l = max; l >= 1; l--) { dp = new bool[N, 51]; for (int i = 0; i < N; i++) { dp[i, inputB[i]] = true; } for (int i = 1; i <= max; i++) { if (i != max) { if (i == l || !flags[i - 1]) { continue; } } // Console.WriteLine(i); for (int j = 0; j < N; j++) { for (int k = 0; k < 51; k++) { if (dp[j, k % i]) { dp[j, k] = true; } } } } bool flag = true; for (int j = 0; j < N; j++) { if (!dp[j, inputA[j]]) { flag = false; } } // Console.WriteLine(flag); if (flag) { flags[l - 1] = false; } } for (int i = 0; i < max; i++) { // Console.WriteLine(flags[max - i - 1]); if (i == 0 || flags[max - i - 1]) { ans = (ans + 1) << 1; } else { ans = ans << 1; } } } if (ok) { Console.WriteLine(ans); } else { Console.WriteLine(-1); } } else { Console.WriteLine(0); } } // nが素数かどうか判定します private static int IsPrime(int n) { for (int i = 2; i < Math.Sqrt(n); i++) { if (n % i == 0) { return i; } } return -1; } //重み付きグラフ用の辺です class Edge { public int to; public int cost; } } }
[["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 203]]
8
742
2
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; using Number = System.Int64; using System.Numerics; using static System.Math; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var n = ri; var a = Enumerate(n, x => ri); var b = Enumerate(n, x => ri); for (int i = 0; i < n; i++) if (a[i] < b[i]) { Console.WriteLine(-1); return; } var mask = 0L; for (int i = 1; i <= 60; i++) { mask |= 1L << i; if (!check(a, b, mask)) continue; for (int j = i - 1; j > 0; j--) { var nmask = mask ^ 1L << j; if (check(a, b, nmask)) { Debug.WriteLine(nmask); mask ^= 1L << j; } } Debug.WriteLine(i); break; } if (mask >= 1L << 60) mask = -1; Console.WriteLine(mask); } bool check(int[] a, int[] b, long mask) { var go = new long[60]; for (int i = 0; i < 60; i++) { go[i] |= 1L << i; for (int j = 1; j <= i; j++) { if ((mask >> j & 1) == 0) continue; go[i] |= go[i % j]; } } for (int i = 0; i < a.Length; i++) { if ((go[a[i]] >> b[i] & 1) == 0) return false; } return true; } const long INF = 1L << 60; // static int[] dx = { -1, 0, 1, 0 }; // static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); try { solver.Solve(); Console.Out.Flush(); } catch { } } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region gcd, lcm static public partial class MathEx { static public int GCD(int n, int m) { return (int)GCD((long)n, m); } static public long GCD(long n, long m) { n = Math.Abs(n); m = Math.Abs(m); while (n != 0) { m %= n; if (m == 0) return n; n %= m; } return m; } static public long LCM(long n, long m) { return (n / GCD(n, m)) * m; } static public long GCD(params long[] a) { var gcd = a[0]; foreach (var x in a) gcd = GCD(gcd, x); return gcd; } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; using Number = System.Int64; using System.Numerics; using static System.Math; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var n = ri; var a = Enumerate(n, x => ri); var b = Enumerate(n, x => ri); for (int i = 0; i < n; i++) if (a[i] < b[i]) { Console.WriteLine(-1); return; } var mask = 0L; for (int i = 1; i <= 60; i++) { mask |= 1L << i; if (!check(a, b, mask)) continue; for (int j = i; j > 0; j--) { var nmask = mask ^ 1L << j; if (check(a, b, nmask)) { Debug.WriteLine(nmask); mask ^= 1L << j; } } Debug.WriteLine(i); break; } if (mask >= 1L << 60) mask = -1; Console.WriteLine(mask); } bool check(int[] a, int[] b, long mask) { var go = new long[60]; for (int i = 0; i < 60; i++) { go[i] |= 1L << i; for (int j = 1; j <= i; j++) { if ((mask >> j & 1) == 0) continue; go[i] |= go[i % j]; } } for (int i = 0; i < a.Length; i++) { if ((go[a[i]] >> b[i] & 1) == 0) return false; } return true; } const long INF = 1L << 60; // static int[] dx = { -1, 0, 1, 0 }; // static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); try { solver.Solve(); Console.Out.Flush(); } catch { } } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region gcd, lcm static public partial class MathEx { static public int GCD(int n, int m) { return (int)GCD((long)n, m); } static public long GCD(long n, long m) { n = Math.Abs(n); m = Math.Abs(m); while (n != 0) { m %= n; if (m == 0) return n; n %= m; } return m; } static public long LCM(long n, long m) { return (n / GCD(n, m)) * m; } static public long GCD(params long[] a) { var gcd = a[0]; foreach (var x in a) gcd = GCD(gcd, x); return gcd; } } #endregion
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
1,295
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; long mod = 1000000007; void calc() { cin = new Scanner(); // string S = new string('?', 99999);//cin.next(); string S = cin.next(); int N = S.Length; long[,] dp = new long[N + 1, 5]; // 0 -> 0start 1-> 0totyu 2->1start 3->1totyu dp[0, 0] = 1; if (S.Length == 1) { if (S == "0") Console.WriteLine(0); else Console.WriteLine(1); return; } for (int i = 0; i < S.Length; i++) { if (S[i] == '?') { // 4 dp[i + 1, 4] += dp[i, 4] * 2; dp[i + 1, 4] %= mod; } else { dp[i + 1, 4] += dp[i, 4]; dp[i + 1, 4] %= mod; } if (i % 2 == 0) { // 0 int pattern1 = 1; if (S[i] == '?') pattern1 *= 2; int activePattern1 = pattern1; if (S[i] == '1' || S[i] == '?') { dp[i + 1, 2] += dp[i, 0]; dp[i + 1, 2] %= mod; activePattern1--; } dp[i + 1, 1] += dp[i, 0] * (activePattern1); dp[i + 1, 1] %= mod; // 3 if (i != S.Length - 1) { int pattern2 = pattern1; if (S[i + 1] == '?') { pattern2 *= 2; } int activePattern2 = pattern2; if ((S[i] == '1' || S[i] == '?') && (S[i + 1] == '1' || S[i + 1] == '?')) { dp[i + 2, 4] += dp[i, 3]; dp[i + 2, 4] %= mod; activePattern2--; } dp[i + 2, 3] += dp[i, 3] * activePattern2; dp[i + 2, 3] %= mod; } else { if (S[i] == '1' || S[i] == '?') { dp[i + 1, 4] += dp[i, 3]; dp[i + 1, 4] %= mod; } } } else { int pattern1 = 1; if (S[i] == '?') pattern1 *= 2; // 1 if (i != S.Length - 2) { int pattern2 = pattern1; if (S[i + 1] == '?') { pattern2 *= 2; } int activePattern2 = pattern2; if ((S[i] == '1' || S[i] == '?') && (S[i + 1] == '1' || S[i + 1] == '?')) { dp[i + 2, 2] += dp[i, 1]; dp[i + 2, 2] %= mod; activePattern2--; } dp[i + 2, 1] += dp[i, 1] * activePattern2; dp[i + 2, 1] %= mod; } else { if ((S[i] == '1' || S[i] == '?') && (S[i + 1] == '1' || S[i + 1] == '?')) { dp[i + 1, 4] += dp[i, 1]; dp[i + 1, 4] %= mod; } } // 2 int activePattern1 = pattern1; if (S[i] == '1' || S[i] == '?') { dp[i + 1, 4] += dp[i, 2]; dp[i + 1, 4] %= mod; activePattern1--; } dp[i + 1, 3] += dp[i, 2] * (activePattern1); dp[i + 1, 3] %= mod; } } for (int i = 0; i < N + 1; i++) { for (int j = 0; j < 5; j++) { // Console.Write(dp[i,j] + " "); } // Console.WriteLine(); } Console.WriteLine(dp[N, 4] % mod); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; long mod = 1000000007; void calc() { cin = new Scanner(); // string S = new string('?', 99999);//cin.next(); string S = cin.next(); int N = S.Length; long[,] dp = new long[N + 1, 5]; // 0 -> 0start 1-> 0totyu 2->1start 3->1totyu dp[0, 0] = 1; if (S.Length == 1) { if (S == "0") Console.WriteLine(0); else Console.WriteLine(1); return; } for (int i = 0; i < S.Length; i++) { if (S[i] == '?') { // 4 dp[i + 1, 4] += dp[i, 4] * 2; dp[i + 1, 4] %= mod; } else { dp[i + 1, 4] += dp[i, 4]; dp[i + 1, 4] %= mod; } if (i % 2 == 0) { // 0 int pattern1 = 1; if (S[i] == '?') pattern1 *= 2; int activePattern1 = pattern1; if (S[i] == '1' || S[i] == '?') { dp[i + 1, 2] += dp[i, 0]; dp[i + 1, 2] %= mod; activePattern1--; } dp[i + 1, 1] += dp[i, 0] * (activePattern1); dp[i + 1, 1] %= mod; // 3 if (i != S.Length - 1) { int pattern2 = pattern1; if (S[i + 1] == '?') { pattern2 *= 2; } int activePattern2 = pattern2; if ((S[i] == '1' || S[i] == '?') && (S[i + 1] == '1' || S[i + 1] == '?')) { dp[i + 2, 4] += dp[i, 3]; dp[i + 2, 4] %= mod; activePattern2--; } dp[i + 2, 3] += dp[i, 3] * activePattern2; dp[i + 2, 3] %= mod; } else { if (S[i] == '1' || S[i] == '?') { dp[i + 1, 4] += dp[i, 3]; dp[i + 1, 4] %= mod; } } } else { int pattern1 = 1; if (S[i] == '?') pattern1 *= 2; // 1 if (i != S.Length - 2) { int pattern2 = pattern1; if (S[i + 1] == '?') { pattern2 *= 2; } int activePattern2 = pattern2; if ((S[i] == '1' || S[i] == '?') && (S[i + 1] == '1' || S[i + 1] == '?')) { dp[i + 2, 2] += dp[i, 1]; dp[i + 2, 2] %= mod; activePattern2--; } dp[i + 2, 1] += dp[i, 1] * activePattern2; dp[i + 2, 1] %= mod; } else { if ((S[i] == '1' || S[i] == '?') && (S[i + 1] == '1' || S[i + 1] == '?')) { dp[i + 2, 4] += dp[i, 1]; dp[i + 2, 4] %= mod; } } // 2 int activePattern1 = pattern1; if (S[i] == '1' || S[i] == '?') { dp[i + 1, 4] += dp[i, 2]; dp[i + 1, 4] %= mod; activePattern1--; } dp[i + 1, 3] += dp[i, 2] * (activePattern1); dp[i + 1, 3] %= mod; } } for (int i = 0; i < N + 1; i++) { for (int j = 0; j < 5; j++) { // Console.Write(dp[i,j] + " "); } // Console.WriteLine(); } Console.WriteLine(dp[N, 4] % mod); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
1,319
4
using System; class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int c = int.Parse(Console.ReadLine()); int d = int.Parse(Console.ReadLine()); Console.WriteLine(Math.Max(a, b) + Math.Max(c, d)); } }
using System; class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int c = int.Parse(Console.ReadLine()); int d = int.Parse(Console.ReadLine()); Console.WriteLine(Math.Min(a, b) + Math.Min(c, d)); } }
[["-", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22]]
8
97
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var a = new int[4]; for (int i = 0; i < 4; i++) { a[i] = int.Parse(ReadLine()); } WriteLine(Math.Max(a[0], a[1]) + Math.Max(a[2], a[3])); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var a = new int[4]; for (int i = 0; i < 4; i++) { a[i] = int.Parse(ReadLine()); } WriteLine(Math.Min(a[0], a[1]) + Math.Min(a[2], a[3])); } }
[["-", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22]]
8
104
4
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var f = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var D = f[0]; var ret = f[1]; for (int i = 0; i < N; i++) { var tmp = int.Parse(Console.ReadLine()); int val = tmp; int choco = 1; while (val <= D) { choco++; val = (choco * tmp) + 1; } ret += choco; } Console.WriteLine(ret); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var f = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var D = f[0]; var ret = f[1]; for (int i = 0; i < N; i++) { var tmp = int.Parse(Console.ReadLine()); int val = tmp + 1; int choco = 1; while (val <= D) { choco++; val = (choco * tmp) + 1; } ret += choco; } Console.WriteLine(ret); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
191
2
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int n = sc.intarr[0]; int[] d_x = sc.intarr; int d = d_x[0]; int x = d_x[1]; int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = sc.intarr[0]; } int sum = x; for (int i = 0; i < n; i++) { sum += ((d - 1) / array[i]); } wr.wri(sum); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int n = sc.intarr[0]; int[] d_x = sc.intarr; int d = d_x[0]; int x = d_x[1]; int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = sc.intarr[0]; } int sum = x; for (int i = 0; i < n; i++) { sum += ((d - 1) / array[i]); sum++; } wr.wri(sum); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
[["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
340
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Math; namespace AtCoderProject { class Program { static void Main(string[] args) { var N = ReadLineInt(); var in2 = ReadLineIntArray(); int D = in2[0]; int X = in2[1]; var input = ReadInputInt(N); var sum = input.Sum(d => (D - 1) / d) + X; Console.WriteLine(sum); } #region READER static int ReadLineInt() => int.Parse(Console.ReadLine()); static int[] ReadLineIntArray() => Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); static IEnumerable<string> ReadInputEnumruble(int count = int.MaxValue) { for (int i = 0; i < count; i++) { yield return Console.ReadLine(); } } static int[] ReadInputInt(int count = int.MaxValue) { return ReadInputEnumruble(count).Select(s => int.Parse(s)).ToArray(); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Math; namespace AtCoderProject { class Program { static void Main(string[] args) { var N = ReadLineInt(); var in2 = ReadLineIntArray(); int D = in2[0]; int X = in2[1]; var input = ReadInputInt(N); var sum = input.Sum(d => 1 + (D - 1) / d) + X; Console.WriteLine(sum); } #region READER static int ReadLineInt() => int.Parse(Console.ReadLine()); static int[] ReadLineIntArray() => Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); static IEnumerable<string> ReadInputEnumruble(int count = int.MaxValue) { for (int i = 0; i < count; i++) { yield return Console.ReadLine(); } } static int[] ReadInputInt(int count = int.MaxValue) { return ReadInputEnumruble(count).Select(s => int.Parse(s)).ToArray(); } #endregion } }
[["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 72]]
8
253
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B___Bitter_Alchemy { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = input[0]; var X = input[1]; var list = new List<int>(); for (int i = 0; i < N - 1; i++) { list.Add(int.Parse(Console.ReadLine())); } var nokori = X - list.Sum(); var result = list.Count() + nokori / list.Min(); Console.Write(result); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B___Bitter_Alchemy { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = input[0]; var X = input[1]; var list = new List<int>(); for (int i = 0; i < N; i++) { list.Add(int.Parse(Console.ReadLine())); } var nokori = X - list.Sum(); var result = list.Count() + nokori / list.Min(); Console.Write(result); Console.ReadLine(); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
175
2
using System; class Program { static void Main(string[] args) { int[] input = GetInt(' '); int N = input[0]; int X = input[1]; int[] m = new int[N]; int sum = 0; int cnt = N; for (int i = 0; i < N; i++) { int inp = GetInt(); m[i] = inp; sum += inp; } Array.Sort(m); while (sum + m[0] < X) { sum += m[0]; N++; } Output(N); } #region Tools static string GetInput() { return Console.ReadLine(); } static string[] GetInput(char split) { return Console.ReadLine().Split(split); } static int GetInt() { return int.Parse(Console.ReadLine()); } static int[] GetInt(char split) { string[] strarray = GetInput(split); int[] res = new int[strarray.Length]; for (int i = 0; i < strarray.Length; i++) { res[i] = int.Parse(strarray[i]); } return res; } static void Output(string str) { Console.WriteLine(str); } static void Output(int str) { Console.WriteLine(str + ""); } #endregion }
using System; class Program { static void Main(string[] args) { int[] input = GetInt(' '); int N = input[0]; int X = input[1]; int[] m = new int[N]; int sum = 0; int cnt = N; for (int i = 0; i < N; i++) { int inp = GetInt(); m[i] = inp; sum += inp; } Array.Sort(m); while (sum + m[0] <= X) { sum += m[0]; N++; } Output(N); } #region Tools static string GetInput() { return Console.ReadLine(); } static string[] GetInput(char split) { return Console.ReadLine().Split(split); } static int GetInt() { return int.Parse(Console.ReadLine()); } static int[] GetInt(char split) { string[] strarray = GetInput(split); int[] res = new int[strarray.Length]; for (int i = 0; i < strarray.Length; i++) { res[i] = int.Parse(strarray[i]); } return res; } static void Output(string str) { Console.WriteLine(str); } static void Output(int str) { Console.WriteLine(str + ""); } #endregion }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
8
302
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Linq; using System.Collections.Generic; namespace VirtualAtCorder { class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(' '); int defSweetsC = int.Parse(a[0]); int weight = int.Parse(a[1]); List<int> material = new List<int>(); int minSweets = 0; int sweetsC = 0; for (int i = 0; i < defSweetsC; i++) { int buf = int.Parse(Console.ReadLine()); if (!IsWeight(buf)) { i--; continue; } material.Add(buf); } minSweets = material.Min(); foreach (var i in material) { weight -= i; if (!IsWeight(weight)) break; sweetsC++; } while (weight >= minSweets) { sweetsC++; weight -= minSweets; } Console.WriteLine(sweetsC); Console.ReadKey(); } static bool Donats(int n) { return 2 <= n && n <= 100; } static bool IsWeight(int m) { return 1 <= m && m <= 1000; } static bool IsSweetWeight(int[] material, int x) { int sum = material.Sum(); return sum <= x && x <= Math.Pow(10, 5); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Linq; using System.Collections.Generic; namespace VirtualAtCorder { class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(' '); int defSweetsC = int.Parse(a[0]); int weight = int.Parse(a[1]); List<int> material = new List<int>(); int minSweets = 0; int sweetsC = 0; for (int i = 0; i < defSweetsC; i++) { int buf = int.Parse(Console.ReadLine()); if (!IsWeight(buf)) { i--; continue; } material.Add(buf); } minSweets = material.Min(); foreach (var i in material) { weight -= i; if (0 > weight) break; sweetsC++; } while (weight >= minSweets) { sweetsC++; weight -= minSweets; } Console.WriteLine(sweetsC); Console.ReadKey(); } static bool Donats(int n) { return 2 <= n && n <= 100; } static bool IsWeight(int m) { return 1 <= m && m <= 1000; } static bool IsSweetWeight(int[] material, int x) { int sum = material.Sum(); return sum <= x && x <= Math.Pow(10, 5); } } }
[["-", 0, 210, 8, 196, 0, 57, 15, 241, 0, 111], ["-", 8, 196, 0, 57, 15, 241, 0, 213, 63, 22], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 203], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 25]]
8
320
6
using System; using System.Collections.Generic; namespace cswork { class Program { public Program() {} Scanner cin; void Omame() { cin = new Scanner(); int a = cin.nextInt(); int b = cin.nextInt(); int c = cin.nextInt(); int x = cin.nextInt(); int y = cin.nextInt(); int ans = int.MaxValue; for (int i = 0; i < 100000; i++) { int value = c * i * 2 + a * Math.Max(x - i, 0) + b * Math.Max(y - i, 0); ans = Math.Min(ans, value); } Console.WriteLine(ans); } static void Main(string[] args) { new Program().Omame(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } }
using System; using System.Collections.Generic; namespace cswork { class Program { public Program() {} Scanner cin; void Omame() { cin = new Scanner(); int a = cin.nextInt(); int b = cin.nextInt(); int c = cin.nextInt(); int x = cin.nextInt(); int y = cin.nextInt(); int ans = int.MaxValue; for (int i = 0; i <= 100000; i++) { int value = c * i * 2 + a * Math.Max(x - i, 0) + b * Math.Max(y - i, 0); ans = Math.Min(ans, value); } Console.WriteLine(ans); } static void Main(string[] args) { new Program().Omame(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
345
2
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var a = int.Parse(spl[0]); var b = int.Parse(spl[1]); var c = int.Parse(spl[2]); var x = int.Parse(spl[3]); var y = int.Parse(spl[4]); long min = long.MaxValue; for (int i = 0; i < Math.Max(x, y); i += 2) { long yen = c * i; int tmp = (x - i / 2); yen += a * (tmp > 0 ? tmp : 0); tmp = (y - i / 2); yen += b * (tmp > 0 ? tmp : 0); min = Math.Min(min, yen); } return min; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var a = int.Parse(spl[0]); var b = int.Parse(spl[1]); var c = int.Parse(spl[2]); var x = int.Parse(spl[3]); var y = int.Parse(spl[4]); long min = long.MaxValue; for (int i = 0; i <= Math.Max(x, y) * 2; i += 2) { long yen = c * i; int tmp = (x - i / 2); yen += a * (tmp > 0 ? tmp : 0); tmp = (y - i / 2); yen += b * (tmp > 0 ? tmp : 0); min = Math.Min(min, yen); } return min; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
306
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int a = sc.NextInt(); int b = sc.NextInt(); int c = sc.NextInt(); int x = sc.NextInt(); int y = sc.NextInt(); int answer = int.MaxValue; for (int i = 0; i <= 10000; i += 2) { int tmpA = i / 2; int tmpB = i / 2; int countA = Math.Max(0, x - tmpA); int countB = Math.Max(0, y - tmpB); int price = countA * a + countB * b + i * c; answer = Math.Min(answer, price); } Console.WriteLine(answer); } private static int GetDivisorCount(int n) { int count = 0; for (int i = 1; i <= n; i++) { if (n % i == 0) { count++; } } return count; } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int a = sc.NextInt(); int b = sc.NextInt(); int c = sc.NextInt(); int x = sc.NextInt(); int y = sc.NextInt(); long answer = long.MaxValue; for (int i = 0; i <= 200000; i += 2) { int tmpA = i / 2; int tmpB = i / 2; int countA = Math.Max(0, x - tmpA); int countB = Math.Max(0, y - tmpB); long price = countA * a + countB * b + i * c; answer = Math.Min(answer, price); } Console.WriteLine(answer); } private static int GetDivisorCount(int n) { int count = 0; for (int i = 1; i <= n; i++) { if (n % i == 0) { count++; } } return count; } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
8
525
8
using System; using System.Collections.Generic; namespace MyProgram { class AtCoder { static void Main() { int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int A = input[0]; int B = input[1]; int C = input[2]; int X = input[3]; int Y = input[4]; int min_price = A * X + B * Y; for (var i = 0; i <= Math.Max(A, B); i++) { int price = i * 2 * C + Math.Max(X - i, 0) * A + Math.Max(Y - i, 0) * B; min_price = Math.Min(min_price, price); } Console.WriteLine(min_price); } } }
using System; using System.Collections.Generic; namespace MyProgram { class AtCoder { static void Main() { int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int A = input[0]; int B = input[1]; int C = input[2]; int X = input[3]; int Y = input[4]; int min_price = A * X + B * Y; for (var i = 0; i <= Math.Max(X, Y); i++) { int price = i * 2 * C + Math.Max(X - i, 0) * A + Math.Max(Y - i, 0) * B; min_price = Math.Min(min_price, price); } Console.WriteLine(min_price); } } }
[["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22]]
8
179
4
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var r = Console.ReadLine().Split().Select(int.Parse).ToArray(); var A = r[0]; var B = r[1]; var C = r[2]; var X = r[3]; var Y = r[4]; int p1 = 0; int p2 = 0; int p3 = 0; p1 = Math.Max(A, B) * 2 * C; p2 = A * X + B * Y; var tmp = X < Y ? B : A; p3 = 2 * C * Math.Min(X, Y) + Math.Abs(X - Y) * tmp; var ret = Math.Min(Math.Min(p1, p2), p3); Console.WriteLine(ret); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var r = Console.ReadLine().Split().Select(int.Parse).ToArray(); var A = r[0]; var B = r[1]; var C = r[2]; var X = r[3]; var Y = r[4]; int p1 = 0; int p2 = 0; int p3 = 0; p1 = Math.Max(X, Y) * 2 * C; p2 = A * X + B * Y; var tmp = X < Y ? B : A; p3 = 2 * C * Math.Min(X, Y) + Math.Abs(X - Y) * tmp; var ret = Math.Min(Math.Min(p1, p2), p3); Console.WriteLine(ret); } } }
[["-", 31, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 31, 16, 31, 213, 3, 4, 0, 28, 0, 22]]
8
215
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { //ここから var vs = IO.ReadLineToLongList(); var A = vs[0]; var B = vs[1]; var C = vs[2]; var X = vs[3]; var Y = vs[4]; long min = long.MaxValue; for (var i = 0; i < 100000; i++) { long sum = 0; sum += 2 * C * i; sum += A * Math.Max(0, X - i); sum += B * Math.Max(0, Y - i); min = Math.Min(min, sum); } //ここまで Console.WriteLine(min); Console.ReadKey(); } } static class Func { static public long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { //ここから var vs = IO.ReadLineToLongList(); var A = vs[0]; var B = vs[1]; var C = vs[2]; var X = vs[3]; var Y = vs[4]; long min = long.MaxValue; for (var i = 0; i <= 100000; i++) { long sum = 0; sum += 2 * C * i; sum += A * Math.Max(0, X - i); sum += B * Math.Max(0, Y - i); min = Math.Min(min, sum); } //ここまで Console.WriteLine(min); Console.ReadKey(); } } static class Func { static public long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
668
2