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.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var NY = cin.ReadIntArray(2); var isOk = false; var sen = 0; var gosen = 0; var man = 0; for (int i = 0; i < NY[0]; i++) { for (int k = 0; k < NY[0] - i; k++) { var money = 10000 * i + 5000 * k + 1000 * (NY[0] - (i + k)); if (money == NY[1]) { sen = NY[0] - (i + k); gosen = k; man = i; isOk = true; break; } } if (isOk) break; } if (isOk) { Console.WriteLine($"{man} {gosen} {sen}"); } else { Console.WriteLine($"{-1} {-1} {-1}"); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var NY = cin.ReadIntArray(2); var isOk = false; var sen = 0; var gosen = 0; var man = 0; for (int i = 0; i <= NY[0]; i++) { for (int k = 0; k <= NY[0] - i; k++) { var money = 10000 * i + 5000 * k + 1000 * (NY[0] - (i + k)); if (money == NY[1]) { sen = NY[0] - (i + k); gosen = k; man = i; isOk = true; break; } } if (isOk) break; } if (isOk) { Console.WriteLine($"{man} {gosen} {sen}"); } else { Console.WriteLine($"{-1} {-1} {-1}"); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
614
4
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { int N = cin.ReadInt; int Y = cin.ReadInt; int co_10000 = -1; int co_5000 = -1; int co_1000 = -1; for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { int money = i * 10000 + j * 5000 + (N - i - j) * 1000; if (money == Y) { co_10000 = i; co_5000 = j; co_1000 = N - i - j; j = N; i = N; } } } WriteLine("{0} {1} {2}", co_10000, co_5000, co_1000); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { int N = cin.ReadInt; int Y = cin.ReadInt; int co_10000 = -1; int co_5000 = -1; int co_1000 = -1; for (int i = 0; i <= N; i++) { for (int j = 0; j <= N - i; j++) { int money = i * 10000 + j * 5000 + (N - i - j) * 1000; if (money == Y) { co_10000 = i; co_5000 = j; co_1000 = N - i - j; j = N; i = N; } } } WriteLine("{0} {1} {2}", co_10000, co_5000, co_1000); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22]]
8
554
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; var y = cin.ReadInt; for (int i = 0; i <= n; i++) { for (int j = 0; j < n - i; j++) { if (n - (i + j) >= 0) { var k = n - (i + j); if ((10000 * i + 5000 * j + 1000 * k) == y) { WriteLine($"{i} {j} {k}"); return; } } continue; } } WriteLine("-1 -1 -1"); } } public static class Extensions {} public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReaddoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; var y = cin.ReadInt; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n - i; j++) { if (n - (i + j) >= 0) { var k = n - (i + j); if ((10000 * i + 5000 * j + 1000 * k) == y) { WriteLine($"{i} {j} {k}"); return; } } } } WriteLine("-1 -1 -1"); } } public static class Extensions {} public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReaddoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 8, 196, 0, 116, 0, 117], ["-", 8, 196, 0, 7, 8, 196, 0, 116, 0, 35]]
8
595
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC085C { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int Yen = int.Parse(str[1]); int x = 0; int y = 0; int z = 0; Boolean flag = false; for (int xi = 0; xi <= n; xi++) { for (int yi = 0; yi <= n - xi; yi++) { if (Yen - (10000 * xi + 5000 * yi + 1000 * (n - xi - yi)) == 0) { flag = true; x = xi; y = yi; z = n - x - y; break; } } } if (!flag) { x = y = z = -1; } Console.WriteLine("{0},{1},{2}", x, y, z); Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC085C { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int Yen = int.Parse(str[1]); int x = 0; int y = 0; int z = 0; Boolean flag = false; for (int xi = 0; xi <= n; xi++) { for (int yi = 0; yi <= n - xi; yi++) { if (Yen - (10000 * xi + 5000 * yi + 1000 * (n - xi - yi)) == 0) { flag = true; x = xi; y = yi; z = n - x - y; break; } } } if (!flag) { x = y = z = -1; } Console.WriteLine("{0} {1} {2}", x, y, z); Console.Read(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
231
2
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var n = cin.nextLong(); var y = cin.nextLong(); for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { var k = n - i - j; if (i * 10000 + j * 5000 + k * 1000 == y) { Console.WriteLine(i + " " + j + " " + k); return; } } } Console.WriteLine("-1 -1 -1"); } } static class C { public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long UpperBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] < key) l = mid + 1; else r = mid; } return l; } } static class Subsequence { /// <summary> /// 最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.LowerBound(dp, a[i])] = a[i]; } return C.LowerBound(dp, long.MaxValue - 1); } /// <summary> /// 重複を許さない最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long UniqueLIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.UpperBound(dp, a[i])] = a[i]; } return C.UpperBound(dp, long.MaxValue - 1); } } 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; } } #region ModInt public class ModInt { public static long Mod; public long num; public ModInt(long n, int mod = (int)1e9 + 7) { num = n; Mod = mod; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var n = cin.nextLong(); var y = cin.nextLong(); for (int i = 0; i <= n; i++) { for (int j = 0; i + j <= n; j++) { var k = n - i - j; if ((i * 10000 + j * 5000 + k * 1000) == y) { Console.WriteLine(i + " " + j + " " + k); return; } } } Console.WriteLine("-1 -1 -1"); } } static class C { public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long UpperBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] < key) l = mid + 1; else r = mid; } return l; } } static class Subsequence { /// <summary> /// 最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.LowerBound(dp, a[i])] = a[i]; } return C.LowerBound(dp, long.MaxValue - 1); } /// <summary> /// 重複を許さない最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long UniqueLIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.UpperBound(dp, a[i])] = a[i]; } return C.UpperBound(dp, long.MaxValue - 1); } } 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; } } #region ModInt public class ModInt { public static long Mod; public long num; public ModInt(long n, int mod = (int)1e9 + 7) { num = n; Mod = mod; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion }
[["+", 8, 196, 0, 7, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25]]
8
1,177
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Diagnostics; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; static int N, Y; public static void Input() { var cin = new Solve(); var input = cin.SplitReader(); N = input[0]; Y = input[1]; } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); for (var i = 0; i <= N; i++) { for (var j = 0; j <= N - i; j++) { int res = Y - 10000 * i - 5000 * j; if (res >= 0 && res % 1000 == 0 && res / 1000 <= N - i - j) { Console.WriteLine($"{i} {j} {N - i - j}"); return; } } } Console.WriteLine("-1 -1 -1"); // Console.Out.Flush(); } public int[] SplitReader() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReaderL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Diagnostics; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; static int N, Y; public static void Input() { var cin = new Solve(); var input = cin.SplitReader(); N = input[0]; Y = input[1]; } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); for (var i = 0; i <= N; i++) { for (var j = 0; j <= N - i; j++) { int res = Y - 10000 * i - 5000 * j; if (res >= 0 && res % 1000 == 0 && res / 1000 == N - i - j) { Console.WriteLine($"{i} {j} {N - i - j}"); return; } } } Console.WriteLine("-1 -1 -1"); // Console.Out.Flush(); } public int[] SplitReader() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReaderL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60]]
8
303
2
using System; using System.Collections.Generic; class MainClass { public static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int Y = int.Parse(s[1]); List<int> list = new List<int>(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i + j > N) break; int k = N - i - j; if (i * 10000 + j * 5000 + k * 1000 == Y) { Console.WriteLine("{0} {1} {2}", i, j, k); return; } } } Console.WriteLine("-1 -1 -1"); } }
using System; using System.Collections.Generic; class MainClass { public static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int Y = int.Parse(s[1]); List<int> list = new List<int>(); for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { if (i + j > N) break; int k = N - i - j; if (i * 10000 + j * 5000 + k * 1000 == Y) { Console.WriteLine("{0} {1} {2}", i, j, k); return; } } } Console.WriteLine("-1 -1 -1"); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
179
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; using static System.Math; namespace ABC_prac { class Program { static void Main(string[] args) { var cin = ReadInts(); int n = cin[0]; int y = cin[1]; int ans = 0; for (int a = 0; a <= n; a++) { for (int b = 0; b <= n; b++) { int c = n - a - b; if (10000 * a + 5000 * b + 1000 * c == y) { WriteLine("{0} {1} {2}", a, b, c); Read(); return; } } } WriteLine("-1 -1 -1"); // WriteLine("{0}", ans); Read(); } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } 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 System.Threading.Tasks; using static System.Console; using static System.Math; namespace ABC_prac { class Program { static void Main(string[] args) { var cin = ReadInts(); int n = cin[0]; int y = cin[1]; int ans = 0; for (int a = 0; a <= n; a++) { for (int b = 0; b <= n; b++) { int c = n - a - b; if (10000 * a + 5000 * b + 1000 * c == y && c >= 0) { WriteLine("{0} {1} {2}", a, b, c); Read(); return; } } } WriteLine("-1 -1 -1"); // WriteLine("{0}", ans); Read(); } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } 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, 7, 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, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
358
4
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { // int n = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); // Console.WriteLine(Console.ReadLine().Replace("2017", "2018")); for (int i = 0; i < a[0]; i++) { for (int j = 0; j < a[0] - i; j++) { if (a[1] == i * 1000 + j * 5000 + (a[0] - i - j) * 10000) { Console.WriteLine($"{(a[0] - i - j)} {j} {i}"); return; } } } Console.WriteLine("-1 -1 -1"); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { // int n = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); // Console.WriteLine(Console.ReadLine().Replace("2017", "2018")); for (int i = 0; i <= a[0]; i++) { for (int j = 0; j <= a[0] - i; j++) { if (a[1] == i * 1000 + j * 5000 + (a[0] - i - j) * 10000) { Console.WriteLine($"{(a[0] - i - j)} {j} {i}"); return; } } } Console.WriteLine("-1 -1 -1"); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
163
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #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 ny = ReadLib.ReadAsIntArray(); Console.WriteLine(Calculation.Calculate(ny[0], ny[1])); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { internal static string Calculate(int n, int y) { for (int n1000 = 0; n1000 <= n; n1000++) { for (int n5000 = 0; n5000 <= n - n1000; n5000++) { var n10000 = n - n1000 - n5000; if (n1000 * 1000 + n5000 * 5000 + n10000 * 10000 == y) { return $"{n1000} {n5000} {n10000}"; } } } return "-1 -1 -1"; } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } 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 WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } 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); } #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 long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return 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); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } 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>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <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, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, 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; } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>拡張メソッドs</summary> static class Extention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #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 ny = ReadLib.ReadAsIntArray(); Console.WriteLine(Calculation.Calculate(ny[0], ny[1])); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { internal static string Calculate(int n, int y) { for (int n1000 = 0; n1000 <= n; n1000++) { for (int n5000 = 0; n5000 <= n - n1000; n5000++) { var n10000 = n - n1000 - n5000; if (n1000 * 1000 + n5000 * 5000 + n10000 * 10000 == y) { return $"{n10000} {n5000} {n1000}"; } } } return "-1 -1 -1"; } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } 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 WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } 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); } #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 long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return 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); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } 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>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <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, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, 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; } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>拡張メソッドs</summary> static class Extention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } }
[["-", 64, 196, 0, 37, 0, 283, 0, 284, 0, 22], ["+", 64, 196, 0, 37, 0, 283, 0, 284, 0, 22]]
8
3,015
4
using System; using System.Collections; using System.Linq; public class Test { public static void Main() { string[] str = Console.ReadLine().Split(' '); int maisu = int.Parse(str[0]); int mokuhyou = int.Parse(str[1]); bool ok = false; for (int x10000 = 1; x10000 <= maisu; x10000++) { for (int x5000 = 1; x5000 <= maisu - x10000; x5000++) { if (10000 * x10000 + 5000 * x5000 + 1000 * (maisu - x10000 - x5000) == mokuhyou) { if (ok == false) { Console.WriteLine(x10000 + " " + x5000 + " " + (maisu - x10000 - x5000)); } ok = true; } } } if (ok == false) { Console.WriteLine("-1 -1 -1"); } } }
using System; using System.Collections; using System.Linq; public class Test { public static void Main() { string[] str = Console.ReadLine().Split(' '); int maisu = int.Parse(str[0]); int mokuhyou = int.Parse(str[1]); bool ok = false; for (int x10000 = 0; x10000 <= maisu; x10000++) { for (int x5000 = 0; x5000 <= maisu - x10000; x5000++) { if (10000 * x10000 + 5000 * x5000 + 1000 * (maisu - x10000 - x5000) == mokuhyou) { if (ok == false) { Console.WriteLine(x10000 + " " + x5000 + " " + (maisu - x10000 - x5000)); } ok = true; } } } if (ok == false) { Console.WriteLine("-1 -1 -1"); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
187
4
using System; using System.Linq; using System.Collections.Generic; public class Test { public static void Main() { string[] line = Console.ReadLine().Split(' '); int n = int.Parse(line[0]); int y = int.Parse(line[1]); int ans10000 = -1; int ans5000 = -1; int ans1000 = -1; for (int a = 0; a <= n; a++) { for (int b = 0; b <= n; b++) { int c = n - a - b; if (a * 10000 + b * 5000 + c * 1000 == y) { ans10000 = a; ans5000 = b; ans1000 = c; break; } } } Console.WriteLine(ans10000 + " " + ans5000 + " " + ans1000); } }
using System; using System.Linq; using System.Collections.Generic; public class Test { public static void Main() { string[] line = Console.ReadLine().Split(' '); int n = int.Parse(line[0]); int y = int.Parse(line[1]); int ans10000 = -1; int ans5000 = -1; int ans1000 = -1; for (int a = 0; a <= n; a++) { for (int b = 0; b + a <= n; b++) { int c = n - a - b; if (a * 10000 + b * 5000 + c * 1000 == y) { ans10000 = a; ans5000 = b; ans1000 = c; break; } } } Console.WriteLine(ans10000 + " " + ans5000 + " " + ans1000); } }
[["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 22]]
8
182
2
using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { var arr = Console.ReadLine().Split(' '); var N = int.Parse(arr[0]); int Y = int.Parse(arr[1]); for (int x = 0; x <= N; x++) for (int y = 0; y <= N; y++) { var z = N - x - y; var sum = (10000 * x) + (5000 * y) + (1000 * z); // if (sum < Y) break; if (sum == Y) { Console.WriteLine($"{x} {y} {z}"); return; } } Console.WriteLine("-1 -1 -1"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { var arr = Console.ReadLine().Split(' '); var N = int.Parse(arr[0]); int Y = int.Parse(arr[1]); for (int x = 0; x <= N; x++) for (int y = 0; y <= N - x; y++) { var z = N - x - y; var sum = (10000 * x) + (5000 * y) + (1000 * z); if (sum == Y) { Console.WriteLine($"{x} {y} {z}"); return; } } Console.WriteLine("-1 -1 -1"); } } }
[["+", 0, 7, 8, 7, 15, 16, 12, 16, 17, 33], ["+", 0, 7, 8, 7, 15, 16, 12, 16, 12, 22]]
8
175
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace Otoshidama { class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { var ny = GetArrayIntInput(); for (int i = 0; i < ny[0]; i++) // 10000 { for (int j = 0; j + i < ny[0]; j++) // 5000 { int thousandNum = ny[0] - i - j; if (ny[1] == i * 10000 + j * 5000 + thousandNum * 1000) { CWrite($"{i} {j} {thousandNum}"); return; } } } CWrite("-1 -1 -1"); } } static string[] GetArrayCharInput() => Console.ReadLine().Split(); static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray(); static int GetIntInput() => Console.ReadLine().ToInt(); static void CWrite(string str) => Console.WriteLine(str); } class SetConsole : IDisposable { readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); public SetConsole() { sw.AutoFlush = false; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } } static class ExtentionsLibrary { public static int[] StringToIntArray(this string str) => str.Split().Select(int.Parse).ToArray(); public static int ToInt(this string str) => int.Parse(str); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace Otoshidama { class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { var ny = GetArrayIntInput(); for (int i = 0; i <= ny[0]; i++) // 10000 { for (int j = 0; j + i <= ny[0]; j++) // 5000 { int thousandNum = ny[0] - i - j; if (ny[1] == i * 10000 + j * 5000 + thousandNum * 1000) { CWrite($"{i} {j} {thousandNum}"); return; } } } CWrite("-1 -1 -1"); } } static string[] GetArrayCharInput() => Console.ReadLine().Split(); static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray(); static int GetIntInput() => Console.ReadLine().ToInt(); static void CWrite(string str) => Console.WriteLine(str); } class SetConsole : IDisposable { readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); public SetConsole() { sw.AutoFlush = false; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } } static class ExtentionsLibrary { public static int[] StringToIntArray(this string str) => str.Split().Select(int.Parse).ToArray(); public static int ToInt(this string str) => int.Parse(str); } }
[["-", 0, 311, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 311, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
350
4
using System; using System.Collections.Generic; using System.Linq; namespace Project { class Program { static void Main(string[] args) { var cr = new CR(); var N = cr.i; var Y = cr.i; for (var z = 0; z < N; z++) { for (var y = 0; y < N - z; y++) { var x_yen = Y - (5000 * y) - (1000 * z); if (x_yen % 10000 != 0) continue; var x = x_yen / 10000; if (x + y + z == N) { Console.WriteLine(x + " " + y + " " + z); return; } } } Console.WriteLine("-1 -1 -1"); } private class CR { System.IO.TextReader _r; Queue<string> _d; public CR() { _r = Console.In; _d = new Queue<string>(); } string Read() { while (_d.Count == 0) foreach (var v in _r.ReadLine().Split(' ')) if (v != "") _d.Enqueue(v); return _d.Dequeue(); } public int i { get { return int.Parse(Read()); } } public string s { get { return Read(); } } } } }
using System; using System.Collections.Generic; using System.Linq; namespace Project { class Program { static void Main(string[] args) { var cr = new CR(); var N = cr.i; var Y = cr.i; for (var z = 0; z <= N; z++) { for (var y = 0; y <= N - z; y++) { var x_yen = Y - (5000 * y) - (1000 * z); if (x_yen % 10000 != 0) continue; var x = x_yen / 10000; if (x + y + z == N) { Console.WriteLine(x + " " + y + " " + z); return; } } } Console.WriteLine("-1 -1 -1"); } private class CR { System.IO.TextReader _r; Queue<string> _d; public CR() { _r = Console.In; _d = new Queue<string>(); } string Read() { while (_d.Count == 0) foreach (var v in _r.ReadLine().Split(' ')) if (v != "") _d.Enqueue(v); return _d.Dequeue(); } public int i { get { return int.Parse(Read()); } } public string s { get { return Read(); } } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
290
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TestApp2 { class Program { static void Main(string[] args) { var str = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var n = str[0]; var y = str[1]; var isOk = false; int sen = -1; int ichiman = -1; int gosen = -1; for (int i = 0; i < n; i++) { var unti = 10000 * i; for (int j = 0; j < n - i; j++) { unti += 5000 * j; var xx = n - j - i; unti += 1000 * xx; if (unti == y) { isOk = true; ichiman = i; gosen = j; sen = xx; break; } else { unti -= (5000 * j + 1000 * xx); } } } if (isOk) Console.WriteLine(ichiman + " " + gosen + " " + sen); else Console.WriteLine(-1 + " " + -1 + " " + -1); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TestApp2 { class Program { static void Main(string[] args) { var str = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var n = str[0]; var y = str[1]; var isOk = false; int sen = -1; int ichiman = -1; int gosen = -1; for (int i = 0; i <= n; i++) { var unti = 10000 * i; for (int j = 0; j <= n - i; j++) { unti += 5000 * j; var xx = n - j - i; unti += 1000 * xx; if (unti == y) { isOk = true; ichiman = i; gosen = j; sen = xx; break; } else { unti -= (5000 * j + 1000 * xx); } } } if (isOk) Console.WriteLine(ichiman + " " + gosen + " " + sen); else Console.WriteLine(-1 + " " + -1 + " " + -1); Console.ReadLine(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
272
4
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { // int kazu = int.Parse(ReadLine()); string[] input = ReadLine().Split(' '); int maisu = int.Parse(input[0]); int kingaku = int.Parse(input[1]); int a = -1, b = -1, c = -1; for (int i = 0; i <= maisu; i++) { for (int j = 0; j <= maisu; j++) { int k = maisu - i - j; if (i * 10000 + j * 5000 + k * 1000 == kingaku) { a = i; b = j; c = k; } } } WriteLine("{0} {1} {2}", a, b, c); } }
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { // int kazu = int.Parse(ReadLine()); string[] input = ReadLine().Split(' '); int maisu = int.Parse(input[0]); int kingaku = int.Parse(input[1]); int a = -1, b = -1, c = -1; for (int i = 0; i <= maisu; i++) { for (int j = 0; j <= maisu; j++) { int k = maisu - i - j; if (i * 10000 + j * 5000 + k * 1000 == kingaku && k >= 0) { a = i; b = j; c = k; } } } WriteLine("{0} {1} {2}", a, b, c); } }
[["+", 0, 7, 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, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
171
4
using System; using System.Linq; namespace ABC085_C { class Program { static void Main(string[] args) { var NY = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NY[0]; var Y = NY[1]; var numi = -1; var numg = -1; var nums = -1; for (int i = 0; i < N; i++) { for (int g = 0; g < N; g++) { var tmps = N - i - g; if (Y == 10000 * i + 5000 * g + 1000 * tmps && tmps >= 0) { numi = i; numg = g; nums = tmps; break; } if (numi != -1) break; } } Console.WriteLine($"{numi} {numg} {nums}"); } } }
using System; using System.Linq; namespace ABC085_C { class Program { static void Main(string[] args) { var NY = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NY[0]; var Y = NY[1]; var numi = -1; var numg = -1; var nums = -1; for (int i = 0; i <= N; i++) { for (int g = 0; g <= N; g++) { var tmps = N - i - g; if (Y == 10000 * i + 5000 * g + 1000 * tmps && tmps >= 0) { numi = i; numg = g; nums = tmps; break; } if (numi != -1) break; } } Console.WriteLine($"{numi} {numg} {nums}"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
190
4
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.ReadLine(); } public void Solve(ConsoleInput cin) { int n = cin.ReadInt; int y = cin.ReadInt; int m = -1; int g = -1; int s = -1; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y) { m = i; g = j; s = n - i - j; } Console.WriteLine(string.Format("{0} {1} {2}", m, g, s)); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.ReadLine(); } public void Solve(ConsoleInput cin) { int n = cin.ReadInt; int y = cin.ReadInt; int m = -1; int g = -1; int s = -1; for (int i = 0; i <= n; i++) for (int j = 0; j <= (n - i); j++) if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y) { m = i; g = j; s = n - i - j; } Console.WriteLine(string.Format("{0} {1} {2}", m, g, s)); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; } } }
[["+", 0, 7, 8, 7, 15, 16, 12, 23, 0, 24], ["+", 8, 7, 15, 16, 12, 23, 0, 16, 17, 33], ["+", 8, 7, 15, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 7, 8, 7, 15, 16, 12, 23, 0, 25]]
8
550
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ARC85_C { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]); long y = long.Parse(s[1]); for (int i = 0; i < n; i++) { for (int j = 0; j < n - i; j++) { if (i * 10000 + j * 5000 + (n - j - i) * 1000 == y) { Console.WriteLine($"{i} {j} {n-j-i}"); return; } } } Console.WriteLine("-1 -1 -1"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ARC85_C { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]); long y = long.Parse(s[1]); for (int i = 0; i < n + 1; i++) { for (int j = 0; j < n - i + 1; j++) { if (i * 10000 + j * 5000 + (n - j - i) * 1000 == y) { Console.WriteLine($"{i} {j} {n-j-i}"); return; } } } Console.WriteLine("-1 -1 -1"); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
180
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace atcoder_b_085 { class _03 { static void Main() { int N; //お札の枚数 int Y; //合計金額 long[] bill = new long[] { 1000, 5000, 10000 }; //値取得 string[] str = Console.ReadLine().Split(' '); N = int.Parse(str[0]); Y = int.Parse(str[1]); for (long i = 0; i <= N; i++) { for (long j = 0; j <= N - i; j++) { long k = N - i - j; if (i + j + k == N && bill[0] * i + bill[1] * j + bill[2] * k == Y) { Console.WriteLine(i.ToString() + " " + j.ToString() + " " + k.ToString()); return; } } } Console.WriteLine("-1 -1 -1"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace atcoder_b_085 { class _03 { static void Main() { int N; //お札の枚数 int Y; //合計金額 long[] bill = new long[] { 10000, 5000, 1000 }; //値取得 string[] str = Console.ReadLine().Split(' '); N = int.Parse(str[0]); Y = int.Parse(str[1]); for (long i = 0; i <= N; i++) { for (long j = 0; j <= N - i; j++) { long k = N - i - j; if (i + j + k == N && bill[0] * i + bill[1] * j + bill[2] * k == Y) { Console.WriteLine(i.ToString() + " " + j.ToString() + " " + k.ToString()); return; } } } Console.WriteLine("-1 -1 -1"); } } }
[["-", 0, 200, 0, 212, 0, 227, 0, 229, 0, 203], ["+", 0, 200, 0, 212, 0, 227, 0, 229, 0, 203]]
8
230
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC85_3 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int Y = int.Parse(s[1]); bool Out = false; for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { int k = N - j - i; if (i * 10000 + j * 5000 + k * 1000 == Y) { Console.WriteLine(i + " " + j + " " + k); Out = true; break; } } if (Out) { break; } } if (!Out) { Console.WriteLine(-1 + " " + -1 + " " + -1); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC85_3 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int Y = int.Parse(s[1]); bool Out = false; for (int i = 0; i <= N; i++) { for (int j = 0; j <= N - i; j++) { int k = N - j - i; if (i * 10000 + j * 5000 + k * 1000 == Y) { Console.WriteLine(i + " " + j + " " + k); Out = true; break; } } if (Out) { break; } } if (!Out) { Console.WriteLine(-1 + " " + -1 + " " + -1); } } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22]]
8
216
2
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var ab = int.Parse(Console.ReadLine().Replace(" ", "")); var sqrt = Math.Sqrt(ab); Console.WriteLine(sqrt * sqrt == ab ? "Yes" : "No"); } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var ab = int.Parse(Console.ReadLine().Replace(" ", "")); var sqrt = Math.Sqrt(ab); Console.WriteLine((int)sqrt == sqrt ? "Yes" : "No"); } } }
[["-", 0, 28, 0, 41, 15, 16, 31, 16, 31, 22], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 41, 15, 16, 31, 74, 0, 24], ["+", 0, 28, 0, 41, 15, 16, 31, 74, 39, 199], ["+", 0, 28, 0, 41, 15, 16, 31, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22]]
8
75
7
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 Solve { public Solve() {} public static int Main() { new Solve().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int Y = cin.nextInt(); for (int x = 0; x < N; x++) { for (int y = 0; y < N - x; y++) { int z = N - (x + y); if (x * 10000 + y * 5000 + z * 1000 == Y) { Console.WriteLine(x + " " + y + " " + z); return; } } } Console.WriteLine("-1 -1 -1"); } } 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 Solve { public Solve() {} public static int Main() { new Solve().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int Y = cin.nextInt(); for (int x = 0; x <= N; x++) { for (int y = 0; y <= N - x; y++) { int z = N - (x + y); if (x * 10000 + y * 5000 + z * 1000 == Y) { Console.WriteLine(x + " " + y + " " + z); return; } } } Console.WriteLine("-1 -1 -1"); } } 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; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
547
4
using System; using System.Collections.Generic; using static System.Console; class Program { static void Main() { var a = NextString(); var b = NextString(); var x = double.Parse(a + b); var sqrt = Math.Pow(x, 0.5); WriteLine(Math.Pow(sqrt, 2) == x ? "Yes" : "No"); } static string NextString() { var result = new List<char>(); while (true) { int next = Read(); if (next < 0) break; var nextChar = (char)next; if (!char.IsWhiteSpace(nextChar)) result.Add(nextChar); else if (nextChar != '\r') break; } return string.Join("", result); } }
using System; using System.Collections.Generic; using static System.Console; class Program { static void Main() { var a = NextString(); var b = NextString(); var x = int.Parse(a + b); var sqrt = (int)Math.Pow(x, 0.5); WriteLine(Math.Pow(sqrt, 2) == x ? "Yes" : "No"); } static string NextString() { var result = new List<char>(); while (true) { int next = Read(); if (next < 0) break; var nextChar = (char)next; if (!char.IsWhiteSpace(nextChar)) result.Add(nextChar); else if (nextChar != '\r') break; } return string.Join("", result); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25]]
8
173
5
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace CompetitiveProgramming { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public long x; public long a; public long b; public long c; public Pair(long X, long Y, long Z, long D) { x = X; a = Y; b = Z; c = D; } public Pair(long a, long x) { this.a = a; this.x = x; } public Pair(long a, long b, long c) { this.a = a; this.b = b; this.c = c; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.a <= p2.a; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.a >= p2.a; } } } class Zettiti : IComparable { public long num; public Zettiti(long num) { this.num = num; } public int CompareTo(object obj) { Zettiti kore = (Zettiti)obj; long knum = Math.Abs(kore.num); long mynum = Math.Abs(num); return mynum.CompareTo(knum); } } class Program { static void Main(string[] args) { // Utils.BinarySearch.Search StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); int n = scan.Integer(); long h = scan.Long(); long[] b = new long[n]; long amax = 0; for (long i = 0; i < n; i++) { amax = Math.Max(amax, scan.Long()); b[i] = scan.Long(); } Array.Sort(b); Array.Reverse(b); long sum = 0; long kaisu = 0; for (kaisu = 0; kaisu < b.Length; kaisu++) { if (b[kaisu] >= amax) { sum += b[kaisu]; } else { break; } if (h <= sum) { Console.WriteLine(kaisu); return; } } if (h <= sum) { Console.WriteLine(kaisu); return; } kaisu += (h - sum) / amax; if ((h - sum) % amax != 0) kaisu++; Console.WriteLine(kaisu); } static bool isOK(long mid, long[] a, long[] f, long k) { long count = 0; for (long i = 0; i < a.Length; i++) { long togo = mid / f[i]; ; count += Math.Max(0, a[i] - togo); } return (count <= k); } static void Output<T>(List<T> list, string kugiri = "\n") { for (int i = 0; i < list.Count; i++) { Console.Write(list[i]); if (i != list.Count - 1) { Console.Write(kugiri); } } } static void Output<T>(T[] list, string kugiri = "\n") { for (int i = 0; i < list.Length; i++) { Console.Write(list[i]); if (i != list.Length - 1) { Console.Write(kugiri); } } } static void Output<T>(T[,] list, string kugiri1 = " ", string kugiri2 = "\n") { int len1 = list.GetLength(0); int len2 = list.GetLength(1); for (int i = 0; i < len1; i++) { for (int j = 0; j < len2; j++) { Console.Write(list[i, j]); if (j != len2 - 1) { Console.Write(kugiri1); } } if (i != len1 - 1) { Console.Write(kugiri2); } } } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } static int[] Manacher(string S) { int i = 0, j = 0; int[] R = new int[S.Length]; while (i < S.Length) { while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j]) ++j; R[i] = j; int k = 1; while (i - k >= 0 && k + R[i - k] < j) { R[i + k] = R[i - k]; ++k; } i += k; j -= k; } return R; } /* static Pair[] a; static int SaikiZentansaku(List<int>now,int count,int last,int n,int m) { List<int> next = new List<int>(); for (int i = 0; i < now.Count; i++) { next.Add(now[i]); } next.Add(last); var kore = next.ToArray(); int ans = 0; if(count==n) { for (int i = 0; i < a.Length; i++) { int A = a[i].a; int b = a[i].b; int c = a[i].c; int d = a[i].x; if (kore[b] - kore[A] == c) { ans += d; } } return ans; } for (int i = last; i <= m; i++) { ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m)); } return ans; }*/ } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private long len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); 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); return (char)b; } public char[] Char(long n) { char[] kore = new char[n]; for (long i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(long n, long m) { char[,] kore = new char[n, m]; for (long i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } 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 long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n, bool minus1 = false) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); if (minus1) kore[i]--; } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w, bool minus1 = false) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); if (minus1) kore[i, j]--; } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n, bool minus1 = false) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); if (minus1) kore[i]--; } return kore; } public int[,] Integer(long h, long w, bool minus1 = false) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); if (minus1) kore[i, j]--; } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { private static long mod = 1000000007; public long num; public Mlong(long num) { if (num < 0) { num += mod; } this.num = num % mod; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n = n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public bool Any() { return _root != null; } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public T max() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.RChild != null) { ima = ima.RChild; } return ima.Value; } public T min() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.LChild != null) { ima = ima.LChild; } return ima.Value; } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } public class PotentializedUnionFind { int _count; int[] par, sizes, rank; long[] weight; public PotentializedUnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; weight = new long[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else { int r = Root(par[X]); weight[X] += weight[par[X]]; return (par[X] = r); } } public bool Merge(int X, int Y, long W) { W += GetWeight(X); W -= GetWeight(Y); X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; weight[X] = -W; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; weight[Y] = W; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); public int Size(int X) => sizes[Root(X)]; public long GetWeight(int X) { Root(X); return weight[X]; } public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X); } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public class SortedMultiSet<T> : IEnumerable<T> { private SortedDictionary<T, int> _dict; public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); } public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); } public bool Contains(T item) { return _dict.ContainsKey(item); } public void Add(T item) { if (_dict.ContainsKey(item)) _dict[item]++; else _dict[item] = 1; } public void Add(IEnumerable<T> items) { foreach (var item in items) Add(item); } public void Remove(T item) { if (!_dict.ContainsKey(item)) throw new ArgumentException(); if (--_dict[item] == 0) _dict.Remove(item); } // Return the last value in the multiset public T Peek() { if (!_dict.Any()) throw new NullReferenceException(); return _dict.Last().Key; } // Return the last value in the multiset and remove it. public T Pop() { T item = Peek(); Remove(item); return item; } public IEnumerator<T> GetEnumerator() { foreach (var kvp in _dict) for (int i = 0; i < kvp.Value; i++) yield return kvp.Key; } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } class Treap<T> : IEnumerable<T> where T : IComparable { public int Length { get { return this.Root == null ? 0 : this.NodeCount(this.Root); } } public T this[int i] { get { if (this.Root.Count < i - 1) throw new IndexOutOfRangeException(); return this.Root.Get(i); } } public Node Root; private IComparer<T> Cmp = Comparer<T>.Default; public Treap(IComparer<T> cmp = null) { if (cmp != null) this.Cmp = cmp; } public Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (l.Priority > r.Priority) { l.R = this.Merge(l.R, r); return this.Update(l); } else { r.L = this.Merge(l, r.L); return this.Update(r); } } // 左にk個、右に残り(n-k)個に分割する public (Node, Node) Split(int k) { return this.Split(this.Root, k); } public (Node, Node) Split(Node t, int k) { if (t == null) return (null, null); if (k <= this.NodeCount(t.L)) { var s = this.Split(t.L, k); t.L = s.Item2; return (s.Item1, this.Update(t)); } else { var s = this.Split(t.R, k - this.NodeCount(t.L) - 1); t.R = s.Item1; return (this.Update(t), s.Item2); } } public int NodeCount(Node node) { return node == null ? 0 : node.Count; } public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); } public int LowerBouond(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) <= 0) return this.LowerBouond(node.L, value); else return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value); } public int UpperBound(T value) { return this.UpperBound(this.Root, value); } public int UpperBound(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) >= 0) return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value); else return this.UpperBound(node.L, value); } public int ValueCount(T value) { return this.UpperBound(value) - this.LowerBouond(value); } public void Insert(T value) { var sub = this.Split(this.Root, this.LowerBouond(value)); var newNode = new Node(value); var merged = this.Merge(sub.Item1, newNode); this.Root = this.Merge(merged, sub.Item2); } public void Erase(T value) { if (this.ValueCount(value) == 0) return; var sub = this.Split(this.Root, this.LowerBouond(value)); this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2); } public void InsertAt(Node node, int k) { var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public void InsertAt(T value, int k) { var node = new Node(value); var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public Node EraseAt(int k) { var sub = this.Split(this.Root, k); var sub2 = this.Split(sub.Item2, 1); var res = sub2.Item1; this.Root = this.Merge(sub.Item1, sub2.Item2); return res; } public Node Update(Node node) { node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1; return node; } public class Node { private static Random Rand = new Random(); public T Value; public Node L = null; public Node R = null; public int Count; public double Priority; public Node(T value, double priority) { this.Value = value; this.Priority = priority; this.Count = 1; } public Node(T value) : this(value, Rand.NextDouble()) {} public T Get(int i) { return this.GetNode(i).Value; } public Node GetNode(int i) { var lcount = 0; if (this.L != null) lcount = this.L.Count; if (lcount == i) return this; else if (lcount < i) return this.R.GetNode(i - lcount - 1); else return this.L.GetNode(i); } } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) yield return this.Root.Get(i); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } public static class ObjectExtension { // ディープコピーの複製を作る拡張メソッド public static T DeepClone<T>(this T src) { using (var memoryStream = new System.IO.MemoryStream()) { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); // シリアライズ memoryStream.Seek(0, System.IO.SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); // デシリアライズ } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace CompetitiveProgramming { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public long x; public long a; public long b; public long c; public Pair(long X, long Y, long Z, long D) { x = X; a = Y; b = Z; c = D; } public Pair(long a, long x) { this.a = a; this.x = x; } public Pair(long a, long b, long c) { this.a = a; this.b = b; this.c = c; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.a <= p2.a; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.a >= p2.a; } } } class Zettiti : IComparable { public long num; public Zettiti(long num) { this.num = num; } public int CompareTo(object obj) { Zettiti kore = (Zettiti)obj; long knum = Math.Abs(kore.num); long mynum = Math.Abs(num); return mynum.CompareTo(knum); } } class Program { static void Main(string[] args) { // Utils.BinarySearch.Search StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); int n = scan.Integer(); long h = scan.Long(); long[] b = new long[n]; long amax = 0; for (long i = 0; i < n; i++) { amax = Math.Max(amax, scan.Long()); b[i] = scan.Long(); } Array.Sort(b); Array.Reverse(b); long sum = 0; long kaisu = 0; for (kaisu = 0; kaisu < b.Length; kaisu++) { if (b[kaisu] >= amax) { sum += b[kaisu]; } else { break; } if (h <= sum) { Console.WriteLine(kaisu + 1); return; } } if (h <= sum) { Console.WriteLine(kaisu); return; } kaisu += (h - sum) / amax; if ((h - sum) % amax != 0) kaisu++; Console.WriteLine(kaisu); } static bool isOK(long mid, long[] a, long[] f, long k) { long count = 0; for (long i = 0; i < a.Length; i++) { long togo = mid / f[i]; ; count += Math.Max(0, a[i] - togo); } return (count <= k); } static void Output<T>(List<T> list, string kugiri = "\n") { for (int i = 0; i < list.Count; i++) { Console.Write(list[i]); if (i != list.Count - 1) { Console.Write(kugiri); } } } static void Output<T>(T[] list, string kugiri = "\n") { for (int i = 0; i < list.Length; i++) { Console.Write(list[i]); if (i != list.Length - 1) { Console.Write(kugiri); } } } static void Output<T>(T[,] list, string kugiri1 = " ", string kugiri2 = "\n") { int len1 = list.GetLength(0); int len2 = list.GetLength(1); for (int i = 0; i < len1; i++) { for (int j = 0; j < len2; j++) { Console.Write(list[i, j]); if (j != len2 - 1) { Console.Write(kugiri1); } } if (i != len1 - 1) { Console.Write(kugiri2); } } } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } static int[] Manacher(string S) { int i = 0, j = 0; int[] R = new int[S.Length]; while (i < S.Length) { while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j]) ++j; R[i] = j; int k = 1; while (i - k >= 0 && k + R[i - k] < j) { R[i + k] = R[i - k]; ++k; } i += k; j -= k; } return R; } /* static Pair[] a; static int SaikiZentansaku(List<int>now,int count,int last,int n,int m) { List<int> next = new List<int>(); for (int i = 0; i < now.Count; i++) { next.Add(now[i]); } next.Add(last); var kore = next.ToArray(); int ans = 0; if(count==n) { for (int i = 0; i < a.Length; i++) { int A = a[i].a; int b = a[i].b; int c = a[i].c; int d = a[i].x; if (kore[b] - kore[A] == c) { ans += d; } } return ans; } for (int i = last; i <= m; i++) { ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m)); } return ans; }*/ } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private long len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); 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); return (char)b; } public char[] Char(long n) { char[] kore = new char[n]; for (long i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(long n, long m) { char[,] kore = new char[n, m]; for (long i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } 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 long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n, bool minus1 = false) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); if (minus1) kore[i]--; } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w, bool minus1 = false) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); if (minus1) kore[i, j]--; } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n, bool minus1 = false) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); if (minus1) kore[i]--; } return kore; } public int[,] Integer(long h, long w, bool minus1 = false) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); if (minus1) kore[i, j]--; } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { private static long mod = 1000000007; public long num; public Mlong(long num) { if (num < 0) { num += mod; } this.num = num % mod; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n = n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public bool Any() { return _root != null; } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public T max() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.RChild != null) { ima = ima.RChild; } return ima.Value; } public T min() { SB_BinarySearchTree<T>.Node ima = _root; while (ima.LChild != null) { ima = ima.LChild; } return ima.Value; } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } public class PotentializedUnionFind { int _count; int[] par, sizes, rank; long[] weight; public PotentializedUnionFind(int N) { _count = N; par = new int[N]; sizes = new int[N]; rank = new int[N]; weight = new long[N]; for (int i = 0; i < N; ++i) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } int Root(int X) { if (par[X] == X) { return X; } else { int r = Root(par[X]); weight[X] += weight[par[X]]; return (par[X] = r); } } public bool Merge(int X, int Y, long W) { W += GetWeight(X); W -= GetWeight(Y); X = Root(X); Y = Root(Y); if (X == Y) return false; --_count; if (rank[X] < rank[Y]) { par[X] = Y; sizes[Y] += sizes[X]; weight[X] = -W; } else { par[Y] = X; sizes[X] += sizes[Y]; if (rank[X] == rank[Y]) ++rank[X]; weight[Y] = W; } return true; } public bool IsSame(int X, int Y) => Root(X) == Root(Y); public int Count => _count; public bool IsParent(int X) => X == Root(X); public int GetParent(int X) => Root(X); public int Size(int X) => sizes[Root(X)]; public long GetWeight(int X) { Root(X); return weight[X]; } public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X); } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public class SortedMultiSet<T> : IEnumerable<T> { private SortedDictionary<T, int> _dict; public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); } public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); } public bool Contains(T item) { return _dict.ContainsKey(item); } public void Add(T item) { if (_dict.ContainsKey(item)) _dict[item]++; else _dict[item] = 1; } public void Add(IEnumerable<T> items) { foreach (var item in items) Add(item); } public void Remove(T item) { if (!_dict.ContainsKey(item)) throw new ArgumentException(); if (--_dict[item] == 0) _dict.Remove(item); } // Return the last value in the multiset public T Peek() { if (!_dict.Any()) throw new NullReferenceException(); return _dict.Last().Key; } // Return the last value in the multiset and remove it. public T Pop() { T item = Peek(); Remove(item); return item; } public IEnumerator<T> GetEnumerator() { foreach (var kvp in _dict) for (int i = 0; i < kvp.Value; i++) yield return kvp.Key; } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } class Treap<T> : IEnumerable<T> where T : IComparable { public int Length { get { return this.Root == null ? 0 : this.NodeCount(this.Root); } } public T this[int i] { get { if (this.Root.Count < i - 1) throw new IndexOutOfRangeException(); return this.Root.Get(i); } } public Node Root; private IComparer<T> Cmp = Comparer<T>.Default; public Treap(IComparer<T> cmp = null) { if (cmp != null) this.Cmp = cmp; } public Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (l.Priority > r.Priority) { l.R = this.Merge(l.R, r); return this.Update(l); } else { r.L = this.Merge(l, r.L); return this.Update(r); } } // 左にk個、右に残り(n-k)個に分割する public (Node, Node) Split(int k) { return this.Split(this.Root, k); } public (Node, Node) Split(Node t, int k) { if (t == null) return (null, null); if (k <= this.NodeCount(t.L)) { var s = this.Split(t.L, k); t.L = s.Item2; return (s.Item1, this.Update(t)); } else { var s = this.Split(t.R, k - this.NodeCount(t.L) - 1); t.R = s.Item1; return (this.Update(t), s.Item2); } } public int NodeCount(Node node) { return node == null ? 0 : node.Count; } public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); } public int LowerBouond(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) <= 0) return this.LowerBouond(node.L, value); else return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value); } public int UpperBound(T value) { return this.UpperBound(this.Root, value); } public int UpperBound(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) >= 0) return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value); else return this.UpperBound(node.L, value); } public int ValueCount(T value) { return this.UpperBound(value) - this.LowerBouond(value); } public void Insert(T value) { var sub = this.Split(this.Root, this.LowerBouond(value)); var newNode = new Node(value); var merged = this.Merge(sub.Item1, newNode); this.Root = this.Merge(merged, sub.Item2); } public void Erase(T value) { if (this.ValueCount(value) == 0) return; var sub = this.Split(this.Root, this.LowerBouond(value)); this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2); } public void InsertAt(Node node, int k) { var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public void InsertAt(T value, int k) { var node = new Node(value); var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public Node EraseAt(int k) { var sub = this.Split(this.Root, k); var sub2 = this.Split(sub.Item2, 1); var res = sub2.Item1; this.Root = this.Merge(sub.Item1, sub2.Item2); return res; } public Node Update(Node node) { node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1; return node; } public class Node { private static Random Rand = new Random(); public T Value; public Node L = null; public Node R = null; public int Count; public double Priority; public Node(T value, double priority) { this.Value = value; this.Priority = priority; this.Count = 1; } public Node(T value) : this(value, Rand.NextDouble()) {} public T Get(int i) { return this.GetNode(i).Value; } public Node GetNode(int i) { var lcount = 0; if (this.L != null) lcount = this.L.Count; if (lcount == i) return this; else if (lcount < i) return this.R.GetNode(i - lcount - 1); else return this.L.GetNode(i); } } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) yield return this.Root.Get(i); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } public static class ObjectExtension { // ディープコピーの複製を作る拡張メソッド public static T DeepClone<T>(this T src) { using (var memoryStream = new System.IO.MemoryStream()) { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); // シリアライズ memoryStream.Seek(0, System.IO.SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); // デシリアライズ } } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
13,841
2
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int s = int.Parse(input[0] + input[1]); double d = Math.Sqrt(s); if (d % 1 == 0) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int s = int.Parse(input[0] + input[1]); double d = Math.Sqrt(s); if (d % 1 == 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
95
4
using System; using System.Collections.Generic; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); List<int> ts = new List<int>(); List<int> xs = new List<int>(); List<int> ys = new List<int>(); for (int i = 0; i < N; i++) { string[] ss = Console.ReadLine().Split(' '); ts.Add(int.Parse(ss[0])); xs.Add(int.Parse(ss[1])); ys.Add(int.Parse(ss[2])); } int t = 0, x = 0, y = 0; for (int i = 0; i < N; i++) { int td = ts[i] - t; int xd = xs[i] - x; int yd = ys[i] - y; int d = Math.Abs(xd) + Math.Abs(yd); if (td < d) { Console.WriteLine("NO"); // Console.ReadLine(); return; } if (td % 2 != d % 2) { Console.WriteLine("NO"); // Console.ReadLine(); return; } t = ts[i]; x = xs[i]; y = ys[i]; } Console.WriteLine("YES"); // Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); List<int> ts = new List<int>(); List<int> xs = new List<int>(); List<int> ys = new List<int>(); for (int i = 0; i < N; i++) { string[] ss = Console.ReadLine().Split(' '); ts.Add(int.Parse(ss[0])); xs.Add(int.Parse(ss[1])); ys.Add(int.Parse(ss[2])); } int t = 0, x = 0, y = 0; for (int i = 0; i < N; i++) { int td = ts[i] - t; int xd = xs[i] - x; int yd = ys[i] - y; int d = Math.Abs(xd) + Math.Abs(yd); if (td < d) { Console.WriteLine("No"); // Console.ReadLine(); return; } if (td % 2 != d % 2) { Console.WriteLine("No"); // Console.ReadLine(); return; } t = ts[i]; x = xs[i]; y = ys[i]; } Console.WriteLine("Yes"); // Console.ReadLine(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
320
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class29 { static void Main() { var NH = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NH[0], H = NH[1]; long[] a = new long[N], b = new long[N]; for (int i = 0; i < N; i++) { var read = Console.ReadLine().Split().Select(int.Parse).ToArray(); a[i] = read[0]; b[i] = read[1]; } Array.Sort(b); Array.Reverse(b); long am = a.Max(); long sum = 0; int count = 0; for (int i = 0; i < N && sum < H; i++) { if (b[i] > am) { sum += b[i]; count++; } } if (count < H) { count += (int)Math.Ceiling((decimal)(H - sum) / am); } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class29 { static void Main() { var NH = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NH[0], H = NH[1]; long[] a = new long[N], b = new long[N]; for (int i = 0; i < N; i++) { var read = Console.ReadLine().Split().Select(int.Parse).ToArray(); a[i] = read[0]; b[i] = read[1]; } Array.Sort(b); Array.Reverse(b); long am = a.Max(); long sum = 0; int count = 0; for (int i = 0; i < N && sum < H; i++) { if (b[i] > am) { sum += b[i]; count++; } } if (sum < H) { count += (int)Math.Ceiling((decimal)(H - sum) / am); } Console.WriteLine(count); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
8
270
2
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static long gcd(long x, long y) { if (y < x) gcd(y, x); while (y != 0) { var z = x % y; x = y; y = z; } return x; } public static long keta(long x) { var z = 1; while (x > 0) { x /= 10; z++; } return z; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); long t = 0, x = 0, y = 0; long bt = 0, bx = 0, by = 0; bool ans = true; for (int i = 0; i < n; i++) { var txy = Reads(); t = txy[0]; x = txy[1]; y = txy[2]; bool f = Math.Abs(x - bx) + Math.Abs(y - by) <= t - bt && Math.Abs(x - bx) + Math.Abs(y - by) % 2 == (t - bt) % 2; if (!f) ans = false; bt = t; bx = x; by = y; } WriteLine(ans ? "Yes" : "No"); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static long gcd(long x, long y) { if (y < x) gcd(y, x); while (y != 0) { var z = x % y; x = y; y = z; } return x; } public static long keta(long x) { var z = 1; while (x > 0) { x /= 10; z++; } return z; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); long t = 0, x = 0, y = 0; long bt = 0, bx = 0, by = 0; bool ans = true; for (int i = 0; i < n; i++) { var txy = Reads(); t = txy[0]; x = txy[1]; y = txy[2]; bool f = Math.Abs(x - bx) + Math.Abs(y - by) <= t - bt && (Math.Abs(x - bx) + Math.Abs(y - by)) % 2 == (t - bt) % 2; if (!f) ans = false; bt = t; bx = x; by = y; } WriteLine(ans ? "Yes" : "No"); Console.Out.Flush(); } } }
[["+", 0, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
384
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); long[] nh = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nh[0]; var h = nh[1]; long[] a = new long[n]; long[] b = new long[n]; for (int i = 0; i < n; i++) { long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a[i] = tmp[0]; b[i] = tmp[1]; } var ok = false; // a < b の場合全て投げる long amax = a.Max(); Array.Sort(b); Array.Reverse(b); long sum = 0; long k = 0; while (k < n) { if (b[k] < amax) { break; } sum += b[k]; k++; if (sum >= h) ok = true; } if (ok) { Console.WriteLine(k); return; } //残りはaで削る k += (long)Math.Ceiling((decimal)(h - sum) / (decimal)amax); Console.WriteLine(k); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); long[] nh = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nh[0]; var h = nh[1]; long[] a = new long[n]; long[] b = new long[n]; for (int i = 0; i < n; i++) { long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a[i] = tmp[0]; b[i] = tmp[1]; } var ok = false; // a < b の場合全て投げる long amax = a.Max(); Array.Sort(b); Array.Reverse(b); long sum = 0; long k = 0; while (k < n) { if (b[k] < amax) { break; } sum += b[k]; k++; if (sum >= h) { ok = true; break; } } if (ok) { Console.WriteLine(k); return; } //残りはaで削る k += (long)Math.Ceiling((decimal)(h - sum) / (decimal)amax); Console.WriteLine(k); } }
[["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
8
296
4
using System; using System.Collections.Generic; namespace cswork { class Program { public Program() {} Scanner cin; void Omame() { cin = new Scanner(); int n = cin.nextInt(); int x0 = 0; int y0 = 0; int t0 = 0; for (int i = 0; i < n; i++) { int t = cin.nextInt(); int x = cin.nextInt(); int y = cin.nextInt(); int l = Math.Abs(x - x0) + Math.Abs(y - y0); if (t - t0 >= l) { if ((t - t0 - l) % 2 == 0) { x0 = x; y0 = y; t0 = t; continue; } } Console.WriteLine("NO"); return; } Console.WriteLine("YES"); } 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 n = cin.nextInt(); int x0 = 0; int y0 = 0; int t0 = 0; for (int i = 0; i < n; i++) { int t = cin.nextInt(); int x = cin.nextInt(); int y = cin.nextInt(); int l = Math.Abs(x - x0) + Math.Abs(y - y0); if (t - t0 >= l) { if ((t - t0 - l) % 2 == 0) { x0 = x; y0 = y; t0 = t; continue; } } Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } 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, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
372
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { class Katana { public readonly int a; public readonly int b; public Katana(int a, int b) { this.a = a; this.b = b; } } private static List<Katana> katanas; private static int Search(int hp, int maxSwingDamage) { int resultTurn = 0; foreach (var katana in katanas) { if (katana.b >= maxSwingDamage) { hp -= katana.b; resultTurn++; if (hp <= 0) { return resultTurn; } } } resultTurn += (int)Math.Ceiling((float)hp / maxSwingDamage); return resultTurn; } static void Main(string[] args) { var firstInputStrings = Console.ReadLine().Split(' '); var N = int.Parse(firstInputStrings[0]); int H = int.Parse(firstInputStrings[1]); katanas = new List<Katana>(); for (int i = 0; i < N; i++) { var inputStrings = Console.ReadLine().Split(' '); var a = int.Parse(inputStrings[0]); var b = int.Parse(inputStrings[1]); katanas.Add(new Katana(a, b)); } var maxSwingDamage = katanas.Max(x => x.a); katanas = katanas.OrderBy(x => -x.b).ToList(); Console.WriteLine(Search(H, maxSwingDamage)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { class Katana { public readonly int a; public readonly int b; public Katana(int a, int b) { this.a = a; this.b = b; } } private static List<Katana> katanas; private static int Search(int hp, int maxSwingDamage) { int resultTurn = 0; foreach (var katana in katanas) { if (katana.b > maxSwingDamage) { hp -= katana.b; resultTurn++; if (hp <= 0) { return resultTurn; } } } resultTurn += (int)Math.Ceiling((double)hp / maxSwingDamage); return resultTurn; } static void Main(string[] args) { var firstInputStrings = Console.ReadLine().Split(' '); var N = int.Parse(firstInputStrings[0]); int H = int.Parse(firstInputStrings[1]); katanas = new List<Katana>(); for (int i = 0; i < N; i++) { var inputStrings = Console.ReadLine().Split(' '); var a = int.Parse(inputStrings[0]); var b = int.Parse(inputStrings[1]); katanas.Add(new Katana(a, b)); } var maxSwingDamage = katanas.Max(x => x.a); katanas = katanas.OrderBy(x => -x.b).ToList(); Console.WriteLine(Search(H, maxSwingDamage)); } }
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199]]
8
331
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; // static List<List<int>> G = new List<List<int>>(); static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { int N; long H; Input(out N, out H); var a = new long[N]; var b = new long[N]; for (var i = 0; i < N; i++) Input(out a[i], out b[i]); Sort(a); Reverse(a); Sort(b); Reverse(b); int ind = 0; long ans = 0; while (ind < N && b[ind] > a[0] && H > 0) { ans++; H -= b[ind++]; } ans += (H + a[0] - 1) / a[0]; OutL(ans); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class IO_ShortCut { public static string[] _ReadSplit => Console.ReadLine().Split(); public static int[] _ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] _ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] _ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; // static List<List<int>> G = new List<List<int>>(); static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { int N; long H; Input(out N, out H); var a = new long[N]; var b = new long[N]; for (var i = 0; i < N; i++) Input(out a[i], out b[i]); Sort(a); Reverse(a); Sort(b); Reverse(b); int ind = 0; long ans = 0; while (ind < N && b[ind] > a[0] && H > 0) { ans++; H -= b[ind++]; } ans += Max(0, (H + a[0] - 1) / a[0]); OutL(ans); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class IO_ShortCut { public static string[] _ReadSplit => Console.ReadLine().Split(); public static int[] _ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] _ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] _ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
[["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
1,711
5
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; List<int[]> txy = new List<int[]>(); int[] tmp = { 0, 0, 0 }; txy.Add(tmp); for (int i = 0; i < N; i++) { txy.Add(cin.ReadIntArray(3)); } Solve2(txy, 0); } public void Solve2(List<int[]> txy, int count) { bool isOk = false; int ky = 0; int _toX = 0; int _toY = 0; for (int i = count + 1; i < count + 2; i++) { if ((txy[i][0] - txy[count][0]) % 2 == 0) //偶数の位置 { if ((((Math.Abs(txy[i][1] - txy[count][1]) % 2) + (Math.Abs(txy[i][2] - txy[count][2]) % 2)) % 2 != 0)) goto ok; } else { if ((((Math.Abs(txy[i][1] - txy[count][1]) % 2) + (Math.Abs(txy[i][2] - txy[count][2]) % 2)) % 2 != 1)) goto ok; } } for (int ix = 0; ix <= txy[count + 1][0] - txy[count][0]; ix++) { ky = (txy[count + 1][0] - txy[count][0]) - ix; if (ix < Math.Abs(txy[count + 1][1] - txy[count][1]) || ky < Math.Abs(txy[count + 1][2] - txy[count][2])) goto ok; for (int i = 0; i <= ix; i++) { _toX = -1 * i + 1 * (ix - i); for (int k = 0; k <= ky; k++) { _toY = -1 * k + 1 * (ky - k); if (txy[count][1] + _toX == txy[count + 1][1] && txy[count][2] + _toY == txy[count + 1][2]) { isOk = true; goto ok; } } } } ok: if (isOk) { if (count + 1 < txy.Count - 1) { count += 1; Solve2(txy, count); } else { Console.WriteLine("Yes"); } } else { Console.WriteLine("No"); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; List<int[]> txy = new List<int[]>(); int[] tmp = { 0, 0, 0 }; txy.Add(tmp); for (int i = 0; i < N; i++) { txy.Add(cin.ReadIntArray(3)); } Solve2(txy, 0); } public void Solve2(List<int[]> txy, int count) { bool isOk = false; int ky = 0; int _toX = 0; int _toY = 0; for (int i = count + 1; i < count + 2; i++) { if ((txy[i][0] - txy[count][0]) % 2 == 0) //偶数の位置 { if ((((Math.Abs(txy[i][1] - txy[count][1]) % 2) + (Math.Abs(txy[i][2] - txy[count][2]) % 2)) % 2 != 0)) goto ok; } else { if ((((Math.Abs(txy[i][1] - txy[count][1]) % 2) + (Math.Abs(txy[i][2] - txy[count][2]) % 2)) % 2 != 1)) goto ok; } } for (int ix = 0; ix <= txy[count + 1][0] - txy[count][0]; ix++) { ky = (txy[count + 1][0] - txy[count][0]) - ix; if (ix < Math.Abs(txy[count + 1][1] - txy[count][1]) || ky < Math.Abs(txy[count + 1][2] - txy[count][2])) continue; for (int i = 0; i <= ix; i++) { _toX = -1 * i + 1 * (ix - i); for (int k = 0; k <= ky; k++) { _toY = -1 * k + 1 * (ky - k); if (txy[count][1] + _toX == txy[count + 1][1] && txy[count][2] + _toY == txy[count + 1][2]) { isOk = true; goto ok; } } } } ok: if (isOk) { if (count + 1 < txy.Count - 1) { count += 1; Solve2(txy, count); } else { Console.WriteLine("Yes"); } } else { Console.WriteLine("No"); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 7, 8, 196, 0, 57, 64, 126, 0, 127], ["-", 0, 7, 8, 196, 0, 57, 64, 126, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117]]
8
998
3
using System; namespace ABC086C_Traveling { class MainClass { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] t = new int[110000]; int[] x = new int[110000]; int[] y = new int[110000]; t[0] = x[0] = y[0] = 0; for (int i = 1; i <= n; i++) { string[] inp = Console.ReadLine().Split(' '); t[i] = int.Parse(inp[0]); x[i] = int.Parse(inp[1]); y[i] = int.Parse(inp[2]); } bool result = true; for (int i = 0; i < n; i++) { int dt = t[i + 1] - t[i]; int dist = Math.Abs(x[i + 1] - x[i]) + Math.Abs(y[i + 1] - y[i]); if (dt - dist < 0 || (dt - dist) % 2 != 0) { result = false; break; } } Console.WriteLine(result ? "YES" : "NO"); } } }
using System; namespace ABC086C_Traveling { class MainClass { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] t = new int[110000]; int[] x = new int[110000]; int[] y = new int[110000]; t[0] = x[0] = y[0] = 0; for (int i = 1; i <= n; i++) { string[] inp = Console.ReadLine().Split(' '); t[i] = int.Parse(inp[0]); x[i] = int.Parse(inp[1]); y[i] = int.Parse(inp[2]); } bool result = true; for (int i = 0; i < n; i++) { int dt = t[i + 1] - t[i]; int dist = Math.Abs(x[i + 1] - x[i]) + Math.Abs(y[i + 1] - y[i]); if (dt - dist < 0 || (dt - dist) % 2 != 0) { result = false; break; } } Console.WriteLine(result ? "Yes" : "No"); } } }
[["-", 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
279
4
using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int max = 0; int[] Throw = new int[x[0]]; for (int i = 0; i < x[0]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); max = Math.Max(max, a[0]); Throw[i] = a[1]; } int swing = 0; for (int i = 0; i < x[0]; i++) { if (Throw[i] > max) swing++; else Throw[i] = 0; } if (Throw.Sum() >= x[1]) { Array.Sort(Throw); Array.Reverse(Throw); int damage = 0; int i = 0; for (;; i++) { damage += Throw[i]; if (damage >= x[1]) break; } Console.WriteLine(i); } else { Console.WriteLine(swing + ((x[1] - Throw.Sum() - 1) / max + 1)); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int max = 0; int[] Throw = new int[x[0]]; for (int i = 0; i < x[0]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); max = Math.Max(max, a[0]); Throw[i] = a[1]; } int swing = 0; for (int i = 0; i < x[0]; i++) { if (Throw[i] > max) swing++; else Throw[i] = 0; } if (Throw.Sum() >= x[1]) { Array.Sort(Throw); Array.Reverse(Throw); int damage = 0; int i = 0; for (;; i++) { damage += Throw[i]; if (damage >= x[1]) break; } Console.WriteLine(i + 1); } else { Console.WriteLine(swing + ((x[1] - Throw.Sum() - 1) / max + 1)); } } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
296
2
using System; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var ans = "YES"; var t = 0; var x = 0; var y = 0; for (int i = 0; i < N; i++) { var inputs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var dt = inputs[0] - t; var dx = Math.Abs(inputs[1] - x); var dy = Math.Abs(inputs[2] - y); if (dx + dy > dt) { ans = "NO"; } if (dt % 2 != (dx + dy) % 2) { ans = "NO"; } t = inputs[0]; x = inputs[1]; y = inputs[2]; } Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var ans = "Yes"; var t = 0; var x = 0; var y = 0; for (int i = 0; i < N; i++) { var inputs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var dt = inputs[0] - t; var dx = Math.Abs(inputs[1] - x); var dy = Math.Abs(inputs[2] - y); if (dx + dy > dt) { ans = "No"; } if (dt % 2 != (dx + dy) % 2) { ans = "No"; } t = inputs[0]; x = inputs[1]; y = inputs[2]; } Console.WriteLine(ans); } }
[["-", 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
213
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC084A { class Program { static void Main(string[] args) { int M, x, a; M = int.Parse(Console.ReadLine()); a = 24 - M; x = M + a; Console.WriteLine(x); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC084A { class Program { static void Main(string[] args) { int M, x, a; M = int.Parse(Console.ReadLine()); a = 24 - M; x = 24 + a; Console.WriteLine(x); Console.ReadKey(); } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 203]]
8
91
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC086C_Traveling { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int x = 0; int y = 0; int t = 0; bool flag = false; for (int i = 0; i < n; i++) { int[] input = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int tmpT = input[0]; int tmpX = input[1]; int tmpY = input[2]; int dist = Math.Abs(tmpX - x) + Math.Abs(tmpY - y); int dt = tmpT - t; if (dist <= dt && (dist % 2 == dt % 2)) { flag = true; x = tmpX; y = tmpY; } else { flag = false; break; } } if (flag) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC086C_Traveling { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int x = 0; int y = 0; int t = 0; bool flag = false; for (int i = 0; i < n; i++) { int[] input = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int tmpT = input[0]; int tmpX = input[1]; int tmpY = input[2]; int dist = Math.Abs(tmpX - x) + Math.Abs(tmpY - y); int dt = tmpT - t; if (dist <= dt && (dist % 2 == dt % 2)) { flag = true; t = tmpT; x = tmpX; y = tmpY; } else { flag = false; break; } } if (flag) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
248
4
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { Console.WriteLine(Input.ScanInt() + 24); } } 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() { Console.WriteLine(48 - Input.ScanInt()); } } 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); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
574
4
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input= Console.ReadLine(); int input = int.Parse(Console.ReadLine()); Console.WriteLine(24 - input); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input= Console.ReadLine(); int input = int.Parse(Console.ReadLine()); Console.WriteLine(24 * 2 - input); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203]]
8
70
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int num1 = Convert.ToInt32(input[0]); Console.WriteLine(48 - num1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int num1 = Convert.ToInt32(input); Console.WriteLine(48 - num1); } } }
[["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
8
70
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { Console.WriteLine(24 - int.Parse(Console.ReadLine())); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { Console.WriteLine(48 - int.Parse(Console.ReadLine())); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203]]
8
53
2
using System; using System.Collections.Generic; using System.Linq; namespace Paiza { class Program { public static void Main(string[] args) { if (true) { arc089_a(); } else { abc085_c(); abc083_b(); abc087_b(); ABC081A(); ABC086A(); ABC081B(); } } private static void arc089_a() { var N = int.Parse(Console.ReadLine()); var t = Enumerable.Range(0, N) .Select(x => Console.ReadLine() .Split(' ') .Select(y => int.Parse(y)) .ToArray()) .ToArray(); int[] prev = new int[] { 0, 0, 0 }; foreach (var item in t) { var dt = item[0] - prev[0]; var dist = Math.Abs(item[1] - prev[1]) + Math.Abs(item[2] - prev[2]); var parity = item[0] % 2 == 0; if (dist > Math.Abs(item[0] - prev[0])) { Console.WriteLine("No"); return; } if (dist % 2 != item[0] % 2) { Console.WriteLine("No"); return; } prev = item; } Console.WriteLine("Yes"); } private static void abc085_c() { var NY = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NY[0]; var Y = NY[1]; // 10000 5000 1000 for (int i = 0; i <= N; i++) { for (int j = 0; j <= N - j; j++) { var k = N - i - j; if (k >= 0) { if (i * 10000 + j * 5000 + k * 1000 == Y) { Console.WriteLine($"{i} {j} {k}"); return; } } } } Console.WriteLine("-1 -1 -1"); } private static void abc083_b() { var NAB = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); var N = NAB[0]; var A = NAB[1]; var B = NAB[2]; int sums = 0; for (int i = 1; i <= N; i++) { var sum = i.ToString() .Select(x => x.ToString()) .Select(x => int.Parse(x)) .Sum(x => x); if (A <= sum && sum <= B) { sums += i; } } Console.WriteLine(sums); } private static void abc087_b() { var ABCX = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var A = ABCX[0]; var B = ABCX[1]; var C = ABCX[2]; var X = ABCX[3]; var count = 0; for (int i = 0; i <= A; i++) { for (int j = 0; j <= B; j++) { for (int k = 0; k <= C; k++) { if (i * 500 + j * 100 + k * 50 == X) { count++; } } } } Console.WriteLine(count); } private static void ABC081B() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int c = 0; while (a.All(x => x % 2 == 0)) { a = a.Select(x => x / 2).ToArray(); c++; } Console.WriteLine(c); } private static void ABC081A() { Console.WriteLine(Console.ReadLine().Count(x => x.ToString() == "1")); } private static void ABC086A() { var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); Console.WriteLine((a[1] * a[0]) % 2 == 0 ? "Even" : "Odd"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Paiza { class Program { public static void Main(string[] args) { if (true) { arc089_a(); } else { abc085_c(); abc083_b(); abc087_b(); ABC081A(); ABC086A(); ABC081B(); } } private static void arc089_a() { var N = int.Parse(Console.ReadLine()); var t = Enumerable.Range(0, N) .Select(x => Console.ReadLine() .Split(' ') .Select(y => int.Parse(y)) .ToArray()) .ToArray(); int[] prev = new int[] { 0, 0, 0 }; foreach (var item in t) { var dt = item[0] - prev[0]; var dist = Math.Abs(item[1] - prev[1]) + Math.Abs(item[2] - prev[2]); var parity = item[0] % 2 == 0; if (dist > Math.Abs(item[0] - prev[0])) { Console.WriteLine("No"); return; } if (dist % 2 != dt % 2) { Console.WriteLine("No"); return; } prev = item; } Console.WriteLine("Yes"); } private static void abc085_c() { var NY = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NY[0]; var Y = NY[1]; // 10000 5000 1000 for (int i = 0; i <= N; i++) { for (int j = 0; j <= N - j; j++) { var k = N - i - j; if (k >= 0) { if (i * 10000 + j * 5000 + k * 1000 == Y) { Console.WriteLine($"{i} {j} {k}"); return; } } } } Console.WriteLine("-1 -1 -1"); } private static void abc083_b() { var NAB = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); var N = NAB[0]; var A = NAB[1]; var B = NAB[2]; int sums = 0; for (int i = 1; i <= N; i++) { var sum = i.ToString() .Select(x => x.ToString()) .Select(x => int.Parse(x)) .Sum(x => x); if (A <= sum && sum <= B) { sums += i; } } Console.WriteLine(sums); } private static void abc087_b() { var ABCX = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var A = ABCX[0]; var B = ABCX[1]; var C = ABCX[2]; var X = ABCX[3]; var count = 0; for (int i = 0; i <= A; i++) { for (int j = 0; j <= B; j++) { for (int k = 0; k <= C; k++) { if (i * 500 + j * 100 + k * 50 == X) { count++; } } } } Console.WriteLine(count); } private static void ABC081B() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int c = 0; while (a.All(x => x % 2 == 0)) { a = a.Select(x => x / 2).ToArray(); c++; } Console.WriteLine(c); } private static void ABC081A() { Console.WriteLine(Console.ReadLine().Count(x => x.ToString() == "1")); } private static void ABC086A() { var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); Console.WriteLine((a[1] * a[0]) % 2 == 0 ? "Even" : "Odd"); } } }
[["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
958
5
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var ab = Reads(); var a = ab[0]; var b = ab[1]; var s = Console.ReadLine(); var ans = "Yes"; for (int i = 0; i < s.Length; i++) { bool f = false; if (i != a && '0' <= s[i] && s[i] <= '9') f = true; else if (s[i] == '-') f = true; if (!f) ans = "No"; } Console.WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var ab = Reads(); var a = ab[0]; var b = ab[1]; var s = Console.ReadLine(); var ans = "Yes"; for (int i = 0; i < s.Length; i++) { bool f = false; if (i != a && '0' <= s[i] && s[i] <= '9') f = true; else if (i == a && s[i] == '-') f = true; if (!f) ans = "No"; } Console.WriteLine(ans); Console.Out.Flush(); } } }
[["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98]]
8
248
4
using System; class Program { static void Main(string[] args) { int n = Input.nextInt(); int nowx = 0; int nowy = 0; int nowt = 0; int tmpx; int tmpy; int tmpt; for (int i = 0; i < n; i++) { tmpt = Input.nextInt(); tmpx = Input.nextInt(); tmpy = Input.nextInt(); if (tmpt - nowt < Math.Abs(tmpx - nowx) + Math.Abs(tmpy - nowy) || (tmpt - nowt) - (Math.Abs(tmpx - nowx) + Math.Abs(tmpy - nowy)) % 2 != 0) { Console.WriteLine("No"); return; } nowx = tmpx; nowy = tmpy; nowt = tmpt; } Console.WriteLine("Yes"); } } class Input { static string[] line = {}; static int index = 0; static void readLine() { line = Console.ReadLine().Split(' '); index = 0; } public static int nextInt() { if (index == line.Length) { readLine(); } index++; return int.Parse(line[index - 1]); } public static long nextLong() { if (index == line.Length) { readLine(); } index++; return long.Parse(line[index - 1]); } public static string next() { if (index == line.Length) { readLine(); } index++; return line[index - 1]; } }
using System; class Program { static void Main(string[] args) { int n = Input.nextInt(); int nowx = 0; int nowy = 0; int nowt = 0; int tmpx; int tmpy; int tmpt; for (int i = 0; i < n; i++) { tmpt = Input.nextInt(); tmpx = Input.nextInt(); tmpy = Input.nextInt(); if (tmpt - nowt < Math.Abs(tmpx - nowx) + Math.Abs(tmpy - nowy) || ((tmpt - nowt) - (Math.Abs(tmpx - nowx) + Math.Abs(tmpy - nowy))) % 2 != 0) { Console.WriteLine("No"); return; } nowx = tmpx; nowy = tmpy; nowt = tmpt; } Console.WriteLine("Yes"); } } class Input { static string[] line = {}; static int index = 0; static void readLine() { line = Console.ReadLine().Split(' '); index = 0; } public static int nextInt() { if (index == line.Length) { readLine(); } index++; return int.Parse(line[index - 1]); } public static long nextLong() { if (index == line.Length) { readLine(); } index++; return long.Parse(line[index - 1]); } public static string next() { if (index == line.Length) { readLine(); } index++; return line[index - 1]; } }
[["+", 31, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
333
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(); int[] a = sc.intarr; int n = a[0]; int t = 0, x = 0, y = 0; bool ans = true; for (int i = 0; i < n; ++i) { int[] b = sc.intarr; int nt = b[0], nx = b[1], ny = b[2]; if (Math.Abs(x - nx) + Math.Abs(y - ny) <= nt - t && Math.Abs(x - nx) + Math.Abs(y - ny) % 2 == (nt - t) % 2) { x = nx; y = ny; t = nt; continue; } else { ans = false; } } if (ans) wr.wri("Yes"); else wr.wri("No"); } } 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(); } 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(); int[] a = sc.intarr; int n = a[0]; int t = 0, x = 0, y = 0; bool ans = true; for (int i = 0; i < n; ++i) { int[] b = sc.intarr; int nt = b[0], nx = b[1], ny = b[2]; if (Math.Abs(x - nx) + Math.Abs(y - ny) <= nt - t && (Math.Abs(x - nx) + Math.Abs(y - ny)) % 2 == (nt - t) % 2) { x = nx; y = ny; t = nt; continue; } else { ans = false; } } if (ans) wr.wri("Yes"); else wr.wri("No"); } } 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(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
[["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
339
2
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var T = new int[100000]; var X = new int[100000]; var Y = new int[100000]; for (int i = 0; i < N; i++) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); T[i] = input[0]; X[i] = input[1]; Y[i] = input[2]; } for (int i = 0; i < N; i++) { if ((X[i] + Y[i]) > T[i]) { Console.WriteLine("No"); return; } if ((T[i] % 2) != (X[i] + Y[i])) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var T = new int[100000]; var X = new int[100000]; var Y = new int[100000]; for (int i = 0; i < N; i++) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); T[i] = input[0]; X[i] = input[1]; Y[i] = input[2]; } for (int i = 0; i < N; i++) { if ((X[i] + Y[i]) > T[i]) { Console.WriteLine("No"); return; } if ((T[i] % 2) != ((X[i] + Y[i]) % 2)) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
[["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 12, 203]]
8
234
4
using System; using System.Collections.Generic; using System.Linq; public class program { public static void Main() { var N = int.Parse(Console.ReadLine()); var t = new int[N + 1]; var x = new int[N + 1]; var y = new int[N + 1]; t[0] = 0; x[0] = 0; y[0] = 0; for (int i = 0; i < N; i++) { var line = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray(); t[i + 1] = line[0]; x[i + 1] = line[1]; y[i + 1] = line[2]; } bool can = true; for (int i = 1; i <= N; i++) { if (isReachable(t[i] - t[i - 1], getDistance(x[i], x[i - 1]), getDistance(y[i], y[i - 1])) == false) { can = false; break; } } if (can) Console.WriteLine("YES"); else Console.WriteLine("NO"); } public static bool isReachable(int t, int x, int y) { return t >= x + y && (x + y - t) % 2 == 0; } public static int getDistance(int a, int b) { var dif = a - b; return dif >= 0 ? dif : -dif; } }
using System; using System.Collections.Generic; using System.Linq; public class program { public static void Main() { var N = int.Parse(Console.ReadLine()); var t = new int[N + 1]; var x = new int[N + 1]; var y = new int[N + 1]; t[0] = 0; x[0] = 0; y[0] = 0; for (int i = 0; i < N; i++) { var line = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray(); t[i + 1] = line[0]; x[i + 1] = line[1]; y[i + 1] = line[2]; } bool can = true; for (int i = 1; i <= N; i++) { if (isReachable(t[i] - t[i - 1], getDistance(x[i], x[i - 1]), getDistance(y[i], y[i - 1])) == false) { can = false; break; } } if (can) Console.WriteLine("Yes"); else Console.WriteLine("No"); } public static bool isReachable(int t, int x, int y) { return t >= x + y && (x + y - t) % 2 == 0; } public static int getDistance(int a, int b) { var dif = a - b; return dif >= 0 ? dif : -dif; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
346
4
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string str = Console.ReadLine(); int N = int.Parse(str); int[][] X = new int [N][]; for (var i = 0; i < N; i++) { string[] str2 = Console.ReadLine().Split(); X[i] = new int[3]; X[i][0] = int.Parse(str2[0]); X[i][1] = int.Parse(str2[1]); X[i][2] = int.Parse(str2[2]); } Array.Sort(X, (a, b) => a[0] - b[0]); string ans = "Yes"; int nt = 0; int xt = 0; int yt = 0; for (var i = 0; i < N; i++) { if (Math.Abs(X[i][1] - xt) + Math.Abs(X[i][2] - yt) <= X[i][0] - nt) { if ((X[i][0] - nt) % 2 == Math.Abs(X[i][1] - xt) % 2 + Math.Abs(X[i][2] - yt) % 2) { nt = X[i][0]; xt = X[i][1]; yt = X[i][2]; } else { ans = "No"; break; } } else { ans = "No"; break; } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string str = Console.ReadLine(); int N = int.Parse(str); int[][] X = new int [N][]; for (var i = 0; i < N; i++) { string[] str2 = Console.ReadLine().Split(); X[i] = new int[3]; X[i][0] = int.Parse(str2[0]); X[i][1] = int.Parse(str2[1]); X[i][2] = int.Parse(str2[2]); } Array.Sort(X, (a, b) => a[0] - b[0]); string ans = "Yes"; int nt = 0; int xt = 0; int yt = 0; for (var i = 0; i < N; i++) { if (Math.Abs(X[i][1] - xt) + Math.Abs(X[i][2] - yt) <= X[i][0] - nt) { if ((X[i][0] - nt) % 2 == (Math.Abs(X[i][1] - xt) + Math.Abs(X[i][2] - yt)) % 2) { nt = X[i][0]; xt = X[i][1]; yt = X[i][2]; } else { ans = "No"; break; } } else { ans = "No"; break; } } Console.WriteLine(ans); } }
[["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
371
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 n = int.Parse(input.ReadLine()); var cc = new int[n]; var ss = new int[n]; var ff = new int[n]; for (int i = 0; i < n - 1; i++) { var spl = input.ReadLine().Split(' '); cc[i] = int.Parse(spl[0]); ss[i] = int.Parse(spl[1]); ff[i] = int.Parse(spl[2]); } for (int i = 0; i < n; i++) { var t = 0; for (int j = i; j < n - 1; j++) { var c = cc[j]; var s = ss[j]; var f = ff[j]; if (t < s) t = s; if (t % f != 0) t = f * t / f + f; t += c; } Console.WriteLine(t); } 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 n = int.Parse(input.ReadLine()); var cc = new int[n]; var ss = new int[n]; var ff = new int[n]; for (int i = 0; i < n - 1; i++) { var spl = input.ReadLine().Split(' '); cc[i] = int.Parse(spl[0]); ss[i] = int.Parse(spl[1]); ff[i] = int.Parse(spl[2]); } for (int i = 0; i < n; i++) { var t = 0; for (int j = i; j < n - 1; j++) { var c = cc[j]; var s = ss[j]; var f = ff[j]; if (t < s) t = s; if (t % f != 0) t = f * (t / f) + f; t += c; } Console.WriteLine(t); } 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; } }
[["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 25]]
8
416
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderProg { class C_Traveling { static void Main(string[] args) { int count = int.Parse(Console.ReadLine()); int reslutCount = count; int reslut = 0; while (count > 0) { string[] input = Console.ReadLine().Split(' '); int time = int.Parse(input[0]); int num = int.Parse(input[1]) + int.Parse(input[2]); if ((time - num) % 2 == 0) { reslut++; } count--; } if (reslutCount == reslut) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderProg { class C_Traveling { static void Main(string[] args) { int count = int.Parse(Console.ReadLine()); int reslutCount = count; int reslut = 0; while (count > 0) { string[] input = Console.ReadLine().Split(' '); int time = int.Parse(input[0]); int num = int.Parse(input[1]) + int.Parse(input[2]); if ((time - num) % 2 == 0 && (time >= num)) { reslut++; } count--; } if (reslutCount == reslut) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 20], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
8
181
6
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var list = new List<Station>(); for (int i = 0; i < n - 1; i++) { list.Add(new Station { Cost = cin.nextLong(), Start = cin.nextLong(), Freq = cin.nextLong() }); } var alist = new List<long>(); for (int i = 0; i < n - 1; i++) { var time = 0L; for (int j = i; j < n - 1; j++) { var cost = list[j].Cost; var start = list[j].Start; var freq = list[j].Freq; // start wait if (time < start) { time = start; } else if (time % freq == 0) { } else { time += (time + freq) - (time % freq); } time += cost; } alist.Add(time); } alist.Add(0); foreach (var item in alist) { Console.WriteLine(item); } } private class Station { public long Cost { get; set; } public long Start { get; set; } public long Freq { get; set; } } } 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 int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } 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; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var list = new List<Station>(); for (int i = 0; i < n - 1; i++) { list.Add(new Station { Cost = cin.nextLong(), Start = cin.nextLong(), Freq = cin.nextLong() }); } var alist = new List<long>(); for (int i = 0; i < n - 1; i++) { var time = 0L; for (int j = i; j < n - 1; j++) { var cost = list[j].Cost; var start = list[j].Start; var freq = list[j].Freq; // start wait if (time < start) { time = start; } else if (time % freq == 0) { } else { time = (time + freq) - (time % freq); } time += cost; } alist.Add(time); } alist.Add(0); foreach (var item in alist) { Console.WriteLine(item); } } private class Station { public long Cost { get; set; } public long Start { get; set; } public long Freq { get; set; } } } 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 int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } 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; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32]]
8
799
2
using System; using System.Linq; namespace ABC086 { class C { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var t_now = 0; var x_now = 0; var y_now = 0; var res = "YES"; for (int i = 0; i < N; i++) { var plan = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var dest_t = plan[0]; var dest_x = plan[1]; var dest_y = plan[2]; var duration = dest_t - t_now; var dist = Math.Abs(dest_x - x_now) + Math.Abs(dest_y - y_now); var loss_time = duration - dist; if (loss_time < 0 || loss_time % 2 == 1) { res = "NO"; break; } else { t_now = dest_t; x_now = dest_x; y_now = dest_y; } } Console.WriteLine(res); } } }
using System; using System.Linq; namespace ABC086 { class C { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var t_now = 0; var x_now = 0; var y_now = 0; var res = "Yes"; for (int i = 0; i < N; i++) { var plan = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var dest_t = plan[0]; var dest_x = plan[1]; var dest_y = plan[2]; var duration = dest_t - t_now; var dist = Math.Abs(dest_x - x_now) + Math.Abs(dest_y - y_now); var loss_time = duration - dist; if (loss_time < 0 || loss_time % 2 == 1) { res = "No"; break; } else { t_now = dest_t; x_now = dest_x; y_now = dest_y; } } Console.WriteLine(res); } } }
[["-", 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
214
4
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Competitive { internal class Solution { public int N; public int[] T, X, Y; public void Run() { N = Input.ReadInt(); T = new int[N]; X = new int[N]; Y = new int[N]; for (int i = 0; i < N; i++) { var line = Input.ReadIntArray(); T[i] = line[0]; X[i] = line[1]; Y[i] = line[2]; } for (int i = 0; i < N; i++) { int x1 = i == 0 ? 0 : X[i - 1]; int y1 = i == 0 ? 0 : Y[i - 1]; int t1 = i == 0 ? 0 : T[i - 1]; int x2 = X[i]; int y2 = Y[i]; int t2 = T[i]; if (!check(x2 - x1, y2 - y1, t2 - t1)) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } public bool check(int x, int y, int t) { int z = t - Math.Abs(x) + Math.Abs(y); return z >= 0 && z % 2 == 0; } } internal static class Input { public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Competitive { internal class Solution { public int N; public int[] T, X, Y; public void Run() { N = Input.ReadInt(); T = new int[N]; X = new int[N]; Y = new int[N]; for (int i = 0; i < N; i++) { var line = Input.ReadIntArray(); T[i] = line[0]; X[i] = line[1]; Y[i] = line[2]; } for (int i = 0; i < N; i++) { int x1 = i == 0 ? 0 : X[i - 1]; int y1 = i == 0 ? 0 : Y[i - 1]; int t1 = i == 0 ? 0 : T[i - 1]; int x2 = X[i]; int y2 = Y[i]; int t2 = T[i]; if (!check(x2 - x1, y2 - y1, t2 - t1)) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } public bool check(int x, int y, int t) { int z = t - Math.Abs(x) - Math.Abs(y); return z >= 0 && z % 2 == 0; } } internal static class Input { public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33]]
8
452
2
using System; using System.Collections.Generic; namespace ABC086 { public class Problem_C { public static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var routes = new List<int[]>(); routes.Add(new int[] { 0, 0, 0 }); for (var i = 0; i < n; i++) { routes.Add(Array.ConvertAll(Console.ReadLine().Split(), int.Parse)); } for (var i = 0; i < routes.Count - 1; i++) { var tDiff = routes[i + 1][0] - routes[i][0]; var dDiff = Math.Abs(routes[i][1] - routes[i + 1][1]) + Math.Abs(routes[i][2] - routes[i + 1][2]); if (dDiff > tDiff || !(tDiff % 2 == 0 && dDiff == 0) && !(tDiff % 2 == 1 && dDiff % 2 == 1)) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
using System; using System.Collections.Generic; namespace ABC086 { public class Problem_C { public static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var routes = new List<int[]>(); routes.Add(new int[] { 0, 0, 0 }); for (var i = 0; i < n; i++) { routes.Add(Array.ConvertAll(Console.ReadLine().Split(), int.Parse)); } for (var i = 0; i < routes.Count - 1; i++) { var tDiff = routes[i + 1][0] - routes[i][0]; var dDiff = Math.Abs(routes[i][1] - routes[i + 1][1]) + Math.Abs(routes[i][2] - routes[i + 1][2]); if (dDiff > tDiff || !(tDiff % 2 == 0 && dDiff % 2 == 0) && !(tDiff % 2 == 1 && dDiff % 2 == 1)) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
[["+", 0, 23, 0, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 23, 0, 16, 12, 16, 31, 16, 12, 203]]
8
261
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; // 初期状態をt[0], x[0], y[0]とすることで便利になります var t = new int[N + 1]; var x = new int[N + 1]; var y = new int[N + 1]; y[0] = x[0] = y[0] = 0; for (int i = 1; i <= N; ++i) { t[i] = cin.ReadInt; x[i] = cin.ReadInt; y[i] = cin.ReadInt; } var flag = true; for (int i = 0; i < N; ++i) { var time = t[i + 1] - t[0]; var dist = Abs(x[i + 1] - x[i]) + Abs(y[i + 1] - y[i]); if (time < dist) flag = false; if (Abs(time - dist) % 2 != 0) flag = false; } if (flag) WriteLine("Yes"); else WriteLine("No"); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; // 初期状態をt[0], x[0], y[0]とすることで便利になります var t = new int[N + 1]; var x = new int[N + 1]; var y = new int[N + 1]; y[0] = x[0] = y[0] = 0; for (int i = 1; i <= N; ++i) { t[i] = cin.ReadInt; x[i] = cin.ReadInt; y[i] = cin.ReadInt; } var flag = true; for (int i = 0; i < N; ++i) { var time = t[i + 1] - t[i]; var dist = Abs(x[i + 1] - x[i]) + Abs(y[i + 1] - y[i]); if (time < dist) flag = false; if (Abs(time - dist) % 2 != 0) flag = false; } if (flag) WriteLine("Yes"); else WriteLine("No"); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
640
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemA { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var A = NN; var B = NN; if ((B - A) % 2 == 1) Console.WriteLine("Alice"); else Console.WriteLine("Borys"); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemA { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var A = NN; var B = NN; if ((B - A) % 2 == 0) Console.WriteLine("Alice"); else Console.WriteLine("Borys"); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
1,449
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int a = sc.NextInt(); int b = sc.NextInt(); string answer = Math.Abs(a - b) % 2 == 1 ? "Alice" : "Borys"; 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 n = sc.NextInt(); int a = sc.NextInt(); int b = sc.NextInt(); string answer = Math.Abs(a - b) % 2 == 0 ? "Alice" : "Borys"; 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, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203]]
8
392
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main() { var temp = ReadLine(); var a = temp[1]; var b = temp[2]; if (b - a % 2 == 0) { Console.WriteLine("Alice"); } else { Console.WriteLine("Borys"); } } 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() { var temp = ReadLine(); var a = temp[1]; var b = temp[2]; if ((b - a) % 2 == 0) { Console.WriteLine("Alice"); } else { Console.WriteLine("Borys"); } } static List<int> ReadLine() { var line = Console.ReadLine(); var array = line.Split(' '); return array.Select(x => int.Parse(x)).ToList(); } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25]]
8
136
2
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; class Program { const long MOD = (long)1e9 + 7; static void Main(string[] args) { // main ↓ int[] n = ScanIntArray(2); Console.WriteLine((int)(Math.Abs(n[0] - n[1])) % 2 == 0 ? "Alice" : "Borys"); // main↑ } public class SegmentTree<Monoid> { private bool debug = false; // 0-indexed SegmentTree public int size; Monoid[] segTree; Monoid unit; public SegmentTree(int inSize, Monoid unit) { this.unit = unit; size = 2; while (size < inSize) size *= 2; segTree = new Monoid[2 * size]; for (int i = 0; i < segTree.Length; i++) { segTree[i] = unit; // 単位元なので全部に代入しておけばよい } } public int BinarySearch(int x) { int high = size; int low = 0; int mid = (high + low) / 2; while (low < high) { // Console.WriteLine(low + " " + high); Monoid cmp = NonRecursiveQuery(0, mid); // Console.WriteLine("[ 0, " + mid + " ] -> " + cmp); if ((dynamic)cmp >= x) { high = mid; } else if ((dynamic)cmp < x) { low = mid + 1; } mid = (high + low) / 2; } return mid; } public void set(int iter, Monoid val) { segTree[iter + size - 1] = val; } public Monoid GetMonoid(int index) { return segTree[index + size - 1]; } public void add(int iter, Monoid val) { update(iter, (dynamic)segTree[iter + size - 1] + (dynamic)val); } public void build() { // 2段目より上の構築 for (int k = size - 2; k >= 0; k--) { segTree[k] = F(segTree[2 * k + 1], segTree[2 * k + 2]); } } public Monoid F(Monoid m1, Monoid m2) { Monoid res = GCD(m1, m2); return res; } public Monoid Query(int ql, int qr, int index, int nl, int nr) { // Recursive // [ql, qr)について考える // index に対応する範囲 nl <= x <= nr if (nr <= ql || qr <= nl) { if (debug) Console.WriteLine("Out: [l , r), [" + nl + " ," + nr + "), " + "index: " + index + " ,unit:" + unit); return unit; } if (ql <= nl && nr <= qr) { if (debug) Console.WriteLine("All in [l , r): [" + nl + " ," + nr + "), " + "index: " + index + ",rangeAns:" + segTree[index]); return segTree[index]; } else { Monoid vl = Query(ql, qr, index * 2 + 1, nl, (nl + nr) / 2); Monoid vr = Query(ql, qr, index * 2 + 2, (nl + nr) / 2, nr); if (debug) Console.WriteLine("Recursive: [l , r),+: [" + nl + ", " + nr + "), index->" + index); if (debug) Console.WriteLine("(vl, vr): (" + vl + ", " + vr + ")"); return F(vl, vr); } } public Monoid NonRecursiveQuery(int l, int r) { // 区間 -> [ l , r ] // 非再帰 int L = l + size - 1; int R = r + size - 1; Monoid s = unit; while (L <= R) { if (L % 2 == 0) { s = F(s, segTree[L]); L++; } if (R % 2 == 1) { s = F(s, segTree[R]); } L /= 2; R /= 2; R--; } return s; } public void update(int k, Monoid x) { k += size - 1; segTree[k] = x; while (true) { k = (k - 1) / 2; segTree[k] = F(segTree[k * 2 + 1], segTree[k * 2 + 2]); if (k == 0) { break; } } } public void print() { Console.Write("Print:"); for (int i = 0; i < segTree.Length; i++) { Console.Write(segTree[i] + " "); } Console.WriteLine(""); } } static int Nibutan(long[] array, long k) { int low = 0; int high = array.Length - 1; int mid = high; while (low < high) { mid = (low + high) / 2; if (array[mid] >= k) // k以上の最小index.ココを変えるだけ { high = mid; } else { low = mid + 1; } mid = (low + high) / 2; } return mid; } static int ScanOneInt() { return int.Parse(Console.ReadLine()); } static long ScanOneLong() { return long.Parse(Console.ReadLine()); } static string[] ScanStringArray(int lines) { string[] str = new string[lines]; for (int i = 0; i < lines; i++) { str[i] = Console.ReadLine(); } return str; } static int[] ScanIntArray(int t) { string[] str = Console.ReadLine().Split(' '); int[] ar = new int[t]; for (int i = 0; i < t; i++) { ar[i] = int.Parse(str[i]); } return ar; } static string[] ScanStringArrayInOneLine(int t) { string[] str = Console.ReadLine().Split(' '); return str; } static Tuple<int, int> ScanTuple() { int[] tmp = ScanIntArray(2); return new Tuple<int, int>(tmp[0], tmp[1] * -1); } static long[] ScanLongArray(int t) { string[] str = Console.ReadLine().Split(' '); long[] ar = new long[t]; for (int i = 0; i < t; i++) { ar[i] = long.Parse(str[i]); } return ar; } static double[] ScanDoubleArray(int t) { string[] str = Console.ReadLine().Split(' '); double[] ar = new double[t]; for (int i = 0; i < t; i++) { ar[i] = double.Parse(str[i]); } return ar; } static int[,] ScanIntSquareArray(int h, int w) { int[,] resAr = new int[h, w]; for (int i = 0; i < h; i++) { int[] ar = ScanIntArray(w); for (int j = 0; j < w; j++) { resAr[i, j] = ar[j]; } } return resAr; } static int[,] CombModMake() { int[,] res = new int[2005, 2005]; for (int i = 0; i < 2005; i++) { for (int j = 0; j < 2005; j++) { if (i == 0 || i < j) { res[i, j] = 0; } else if (j == 0 || i == j) { res[i, j] = 1; } else { res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % (int)MOD; } } } return res; } // int, long両方で出来るGCDを作った static T GCD<T>(T a, T b) { if ((dynamic)b == 0) { return a; } else { return GCD((dynamic)b, (dynamic)a % (dynamic)b); } } static bool isPrime(int a) // O(sqrt N) { int max = (int)Math.Sqrt(a); if (a == 1) return false; for (int i = 2; i <= max; i++) { if (a % i == 0) { return false; } } return true; } } public class Pair<T, U> : IComparable where T : IComparable<T> where U : IComparable<U> { public T Item1; public U Item2; public int CompareTo(object obj) { Pair<T, U> pair = (Pair<T, U>)obj; return Item1.CompareTo(pair.Item1); } public Pair(T t, U u) { Item1 = t; Item2 = u; } } // 計算量: Push -> O(logN), Peek -> O(1)。Clear() -> O(logN) // ToArray()で配列化 public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /* -> Item: _heap(ヒープを持つ.sizeはmaxSize) -> Item: _type -> 0:asc(昇順), 1:desc(降順) */ public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); // typeが0なら昇順, 1なら降順にソートするCompare } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() // O(1) { return _count; } public T Peek() // O(1) { return _heap[0]; } public bool Contains(T x) // O(N)なので注意 { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (Count() > 0) Pop(); } public IEnumerator<T> GetEnumerator() // なにこれ { var ret = new List<T>(); while (Count() > 0) { ret.Add(Pop()); } foreach (var r in ret) { Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class GenericOperation<T> { public GenericOperation() { var availableT = new Type[] { typeof(int), typeof(uint), typeof(short), typeof(ushort), typeof(long), typeof(ulong), typeof(byte), typeof(decimal), typeof(double) }; if (!availableT.Contains(typeof(T))) { throw new NotSupportedException(); } var p1 = Expression.Parameter(typeof(T)); var p2 = Expression.Parameter(typeof(T)); Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2) .Compile(); Subtract = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2) .Compile(); Multiply = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2) .Compile(); Divide = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2) .Compile(); Modulo = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2) .Compile(); Equal = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2) .Compile(); GreaterThan = Expression .Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2) .Compile(); GreaterThanOrEqual = Expression .Lambda<Func<T, T, bool>>( Expression.GreaterThanOrEqual(p1, p2), p1, p2) .Compile(); LessThan = Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2) .Compile(); LessThanOrEqual = Expression .Lambda<Func<T, T, bool>>( Expression.LessThanOrEqual(p1, p2), p1, p2) .Compile(); } public Func<T, T, T> Add { get; private set; } public Func<T, T, T> Subtract { get; private set; } public Func<T, T, T> Multiply { get; private set; } public Func<T, T, T> Divide { get; private set; } public Func<T, T, T> Modulo { get; private set; } public Func<T, T, bool> Equal { get; private set; } public Func<T, T, bool> GreaterThan { get; private set; } public Func<T, T, bool> GreaterThanOrEqual { get; private set; } public Func<T, T, bool> LessThan { get; private set; } public Func<T, T, bool> LessThanOrEqual { get; private set; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; class Program { const long MOD = (long)1e9 + 7; static void Main(string[] args) { // main ↓ int[] n = ScanIntArray(3); Console.WriteLine((int)(Math.Abs(n[2] - n[1])) % 2 == 0 ? "Alice" : "Borys"); // main↑ } public class SegmentTree<Monoid> { private bool debug = false; // 0-indexed SegmentTree public int size; Monoid[] segTree; Monoid unit; public SegmentTree(int inSize, Monoid unit) { this.unit = unit; size = 2; while (size < inSize) size *= 2; segTree = new Monoid[2 * size]; for (int i = 0; i < segTree.Length; i++) { segTree[i] = unit; // 単位元なので全部に代入しておけばよい } } public int BinarySearch(int x) { int high = size; int low = 0; int mid = (high + low) / 2; while (low < high) { // Console.WriteLine(low + " " + high); Monoid cmp = NonRecursiveQuery(0, mid); // Console.WriteLine("[ 0, " + mid + " ] -> " + cmp); if ((dynamic)cmp >= x) { high = mid; } else if ((dynamic)cmp < x) { low = mid + 1; } mid = (high + low) / 2; } return mid; } public void set(int iter, Monoid val) { segTree[iter + size - 1] = val; } public Monoid GetMonoid(int index) { return segTree[index + size - 1]; } public void add(int iter, Monoid val) { update(iter, (dynamic)segTree[iter + size - 1] + (dynamic)val); } public void build() { // 2段目より上の構築 for (int k = size - 2; k >= 0; k--) { segTree[k] = F(segTree[2 * k + 1], segTree[2 * k + 2]); } } public Monoid F(Monoid m1, Monoid m2) { Monoid res = GCD(m1, m2); return res; } public Monoid Query(int ql, int qr, int index, int nl, int nr) { // Recursive // [ql, qr)について考える // index に対応する範囲 nl <= x <= nr if (nr <= ql || qr <= nl) { if (debug) Console.WriteLine("Out: [l , r), [" + nl + " ," + nr + "), " + "index: " + index + " ,unit:" + unit); return unit; } if (ql <= nl && nr <= qr) { if (debug) Console.WriteLine("All in [l , r): [" + nl + " ," + nr + "), " + "index: " + index + ",rangeAns:" + segTree[index]); return segTree[index]; } else { Monoid vl = Query(ql, qr, index * 2 + 1, nl, (nl + nr) / 2); Monoid vr = Query(ql, qr, index * 2 + 2, (nl + nr) / 2, nr); if (debug) Console.WriteLine("Recursive: [l , r),+: [" + nl + ", " + nr + "), index->" + index); if (debug) Console.WriteLine("(vl, vr): (" + vl + ", " + vr + ")"); return F(vl, vr); } } public Monoid NonRecursiveQuery(int l, int r) { // 区間 -> [ l , r ] // 非再帰 int L = l + size - 1; int R = r + size - 1; Monoid s = unit; while (L <= R) { if (L % 2 == 0) { s = F(s, segTree[L]); L++; } if (R % 2 == 1) { s = F(s, segTree[R]); } L /= 2; R /= 2; R--; } return s; } public void update(int k, Monoid x) { k += size - 1; segTree[k] = x; while (true) { k = (k - 1) / 2; segTree[k] = F(segTree[k * 2 + 1], segTree[k * 2 + 2]); if (k == 0) { break; } } } public void print() { Console.Write("Print:"); for (int i = 0; i < segTree.Length; i++) { Console.Write(segTree[i] + " "); } Console.WriteLine(""); } } static int Nibutan(long[] array, long k) { int low = 0; int high = array.Length - 1; int mid = high; while (low < high) { mid = (low + high) / 2; if (array[mid] >= k) // k以上の最小index.ココを変えるだけ { high = mid; } else { low = mid + 1; } mid = (low + high) / 2; } return mid; } static int ScanOneInt() { return int.Parse(Console.ReadLine()); } static long ScanOneLong() { return long.Parse(Console.ReadLine()); } static string[] ScanStringArray(int lines) { string[] str = new string[lines]; for (int i = 0; i < lines; i++) { str[i] = Console.ReadLine(); } return str; } static int[] ScanIntArray(int t) { string[] str = Console.ReadLine().Split(' '); int[] ar = new int[t]; for (int i = 0; i < t; i++) { ar[i] = int.Parse(str[i]); } return ar; } static string[] ScanStringArrayInOneLine(int t) { string[] str = Console.ReadLine().Split(' '); return str; } static Tuple<int, int> ScanTuple() { int[] tmp = ScanIntArray(2); return new Tuple<int, int>(tmp[0], tmp[1] * -1); } static long[] ScanLongArray(int t) { string[] str = Console.ReadLine().Split(' '); long[] ar = new long[t]; for (int i = 0; i < t; i++) { ar[i] = long.Parse(str[i]); } return ar; } static double[] ScanDoubleArray(int t) { string[] str = Console.ReadLine().Split(' '); double[] ar = new double[t]; for (int i = 0; i < t; i++) { ar[i] = double.Parse(str[i]); } return ar; } static int[,] ScanIntSquareArray(int h, int w) { int[,] resAr = new int[h, w]; for (int i = 0; i < h; i++) { int[] ar = ScanIntArray(w); for (int j = 0; j < w; j++) { resAr[i, j] = ar[j]; } } return resAr; } static int[,] CombModMake() { int[,] res = new int[2005, 2005]; for (int i = 0; i < 2005; i++) { for (int j = 0; j < 2005; j++) { if (i == 0 || i < j) { res[i, j] = 0; } else if (j == 0 || i == j) { res[i, j] = 1; } else { res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % (int)MOD; } } } return res; } // int, long両方で出来るGCDを作った static T GCD<T>(T a, T b) { if ((dynamic)b == 0) { return a; } else { return GCD((dynamic)b, (dynamic)a % (dynamic)b); } } static bool isPrime(int a) // O(sqrt N) { int max = (int)Math.Sqrt(a); if (a == 1) return false; for (int i = 2; i <= max; i++) { if (a % i == 0) { return false; } } return true; } } public class Pair<T, U> : IComparable where T : IComparable<T> where U : IComparable<U> { public T Item1; public U Item2; public int CompareTo(object obj) { Pair<T, U> pair = (Pair<T, U>)obj; return Item1.CompareTo(pair.Item1); } public Pair(T t, U u) { Item1 = t; Item2 = u; } } // 計算量: Push -> O(logN), Peek -> O(1)。Clear() -> O(logN) // ToArray()で配列化 public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /* -> Item: _heap(ヒープを持つ.sizeはmaxSize) -> Item: _type -> 0:asc(昇順), 1:desc(降順) */ public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); // typeが0なら昇順, 1なら降順にソートするCompare } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() // O(1) { return _count; } public T Peek() // O(1) { return _heap[0]; } public bool Contains(T x) // O(N)なので注意 { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (Count() > 0) Pop(); } public IEnumerator<T> GetEnumerator() // なにこれ { var ret = new List<T>(); while (Count() > 0) { ret.Add(Pop()); } foreach (var r in ret) { Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class GenericOperation<T> { public GenericOperation() { var availableT = new Type[] { typeof(int), typeof(uint), typeof(short), typeof(ushort), typeof(long), typeof(ulong), typeof(byte), typeof(decimal), typeof(double) }; if (!availableT.Contains(typeof(T))) { throw new NotSupportedException(); } var p1 = Expression.Parameter(typeof(T)); var p2 = Expression.Parameter(typeof(T)); Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2) .Compile(); Subtract = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2) .Compile(); Multiply = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2) .Compile(); Divide = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2) .Compile(); Modulo = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2) .Compile(); Equal = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2) .Compile(); GreaterThan = Expression .Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2) .Compile(); GreaterThanOrEqual = Expression .Lambda<Func<T, T, bool>>( Expression.GreaterThanOrEqual(p1, p2), p1, p2) .Compile(); LessThan = Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2) .Compile(); LessThanOrEqual = Expression .Lambda<Func<T, T, bool>>( Expression.LessThanOrEqual(p1, p2), p1, p2) .Compile(); } public Func<T, T, T> Add { get; private set; } public Func<T, T, T> Subtract { get; private set; } public Func<T, T, T> Multiply { get; private set; } public Func<T, T, T> Divide { get; private set; } public Func<T, T, T> Modulo { get; private set; } public Func<T, T, bool> Equal { get; private set; } public Func<T, T, bool> GreaterThan { get; private set; } public Func<T, T, bool> GreaterThanOrEqual { get; private set; } public Func<T, T, bool> LessThan { get; private set; } public Func<T, T, bool> LessThanOrEqual { get; private set; } }
[["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
8
3,006
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { Scanner cin = new Scanner(); int N = cin.Int(); int A = cin.Int(); int B = cin.Int(); Console.WriteLine(B - A % 2 == 0 ? "Alice" : "Borys"); Console.ReadLine(); } } 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; using System.Text; using System.Threading.Tasks; class Program { static void Main() { Scanner cin = new Scanner(); int N = cin.Int(); int A = cin.Int(); int B = cin.Int(); Console.WriteLine((B - A) % 2 == 0 ? "Alice" : "Borys"); Console.ReadLine(); } } 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; } }
[["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 25]]
8
451
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC020A { class Program { static void Main(string[] args) { int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int A = input[1]; int B = input[2]; if ((B - A) % 2 == 0) { Console.WriteLine("Borys"); } else { Console.WriteLine("Alice"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC020A { class Program { static void Main(string[] args) { int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int A = input[1]; int B = input[2]; if ((B - A) % 2 == 0) { Console.WriteLine("Alice"); } else { Console.WriteLine("Borys"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
131
4
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.TotalLen = inpt[0]; int alicePos = inpt[1]; int bolicePos = inpt[2]; String ans = "Bolice"; if (bolicePos - alicePos == 1 && alicePos == 1) { ans = "Bolice"; } else if ((bolicePos - alicePos) % 2 == 0) { ans = "Alice"; } Console.WriteLine(ans); } private int TotalLen; public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 5 2 4 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.TotalLen = inpt[0]; int alicePos = inpt[1]; int bolicePos = inpt[2]; String ans = "Borys"; if (bolicePos - alicePos == 1 && alicePos == 1) { ans = "Borys"; } else if ((bolicePos - alicePos) % 2 == 0) { ans = "Alice"; } Console.WriteLine(ans); } private int TotalLen; public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 5 2 4 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["-", 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
267
4
using System; using System.Text; using System.Collections.Generic; using System.Collections; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { public static class StringExtensions { public static string ToTitleCase(this string self) { return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase( self); } } class Program { static void Main(string[] args) { // var N = long.Parse(Console.ReadLine()); Solve(); } static long N; static long[] A; static void Solve() { N = long.Parse(Console.ReadLine()); A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var ans = true; var low = 0L; var high = A.Max() * N; var mid = 0L; while (low + 1 < high) { mid = (low + high) / 2; if (Check(mid) > 2) { high = mid; } else { low = mid; } } var max = (Check(high) == 2 ? high : low); low = 0L; high = A.Max() * N; while (low + 1 < high) { mid = (low + high) / 2; if (Check(mid) >= 2) { high = mid; } else { low = mid; } } var min = (Check(low) == 2 ? low : high); if (min <= max) { Console.WriteLine(min + " " + max); } else { Console.WriteLine(-1); } } static long Check(long inp) { for (int i = 0; i < N; i++) { inp = inp - inp % A[i]; } return inp; } class Treap<T> : IEnumerable<T> where T : IComparable { public int Length { get { return this.Root == null ? 0 : this.NodeCount(this.Root); } } public T this[int i] { get { if (this.Root.Count < i - 1) throw new IndexOutOfRangeException(); return this.Root.Get(i); } } public Node Root; private IComparer<T> Cmp = Comparer<T>.Default; public Treap(IComparer<T> cmp = null) { if (cmp != null) this.Cmp = cmp; } public Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (l.Priority > r.Priority) { l.R = this.Merge(l.R, r); return this.Update(l); } else { r.L = this.Merge(l, r.L); return this.Update(r); } } // 左にk個、右に残り(n-k)個に分割する public (Node, Node) Split(int k) { return this.Split(this.Root, k); } public (Node, Node) Split(Node t, int k) { if (t == null) return (null, null); if (k <= this.NodeCount(t.L)) { var s = this.Split(t.L, k); t.L = s.Item2; return (s.Item1, this.Update(t)); } else { var s = this.Split(t.R, k - this.NodeCount(t.L) - 1); t.R = s.Item1; return (this.Update(t), s.Item2); } } public int NodeCount(Node node) { return node == null ? 0 : node.Count; } public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); } public int LowerBouond(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) <= 0) return this.LowerBouond(node.L, value); else return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value); } public int UpperBound(T value) { return this.UpperBound(this.Root, value); } public int UpperBound(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) >= 0) return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value); else return this.UpperBound(node.L, value); } public int ValueCount(T value) { return this.UpperBound(value) - this.LowerBouond(value); } public void Insert(T value) { var sub = this.Split(this.Root, this.LowerBouond(value)); var newNode = new Node(value); var merged = this.Merge(sub.Item1, newNode); this.Root = this.Merge(merged, sub.Item2); } public void Erase(T value) { if (this.ValueCount(value) == 0) return; var sub = this.Split(this.Root, this.LowerBouond(value)); this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2); } public void InsertAt(Node node, int k) { var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public void InsertAt(T value, int k) { var node = new Node(value); var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public Node EraseAt(int k) { var sub = this.Split(this.Root, k); var sub2 = this.Split(sub.Item2, 1); var res = sub2.Item1; this.Root = this.Merge(sub.Item1, sub2.Item2); return res; } public Node Update(Node node) { node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1; return node; } public class Node { private static Random Rand = new Random(); public T Value; public Node L = null; public Node R = null; public int Count; public double Priority; public Node(T value, double priority) { this.Value = value; this.Priority = priority; this.Count = 1; } public Node(T value) : this(value, Rand.NextDouble()) {} public T Get(int i) { return this.GetNode(i).Value; } public Node GetNode(int i) { var lcount = 0; if (this.L != null) lcount = this.L.Count; if (lcount == i) return this; else if (lcount < i) return this.R.GetNode(i - lcount - 1); else return this.L.GetNode(i); } } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) yield return this.Root.Get(i); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } } }
using System; using System.Text; using System.Collections.Generic; using System.Collections; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { public static class StringExtensions { public static string ToTitleCase(this string self) { return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase( self); } } class Program { static void Main(string[] args) { // var N = long.Parse(Console.ReadLine()); Solve(); } static long N; static long[] A; static void Solve() { N = long.Parse(Console.ReadLine()); A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var ans = true; var low = 0L; var high = 2 + A.Max() * N; var mid = 0L; while (low + 1 < high) { mid = (low + high) / 2; if (Check(mid) > 2) { high = mid; } else { low = mid; } } var max = (Check(high) == 2 ? high : low); low = 0L; high = 2 + A.Max() * N; while (low + 1 < high) { mid = (low + high) / 2; if (Check(mid) >= 2) { high = mid; } else { low = mid; } } var min = (Check(low) == 2 ? low : high); if (min <= max) { Console.WriteLine(min + " " + max); } else { Console.WriteLine(-1); } } static long Check(long inp) { for (int i = 0; i < N; i++) { inp = inp - inp % A[i]; } return inp; } class Treap<T> : IEnumerable<T> where T : IComparable { public int Length { get { return this.Root == null ? 0 : this.NodeCount(this.Root); } } public T this[int i] { get { if (this.Root.Count < i - 1) throw new IndexOutOfRangeException(); return this.Root.Get(i); } } public Node Root; private IComparer<T> Cmp = Comparer<T>.Default; public Treap(IComparer<T> cmp = null) { if (cmp != null) this.Cmp = cmp; } public Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (l.Priority > r.Priority) { l.R = this.Merge(l.R, r); return this.Update(l); } else { r.L = this.Merge(l, r.L); return this.Update(r); } } // 左にk個、右に残り(n-k)個に分割する public (Node, Node) Split(int k) { return this.Split(this.Root, k); } public (Node, Node) Split(Node t, int k) { if (t == null) return (null, null); if (k <= this.NodeCount(t.L)) { var s = this.Split(t.L, k); t.L = s.Item2; return (s.Item1, this.Update(t)); } else { var s = this.Split(t.R, k - this.NodeCount(t.L) - 1); t.R = s.Item1; return (this.Update(t), s.Item2); } } public int NodeCount(Node node) { return node == null ? 0 : node.Count; } public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); } public int LowerBouond(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) <= 0) return this.LowerBouond(node.L, value); else return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value); } public int UpperBound(T value) { return this.UpperBound(this.Root, value); } public int UpperBound(Node node, T value) { if (node == null) return 0; if (this.Cmp.Compare(value, node.Value) >= 0) return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value); else return this.UpperBound(node.L, value); } public int ValueCount(T value) { return this.UpperBound(value) - this.LowerBouond(value); } public void Insert(T value) { var sub = this.Split(this.Root, this.LowerBouond(value)); var newNode = new Node(value); var merged = this.Merge(sub.Item1, newNode); this.Root = this.Merge(merged, sub.Item2); } public void Erase(T value) { if (this.ValueCount(value) == 0) return; var sub = this.Split(this.Root, this.LowerBouond(value)); this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2); } public void InsertAt(Node node, int k) { var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public void InsertAt(T value, int k) { var node = new Node(value); var sub = this.Split(this.Root, k); var merged = this.Merge(sub.Item1, node); this.Root = this.Merge(merged, sub.Item2); } public Node EraseAt(int k) { var sub = this.Split(this.Root, k); var sub2 = this.Split(sub.Item2, 1); var res = sub2.Item1; this.Root = this.Merge(sub.Item1, sub2.Item2); return res; } public Node Update(Node node) { node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1; return node; } public class Node { private static Random Rand = new Random(); public T Value; public Node L = null; public Node R = null; public int Count; public double Priority; public Node(T value, double priority) { this.Value = value; this.Priority = priority; this.Count = 1; } public Node(T value) : this(value, Rand.NextDouble()) {} public T Get(int i) { return this.GetNode(i).Value; } public Node GetNode(int i) { var lcount = 0; if (this.L != null) lcount = this.L.Count; if (lcount == i) return this; else if (lcount < i) return this.R.GetNode(i - lcount - 1); else return this.L.GetNode(i); } } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) yield return this.Root.Get(i); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
8
1,570
4
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; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var n = rint(); var a = inta(); Array.Reverse(a); var min = 2; var max = 3; if (a[0] != 2) { WriteLine(-1); return; } for (int i = 1; i < n; i++) { if (max < a[i] || min > max) { WriteLine(-1); return; } if (min <= a[i] && a[i] <= max) { min = a[i]; max = 2 * a[i] - 1; } else { var tempmin = (min + a[i] - 1) / a[i]; var tempmax = (max + a[i]) / a[i]; min = a[i] * tempmin; max = a[i] * tempmax - 1; } // WriteLine($"{min} {max}"); } if (min > max) { WriteLine(-1); } else { WriteLine($"{min} {max}"); } } 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) { if (n < r) return 0; 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] = double.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- 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); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
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; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var n = rint(); var a = inta(); Array.Reverse(a); long min = 2; long max = 3; if (a[0] != 2) { WriteLine(-1); return; } for (int i = 1; i < n; i++) { if (max < a[i] || min > max) { WriteLine(-1); return; } if (min <= a[i] && a[i] <= max) { min = a[i]; max = 2 * a[i] - 1; } else { var tempmin = (min + a[i] - 1) / a[i]; var tempmax = (max + a[i]) / a[i]; min = a[i] * tempmin; max = a[i] * tempmax - 1; } // WriteLine($"{min} {max}"); } if (min > max) { WriteLine(-1); } else { WriteLine($"{min} {max}"); } } 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) { if (n < r) return 0; 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] = double.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- 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); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,285
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static Math2; using static Output; using static Utils; public class CP { Input sc; public void Solve() { sc = new Input(); var t = 1; while (t-- > 0) { ttttt(); } } public void ttttt() { int k = sc.cin<int>(); var a = sc.cinarr<int>(); int l = 2; int r = 2; for (int i = k - 1; i >= 0; --i) { if ((l - 1) / a[i] == r / a[i]) { Put(-1); return; } l = (l + a[i] - 1) / a[i] * a[i]; r = (r / a[i]) * a[i] + a[i] - 1; } Put(l, r); } } public static class NumberTheory { public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static Dictionary<int, int> FactoricalPF(int N) { var ret = new Dictionary<int, int>(); for (int i = 2; i <= N; ++i) { int ni = i; for (int j = 2; j * j <= ni; ++j) { int cnt = 0; while (ni % j == 0) { ++cnt; ni /= j; } if (cnt == 0) continue; if (ret.ContainsKey(j)) ret[j] += cnt; else ret[j] = cnt; } if (ni >= 2) { if (ret.ContainsKey(ni)) ret[ni] += 1; else ret[ni] = 1; } } return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } public static List<int> seive(int n) { var ret = new List<int>(); bool[] isPrime = new bool[n + 1]; for (int i = 1; i <= n; ++i) isPrime[i] = true; isPrime[1] = false; for (int i = 1; i <= n; ++i) { int j = i; if (isPrime[i]) ret.Add(i); else continue; while (j <= n) { j += i; if (j > n) continue; isPrime[j] = false; } } return ret; } public static bool isPrime(long n) { for (int i = 2; i * i <= n; ++i) { if (n % i == 0) return false; } return true; } } public class BinarySearch { public static int Lower_Bound<T>(IList<T> Array, T Target) { return Lower_Bound<T>(Array, Target, Comparer<T>.Default.Compare); } public static int Lower_Bound<T>(IList<T> Array, T Target, Comparison<T> Comp) { var cmp = Comparer<T>.Create(Comp); var l = -1; // always ng var r = Array.Count(); // always ok while (r - l > 1) { var mid = l + (r - l) / 2; var res = cmp.Compare(Array[mid], Target); if (res >= 0) r = mid; else l = mid; } return r; } public static int Upper_Bound<T>(IList<T> Array, T Target) { return Upper_Bound<T>(Array, Target, Comparer<T>.Default.Compare); } public static int Upper_Bound<T>(IList<T> Array, T Target, Comparison<T> Comp) { var cmp = Comparer<T>.Create(Comp); var l = -1; var r = Array.Count; while (r - l > 1) { var mid = l + (r - l) / 2; var res = cmp.Compare(Array[mid], Target); if (res > 0) r = mid; else l = mid; } return r; } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const long MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { if (a == 0) return b; while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } 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 long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } 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(string N) { int ret = 0; for (int i = 0; i < N.Length; ++i) ret += N[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } public static bool NextPermutation<T>(IList<T> lis, Comparison<T> cmp) { int n = lis.Count; int i = n - 1; while (i - 1 >= 0) { if (cmp(lis[i - 1], lis[i]) < 0) break; --i; } if (i == 0) return false; int j = i; while (j + 1 < n) { if (cmp(lis[i - 1], lis[j + 1]) > 0) break; ++j; } var _q = lis[j]; lis[j] = lis[i - 1]; lis[i - 1] = _q; int k = i; int l = n - 1; while (k < l) { var _p = lis[k]; lis[k] = lis[l]; lis[l] = _p; ++k; --l; } return true; } public static bool NextPermutation<T>(IList<T> lis) => NextPermutation(lis, Comparer<T>.Default.Compare); } public class PriorityQueue<T> { List<T> _item; public int Count { get { return _item.Count; } } bool _isascend { get; set; } public T Peek { get { return _item[0]; } } Comparison<T> Comp; public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null) : this(Comparer<T>.Default.Compare, IsAscend, list) {} public PriorityQueue(Comparison<T> cmp, bool IsAscend = true, IEnumerable<T> list = null) { _item = new List<T>(); _isascend = IsAscend; this.Comp = cmp; if (list != null) { _item.AddRange(list); Build(); } } private int Compare(int i, int j) => (_isascend ? -1 : 1) * Comp(_item[i], _item[j]); private void Swap(int i, int j) { var t = _item[i]; _item[i] = _item[j]; _item[j] = t; } private int Parent(int i) => (i - 1) >> 1; private int Left(int i) => (i << 1) + 1; public T Enqueue(T val) { int i = _item.Count; _item.Add(val); while (i > 0) { int p = Parent(i); if (Compare(i, p) > 0) Swap(i, p); i = p; } return val; } private void Heapify(int index) { for (int i = index, j; (j = Left(i)) < _item.Count; i = j) { if (j != _item.Count - 1 && Compare(j, j + 1) < 0) j++; if (Compare(i, j) < 0) Swap(i, j); } } public T Dequeue() { T val = _item[0]; _item[0] = _item[_item.Count - 1]; _item.RemoveAt(_item.Count - 1); Heapify(0); return val; } private void Build() { for (var i = (_item.Count >> 1) - 1; i >= 0; i--) Heapify(i); } public bool Any() => Count > 0; } class Program { static void Main(string[] args) { var CP = new CP(); CP.Solve(); } } public static class Output { public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void PutV<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } } public class Input { public static string Str => Console.ReadLine(); public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U)); public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); public static T Cast<T>(string s) { if (IsTypeEqual<T, int>()) return ConvertType<T, int>(int.Parse(s)); else if (IsTypeEqual<T, long>()) return ConvertType<T, long>(long.Parse(s)); else if (IsTypeEqual<T, double>()) return ConvertType<T, double>(double.Parse(s)); else if (IsTypeEqual<T, char>()) return ConvertType<T, char>(char.Parse(s)); else return ConvertType<T, string>(s); } public static T[] Castarr<T>(string[] s) { var ret = new T[s.Length]; int i = 0; if (IsTypeEqual<T, char>()) { var list = new List<T>(); foreach (var t in s) { foreach (var u in t) { list.Add(ConvertType<T, char>(char.Parse(u.ToString()))); } } return list.ToArray(); } foreach (var t in s) { if (IsTypeEqual<T, int>()) ret[i++] = ConvertType<T, int>(int.Parse(t)); else if (IsTypeEqual<T, long>()) ret[i++] = ConvertType<T, long>(long.Parse(t)); else if (IsTypeEqual<T, double>()) ret[i++] = ConvertType<T, double>(double.Parse(t)); else ret[i++] = ConvertType<T, string>(t); } return ret; } Queue<string> q = new Queue<string>(); void next() { var ss = Str.Split(' '); foreach (var item in ss) q.Enqueue(item); } public T cin<T>() { if (!q.Any()) next(); return Cast<T>(q.Dequeue()); } public void mul<T>(out T t) { t = cin<T>(); } public void mul<T, U>(out T t, out U u) { t = cin<T>(); u = cin<U>(); } public void mul<T, U, V>(out T t, out U u, out V v) { t = cin<T>(); u = cin<U>(); v = cin<V>(); } public void mul<T, U, V, W>(out T t, out U u, out V v, out W w) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); } public void mul<T, U, V, W, X>(out T t, out U u, out V v, out W w, out X x) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); } public void mul<T, U, V, W, X, Y>(out T t, out U u, out V v, out W w, out X x, out Y y) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); } public void mul<T, U, V, W, X, Y, Z>(out T t, out U u, out V v, out W w, out X x, out Y y, out Z z) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); z = cin<Z>(); } public T[] cinarr<T>() { return Castarr<T>(Str.Split(' ')); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static Math2; using static Output; using static Utils; public class CP { Input sc; public void Solve() { sc = new Input(); var t = 1; while (t-- > 0) { ttttt(); } } public void ttttt() { int k = sc.cin<int>(); var a = sc.cinarr<long>(); long l = 2; long r = 2; for (int i = k - 1; i >= 0; --i) { if ((l - 1) / a[i] == r / a[i]) { Put(-1); return; } l = (l + a[i] - 1) / a[i] * a[i]; r = (r / a[i]) * a[i] + a[i] - 1; } Put(l, r); } } public static class NumberTheory { public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static Dictionary<int, int> FactoricalPF(int N) { var ret = new Dictionary<int, int>(); for (int i = 2; i <= N; ++i) { int ni = i; for (int j = 2; j * j <= ni; ++j) { int cnt = 0; while (ni % j == 0) { ++cnt; ni /= j; } if (cnt == 0) continue; if (ret.ContainsKey(j)) ret[j] += cnt; else ret[j] = cnt; } if (ni >= 2) { if (ret.ContainsKey(ni)) ret[ni] += 1; else ret[ni] = 1; } } return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } public static List<int> seive(int n) { var ret = new List<int>(); bool[] isPrime = new bool[n + 1]; for (int i = 1; i <= n; ++i) isPrime[i] = true; isPrime[1] = false; for (int i = 1; i <= n; ++i) { int j = i; if (isPrime[i]) ret.Add(i); else continue; while (j <= n) { j += i; if (j > n) continue; isPrime[j] = false; } } return ret; } public static bool isPrime(long n) { for (int i = 2; i * i <= n; ++i) { if (n % i == 0) return false; } return true; } } public class BinarySearch { public static int Lower_Bound<T>(IList<T> Array, T Target) { return Lower_Bound<T>(Array, Target, Comparer<T>.Default.Compare); } public static int Lower_Bound<T>(IList<T> Array, T Target, Comparison<T> Comp) { var cmp = Comparer<T>.Create(Comp); var l = -1; // always ng var r = Array.Count(); // always ok while (r - l > 1) { var mid = l + (r - l) / 2; var res = cmp.Compare(Array[mid], Target); if (res >= 0) r = mid; else l = mid; } return r; } public static int Upper_Bound<T>(IList<T> Array, T Target) { return Upper_Bound<T>(Array, Target, Comparer<T>.Default.Compare); } public static int Upper_Bound<T>(IList<T> Array, T Target, Comparison<T> Comp) { var cmp = Comparer<T>.Create(Comp); var l = -1; var r = Array.Count; while (r - l > 1) { var mid = l + (r - l) / 2; var res = cmp.Compare(Array[mid], Target); if (res > 0) r = mid; else l = mid; } return r; } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const long MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { if (a == 0) return b; while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } 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 long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } 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(string N) { int ret = 0; for (int i = 0; i < N.Length; ++i) ret += N[i] - '0'; return ret; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } public static bool NextPermutation<T>(IList<T> lis, Comparison<T> cmp) { int n = lis.Count; int i = n - 1; while (i - 1 >= 0) { if (cmp(lis[i - 1], lis[i]) < 0) break; --i; } if (i == 0) return false; int j = i; while (j + 1 < n) { if (cmp(lis[i - 1], lis[j + 1]) > 0) break; ++j; } var _q = lis[j]; lis[j] = lis[i - 1]; lis[i - 1] = _q; int k = i; int l = n - 1; while (k < l) { var _p = lis[k]; lis[k] = lis[l]; lis[l] = _p; ++k; --l; } return true; } public static bool NextPermutation<T>(IList<T> lis) => NextPermutation(lis, Comparer<T>.Default.Compare); } public class PriorityQueue<T> { List<T> _item; public int Count { get { return _item.Count; } } bool _isascend { get; set; } public T Peek { get { return _item[0]; } } Comparison<T> Comp; public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null) : this(Comparer<T>.Default.Compare, IsAscend, list) {} public PriorityQueue(Comparison<T> cmp, bool IsAscend = true, IEnumerable<T> list = null) { _item = new List<T>(); _isascend = IsAscend; this.Comp = cmp; if (list != null) { _item.AddRange(list); Build(); } } private int Compare(int i, int j) => (_isascend ? -1 : 1) * Comp(_item[i], _item[j]); private void Swap(int i, int j) { var t = _item[i]; _item[i] = _item[j]; _item[j] = t; } private int Parent(int i) => (i - 1) >> 1; private int Left(int i) => (i << 1) + 1; public T Enqueue(T val) { int i = _item.Count; _item.Add(val); while (i > 0) { int p = Parent(i); if (Compare(i, p) > 0) Swap(i, p); i = p; } return val; } private void Heapify(int index) { for (int i = index, j; (j = Left(i)) < _item.Count; i = j) { if (j != _item.Count - 1 && Compare(j, j + 1) < 0) j++; if (Compare(i, j) < 0) Swap(i, j); } } public T Dequeue() { T val = _item[0]; _item[0] = _item[_item.Count - 1]; _item.RemoveAt(_item.Count - 1); Heapify(0); return val; } private void Build() { for (var i = (_item.Count >> 1) - 1; i >= 0; i--) Heapify(i); } public bool Any() => Count > 0; } class Program { static void Main(string[] args) { var CP = new CP(); CP.Solve(); } } public static class Output { public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void PutV<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } } public class Input { public static string Str => Console.ReadLine(); public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U)); public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); public static T Cast<T>(string s) { if (IsTypeEqual<T, int>()) return ConvertType<T, int>(int.Parse(s)); else if (IsTypeEqual<T, long>()) return ConvertType<T, long>(long.Parse(s)); else if (IsTypeEqual<T, double>()) return ConvertType<T, double>(double.Parse(s)); else if (IsTypeEqual<T, char>()) return ConvertType<T, char>(char.Parse(s)); else return ConvertType<T, string>(s); } public static T[] Castarr<T>(string[] s) { var ret = new T[s.Length]; int i = 0; if (IsTypeEqual<T, char>()) { var list = new List<T>(); foreach (var t in s) { foreach (var u in t) { list.Add(ConvertType<T, char>(char.Parse(u.ToString()))); } } return list.ToArray(); } foreach (var t in s) { if (IsTypeEqual<T, int>()) ret[i++] = ConvertType<T, int>(int.Parse(t)); else if (IsTypeEqual<T, long>()) ret[i++] = ConvertType<T, long>(long.Parse(t)); else if (IsTypeEqual<T, double>()) ret[i++] = ConvertType<T, double>(double.Parse(t)); else ret[i++] = ConvertType<T, string>(t); } return ret; } Queue<string> q = new Queue<string>(); void next() { var ss = Str.Split(' '); foreach (var item in ss) q.Enqueue(item); } public T cin<T>() { if (!q.Any()) next(); return Cast<T>(q.Dequeue()); } public void mul<T>(out T t) { t = cin<T>(); } public void mul<T, U>(out T t, out U u) { t = cin<T>(); u = cin<U>(); } public void mul<T, U, V>(out T t, out U u, out V v) { t = cin<T>(); u = cin<U>(); v = cin<V>(); } public void mul<T, U, V, W>(out T t, out U u, out V v, out W w) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); } public void mul<T, U, V, W, X>(out T t, out U u, out V v, out W w, out X x) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); } public void mul<T, U, V, W, X, Y>(out T t, out U u, out V v, out W w, out X x, out Y y) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); } public void mul<T, U, V, W, X, Y, Z>(out T t, out U u, out V v, out W w, out X x, out Y y, out Z z) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); z = cin<Z>(); } public T[] cinarr<T>() { return Castarr<T>(Str.Split(' ')); } }
[["-", 0, 213, 63, 214, 141, 236, 237, 238, 0, 199], ["+", 0, 213, 63, 214, 141, 236, 237, 238, 0, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
3,558
6
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; using System.Diagnostics; class Scanner { private readonly char Separator = ' '; private int Index = 0; private string[] Line = new string[0]; public string Next() { if (Index >= Line.Length) { Line = Console.ReadLine().Split(Separator); Index = 0; } var ret = Line[Index]; Index++; return ret; } public int NextInt() { return int.Parse(Next()); } private long NextLong() { return long.Parse(Next()); } } class Program { private int K; private int[] A; private void Scan() { var sc = new Scanner(); K = sc.NextInt(); A = new int[K]; for (int i = 0; i < K; i++) { A[i] = sc.NextInt(); } } public void Solve() { Scan(); int max = 2, min = 2; for (int i = K - 1; i >= 0; i--) { if (((min + A[i] - 1) / A[i]) * A[i] > max) { Console.WriteLine(-1); return; } max = (max / A[i]) * A[i] + A[i] - 1; min = ((min + A[i] - 1) / A[i]) * A[i]; } Console.WriteLine($"{min} {max}"); } static public void Main() { new Program().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; using System.Diagnostics; class Scanner { private readonly char Separator = ' '; private int Index = 0; private string[] Line = new string[0]; public string Next() { if (Index >= Line.Length) { Line = Console.ReadLine().Split(Separator); Index = 0; } var ret = Line[Index]; Index++; return ret; } public int NextInt() { return int.Parse(Next()); } private long NextLong() { return long.Parse(Next()); } } class Program { private int K; private long[] A; private void Scan() { var sc = new Scanner(); K = sc.NextInt(); A = new long[K]; for (int i = 0; i < K; i++) { A[i] = sc.NextInt(); } } public void Solve() { Scan(); long max = 2, min = 2; for (int i = K - 1; i >= 0; i--) { if (((min + A[i] - 1) / A[i]) * A[i] > max) { Console.WriteLine(-1); return; } max = (max / A[i]) * A[i] + A[i] - 1; min = ((min + A[i] - 1) / A[i]) * A[i]; } Console.WriteLine($"{min} {max}"); } static public void Main() { new Program().Solve(); } }
[["-", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["+", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
391
6
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int K = int.Parse(Console.ReadLine()); var A = cin.ReadSplit(); Reverse(A); var ansmin = 2; var ansmax = 2; for (var i = 0; i < K; i++) { int m = ((ansmin + A[i] - 1) / A[i]) * A[i]; if (m > ansmax) { Console.WriteLine(-1); return; } int M = ((ansmax / A[i]) + 1) * A[i] - 1; ansmin = m; ansmax = M; } Console.WriteLine($"{ansmin} {ansmax}"); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } struct Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private readonly bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public Pair(T f, U s) { first = f; second = s; CompWithFirst = true; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } } public class PriorityQueue<T> where T : IComparable<T> { private List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Contains(T search) { return Q.Contains(search); } } public class Scanner { public int[] ReadSplit() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] ReadSplitL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(T[] a, int i, int j) { T k = a[i]; a[i] = a[j]; a[j] = k; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int K = int.Parse(Console.ReadLine()); var A = cin.ReadSplit(); Reverse(A); long ansmin = 2; long ansmax = 2; for (var i = 0; i < K; i++) { long m = ((ansmin + A[i] - 1) / A[i]) * A[i]; if (m > ansmax) { Console.WriteLine(-1); return; } long M = ((ansmax / A[i]) + 1) * A[i] - 1; ansmin = m; ansmax = M; } Console.WriteLine($"{ansmin} {ansmax}"); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } struct Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private readonly bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public Pair(T f, U s) { first = f; second = s; CompWithFirst = true; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } } public class PriorityQueue<T> where T : IComparable<T> { private List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Contains(T search) { return Q.Contains(search); } } public class Scanner { public int[] ReadSplit() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] ReadSplitL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(T[] a, int i, int j) { T k = a[i]; a[i] = a[j]; a[j] = k; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,179
8
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Program { public class AGC020B { static public void Solve() { var K = NextInt; var Alist = NextIntList(K); var minN = 2; var maxN = 2; Alist.Reverse(); foreach (var item in Alist) { minN = ((minN - 1) / item + 1) * item; maxN = (maxN / item) * item + item - 1; if (minN > maxN) { Console.WriteLine(-1); return; } } Console.WriteLine(minN + " " + maxN); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static class Console_ { private static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); static List<int> NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList(); static List<long> NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList(); static List<double> NextDoubleList(int N) => Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList(); static List<string> NextStringList(int N) => Enumerable.Repeat(0, N).Select(_ => NextString).ToList(); static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } static IEnumerable<long> Prime(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i]) yield return 2 * i + 1; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i < max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; public Tuple<TKey, TValue> Pop() => q.Pop(); } class Mod { static public long _mod = 1000000007; private long _val = 0; public Mod(long x) { _val = x; } static public implicit operator Mod(long x) => new Mod(x); static public explicit operator long(Mod x) => x._val; static public Mod operator +(Mod x) => x._val; static public Mod operator -(Mod x) => -x._val; static public Mod operator ++(Mod x) => x._val + 1; static public Mod operator --(Mod x) => x._val - 1; static public Mod operator +(Mod x, Mod y) => (x._val + y._val) % _mod; static public Mod operator -(Mod x, Mod y) => ((((x._val - y._val) % _mod) + _mod) % _mod); static public Mod operator *(Mod x, Mod y) => (x._val * y._val) % _mod; static public Mod operator /(Mod x, Mod y) => (x._val * Inverse(y._val)) % _mod; static public bool operator ==(Mod x, Mod y) => x._val == y._val; static public bool operator !=(Mod x, Mod y) => x._val != y._val; static public bool operator<(Mod x, Mod y) => x._val < y._val; static public bool operator>(Mod x, Mod y) => x._val > y._val; static public bool operator <=(Mod x, Mod y) => x._val <= y._val; static public bool operator >=(Mod x, Mod y) => x._val >= y._val; static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } override public bool Equals(object obj) => obj == null ? false : _val == ((Mod)obj)._val; public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; public override int GetHashCode() => _val.GetHashCode(); public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>(); static private List<Mod> _ifact = new List<Mod>(); static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) { _fact.Add(1); _ifact.Add(1); } else { _fact.Add(_fact[i - 1] * i); _ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2)); } } static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _ifact[n - k] * _ifact[k] * _fact[n]; } } static private List<long> _fact = new List<long>(); static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) _fact.Add(1); else _fact.Add(_fact[i - 1] * i); } static public long Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Program { public class AGC020B { static public void Solve() { var K = NextInt; var Alist = NextLongList(K); var minN = 2L; var maxN = 2L; Alist.Reverse(); foreach (var item in Alist) { minN = ((minN - 1) / item + 1) * item; maxN = (maxN / item) * item + item - 1; if (minN > maxN) { Console.WriteLine(-1); return; } } Console.WriteLine(minN + " " + maxN); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static class Console_ { private static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); static List<int> NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList(); static List<long> NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList(); static List<double> NextDoubleList(int N) => Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList(); static List<string> NextStringList(int N) => Enumerable.Repeat(0, N).Select(_ => NextString).ToList(); static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } static IEnumerable<long> Prime(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i]) yield return 2 * i + 1; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i < max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; public Tuple<TKey, TValue> Pop() => q.Pop(); } class Mod { static public long _mod = 1000000007; private long _val = 0; public Mod(long x) { _val = x; } static public implicit operator Mod(long x) => new Mod(x); static public explicit operator long(Mod x) => x._val; static public Mod operator +(Mod x) => x._val; static public Mod operator -(Mod x) => -x._val; static public Mod operator ++(Mod x) => x._val + 1; static public Mod operator --(Mod x) => x._val - 1; static public Mod operator +(Mod x, Mod y) => (x._val + y._val) % _mod; static public Mod operator -(Mod x, Mod y) => ((((x._val - y._val) % _mod) + _mod) % _mod); static public Mod operator *(Mod x, Mod y) => (x._val * y._val) % _mod; static public Mod operator /(Mod x, Mod y) => (x._val * Inverse(y._val)) % _mod; static public bool operator ==(Mod x, Mod y) => x._val == y._val; static public bool operator !=(Mod x, Mod y) => x._val != y._val; static public bool operator<(Mod x, Mod y) => x._val < y._val; static public bool operator>(Mod x, Mod y) => x._val > y._val; static public bool operator <=(Mod x, Mod y) => x._val <= y._val; static public bool operator >=(Mod x, Mod y) => x._val >= y._val; static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } override public bool Equals(object obj) => obj == null ? false : _val == ((Mod)obj)._val; public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; public override int GetHashCode() => _val.GetHashCode(); public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>(); static private List<Mod> _ifact = new List<Mod>(); static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) { _fact.Add(1); _ifact.Add(1); } else { _fact.Add(_fact[i - 1] * i); _ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2)); } } static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _ifact[n - k] * _ifact[k] * _fact[n]; } } static private List<long> _fact = new List<long>(); static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) _fact.Add(1); else _fact.Add(_fact[i - 1] * i); } static public long Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
2,409
6
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static long k = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 static long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); static void Main() { long minAnswer = SearchMin(0, 1000000000000000000); long maxAnswer = Search(0, 1000000000000000000); if (minAnswer <= 1) Console.WriteLine(-1); else Console.WriteLine(minAnswer + " " + maxAnswer); } static long Search(long min, long max) //二分探索法で最大値を求める { while (true) { long mid = min + (max - min) / 2; if (CheckMin(mid)) min = mid; //さらに大きくても成り立つかも else max = mid; if (max - min <= 1) { if (CheckMin(max)) { return max; //最大値で成り立つかの確認を優先 } else { return min; } break; } } } static long SearchMin(long min, long max) //二分探索法で最小値を求める { while (true) { long mid = min + (max - min) / 2; if (Check(mid)) max = mid; //さらに小さくても成り立つかも else min = mid; if (max - min <= 1) { if (Check(min)) { return min; //最小値で成り立つかの確認を優先 } else { return max; } break; } } } static bool Check(long testNum) { for (long i = 0; i < k; i++) { if (testNum < nums[i]) return false; long memo = testNum % nums[i]; testNum -= memo; } if (testNum < 2) return false; return true; } static bool CheckMin(long testNum) { for (long i = 0; i < k; i++) { if (testNum < nums[i]) return true; long memo = testNum % nums[i]; testNum -= memo; } if (testNum <= 2) return true; return false; } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static long k = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 static long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); static void Main() { long minAnswer = SearchMin(0, 1000000000000000000); long maxAnswer = Search(0, 1000000000000000000); if (minAnswer > maxAnswer) Console.WriteLine(-1); else Console.WriteLine(minAnswer + " " + maxAnswer); } static long Search(long min, long max) //二分探索法で最大値を求める { while (true) { long mid = min + (max - min) / 2; if (CheckMin(mid)) min = mid; //さらに大きくても成り立つかも else max = mid; if (max - min <= 1) { if (CheckMin(max)) { return max; //最大値で成り立つかの確認を優先 } else { return min; } break; } } } static long SearchMin(long min, long max) //二分探索法で最小値を求める { while (true) { long mid = min + (max - min) / 2; if (Check(mid)) max = mid; //さらに小さくても成り立つかも else min = mid; if (max - min <= 1) { if (Check(min)) { return min; //最小値で成り立つかの確認を優先 } else { return max; } break; } } } static bool Check(long testNum) { for (long i = 0; i < k; i++) { if (testNum < nums[i]) return false; long memo = testNum % nums[i]; testNum -= memo; } if (testNum < 2) return false; return true; } static bool CheckMin(long testNum) { for (long i = 0; i < k; i++) { if (testNum < nums[i]) return true; long memo = testNum % nums[i]; testNum -= memo; } if (testNum <= 2) return true; return false; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
405
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC020B { class Program { static void Main(string[] args) { int K = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); bool ok = true; if (input[K - 1] != 2) { ok = false; } int min = 2; int max = 3; for (int i = 1; i < K; i++) { if (!ok) { break; } int num = input[K - 1 - i]; if (num >= max * 2) { ok = false; } else { if (num > min) { min = num; } else { min = (min + num - 1) / num * num; } max = (max / num) * num + (num - 1); } } if (min > max) { ok = false; } if (ok) { Console.WriteLine(min.ToString() + " " + max.ToString()); } else { Console.WriteLine(-1); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC020B { class Program { static void Main(string[] args) { int K = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); bool ok = true; if (input[K - 1] != 2) { ok = false; } long min = 2; long max = 3; for (int i = 1; i < K; i++) { if (!ok) { break; } int num = input[K - 1 - i]; if (num >= max * 2) { ok = false; } else { if (num > min) { min = num; } else { min = (min + num - 1) / num * num; } max = (max / num) * num + (num - 1); } } if (min > max) { ok = false; } if (ok) { Console.WriteLine(min.ToString() + " " + max.ToString()); } else { Console.WriteLine(-1); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
275
4
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { void solve() { int k = int.Parse(Console.ReadLine()); int[] a = new int[k]; int idx = 0; int max = 2, min = 2; bool f_invalid = false; string[] buff = Console.ReadLine().Split(' '); for (int i = 0; i < k; ++i) { int p = int.Parse(buff[i]); if (idx == 0 || a[idx - 1] != p) { a[idx++] = p; } } int c = 4; for (int i = idx - 1; i >= 0; --i) { int g = a[i]; min = ((min - 1) / g) * g + g; max = (max / g) * g + g - 1; if (min > max) { f_invalid = true; break; } } if (f_invalid) { Console.WriteLine("-1"); } else { Console.WriteLine(min + " " + max); } } public static int Main() { bool loop = false; #if ES_DEBUG loop = true; #endif do { new Program().solve(); } while (loop); return 0; } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { void solve() { int k = int.Parse(Console.ReadLine()); int[] a = new int[k]; int idx = 0; long max = 2, min = 2; bool f_invalid = false; string[] buff = Console.ReadLine().Split(' '); for (int i = 0; i < k; ++i) { int p = int.Parse(buff[i]); if (idx == 0 || a[idx - 1] != p) { a[idx++] = p; } } for (int i = idx - 1; i >= 0; --i) { int g = a[i]; min = ((min - 1) / g) * g + g; max = (max / g) * g + g - 1; if (min > max) { f_invalid = true; break; } } if (f_invalid) { Console.WriteLine("-1"); } else { Console.WriteLine(min + " " + max); } } public static int Main() { bool loop = false; #if ES_DEBUG loop = true; #endif do { new Program().solve(); } while (loop); return 0; } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 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, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
8
294
7
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int k = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int makablePairMin = 2; int makablePairMax = 2; for (int i = a.Length - 1; i >= 0; i--) { int possibleMinWinner = (makablePairMin / a[i] + (makablePairMin % a[i] != 0 ? 1 : 0)) * a[i]; int possibleMaxWinner = (makablePairMax / a[i]) * a[i]; if (possibleMaxWinner >= possibleMinWinner) { makablePairMin = possibleMinWinner; makablePairMax = possibleMaxWinner + a[i] - 1; } else { Console.WriteLine(-1); return; } } Console.WriteLine($"{makablePairMin} {makablePairMax}"); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int k = int.Parse(Console.ReadLine()); long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); long makablePairMin = 2; long makablePairMax = 2; for (int i = a.Length - 1; i >= 0; i--) { long possibleMinWinner = (makablePairMin / a[i] + (makablePairMin % a[i] != 0 ? 1 : 0)) * a[i]; long possibleMaxWinner = (makablePairMax / a[i]) * a[i]; if (possibleMaxWinner >= possibleMinWinner) { makablePairMin = possibleMinWinner; makablePairMax = possibleMaxWinner + a[i] - 1; } else { Console.WriteLine(-1); return; } } Console.WriteLine($"{makablePairMin} {makablePairMax}"); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
8
196
12
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { int N = re.i(); int[] A = re.ia(); if (A[N - 1] != 2) { sb.Append("-1\n"); return; } int min = 2; int max = 3; for (int i = N - 2; i >= 0; i--) { if (A[i] > max) { sb.Append("-1\n"); return; } min = (min - 1) / A[i] * A[i] + A[i]; max = max / A[i] * A[i]; if (max < min) { sb.Append("-1\n"); return; } max += A[i] - 1; } sb.Append(min + " " + max + "\n"); } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { int N = re.i(); long[] A = re.la(); if (A[N - 1] != 2) { sb.Append("-1\n"); return; } long min = 2; long max = 3; for (int i = N - 2; i >= 0; i--) { if (A[i] > max) { sb.Append("-1\n"); return; } min = (min - 1) / A[i] * A[i] + A[i]; max = max / A[i] * A[i]; if (max < min) { sb.Append("-1\n"); return; } max += A[i] - 1; } sb.Append(min + " " + max + "\n"); } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,844
8
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; XRand rnd; void calc() { cin = new Scanner(); rnd = new XRand(); int N = cin.nextInt(); int[] A = cin.ArrayInt(N); randomshuffle(A); int sum = A.Sum(); int MAX = 10000; bool[] dp = new bool[MAX]; dp[0] = true; for (int i = 0; i < N; i++) { bool[] nextdp = new bool[MAX]; for (int j = 0; j < MAX; j++) { if (!dp[j]) continue; int low = Math.Abs(j - A[i]); int high = j + A[i]; if (low < MAX) nextdp[low] = true; if (high < MAX) nextdp[high] = true; } dp = nextdp; } int ans = 0; for (int i = 0; i < MAX; i++) { if (dp[i]) { ans = (sum + i) / 2; break; } } Console.WriteLine(ans); } //配列のランダム並び替え void randomshuffle<T>(T[] a) { int len = a.Length; for (int i = 0; i < len - 1; i++) { swap(ref a[i], ref a[i + rnd.nextInt(len - i)]); } } // swap void swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } } class XRand { uint x, y, z, w; public XRand() { init(); } public XRand(uint s) { init(); init_xor128(s); } void init() { x = 314159265; y = 358979323; z = 846264338; w = 327950288; } public void init_xor128(uint s) { z ^= s; z ^= z >> 21; z ^= z << 35; z ^= z >> 4; z *= 736338717; } uint next() { uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; } public long nextLong(long m) { return (long)((((ulong)next() << 32) + next()) % (ulong)m); } public int nextInt(int m) { return (int)(next() % m); } public int nextIntP(int a) { return (int)Math.Pow(a, nextDouble()); } public int nextInt(int min, int max) { return min + nextInt(max - min + 1); } public double nextDouble() { return (double)next() / uint.MaxValue; } public double nextDoubleP(double a) { return Math.Pow(a, nextDouble()); } } 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; XRand rnd; void calc() { cin = new Scanner(); rnd = new XRand(); int N = cin.nextInt(); int[] A = cin.ArrayInt(N); // randomshuffle(A); int sum = A.Sum(); int MAX = 100000; bool[] dp = new bool[MAX]; dp[0] = true; for (int i = 0; i < N; i++) { bool[] nextdp = new bool[MAX]; for (int j = 0; j < MAX; j++) { if (!dp[j]) continue; int low = Math.Abs(j - A[i]); int high = j + A[i]; if (low < MAX) nextdp[low] = true; if (high < MAX) nextdp[high] = true; } dp = nextdp; } int ans = 0; for (int i = 0; i < MAX; i++) { if (dp[i]) { ans = (sum + i) / 2; break; } } Console.WriteLine(ans); } //配列のランダム並び替え void randomshuffle<T>(T[] a) { int len = a.Length; for (int i = 0; i < len - 1; i++) { swap(ref a[i], ref a[i + rnd.nextInt(len - i)]); } } // swap void swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } } class XRand { uint x, y, z, w; public XRand() { init(); } public XRand(uint s) { init(); init_xor128(s); } void init() { x = 314159265; y = 358979323; z = 846264338; w = 327950288; } public void init_xor128(uint s) { z ^= s; z ^= z >> 21; z ^= z << 35; z ^= z >> 4; z *= 736338717; } uint next() { uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; } public long nextLong(long m) { return (long)((((ulong)next() << 32) + next()) % (ulong)m); } public int nextInt(int m) { return (int)(next() % m); } public int nextIntP(int a) { return (int)Math.Pow(a, nextDouble()); } public int nextInt(int min, int max) { return min + nextInt(max - min + 1); } public double nextDouble() { return (double)next() / uint.MaxValue; } public double nextDoubleP(double a) { return Math.Pow(a, nextDouble()); } } 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; } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
1,039
7
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { const int MB = 64; public void Solve() { int sum = A.Sum(); Array.Sort(A); int NN = (sum + 1 + MB - 1) / MB; ulong[] dp = new ulong[NN + 1]; dp[0] = 1; for (int i = 0; i < N; i++) { ulong[] ndp = new ulong[NN + 1]; int nj = A[i] / MB; int nb = A[i] % MB; for (int j = 0; j + nj + 1 <= NN; j++) { ndp[j] |= dp[j]; ndp[j + nj] |= dp[j] << nb; ndp[j + nj + 1] |= dp[j] >> (MB - nb); } dp = ndp; } // Console.WriteLine(String.Join(" ",dp.Select(v => // String.Format("{0:X}",v)))); int trgt = sum % 2 == 0 ? sum / 2 : (sum / 2 + 1); for (int k = trgt; k <= sum; k++) { int ii = k / MB; int jj = k % MB; if (((dp[ii] >> jj) & 1) == 1) { Console.WriteLine(k); return; } } } int N; int[] A; public Sol() { N = ri(); A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { const int MB = 64; public void Solve() { int sum = A.Sum(); Array.Sort(A); int NN = (sum + 1 + MB - 1) / MB; ulong[] dp = new ulong[NN + 1]; dp[0] = 1; for (int i = 0; i < N; i++) { ulong[] ndp = new ulong[NN + 1]; int nj = A[i] / MB; int nb = A[i] % MB; for (int j = 0; j + nj + 1 <= NN; j++) { ndp[j] |= dp[j]; ndp[j + nj] |= dp[j] << nb; if (nb > 0) ndp[j + nj + 1] |= dp[j] >> (MB - nb); } dp = ndp; // Console.WriteLine(String.Join(" ",dp.Select(v => // String.Format("{0:X}",v)))); } int trgt = sum % 2 == 0 ? sum / 2 : (sum / 2 + 1); for (int k = trgt; k <= sum; k++) { int ii = k / MB; int jj = k % MB; if (((dp[ii] >> jj) & 1) == 1) { Console.WriteLine(k); return; } } } int N; int[] A; public Sol() { N = ri(); A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
8
568
6
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC085A { class Program { static void Main(string[] args) { var S = Console.ReadLine(); string ans = "2017/01/" + S.Substring(8, 2); Console.WriteLine(ans); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String ReadNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int ReadInt => int.Parse(ReadNext()); public static long ReadLong => long.Parse(ReadNext()); public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); } static class Debug { static public void Draw2D(int[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j] % 10); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D(int[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC085A { class Program { static void Main(string[] args) { var S = Console.ReadLine(); string ans = "2018/01/" + S.Substring(8, 2); Console.WriteLine(ans); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String ReadNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int ReadInt => int.Parse(ReadNext()); public static long ReadLong => long.Parse(ReadNext()); public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); } static class Debug { static public void Draw2D(int[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j] % 10); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D(int[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 16, 31, 5, 0, 222]]
8
536
2
using System; namespace ino { class ABC84c { static void Main() { int n = int.Parse(Console.ReadLine()); int[] c = new int[n - 1]; int[] s = new int[n - 1]; int[] f = new int[n - 1]; string[] csf; for (int i = 0; i < n - 1; i++) { csf = Console.ReadLine().Split(' '); c[i] = int.Parse(csf[0]); s[i] = int.Parse(csf[1]); f[i] = int.Parse(csf[2]); } for (int i = 0; i < n - 1; i++) { int ans = 0; for (int j = i; j < n - 1; j++) { if (ans <= s[j]) { ans = s[j]; ans += c[j]; } else { if (ans % f[j] == 0) { ans += c[j]; } else { ans += f[j] - (ans - 1) % f[j]; ans += c[j]; } } } Console.WriteLine(ans); } Console.WriteLine(0); } } }
using System; namespace ino { class ABC84c { static void Main() { int n = int.Parse(Console.ReadLine()); int[] c = new int[n - 1]; int[] s = new int[n - 1]; int[] f = new int[n - 1]; string[] csf; for (int i = 0; i < n - 1; i++) { csf = Console.ReadLine().Split(' '); c[i] = int.Parse(csf[0]); s[i] = int.Parse(csf[1]); f[i] = int.Parse(csf[2]); } for (int i = 0; i < n - 1; i++) { int ans = 0; for (int j = i; j < n - 1; j++) { if (ans <= s[j]) { ans = s[j]; ans += c[j]; } else { if (ans % f[j] == 0) { ans += c[j]; } else { ans += f[j] - ans % f[j]; ans += c[j]; } } } Console.WriteLine(ans); } Console.WriteLine(0); } } }
[["-", 0, 11, 12, 16, 12, 16, 31, 23, 0, 24], ["-", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["-", 12, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 12, 16, 31, 23, 0, 25]]
8
285
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line1[0]; // var M = line1[1]; // var a = new long[M]; // var b = new long[M]; // int bridge = 0; // int[,] dag = new int[N,N]; // for (int i = 0; i < M; i++) //{ // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // a[i] = line2[0]-1; // b[i] = line2[1]-1; // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // for (int i = 0; i < M; i++) //{ // bool[] visited = new bool[N]; // dag[a[i], b[i]] = 0; // dag[b[i], a[i]] = 0; // DFS(0,visited,dag); // if (visited.Where(n => n == true).Count() != N) // { // bridge++; // } // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // Console.WriteLine(bridge); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var A = line1[0]; // var B = line1[1]; // var C = line1[2]; // var D = line1[3]; // var E = line1[4]; // var F = line1[5]; // var N = int.Parse(Console.ReadLine()); // char[] mozi = new char[N]; // long[] MARCH = new long[5]; // long cnt = 0; // for (int i = 0; i < N; i++) //{ // mozi[i] = Console.ReadLine().ToCharArray()[0]; //} // MARCH[0] = mozi.Where(n => n == 'M').Count(); // MARCH[1] = mozi.Where(n => n == 'A').Count(); // MARCH[2] = mozi.Where(n => n == 'R').Count(); // MARCH[3] = mozi.Where(n => n == 'C').Count(); // MARCH[4] = mozi.Where(n => n == 'H').Count(); // for (int i = 0; i < 3; i++) //{ // for (int j = i + 1; j < 4; j++) // { // for (int k = j + 1; k < 5; k++) // { // cnt += MARCH[i] * MARCH[j] * MARCH[k]; // } // } //} // Console.WriteLine(cnt); // var N = int.Parse(Console.ReadLine()); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int candy = 0; // int MAX = 0; // for (int i = 0; i < N; i++) //{ // for (int k = 0; k <= i; k++) // { // candy += line1[k]; // } // for (int j = N - 1; j >= i; j--) // { // candy += line2[j]; // } // MAX = Math.Max(candy,MAX); // candy = 0; //} // Console.WriteLine(MAX); // var N = int.Parse(Console.ReadLine()); // List<int[]> list = new List<int[]>(); // int t = 0; // int x = 0; // int y = 0; // for (int i = 0; i < N; i++) //{ // var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // list.Add(txy); //} // foreach (var item in list) //{ // if (item[0] - t >= Math.Abs(item[1] + item[2] - x - y)) // { // if (((item[0] - t) % 2 == 1 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 1) || // ((item[0] - t) % 2 == 0 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 0)) // { // t = item[0]; // x = item[1]; // y = item[2]; // } // else // { // Console.WriteLine("No"); // return; // } // } // else // { // Console.WriteLine("No"); // return; // } //} // Console.WriteLine("Yes"); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // if (line1[1] >= 10000) //{ // for (int i = 0; i <= line1[1]/10000; i++) // { // for (int j = 0; j <= line1[1] / 5000; j++) // { // if (10000 * i + 5000 * j + (line1[0] - i - j) * 1000 == // line1[1] && line1[0] - i - j >= 0) // { // Console.WriteLine("{0} {1} {2}",i,j,line1[0] - i - j); // return; // } // } // } //} // else //{ // for (int i = 0; i < 2; i++) // { // for (int j = 0; j <= 9; j++) // { // if (5000 * i + 1000 * j == line1[1] && i + j == line1[0]) // { // Console.WriteLine("{0} {1} {2}", 0, i, j); // return; // } // } // } //} // Console.WriteLine("{0} {1} {2}", -1, -1, -1); var N = int.Parse(Console.ReadLine()); int[,] station = new int[N, 3]; long sum = 0; for (int i = 0; i < N - 1; i++) { var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); station[i, 0] = line[0]; station[i, 1] = line[1]; station[i, 2] = line[2]; } for (int j = 0; j < N - 1; j++) { for (int i = j; i < N - 1; i++) { var F = station[i, 2]; var S = station[i, 1]; if (i == j) { sum += station[i, 0] + station[i, 1]; } else { if (sum < S) { sum = S + station[i, 0]; } else if (sum % F == 0) { sum += station[i, 0]; } else { sum += F - (sum % F) + sum + station[i, 0]; } } } Console.WriteLine(sum); sum = 0; } Console.WriteLine(sum); } public static void DFS(int v, bool[] visited, int[,] dag) { visited[v] = true; for (int i = 0; i < visited.Length; i++) { if (dag[v, i] == 0) continue; if (visited[i]) continue; DFS(i, visited, dag); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line1[0]; // var M = line1[1]; // var a = new long[M]; // var b = new long[M]; // int bridge = 0; // int[,] dag = new int[N,N]; // for (int i = 0; i < M; i++) //{ // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // a[i] = line2[0]-1; // b[i] = line2[1]-1; // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // for (int i = 0; i < M; i++) //{ // bool[] visited = new bool[N]; // dag[a[i], b[i]] = 0; // dag[b[i], a[i]] = 0; // DFS(0,visited,dag); // if (visited.Where(n => n == true).Count() != N) // { // bridge++; // } // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // Console.WriteLine(bridge); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var A = line1[0]; // var B = line1[1]; // var C = line1[2]; // var D = line1[3]; // var E = line1[4]; // var F = line1[5]; // var N = int.Parse(Console.ReadLine()); // char[] mozi = new char[N]; // long[] MARCH = new long[5]; // long cnt = 0; // for (int i = 0; i < N; i++) //{ // mozi[i] = Console.ReadLine().ToCharArray()[0]; //} // MARCH[0] = mozi.Where(n => n == 'M').Count(); // MARCH[1] = mozi.Where(n => n == 'A').Count(); // MARCH[2] = mozi.Where(n => n == 'R').Count(); // MARCH[3] = mozi.Where(n => n == 'C').Count(); // MARCH[4] = mozi.Where(n => n == 'H').Count(); // for (int i = 0; i < 3; i++) //{ // for (int j = i + 1; j < 4; j++) // { // for (int k = j + 1; k < 5; k++) // { // cnt += MARCH[i] * MARCH[j] * MARCH[k]; // } // } //} // Console.WriteLine(cnt); // var N = int.Parse(Console.ReadLine()); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int candy = 0; // int MAX = 0; // for (int i = 0; i < N; i++) //{ // for (int k = 0; k <= i; k++) // { // candy += line1[k]; // } // for (int j = N - 1; j >= i; j--) // { // candy += line2[j]; // } // MAX = Math.Max(candy,MAX); // candy = 0; //} // Console.WriteLine(MAX); // var N = int.Parse(Console.ReadLine()); // List<int[]> list = new List<int[]>(); // int t = 0; // int x = 0; // int y = 0; // for (int i = 0; i < N; i++) //{ // var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // list.Add(txy); //} // foreach (var item in list) //{ // if (item[0] - t >= Math.Abs(item[1] + item[2] - x - y)) // { // if (((item[0] - t) % 2 == 1 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 1) || // ((item[0] - t) % 2 == 0 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 0)) // { // t = item[0]; // x = item[1]; // y = item[2]; // } // else // { // Console.WriteLine("No"); // return; // } // } // else // { // Console.WriteLine("No"); // return; // } //} // Console.WriteLine("Yes"); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // if (line1[1] >= 10000) //{ // for (int i = 0; i <= line1[1]/10000; i++) // { // for (int j = 0; j <= line1[1] / 5000; j++) // { // if (10000 * i + 5000 * j + (line1[0] - i - j) * 1000 == // line1[1] && line1[0] - i - j >= 0) // { // Console.WriteLine("{0} {1} {2}",i,j,line1[0] - i - j); // return; // } // } // } //} // else //{ // for (int i = 0; i < 2; i++) // { // for (int j = 0; j <= 9; j++) // { // if (5000 * i + 1000 * j == line1[1] && i + j == line1[0]) // { // Console.WriteLine("{0} {1} {2}", 0, i, j); // return; // } // } // } //} // Console.WriteLine("{0} {1} {2}", -1, -1, -1); var N = int.Parse(Console.ReadLine()); int[,] station = new int[N, 3]; long sum = 0; for (int i = 0; i < N - 1; i++) { var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); station[i, 0] = line[0]; station[i, 1] = line[1]; station[i, 2] = line[2]; } for (int j = 0; j < N - 1; j++) { for (int i = j; i < N - 1; i++) { var F = station[i, 2]; var S = station[i, 1]; if (i == j) { sum += station[i, 0] + station[i, 1]; } else { if (sum < S) { sum = S + station[i, 0]; } else if (sum % F == 0) { sum += station[i, 0]; } else { sum += F - (sum % F) + station[i, 0]; } } } Console.WriteLine(sum); sum = 0; } Console.WriteLine(sum); } public static void DFS(int v, bool[] visited, int[,] dag) { visited[v] = true; for (int i = 0; i < visited.Length; i++) { if (dag[v, i] == 0) continue; if (visited[i]) continue; DFS(i, visited, dag); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } }
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
8
814
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var C = new int[N - 1]; var S = new int[N - 1]; var F = new int[N - 1]; for (int i = 0; i < N - 1; i++) { var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); C[i] = input[0]; S[i] = input[1]; F[i] = input[2]; } for (int i = 0; i < N - 1; i++) { var ans = S[i] + C[i]; for (int j = i + 1; j < N - 1; j++) { if (ans < S[j]) { ans = S[j] + C[j]; } else { var tmp = ans - S[j]; if (tmp % F[j] == 0) { ans = S[j] + F[j] * (tmp / F[j]) + C[j]; } else { ans = S[j] + F[j] * (tmp / F[j]) + tmp % F[j] + C[j]; } } } Console.WriteLine(ans); } Console.WriteLine(0); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var C = new int[N - 1]; var S = new int[N - 1]; var F = new int[N - 1]; for (int i = 0; i < N - 1; i++) { var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); C[i] = input[0]; S[i] = input[1]; F[i] = input[2]; } for (int i = 0; i < N - 1; i++) { var ans = S[i] + C[i]; for (int j = i + 1; j < N - 1; j++) { if (ans < S[j]) { ans = S[j] + C[j]; } else { var tmp = ans - S[j]; if (tmp % F[j] == 0) { ans = S[j] + F[j] * (tmp / F[j]) + C[j]; } else { ans = S[j] + F[j] * (tmp / F[j]) + F[j] + C[j]; } } } Console.WriteLine(ans); } Console.WriteLine(0); } } }
[["-", 0, 11, 12, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 11, 12, 16, 31, 16, 12, 16, 17, 109]]
8
349
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC084C { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); int[] C = new int[N]; int[] S = new int[N]; int[] F = new int[N]; for (int i = 0; i < N - 1; i++) { var line = Console.ReadLine().Split().Select(int.Parse).ToArray(); C[i] = line[0]; S[i] = line[1]; F[i] = line[2]; } for (int j = 0; j < N - 1; j++) { int ans = 0; for (int i = j; i < N - 1; i++) { if (ans < S[i]) ans = S[i]; else { int n = (ans - S[i]) / F[i]; ans = S[i] + n * F[i]; } ans += C[i]; } Console.WriteLine(ans); } Console.WriteLine(0); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC084C { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); int[] C = new int[N]; int[] S = new int[N]; int[] F = new int[N]; for (int i = 0; i < N - 1; i++) { var line = Console.ReadLine().Split().Select(int.Parse).ToArray(); C[i] = line[0]; S[i] = line[1]; F[i] = line[2]; } for (int j = 0; j < N - 1; j++) { int ans = 0; for (int i = j; i < N - 1; i++) { if (ans <= S[i]) ans = S[i]; else { int n = (ans - S[i] - 1) / F[i] + 1; ans = S[i] + n * F[i]; } ans += C[i]; } Console.WriteLine(ans); } Console.WriteLine(0); Console.ReadKey(); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
283
6
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { this.Ekicount = int.Parse(Reader.ReadLine()); this.EkiInfo = new int [this.Ekicount][]; for (int i = 0; i < Ekicount - 1; i++) { this.EkiInfo[i] = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); } List<long> ans = new List<long>(); for (int i = this.Ekicount - 1; i >= 0; i--) { ans.Add(GetAns(i, 0)); } ans.Reverse(); StringBuilder txt = new StringBuilder(); ans.ForEach(a => txt.AppendLine(a.ToString())); Console.Write(txt.ToString()); } private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int, Dictionary<int, long>>(); private long GetAns(int ekiNum, int startTime) { if (ekiNum == this.Ekicount - 1) { return startTime; } int first = this.EkiInfo[ekiNum][1]; int interval = this.EkiInfo[ekiNum][2]; int nextMove = this.EkiInfo[ekiNum][0]; int subStart = Math.Max(startTime, first); if (subStart % interval != 0) { subStart += (subStart % interval); } if (!dic.ContainsKey(ekiNum)) { dic.Add(ekiNum, new Dictionary<int, long>()); } if (dic[ekiNum].ContainsKey(subStart)) { return dic[ekiNum][subStart]; } long ans = GetAns(ekiNum + 1, subStart + nextMove); dic[ekiNum][subStart] = ans; return ans; } private int[][] EkiInfo; private int Ekicount; public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 3 6 5 1 1 10 1 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { this.Ekicount = int.Parse(Reader.ReadLine()); this.EkiInfo = new int [this.Ekicount][]; for (int i = 0; i < Ekicount - 1; i++) { this.EkiInfo[i] = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); } List<long> ans = new List<long>(); for (int i = this.Ekicount - 1; i >= 0; i--) { ans.Add(GetAns(i, 0)); } ans.Reverse(); StringBuilder txt = new StringBuilder(); ans.ForEach(a => txt.AppendLine(a.ToString())); Console.Write(txt.ToString()); } private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int, Dictionary<int, long>>(); private long GetAns(int ekiNum, int startTime) { if (ekiNum == this.Ekicount - 1) { return startTime; } int first = this.EkiInfo[ekiNum][1]; int interval = this.EkiInfo[ekiNum][2]; int nextMove = this.EkiInfo[ekiNum][0]; int subStart = Math.Max(startTime, first); if (subStart % interval != 0) { subStart += interval - (subStart % interval); } if (!dic.ContainsKey(ekiNum)) { dic.Add(ekiNum, new Dictionary<int, long>()); } if (dic[ekiNum].ContainsKey(subStart)) { return dic[ekiNum][subStart]; } long ans = GetAns(ekiNum + 1, subStart + nextMove); dic[ekiNum][subStart] = ans; return ans; } private int[][] EkiInfo; private int Ekicount; public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 3 6 5 1 1 10 1 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33]]
8
537
2
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; class hawawa { static Printer sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main() { Console.SetOut(sw); solve(); Console.Out.Flush(); } static void solve() { Scanner scanner = new Scanner(); int n = scanner.nextInt(); Tuple<int, int, int>[] info = new Tuple<int, int, int>[n - 1]; for (int i = 0; i < n - 1; i++) { int c = scanner.nextInt(); int s = scanner.nextInt(); int f = scanner.nextInt(); info[i] = Tuple.Create(c, s, f); } long[] ans = new long[n]; for (int i = n - 1; i >= 0; i--) { int now = i; long t = 0; while (now != n - 1) { int start = info[now].Item2; int use = info[now].Item1; int f = info[now].Item3; if (t <= start) { t = start + use; now++; continue; } t -= start; if (t % f == 0) { t += start + use; } else { t += (t / f + 1) * f + start + use; } now++; } ans[i] = t; } foreach (var i in ans) { Console.WriteLine(i); } } } 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()); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; class hawawa { static Printer sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main() { Console.SetOut(sw); solve(); Console.Out.Flush(); } static void solve() { Scanner scanner = new Scanner(); int n = scanner.nextInt(); Tuple<int, int, int>[] info = new Tuple<int, int, int>[n - 1]; for (int i = 0; i < n - 1; i++) { int c = scanner.nextInt(); int s = scanner.nextInt(); int f = scanner.nextInt(); info[i] = Tuple.Create(c, s, f); } long[] ans = new long[n]; for (int i = n - 1; i >= 0; i--) { int now = i; long t = 0; while (now != n - 1) { int start = info[now].Item2; int use = info[now].Item1; int f = info[now].Item3; if (t <= start) { t = start + use; now++; continue; } t -= start; if (t % f == 0) { t += start + use; } else { t = (t / f + 1) * f + start + use; } now++; } ans[i] = t; } foreach (var i in ans) { Console.WriteLine(i); } } } 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()); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } }
[["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32]]
8
2,232
2
using System; using System.Linq; namespace ABC084 { class D { static void Main(string[] args) { int Q = int.Parse(Console.ReadLine()); int[] l = new int[Q]; int[] r = new int[Q]; string[] input; for (int i = 0; i < Q; i++) { input = Console.ReadLine().Split(' '); l[i] = int.Parse(input[0]); r[i] = int.Parse(input[1]); } int Max = r.Max(); int[] s = new int[Max]; s[0] = 0; for (int i = 1; i < Max; i++) { if ((i % 2) != 0) { // i が奇数 if (IsPrimeNumber(i) && IsPrimeNumber((i + 1) / 2)) { s[i] = s[i - 1] + 1; } } if (s[i] == 0) { s[i] = s[i - 1]; } } int k = 0; for (int j = 0; j < Q; j++) { k = s[r[j] - 1] - s[l[j] - 1]; if (r[j] == l[j] && (IsPrimeNumber(r[j]) && IsPrimeNumber((r[j] + 1) / 2))) { k = 1; } Console.WriteLine(k); } } static bool IsPrimeNumber(int number) { double i = number; // 平方根を求める double x = Math.Sqrt(i); // 平方根以下の値で割り切れるのか確認する // 最小値は2 for (double j = 2; j <= x; j++) { if ((number % j) == 0) { return false; } } if (number == 1) { return false; } return true; } } }
using System; using System.Linq; namespace ABC084 { class D { static void Main(string[] args) { int Q = int.Parse(Console.ReadLine()); int[] l = new int[Q]; int[] r = new int[Q]; string[] input; for (int i = 0; i < Q; i++) { input = Console.ReadLine().Split(' '); l[i] = int.Parse(input[0]); r[i] = int.Parse(input[1]); } int Max = r.Max(); int[] s = new int[Max + 1]; s[0] = 0; for (int i = 1; i <= Max; i++) { if ((i % 2) != 0) { // i が奇数 if (IsPrimeNumber(i) && IsPrimeNumber((i + 1) / 2)) { s[i] = s[i - 1] + 1; } } if (s[i] == 0) { s[i] = s[i - 1]; } } int k = 0; for (int j = 0; j < Q; j++) { k = s[r[j]] - s[l[j] - 1]; if (r[j] == l[j] && (IsPrimeNumber(r[j]) && IsPrimeNumber((r[j] + 1) / 2))) { k = 1; } Console.WriteLine(k); } } static bool IsPrimeNumber(int number) { double i = number; // 平方根を求める double x = Math.Sqrt(i); // 平方根以下の値で割り切れるのか確認する // 最小値は2 for (double j = 2; j <= x; j++) { if ((number % j) == 0) { return false; } } if (number == 1) { return false; } return true; } } }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
406
6
using System; using System.Linq; using System.Collections.Generic; using System.Text; namespace Program { public class ABC084D { static public void Main(string[] args) { var prime = new HashSet<int>(Prime(10000000)); var sumary = new int[100001]; foreach (var item in prime) { if (prime.Contains((item + 1) / 2)) { sumary[item] = 1; } } for (int i = 1; i <= 100000; ++i) { sumary[i] += sumary[i - 1]; } var Q = NextInt; for (int i = 0; i < Q; ++i) { var l = NextInt; var r = NextInt; Console.WriteLine(sumary[r] - sumary[l - 1]); } } static class Console_ { private static Queue<string> param = new Queue<string>(); public static int NextInt() => int.Parse(NextString()); public static long NextLong() => long.Parse(NextString()); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => Console_.NextInt(); static long NextLong => Console_.NextLong(); static string NextString => Console_.NextString(); static IEnumerable<int> Prime(int x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (int)(Math.Sqrt(x) / 2); for (int i = 1; i <= max; ++i) { if (!table[i]) { var add = 2 * i + 1; yield return add; for (int j = 2 * i * (i + 1); j <= halfx; j += add) { table[j] = true; } } } for (int i = max + 1; i <= halfx; ++i) { if (!table[i]) yield return 2 * i + 1; } } } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; namespace Program { public class ABC084D { static public void Main(string[] args) { var prime = new HashSet<int>(Prime(100000)); var sumary = new int[100001]; foreach (var item in prime) { if (prime.Contains((item + 1) / 2)) { sumary[item] = 1; } } for (int i = 1; i <= 100000; ++i) { sumary[i] += sumary[i - 1]; } var Q = NextInt; for (int i = 0; i < Q; ++i) { var l = NextInt; var r = NextInt; Console.WriteLine(sumary[r] - sumary[l - 1]); } } static class Console_ { private static Queue<string> param = new Queue<string>(); public static int NextInt() => int.Parse(NextString()); public static long NextLong() => long.Parse(NextString()); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => Console_.NextInt(); static long NextLong => Console_.NextLong(); static string NextString => Console_.NextString(); static IEnumerable<int> Prime(int x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (int)(Math.Sqrt(x) / 2); for (int i = 1; i <= max; ++i) { if (!table[i]) { var add = 2 * i + 1; yield return add; for (int j = 2 * i * (i + 1); j <= halfx; j += add) { table[j] = true; } } } for (int i = max + 1; i <= halfx; ++i) { if (!table[i]) yield return 2 * i + 1; } } } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203]]
8
470
2
using System; using System.Linq; using System.Collections.Generic; using System.Text; namespace Program { public class ABC084D { static public void Main(string[] args) { var table = new bool[100001]; table[0] = table[1] = true; for (int i = 2; i <= 316; ++i) { if (!table[i]) { for (int j = i * i; j <= 316; j += i) { table[j] = true; } } } var sumary = new int[100001]; for (int i = 1; i <= 100000; ++i) { if (!table[i] && ((i + 1) % 2 == 0) && !table[(i + 1) / 2]) { sumary[i] = 1; } sumary[i] += sumary[i - 1]; } var Q = NextInt; for (int i = 0; i < Q; ++i) { var l = NextInt; var r = NextInt; Console.WriteLine(sumary[r] - sumary[l - 1]); } } static class Console_ { private static Queue<string> param = new Queue<string>(); public static int NextInt() => int.Parse(NextString()); public static long NextLong() => long.Parse(NextString()); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => Console_.NextInt(); static long NextLong => Console_.NextLong(); static string NextString => Console_.NextString(); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; namespace Program { public class ABC084D { static public void Main(string[] args) { var table = new bool[100001]; table[0] = table[1] = true; for (int i = 2; i <= 316; ++i) { if (!table[i]) { for (int j = i * i; j <= 100000; j += i) { table[j] = true; } } } var sumary = new int[100001]; for (int i = 1; i <= 100000; ++i) { if (!table[i] && ((i + 1) % 2 == 0) && !table[(i + 1) / 2]) { sumary[i] = 1; } sumary[i] += sumary[i - 1]; } var Q = NextInt; for (int i = 0; i < Q; ++i) { var l = NextInt; var r = NextInt; Console.WriteLine(sumary[r] - sumary[l - 1]); } } static class Console_ { private static Queue<string> param = new Queue<string>(); public static int NextInt() => int.Parse(NextString()); public static long NextLong() => long.Parse(NextString()); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => Console_.NextInt(); static long NextLong => Console_.NextLong(); static string NextString => Console_.NextString(); } }
[["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 203]]
8
371
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC084D { class Program { static void Main(string[] args) { bool[] primes = Enumerable.Repeat(true, 100001).ToArray(); primes[0] = false; primes[1] = false; for (int i = 2; i < 100001; i++) { if (primes[i]) { int num = i * 2; while (num < 100001) { primes[num] = false; num += i; } } } int[] like2017Nums = new int[100001]; int likeNum = 0; for (int i = 0; i < 100001; i++) { if (primes[i] && primes[(i + 1) / 2]) { likeNum++; // 2は外れるので大丈夫 like2017Nums[i] = likeNum; } } int Q = int.Parse(Console.ReadLine()); for (int i = 0; i < Q; i++) { int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int l = input[0]; int r = input[1]; Console.WriteLine(like2017Nums[r] - like2017Nums[l - 1]); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC084D { class Program { static void Main(string[] args) { bool[] primes = Enumerable.Repeat(true, 100001).ToArray(); primes[0] = false; primes[1] = false; for (int i = 2; i < 100001; i++) { if (primes[i]) { int num = i * 2; while (num < 100001) { primes[num] = false; num += i; } } } int[] like2017Nums = new int[100001]; int likeNum = 0; for (int i = 0; i < 100001; i++) { if (primes[i] && primes[(i + 1) / 2]) { likeNum++; // 2は外れるので大丈夫 } like2017Nums[i] = likeNum; } int Q = int.Parse(Console.ReadLine()); for (int i = 0; i < Q; i++) { int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int l = input[0]; int r = input[1]; Console.WriteLine(like2017Nums[r] - like2017Nums[l - 1]); } } } }
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
289
2
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; class hawawa { static Printer sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main() { Console.SetOut(sw); solve(); Console.Out.Flush(); } static void solve() { Scanner scanner = new Scanner(); int q = scanner.nextInt(); int[] cnt = new int[100001]; bool[] check = Enumerable.Repeat(true, 100000).ToArray(); check[0] = check[1] = false; for (int i = 2; i * i <= 100000; i += 2) { if (check[i]) { for (int j = i * i; j <= 100000; j += i) { check[j] = false; } } if (i == 2) { i--; } } cnt[0] = 0; for (int i = 0; i < 100000; i++) { if (i % 2 == 1 && check[i] && check[(i + 1) / 2]) { cnt[i + 1] = cnt[i] + 1; } else { cnt[i + 1] = cnt[i]; } } for (int i = 0; i < q; i++) { int l = scanner.nextInt(); int r = scanner.nextInt(); Console.WriteLine(cnt[r + 1] - cnt[l]); } } } 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()); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; class hawawa { static Printer sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main() { Console.SetOut(sw); solve(); Console.Out.Flush(); } static void solve() { Scanner scanner = new Scanner(); int q = scanner.nextInt(); int[] cnt = new int[100001]; bool[] check = Enumerable.Repeat(true, 100001).ToArray(); check[0] = check[1] = false; for (int i = 2; i * i <= 100000; i += 2) { if (check[i]) { for (int j = i * i; j <= 100000; j += i) { check[j] = false; } } if (i == 2) { i--; } } cnt[0] = 0; for (int i = 0; i < 100000; i++) { if (i % 2 == 1 && check[i] && check[(i + 1) / 2]) { cnt[i + 1] = cnt[i] + 1; } else { cnt[i + 1] = cnt[i]; } } for (int i = 0; i < q; i++) { int l = scanner.nextInt(); int r = scanner.nextInt(); Console.WriteLine(cnt[r + 1] - cnt[l]); } } } 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()); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } }
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203]]
8
2,216
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var A = cin.ReadInt; var B = cin.ReadInt; var C = cin.ReadInt; var D = cin.ReadInt; if (A + B < C + D) WriteLine("Left"); if (A + B == C + D) WriteLine("Balanced"); if (A + B > C + D) WriteLine("Right"); } public void Display(char[] array) { var txt = ""; foreach (var item in array) { txt += " " + item; } WriteLine("{0}", txt); } public void Display(int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0}", txt); } public void Display(int index, int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0} : {1}", index, txt); } public void Display(List<int>[] list) { for (int i = 0; i < list.Length; i++) { Display(i, list[i].ToArray()); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } struct ModInt { const int M = 1000000007; public long V; public ModInt(long v) { V = (v %= M) < 0 ? v + M : v; } public static implicit operator ModInt(long v) => new ModInt(v); public static ModInt operator +(ModInt x) => x; public static ModInt operator -(ModInt x) => -x.V; public static ModInt operator +(ModInt x, ModInt y) => x.V + y.V; public static ModInt operator -(ModInt x, ModInt y) => x.V - y.V; public static ModInt operator *(ModInt x, ModInt y) => x.V * y.V; public static ModInt operator /(ModInt x, ModInt y) => x.V * y.Inv(); public ModInt Pow(int i) => MPow(V, i); public ModInt Inv() => MPow(V, M - 2); public override string ToString() => $"{V}"; static long MPow(long b, int i) { for (var r = 1L;; b = b * b % M) { if (i % 2 > 0) r = r * b % M; if ((i /= 2) < 1) return r; } } public static long MFactorial(int n) { for (long x = 1, i = 1;; x = x * ++i % M) if (i >= n) return x; } public static long MNpr(int n, int r) { if (n < r) return 0; for (long x = 1, i = n - r;; x = x * ++i % M) if (i >= n) return x; } public static ModInt MNcr(int n, int r) => n < r ? 0 : n - r < r ? MNcr(n, n - r) : (ModInt)MNpr(n, r) / MFactorial(r); } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var A = cin.ReadInt; var B = cin.ReadInt; var C = cin.ReadInt; var D = cin.ReadInt; if (A + B > C + D) WriteLine("Left"); if (A + B == C + D) WriteLine("Balanced"); if (A + B < C + D) WriteLine("Right"); } public void Display(char[] array) { var txt = ""; foreach (var item in array) { txt += " " + item; } WriteLine("{0}", txt); } public void Display(int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0}", txt); } public void Display(int index, int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0} : {1}", index, txt); } public void Display(List<int>[] list) { for (int i = 0; i < list.Length; i++) { Display(i, list[i].ToArray()); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } struct ModInt { const int M = 1000000007; public long V; public ModInt(long v) { V = (v %= M) < 0 ? v + M : v; } public static implicit operator ModInt(long v) => new ModInt(v); public static ModInt operator +(ModInt x) => x; public static ModInt operator -(ModInt x) => -x.V; public static ModInt operator +(ModInt x, ModInt y) => x.V + y.V; public static ModInt operator -(ModInt x, ModInt y) => x.V - y.V; public static ModInt operator *(ModInt x, ModInt y) => x.V * y.V; public static ModInt operator /(ModInt x, ModInt y) => x.V * y.Inv(); public ModInt Pow(int i) => MPow(V, i); public ModInt Inv() => MPow(V, M - 2); public override string ToString() => $"{V}"; static long MPow(long b, int i) { for (var r = 1L;; b = b * b % M) { if (i % 2 > 0) r = r * b % M; if ((i /= 2) < 1) return r; } } public static long MFactorial(int n) { for (long x = 1, i = 1;; x = x * ++i % M) if (i >= n) return x; } public static long MNpr(int n, int r) { if (n < r) return 0; for (long x = 1, i = n - r;; x = x * ++i % M) if (i >= n) return x; } public static ModInt MNcr(int n, int r) => n < r ? 0 : n - r < r ? MNcr(n, n - r) : (ModInt)MNpr(n, r) / MFactorial(r); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
1,102
4
using System; using System.Collections.Generic; using System.Linq; namespace easy_Atcoder { class Program { static void Main(string[] args) { int[] ABCD = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int left = ABCD[0] + ABCD[1]; int right = ABCD[2] + ABCD[3]; if (left > right) { Console.WriteLine("Left"); } else if (left < right) { Console.WriteLine("Right"); } else { Console.WriteLine("Balaced"); } } // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse); // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // long N = NK[0]; // long K = NK[1]; // long K = long.Parse(Console.ReadLine()); // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // string S = Console.ReadLine(); // int x = int.Parse(Console.ReadLine()); // int b = int.Parse(Console.ReadLine()); // int N = int.Parse(Console.ReadLine()); // float N = float.Parse(Console.ReadLine()); // string c = Console.ReadLine(); // string B = Console.ReadLine(); // string[] s = Console.ReadLine().Split(); // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), // Console.ReadLine() }).Select(float.Parse); float[] a = // Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X = // Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new // int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[] // s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new // Dictionary<long,long>(); for(int i=0;i<s[0];i++){ // long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];} // else{hs.Add(q[0],q[1]);} // } // //最小公倍数 // static long Lcm(long a, long b) // { // return a/Gcd(a,b)*b; // } // //最大公約数 // static long Gcd(long m, long n) // { // if(n==0)return m; // return Gcd(n,m%n); // } } }
using System; using System.Collections.Generic; using System.Linq; namespace easy_Atcoder { class Program { static void Main(string[] args) { int[] ABCD = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int left = ABCD[0] + ABCD[1]; int right = ABCD[2] + ABCD[3]; if (left > right) { Console.WriteLine("Left"); } else if (left < right) { Console.WriteLine("Right"); } else { Console.WriteLine("Balanced"); } } // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse); // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // long N = NK[0]; // long K = NK[1]; // long K = long.Parse(Console.ReadLine()); // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // string S = Console.ReadLine(); // int x = int.Parse(Console.ReadLine()); // int b = int.Parse(Console.ReadLine()); // int N = int.Parse(Console.ReadLine()); // float N = float.Parse(Console.ReadLine()); // string c = Console.ReadLine(); // string B = Console.ReadLine(); // string[] s = Console.ReadLine().Split(); // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), // Console.ReadLine() }).Select(float.Parse); float[] a = // Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X = // Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new // int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[] // s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new // Dictionary<long,long>(); for(int i=0;i<s[0];i++){ // long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];} // else{hs.Add(q[0],q[1]);} // } // //最小公倍数 // static long Lcm(long a, long b) // { // return a/Gcd(a,b)*b; // } // //最大公約数 // static long Gcd(long m, long n) // { // if(n==0)return m; // return Gcd(n,m%n); // } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
167
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { var cin = GetIntArray(); var left = cin[0] + cin[1]; var right = cin[2] + cin[3]; var ans = left > right ? "Left" : left == right ? "Balanced" : "Rigth"; Console.Write(ans); } static public string GetStr() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static 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); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { var cin = GetIntArray(); var left = cin[0] + cin[1]; var right = cin[2] + cin[3]; var ans = left > right ? "Left" : left == right ? "Balanced" : "Right"; Console.Write(ans); } static public string GetStr() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static 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); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } } }
[["-", 0, 212, 0, 41, 75, 41, 75, 5, 0, 222], ["+", 0, 212, 0, 41, 75, 41, 75, 5, 0, 222]]
8
657
2
using System; class Program { static void Main(string[] args) { var abcd = Console.ReadLine().Split(' '); var a = int.Parse(abcd[0]); var b = int.Parse(abcd[1]); var c = int.Parse(abcd[2]); var d = int.Parse(abcd[3]); if (a + b > c + d) { Console.WriteLine("Left"); } else if (a + b < c + d) { Console.WriteLine("Right"); } else { Console.WriteLine("Balance"); } } }
using System; class Program { static void Main(string[] args) { var abcd = Console.ReadLine().Split(' '); var a = int.Parse(abcd[0]); var b = int.Parse(abcd[1]); var c = int.Parse(abcd[2]); var d = int.Parse(abcd[3]); if (a + b > c + d) { Console.WriteLine("Left"); } else if (a + b < c + d) { Console.WriteLine("Right"); } else { Console.WriteLine("Balanced"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
141
2
using System; using System.Linq; class Program { public static void Main(string[] args) { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (s[0] + s[1] > s[2] + s[3]) Console.WriteLine("Left"); else if (s[0] + s[1] < s[2] + s[3]) Console.WriteLine("Rigth"); else Console.WriteLine("Balanced"); } }
using System; using System.Linq; class Program { public static void Main(string[] args) { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (s[0] + s[1] > s[2] + s[3]) Console.WriteLine("Left"); else if (s[0] + s[1] < s[2] + s[3]) Console.WriteLine("Right"); else Console.WriteLine("Balanced"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
123
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class aaaa { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int C = int.Parse(input[2]); int D = int.Parse(input[3]); int L = A + B; int R = C + D; if (L > R) { Console.WriteLine("Left"); } else if (L == R) { Console.WriteLine("balanced"); } else { Console.WriteLine("Right"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class aaaa { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int C = int.Parse(input[2]); int D = int.Parse(input[3]); int L = A + B; int R = C + D; if (L > R) { Console.WriteLine("Left"); } else if (L == R) { Console.WriteLine("Balanced"); } else { Console.WriteLine("Right"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
177
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProgrammingContest { class MainClass : IDisposable { Scanner sc; Writer wr; string backPath = ".."; char dirSep = System.IO.Path.DirectorySeparatorChar; string inFilePath = string.Empty; string outFilePath = string.Empty; public MainClass() { this.inFilePath = this.backPath + this.dirSep + this.backPath + this.dirSep + "in.txt"; this.outFilePath = this.backPath + this.dirSep + this.backPath + this.dirSep + "out.txt"; this.wr = new Writer(this.isReactive); // this.wr = new Writer(this.outFilePath); #if DEBUG if (!this.isReactive) { this.sc = new Scanner(this.inFilePath); } else { this.sc = new Scanner(); } #else this.sc = new Scanner(); #endif } static void Main(string[] args) { using (var mainClass = new MainClass()) { mainClass.Solve(); } } public void Dispose() { if (this.sc != null) { this.sc.Dispose(); this.sc = null; } if (this.wr != null) { this.wr.Dispose(); this.wr = null; } } void MakeTestCase() { Random rand = new Random(); if (this.wr != null) { this.wr.Dispose(); } this.wr = new Writer(inFilePath); } void Solve() { int ab = sc.NextInt + sc.NextInt; int cd = sc.NextInt + sc.NextInt; wr.WriteLine(ab < cd ? "Left" : ab == cd ? "Balanced" : "Right"); } bool isReactive = false; // TODO: reactive check !! } class Writer : IDisposable { private System.IO.TextWriter writer; private StringBuilder sb; private bool isReactive; public Writer(string path) : this(new System.IO.StreamWriter(path)) {} public Writer(bool isReactive) : this(null, isReactive) {} public Writer(System.IO.TextWriter writer = null, bool isReactive = false) { this.writer = (writer ?? Console.Out); this.isReactive = isReactive; if (!this.isReactive) { this.sb = new StringBuilder(); } } public void Dispose() { if (!this.isReactive) { this.writer.Write(sb.ToString()); } if (!this.writer.Equals(Console.Out)) { this.writer.Dispose(); } } public void Write(object val) { if (this.isReactive) { this.writer.Write(val.ToString()); this.writer.Flush(); } else { this.sb.Append(val.ToString()); } } public void Write(string format, params object[] vals) { if (this.isReactive) { this.writer.Write(format, vals); this.writer.Flush(); } else { this.sb.AppendFormat(format, vals); } } public void WriteLine(object val = null) { this.Write((val ?? string.Empty).ToString() + System.Environment.NewLine); } public void WriteLine(int val) { this.WriteLine(val.ToString()); } public void WriteLine(long val) { this.WriteLine(val.ToString()); } public void WriteLine(string val) { this.WriteLine((object)val); } public void WriteLine(string format, params object[] vals) { this.Write(format + System.Environment.NewLine, vals); } } class Scanner : IDisposable { private Queue<string> buffer; private char[] sep; private System.IO.TextReader reader; public Scanner(string path, char[] sep = null) : this(new System.IO.StreamReader(path), sep) {} public Scanner(System.IO.TextReader reader = null, char[] sep = null) { this.buffer = new Queue<string>(); this.sep = (sep ?? new char[] { ' ' }); this.reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.buffer.Count == 0 && this.reader.Peek() != -1) { string str = string.Empty; for (; string.IsNullOrEmpty(str); str = this.reader.ReadLine()) ; str.Split(this.sep).ToList().ForEach(el => this.buffer.Enqueue(el)); } } public void Dispose() { if (!this.reader.Equals(Console.In)) { this.reader.Dispose(); } } public string Next { get { this.CheckBuffer(); return this.buffer.Dequeue(); } } public string[] GetStringArray(int N) { return Enumerable.Range(0, N).Select(e => this.Next).ToArray(); } public int NextInt { get { return int.Parse(this.Next); } } public int[] GetIntArray(int N) { return Enumerable.Range(0, N).Select(e => this.NextInt).ToArray(); } public double NextDouble { get { return double.Parse(this.Next); } } public double[] GetdoubleArray(int N) { return Enumerable.Range(0, N).Select(e => this.NextDouble).ToArray(); } public long NextLong { get { return long.Parse(this.Next); } } public long[] GetLongArray(int N) { return Enumerable.Range(0, N).Select(e => this.NextLong).ToArray(); } public bool IsEnd { get { this.CheckBuffer(); return this.buffer.Count == 0; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProgrammingContest { class MainClass : IDisposable { Scanner sc; Writer wr; string backPath = ".."; char dirSep = System.IO.Path.DirectorySeparatorChar; string inFilePath = string.Empty; string outFilePath = string.Empty; public MainClass() { this.inFilePath = this.backPath + this.dirSep + this.backPath + this.dirSep + "in.txt"; this.outFilePath = this.backPath + this.dirSep + this.backPath + this.dirSep + "out.txt"; this.wr = new Writer(this.isReactive); // this.wr = new Writer(this.outFilePath); #if DEBUG if (!this.isReactive) { this.sc = new Scanner(this.inFilePath); } else { this.sc = new Scanner(); } #else this.sc = new Scanner(); #endif } static void Main(string[] args) { using (var mainClass = new MainClass()) { mainClass.Solve(); } } public void Dispose() { if (this.sc != null) { this.sc.Dispose(); this.sc = null; } if (this.wr != null) { this.wr.Dispose(); this.wr = null; } } void MakeTestCase() { Random rand = new Random(); if (this.wr != null) { this.wr.Dispose(); } this.wr = new Writer(inFilePath); } void Solve() { int ab = sc.NextInt + sc.NextInt; int cd = sc.NextInt + sc.NextInt; wr.WriteLine(ab > cd ? "Left" : ab == cd ? "Balanced" : "Right"); } bool isReactive = false; // TODO: reactive check !! } class Writer : IDisposable { private System.IO.TextWriter writer; private StringBuilder sb; private bool isReactive; public Writer(string path) : this(new System.IO.StreamWriter(path)) {} public Writer(bool isReactive) : this(null, isReactive) {} public Writer(System.IO.TextWriter writer = null, bool isReactive = false) { this.writer = (writer ?? Console.Out); this.isReactive = isReactive; if (!this.isReactive) { this.sb = new StringBuilder(); } } public void Dispose() { if (!this.isReactive) { this.writer.Write(sb.ToString()); } if (!this.writer.Equals(Console.Out)) { this.writer.Dispose(); } } public void Write(object val) { if (this.isReactive) { this.writer.Write(val.ToString()); this.writer.Flush(); } else { this.sb.Append(val.ToString()); } } public void Write(string format, params object[] vals) { if (this.isReactive) { this.writer.Write(format, vals); this.writer.Flush(); } else { this.sb.AppendFormat(format, vals); } } public void WriteLine(object val = null) { this.Write((val ?? string.Empty).ToString() + System.Environment.NewLine); } public void WriteLine(int val) { this.WriteLine(val.ToString()); } public void WriteLine(long val) { this.WriteLine(val.ToString()); } public void WriteLine(string val) { this.WriteLine((object)val); } public void WriteLine(string format, params object[] vals) { this.Write(format + System.Environment.NewLine, vals); } } class Scanner : IDisposable { private Queue<string> buffer; private char[] sep; private System.IO.TextReader reader; public Scanner(string path, char[] sep = null) : this(new System.IO.StreamReader(path), sep) {} public Scanner(System.IO.TextReader reader = null, char[] sep = null) { this.buffer = new Queue<string>(); this.sep = (sep ?? new char[] { ' ' }); this.reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.buffer.Count == 0 && this.reader.Peek() != -1) { string str = string.Empty; for (; string.IsNullOrEmpty(str); str = this.reader.ReadLine()) ; str.Split(this.sep).ToList().ForEach(el => this.buffer.Enqueue(el)); } } public void Dispose() { if (!this.reader.Equals(Console.In)) { this.reader.Dispose(); } } public string Next { get { this.CheckBuffer(); return this.buffer.Dequeue(); } } public string[] GetStringArray(int N) { return Enumerable.Range(0, N).Select(e => this.Next).ToArray(); } public int NextInt { get { return int.Parse(this.Next); } } public int[] GetIntArray(int N) { return Enumerable.Range(0, N).Select(e => this.NextInt).ToArray(); } public double NextDouble { get { return double.Parse(this.Next); } } public double[] GetdoubleArray(int N) { return Enumerable.Range(0, N).Select(e => this.NextDouble).ToArray(); } public long NextLong { get { return long.Parse(this.Next); } } public long[] GetLongArray(int N) { return Enumerable.Range(0, N).Select(e => this.NextLong).ToArray(); } public bool IsEnd { get { this.CheckBuffer(); return this.buffer.Count == 0; } } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47]]
8
1,240
2
using System; namespace AtCoder_1223_1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]); if (a + b < c + d) { Console.WriteLine("Left"); } else if (a + b == c + d) { Console.WriteLine("Balanced"); } else { Console.WriteLine("Right"); } } } }
using System; namespace AtCoder_1223_1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]); if (a + b < c + d) { Console.WriteLine("Right"); } else if (a + b == c + d) { Console.WriteLine("Balanced"); } else { Console.WriteLine("Left"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
147
4
using System; class MainClass { static void Main() { //入力 string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int a = int.Parse(input[1]); int b = int.Parse(input[2]); int sum = 0; //出力 for (var i = 1; i <= n; i++) { var minisum = 0; var j = i; while (j >= 10) { minisum += j % 10; j = j / 10 - j % 10; } if (j != 0) { minisum += j; } if (a <= minisum && minisum <= b) { sum += i; } } Console.WriteLine(sum); } }
using System; class MainClass { static void Main() { //入力 string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int a = int.Parse(input[1]); int b = int.Parse(input[2]); int sum = 0; //出力 for (var i = 1; i <= n; i++) { var minisum = 0; var j = i; while (j >= 10) { minisum += j % 10; j = j / 10; } if (j != 0) { minisum += j; } if (a <= minisum && minisum <= b) { sum += i; } } Console.WriteLine(sum); } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 17, 109], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 203]]
8
163
4
using System; using System.Collections.Generic; namespace cswork { class Program { public Program() {} Scanner cin; void Omame() { cin = new Scanner(); long n = cin.nextLong(); long a = cin.nextLong(); long b = cin.nextLong(); long ans = 0; for (int i = 1; i <= n; i++) { string s = i.ToString(); int tmp = 0; for (int j = 0; j < s.Length; j++) { tmp += s[j]; } if (a <= tmp && tmp <= b) { ans += i; } } 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(); long n = cin.nextLong(); long a = cin.nextLong(); long b = cin.nextLong(); long ans = 0; for (int i = 1; i <= n; i++) { string s = i.ToString(); int tmp = 0; for (int j = 0; j < s.Length; j++) { tmp += s[j] - '0'; } if (a <= tmp && tmp <= b) { ans += i; } } 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()); } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 252, 0, 104], ["+", 0, 1, 0, 11, 12, 16, 12, 252, 0, 253]]
8
334
4