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.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var S = sc.ReadStr(); var len = S.Length; var dis = S.Distinct().Count(); if (len == dis) Console.WriteLine("Yes"); else Console.WriteLine("No"); } static int INF = int.MaxValue; static long LINF = long.MaxValue; static Scanner sc = new Scanner(); } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); public int nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } } class Vector<T> : List<T> where T : new() { public Vector() {} public Vector(int count, T defaultValue) { for (int i = 0; i < count; i++) { this.Add(defaultValue); } } } class PriorityQueue<T> where T : IComparable<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; public PriorityQueue(int capacity, bool greater = true) { this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Array[n].CompareTo(this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var S = sc.ReadStr(); var len = S.Length; var dis = S.Distinct().Count(); if (len == dis) Console.WriteLine("yes"); else Console.WriteLine("no"); } static int INF = int.MaxValue; static long LINF = long.MaxValue; static Scanner sc = new Scanner(); } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); public int nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } } class Vector<T> : List<T> where T : new() { public Vector() {} public Vector(int count, T defaultValue) { for (int i = 0; i < count; i++) { this.Add(defaultValue); } } } class PriorityQueue<T> where T : IComparable<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; public PriorityQueue(int capacity, bool greater = true) { this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Array[n].CompareTo(this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
1,615
4
using System; using static System.Console; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var s = ReadLine(); var h = new HashSet<char>(); bool isYes = true; for (int i = 0; i < s.Length; i++) { if (!h.Add(s[i])) { isYes = false; } } WriteLine(isYes ? "Yes" : "No"); } static int InputNum() { return int.Parse(ReadLine()); } static List<int> InputNumList() { return ReadLine().Split(' ').Select(int.Parse).ToList(); } } }
using System; using static System.Console; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var s = ReadLine(); var h = new HashSet<char>(); bool isYes = true; for (int i = 0; i < s.Length; i++) { if (!h.Add(s[i])) { isYes = false; } } WriteLine(isYes ? "yes" : "no"); } static int InputNum() { return int.Parse(ReadLine()); } static List<int> InputNumList() { return ReadLine().Split(' ').Select(int.Parse).ToList(); } } }
[["-", 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
163
4
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { // int[] N = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = int.Parse(Console.ReadLine()); int[] N = new int [n].Select(x => int.Parse(Console.ReadLine())).ToArray(); int pos = 1; int res = 0; while (true) { if (N[pos - 1] == -1) { res = -1; break; } pos = N[pos - 1]; N[pos - 1] = -1; res++; if (pos == 2) break; } Console.WriteLine(res); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { // int[] N = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = int.Parse(Console.ReadLine()); int[] N = new int [n].Select(x => int.Parse(Console.ReadLine())).ToArray(); int pos = 1; int res = 0; while (true) { if (N[pos - 1] == -1) { res = -1; break; } int temp = N[pos - 1]; N[pos - 1] = -1; pos = temp; res++; if (pos == 2) break; } Console.WriteLine(res); } }
[["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22]]
8
146
7
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramC { static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var n = long.Parse(inputs[0]); var m = long.Parse(inputs[1]); if (Math.Abs(n - m) > 1) { Console.WriteLine(0); return; } long nn = 1, nm = 1; for (var i = n; i > 1; i--) { nn = (nn * i) % (long)(1e9 + 7); } for (var i = m; i > 1; i--) { nm = (nm * i) % (long)(1e9 + 7); } var key = nn == nm ? 2 : 1; Console.WriteLine((nn * nm) % ((long)1e9 + 7) * 2 % ((long)1e9 + 7)); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramC { static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var n = long.Parse(inputs[0]); var m = long.Parse(inputs[1]); if (Math.Abs(n - m) > 1) { Console.WriteLine(0); return; } long nn = 1, nm = 1; for (var i = n; i > 1; i--) { nn = (nn * i) % (long)(1e9 + 7); } for (var i = m; i > 1; i--) { nm = (nm * i) % (long)(1e9 + 7); } var key = nn == nm ? 2 : 1; Console.WriteLine((nn * nm) % ((long)1e9 + 7) * key % ((long)1e9 + 7)); } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
8
217
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class Program { public static void Main() { const long MOD = 1000000007; var input = Console.ReadLine().Split(); int n = int.Parse(input[0]); int m = int.Parse(input[1]); if (n - m > 1 || m - n > 1) { Console.WriteLine(0); return; } long N = 1; for (int i = 1; i <= n; i++) { N = (N * i) % MOD; } long M = 1; for (int i = 1; i <= m; i++) { M = (M * i) % MOD; } long ans; if (n == m) { ans = 2 * N * m % MOD; } else { ans = N * M % MOD; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class Program { public static void Main() { const long MOD = 1000000007; var input = Console.ReadLine().Split(); int n = int.Parse(input[0]); int m = int.Parse(input[1]); if (n - m > 1 || m - n > 1) { Console.WriteLine(0); return; } long N = 1; for (int i = 1; i <= n; i++) { N = (N * i) % MOD; } long M = 1; for (int i = 1; i <= m; i++) { M = (M * i) % MOD; } long ans; if (n == m) { ans = 2 * N * M % MOD; } else { ans = N * M % MOD; } Console.WriteLine(ans); } }
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22]]
8
204
2
using System; using System.Collections.Generic; using System.Linq; namespace program { class Program { static void Main() { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = input[0]; int M = input[1]; if (Math.Abs(M - N) > 1) { Console.WriteLine(-1); return; } ulong dog = 1, monkey = 1; for (uint i = 2; i <= M; i++) { dog = dog * i % 1000000007; } for (uint i = 2; i <= N; i++) { monkey = monkey * i % 1000000007; } ulong ans = dog * monkey % 1000000007; if (N == M) ans = ans * 2 % 1000000007; Console.WriteLine(ans); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace program { class Program { static void Main() { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = input[0]; int M = input[1]; if (Math.Abs(M - N) > 1) { Console.WriteLine(0); return; } ulong dog = 1, monkey = 1; for (uint i = 2; i <= M; i++) { dog = dog * i % 1000000007; } for (uint i = 2; i <= N; i++) { monkey = monkey * i % 1000000007; } ulong ans = dog * monkey % 1000000007; if (N == M) ans = ans * 2 % 1000000007; Console.WriteLine(ans); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
198
3
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var a = input[0]; var b = input[1]; var ans = 0L; if (a == b) { ans = 2 * f(a) * f(b); } else if (Math.Abs(a - b) == 1) { ans = f(a) * f(b); } Console.WriteLine(ans % 1000000007); } static long f(long n) { long x = 1L; for (var i = 1L; i <= n; i++) { x *= i; } return x; } }
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var a = input[0]; var b = input[1]; var ans = 0L; if (a == b) { ans = 2 * f(a) * f(b); } else if (Math.Abs(a - b) == 1) { ans = f(a) * f(b); } Console.WriteLine(ans % 1000000007); } static long f(long n) { long x = 1L; for (var i = 1L; i <= n; i++) { x *= i; x %= 1000000007; } return x; } }
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
172
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace csharp { class Program { static void Main(string[] args) { var csl = Console.ReadLine(); var N = ulong.Parse(csl.Split(' ')[0]); var M = ulong.Parse(csl.Split(' ')[1]); long sa = (long)N - (long)M; if (sa < 0) { sa = -1 * sa; } if (sa >= 2) { Console.WriteLine(0); } else if (sa == 1) { ulong n_kai = N; for (ulong n = N - 1; n > 0; n--) { n_kai *= n; if (n_kai >= 1000000007) { n_kai -= 1000000007; } } ulong m_kai = M; for (ulong m = M - 1; m > 0; m--) { m_kai *= m; if (m_kai >= 1000000007) { m_kai -= 1000000007; } } ulong result = n_kai * m_kai; if (result > 1000000007) { Console.WriteLine(result % 1000000007); } else { Console.WriteLine(result); } } else if (sa == 0) { ulong n_kai = N; for (ulong n = N - 1; n > 0; n--) { n_kai *= n; if (n_kai >= 1000000007) { n_kai -= 1000000007; } } ulong m_kai = M; for (ulong m = M - 1; m > 0; m--) { m_kai *= m; if (m_kai >= 1000000007) { m_kai -= 1000000007; } } ulong result = 2 * n_kai * m_kai; if (result > 1000000007) { Console.WriteLine(result % 1000000007); } else { Console.WriteLine(result); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace csharp { class Program { static void Main(string[] args) { var csl = Console.ReadLine(); var N = ulong.Parse(csl.Split(' ')[0]); var M = ulong.Parse(csl.Split(' ')[1]); long sa = (long)N - (long)M; if (sa < 0) { sa = -1 * sa; } if (sa >= 2) { Console.WriteLine(0); } else if (sa == 1) { ulong n_kai = N; for (ulong n = N - 1; n > 0; n--) { n_kai *= n; if (n_kai > 1000000007) { n_kai %= 1000000007; } } ulong m_kai = M; for (ulong m = M - 1; m > 0; m--) { m_kai *= m; if (m_kai > 1000000007) { m_kai %= 1000000007; } } ulong result = n_kai * m_kai; if (result > 1000000007) { Console.WriteLine(result % 1000000007); } else { Console.WriteLine(result); } } else if (sa == 0) { ulong n_kai = N; for (ulong n = N - 1; n > 0; n--) { n_kai *= n; if (n_kai >= 1000000007) { n_kai %= 1000000007; } } ulong m_kai = M; for (ulong m = M - 1; m > 0; m--) { m_kai *= m; if (m_kai >= 1000000007) { m_kai %= 1000000007; } } ulong result = 2 * n_kai * m_kai; if (result > 1000000007) { Console.WriteLine(result % 1000000007); } else { Console.WriteLine(result); } } } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 132]]
8
382
12
using System; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nm = ReadLib.ReadAsIntArray(); var n = nm[0]; var m = nm[1]; int val = CalcVal(n, m); Console.WriteLine(val); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } private static int CalcVal(int n, int m) { if (Math.Abs(n - m) > 1) { return 0; } var factorN = Enumerable.Range(1, n) .Select(i => (ModInt)i) .Aggregate((ModInt)1, (b, i) => b * i); var factorM = Enumerable.Range(1, m) .Select(i => (ModInt)i) .Aggregate((ModInt)1, (b, i) => b * i); var rawVal = factorN * factorM; if (n == m) { rawVal *= 2; } return (int)rawVal; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } /// <summary>nCr, 組み合わせ</summary> public static long Combination(int n, int r) { if (r == 0) { return 1; } // 分子 var moleculeArr = Enumerable.Range(0, Math.Min(n - r, r)).Select(i => n - i).ToArray(); var moleculeArrLength = moleculeArr.Length; // 分母 var denominatorArr = Enumerable.Range(1, Math.Max(n - r, r)).ToArray(); for (var m = 0; m < moleculeArrLength; m++) { while (true) { var mVal = moleculeArr[m]; var gcds = denominatorArr.Select(b => Gcd(mVal, b)); var maxGcd = gcds.Max(); var maxI = gcds.ToList().IndexOf(maxGcd); if (maxGcd == 1) { break; } denominatorArr[maxI] /= maxGcd; moleculeArr[m] /= maxGcd; } } return FullPower(moleculeArr); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static int Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { var mod = a % b; if (mod == 0) { break; } a = b; b = mod; } return (int)b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)value % mod; this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } }
using System; using System.Collections.Generic; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nm = ReadLib.ReadAsIntArray(); var n = nm[0]; var m = nm[1]; int val = CalcVal(n, m); Console.WriteLine(val); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } private static int CalcVal(int n, int m) { if (Math.Abs(n - m) > 1) { return 0; } var factorN = Enumerable.Range(1, n) .Select(i => (ModInt)i) .Aggregate((ModInt)1, (b, i) => b * i); var factorM = Enumerable.Range(1, m) .Select(i => (ModInt)i) .Aggregate((ModInt)1, (b, i) => b * i); var rawVal = factorN * factorM; if (n == m) { rawVal *= 2; } return (int)rawVal; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } /// <summary>nCr, 組み合わせ</summary> public static long Combination(int n, int r) { if (r == 0) { return 1; } // 分子 var moleculeArr = Enumerable.Range(0, Math.Min(n - r, r)).Select(i => n - i).ToArray(); var moleculeArrLength = moleculeArr.Length; // 分母 var denominatorArr = Enumerable.Range(1, Math.Max(n - r, r)).ToArray(); for (var m = 0; m < moleculeArrLength; m++) { while (true) { var mVal = moleculeArr[m]; var gcds = denominatorArr.Select(b => Gcd(mVal, b)); var maxGcd = gcds.Max(); var maxI = gcds.ToList().IndexOf(maxGcd); if (maxGcd == 1) { break; } denominatorArr[maxI] /= maxGcd; moleculeArr[m] /= maxGcd; } } return FullPower(moleculeArr); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static int Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { var mod = a % b; if (mod == 0) { break; } a = b; b = mod; } return (int)b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { long value = item1.Value + item2; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { long value = Math.BigMul(item1.Value, item2); return new ModInt(value, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } }
[["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 25]]
8
1,774
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static void Main() { Sc sc = new Sc(); int[] s = sc.Ia; int[][] a = new int[s[2]][]; List<int[]> li = new List<int[]>(); string ans = "YES"; bool[] b = new bool[s[2]]; for (int i = 0; i < s[2]; i++) { a[i] = sc.Ia; if ((a[i][0] == 0 || a[i][0] == s[0] || a[i][1] == 0 || a[i][1] == s[1]) && (a[i][2] == 0 || a[i][2] == s[0] || a[i][3] == 0 || a[i][3] == s[1])) { if (a[i][1] == 0) { li.Add(new int[] { a[i][0], i }); } else if (a[i][0] == s[0]) { li.Add(new int[] { a[i][1] + (int)2e8, i }); } else if (a[i][1] == s[1]) { li.Add(new int[] { (int)5e8 - a[i][0], i }); } else { li.Add(new int[] { (int)8e8 - a[i][1], i }); } if (a[i][3] == 0) { li.Add(new int[] { a[i][2], i + 1 }); } else if (a[i][2] == s[0]) { li.Add(new int[] { a[i][3] + (int)2e8, i }); } else if (a[i][3] == s[1]) { li.Add(new int[] { (int)5e8 - a[i][2], i }); } else { li.Add(new int[] { (int)8e8 - a[i][3], i }); } b[i] = true; } a[i][0] = -1; a[i][1] = -1; } li.Sort((u, v) => u[0] - v[0]); St st1 = new St(0, li.Count, true); St st2 = new St(0, li.Count, false); for (int i = 0; i < li.Count; i++) { if (a[li[i][1]][0] == -1) { a[li[i][1]][0] = i; } else { st1.Ud(a[li[i][1]][0], i); st2.Ud(a[li[i][1]][0], i); st1.Ud(i, a[li[i][1]][0]); st2.Ud(i, a[li[i][1]][0]); a[li[i][1]][1] = i; } } for (int i = 0; i < s[2]; i++) { if (b[i] && a[i][1] - a[i][0] != 1) { if (st1.Get(a[i][0] + 1, a[i][1] - 1).d > a[i][1] || st2.Get(a[i][0] + 1, a[i][1] - 1).d < a[i][0]) { ans = "NO"; } } } Console.WriteLine(ans); } } public class St { public class Mo { public int n; public long d; public Mo(long d, int n) { this.d = d; this.n = n; } } public Mo[] dat; private int m = 1, f; private bool mm; private Mo du; private Func<Mo, Mo, bool> compare; public St(int f, int n, bool mm) { this.f = f; n += f ^ 1; this.mm = mm; if (mm) { du = new Mo(long.MinValue, -1); compare = CoMax; } else { du = new Mo(long.MaxValue, -1); compare = CoMin; } while (m < n) { m *= 2; } dat = new Mo[m + n - 1]; for (int i = 0; i < m + n - 1; i++) { dat[i] = du; } } private bool CoMax(Mo x, Mo y) { return x.d > y.d; } private bool CoMin(Mo x, Mo y) { return x.d < y.d; } public void Ud(int q, long b) { q += m - 1 - f; if (dat[q] == du) { int z = q; dat[q] = new Mo(b, q - (m - 1 - f)); while (q > 0 && compare(dat[z], dat[(q - 1) / 2])) { dat[(q - 1) / 2] = dat[z]; q = (q - 1) / 2; } } else { b += dat[q].d; dat[q].d = du.d; dat[q] = new Mo(b, q - (m - 1 - f)); q = (q - 1) / 2; while (q >= 0) { Mo o = compare(dat[2 * q + 1], dat[2 * q + 2]) ? dat[2 * q + 1] : dat[2 * q + 2]; if (dat[q] == o) { break; } dat[q] = o; q = (q - 1) / 2; } } } private Mo Fdg(int a, int b, int k, int l, int r) { if (r < a || b < l) { return du; } if (a <= l && r <= b) { return dat[k]; } Mo p = Fdg(a, b, k * 2 + 1, l, (l + r) / 2); Mo q = Fdg(a, b, k * 2 + 2, (l + r + 1) / 2, r); return compare(p, q) ? p : q; } public Mo Get(int a, int b) { return Fdg(a, b, 0, f, m - (f ^ 1)); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static void Main() { Sc sc = new Sc(); int[] s = sc.Ia; int[][] a = new int[s[2]][]; List<int[]> li = new List<int[]>(); string ans = "YES"; bool[] b = new bool[s[2]]; for (int i = 0; i < s[2]; i++) { a[i] = sc.Ia; if ((a[i][0] == 0 || a[i][0] == s[0] || a[i][1] == 0 || a[i][1] == s[1]) && (a[i][2] == 0 || a[i][2] == s[0] || a[i][3] == 0 || a[i][3] == s[1])) { if (a[i][1] == 0) { li.Add(new int[] { a[i][0], i }); } else if (a[i][0] == s[0]) { li.Add(new int[] { a[i][1] + (int)2e8, i }); } else if (a[i][1] == s[1]) { li.Add(new int[] { (int)5e8 - a[i][0], i }); } else { li.Add(new int[] { (int)8e8 - a[i][1], i }); } if (a[i][3] == 0) { li.Add(new int[] { a[i][2], i }); } else if (a[i][2] == s[0]) { li.Add(new int[] { a[i][3] + (int)2e8, i }); } else if (a[i][3] == s[1]) { li.Add(new int[] { (int)5e8 - a[i][2], i }); } else { li.Add(new int[] { (int)8e8 - a[i][3], i }); } b[i] = true; } a[i][0] = -1; a[i][1] = -1; } li.Sort((u, v) => u[0] - v[0]); St st1 = new St(0, li.Count, true); St st2 = new St(0, li.Count, false); for (int i = 0; i < li.Count; i++) { if (a[li[i][1]][0] == -1) { a[li[i][1]][0] = i; } else { st1.Ud(a[li[i][1]][0], i); st2.Ud(a[li[i][1]][0], i); st1.Ud(i, a[li[i][1]][0]); st2.Ud(i, a[li[i][1]][0]); a[li[i][1]][1] = i; } } for (int i = 0; i < s[2]; i++) { if (b[i] && a[i][1] - a[i][0] != 1) { if (st1.Get(a[i][0] + 1, a[i][1] - 1).d > a[i][1] || st2.Get(a[i][0] + 1, a[i][1] - 1).d < a[i][0]) { ans = "NO"; } } } Console.WriteLine(ans); } } public class St { public class Mo { public int n; public long d; public Mo(long d, int n) { this.d = d; this.n = n; } } public Mo[] dat; private int m = 1, f; private bool mm; private Mo du; private Func<Mo, Mo, bool> compare; public St(int f, int n, bool mm) { this.f = f; n += f ^ 1; this.mm = mm; if (mm) { du = new Mo(long.MinValue, -1); compare = CoMax; } else { du = new Mo(long.MaxValue, -1); compare = CoMin; } while (m < n) { m *= 2; } dat = new Mo[m + n - 1]; for (int i = 0; i < m + n - 1; i++) { dat[i] = du; } } private bool CoMax(Mo x, Mo y) { return x.d > y.d; } private bool CoMin(Mo x, Mo y) { return x.d < y.d; } public void Ud(int q, long b) { q += m - 1 - f; if (dat[q] == du) { int z = q; dat[q] = new Mo(b, q - (m - 1 - f)); while (q > 0 && compare(dat[z], dat[(q - 1) / 2])) { dat[(q - 1) / 2] = dat[z]; q = (q - 1) / 2; } } else { b += dat[q].d; dat[q].d = du.d; dat[q] = new Mo(b, q - (m - 1 - f)); q = (q - 1) / 2; while (q >= 0) { Mo o = compare(dat[2 * q + 1], dat[2 * q + 2]) ? dat[2 * q + 1] : dat[2 * q + 2]; if (dat[q] == o) { break; } dat[q] = o; q = (q - 1) / 2; } } } private Mo Fdg(int a, int b, int k, int l, int r) { if (r < a || b < l) { return du; } if (a <= l && r <= b) { return dat[k]; } Mo p = Fdg(a, b, k * 2 + 1, l, (l + r) / 2); Mo q = Fdg(a, b, k * 2 + 2, (l + r + 1) / 2, r); return compare(p, q) ? p : q; } public Mo Get(int a, int b) { return Fdg(a, b, 0, f, m - (f ^ 1)); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
[["-", 0, 28, 0, 227, 0, 229, 0, 16, 17, 72], ["-", 0, 28, 0, 227, 0, 229, 0, 16, 12, 203]]
8
1,823
2
using System; using System.Collections.Generic; using System.Linq; namespace arc076_c { class Program { static int[] x; static bool onedge(int a, int b) { if (a == 0 || a == x[0]) return true; if (b == 0 || b == x[1]) return true; return false; } static int howlong(int a, int b) { if (a == 0) return b; // up if (b == x[1]) return x[1] + a; // right if (a == x[0]) return x[1] + x[0] + (x[1] - b); // down else return x[1] + x[0] + x[1] + (x[0] - a); // left } static void Main(string[] args) { x = Console.ReadLine().Split().Select(int.Parse).ToArray(); List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < x[2]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (onedge(a[0], a[1]) && onedge(a[2], a[3])) { int n1 = howlong(a[0], a[1]); list.Add(new Tuple<int, int>(n1, i)); int n2 = howlong(a[2], a[3]); list.Add(new Tuple<int, int>(n2, i)); } } Tuple<int, int>[] arr = list.ToArray(); Array.Sort(arr); Stack<int> stack = new Stack<int>(); foreach (var tup in arr) { if (stack.Count == 0) stack.Push(tup.Item1); else if (stack.Peek() == tup.Item2) stack.Pop(); else stack.Push(tup.Item2); } Console.WriteLine(stack.Count == 0 ? "YES" : "NO"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace arc076_c { class Program { static int[] x; static bool onedge(int a, int b) { if (a == 0 || a == x[0]) return true; if (b == 0 || b == x[1]) return true; return false; } static int howlong(int a, int b) { if (a == 0) return b; // up if (b == x[1]) return x[1] + a; // right if (a == x[0]) return x[1] + x[0] + (x[1] - b); // down else return x[1] + x[0] + x[1] + (x[0] - a); // left } static void Main(string[] args) { x = Console.ReadLine().Split().Select(int.Parse).ToArray(); List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < x[2]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (onedge(a[0], a[1]) && onedge(a[2], a[3])) { int n1 = howlong(a[0], a[1]); list.Add(new Tuple<int, int>(n1, i)); int n2 = howlong(a[2], a[3]); list.Add(new Tuple<int, int>(n2, i)); } } Tuple<int, int>[] arr = list.ToArray(); Array.Sort(arr); Stack<int> stack = new Stack<int>(); foreach (var tup in arr) { if (stack.Count == 0) stack.Push(tup.Item2); else if (stack.Peek() == tup.Item2) stack.Pop(); else stack.Push(tup.Item2); } Console.WriteLine(stack.Count == 0 ? "YES" : "NO"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
8
485
2
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class A { public static void Main() { string s = GetString(); var set = new HashSet<char>(); for (int i = 0; i < s.Length; i++) set.Add(s[i]); if (set.Count == 1) { Console.Write(0); return; } var list = set.ToList(); int ans = int.MaxValue; foreach (char c in list) { int tmp = 0; char[] current = s.ToCharArray(); char[] next = new char[s.Length]; while (true) { var tmpSet = new HashSet<char>(); for (int i = 0; i < s.Length - tmp; i++) { next[i] = current[i]; if ((i + 1 < s.Length - tmp) && (current[i + 1] == c)) next[i] = c; tmpSet.Add(next[i]); } tmp++; current = next; if (tmpSet.Count == 1) { ans = Math.Min(ans, tmp); break; } } } Console.WriteLine(ans); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class A { public static void Main() { string s = GetString(); var set = new HashSet<char>(); for (int i = 0; i < s.Length; i++) set.Add(s[i]); if (set.Count == 1) { Console.Write(0); return; } var list = set.ToList(); int ans = int.MaxValue; foreach (char c in list) { int tmp = 0; char[] current = s.ToCharArray(); char[] next = new char[s.Length]; while (true) { var tmpSet = new HashSet<char>(); for (int i = 0; i < s.Length - 1 - tmp; i++) { next[i] = current[i]; if ((i + 1 < s.Length - tmp) && (current[i + 1] == c)) next[i] = c; tmpSet.Add(next[i]); } tmp++; current = next; if (tmpSet.Count == 1) { ans = Math.Min(ans, tmp); break; } } } Console.WriteLine(ans); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
[["+", 0, 7, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33]]
8
431
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { string a = Console.ReadLine(); int[] alpha = new int[26]; for (int j = 0; j < 'z' - 'a'; j++) { int i = j + 'a'; int maxvalue = 0, KOushin = 0; for (int k = 0; k < a.Length; k++) { if (a[k] == (char)i) { maxvalue = Math.Max( maxvalue, KOushin); /*maxvalue < KOushin ? KOushin : maxvalue;*/ KOushin = 0; } else { KOushin++; } } maxvalue = Math.Max(maxvalue, KOushin); alpha[j] = maxvalue; } Array.Sort(alpha); Console.WriteLine(alpha[0]); } public static Boolean uso() { return false; } public static long gcd(long a, long b) { while (true) { if (a == 0) { return b; } if (b == 0) { return a; } if (a > b) { a -= b; } else { b -= a; } } } public static long lcm(long a, long b) { return a * b / gcd(a, b); } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (long i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } } public static class Read { public static void outl(string n = "") { Console.WriteLine(n); return; } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { string a = Console.ReadLine(); int[] ret = new int[26]; for (int j = 0; j <= 'z' - 'a'; j++) { int i = j + 'a'; int maxvalue = 0, KOushin = 0; for (int k = 0; k < a.Length; k++) { if (a[k] == (char)i) { maxvalue = Math.Max( maxvalue, KOushin); /*maxvalue < KOushin ? KOushin : maxvalue;*/ KOushin = 0; } else { KOushin++; } } maxvalue = Math.Max(maxvalue, KOushin); ret[j] = maxvalue; } Array.Sort(ret); Console.WriteLine(ret[0]); } public static Boolean uso() { return false; } public static long gcd(long a, long b) { while (true) { if (a == 0) { return b; } if (b == 0) { return a; } if (a > b) { a -= b; } else { b -= a; } } } public static long lcm(long a, long b) { return a * b / gcd(a, b); } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (long i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } } public static class Read { public static void outl(string n = "") { Console.WriteLine(n); return; } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22]]
8
506
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.Virtual { class AGC016_B { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int n = ReadInt(); int[] array = ReadInts(); Array.Sort(array); if (array[n - 1] - array[0] > 1) { WriteLine("No"); return; } if (array[n - 1] == array[0] && array[0] == n + 1) { WriteLine("Yes"); return; } int smallCnt = 0; int largeCnt = 0; for (int i = 0; i < n; i++) { if (array[i] == array[n - 1]) largeCnt++; else smallCnt++; } int min = 1; int max = largeCnt / 2; if (largeCnt > 1 && min + smallCnt <= array[n - 1] && array[n - 1] <= max + smallCnt) { WriteLine("Yes"); } else { WriteLine("No"); } } private static string Read() { return ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.Virtual { class AGC016_B { static void Main(string[] args) { Method(args); ReadLine(); } static void Method(string[] args) { int n = ReadInt(); int[] array = ReadInts(); Array.Sort(array); if (array[n - 1] - array[0] > 1) { WriteLine("No"); return; } if (array[n - 1] == array[0] && array[0] == n - 1) { WriteLine("Yes"); return; } int smallCnt = 0; int largeCnt = 0; for (int i = 0; i < n; i++) { if (array[i] == array[n - 1]) largeCnt++; else smallCnt++; } int min = 1; int max = largeCnt / 2; if (largeCnt > 1 && min + smallCnt <= array[n - 1] && array[n - 1] <= max + smallCnt) { WriteLine("Yes"); } else { WriteLine("No"); } } private static string Read() { return ReadLine(); } 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, 57, 15, 16, 12, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33]]
8
414
2
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long maxNum = nums.Max(); long minNum = nums.Min(); long minCount = 0; //小さい数の猫の数 long maxCount = 0; for (long i = 0; i < n; i++) { if (nums[i] == minNum) minCount++; } maxCount = n - minCount; if (maxNum - minNum >= 2) Console.WriteLine("No"); else if (maxNum - minNum == 0) { if (maxNum == 1 || maxNum == n - 1) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else if (maxNum - minNum == 1) { if (maxCount == 1) Console.WriteLine("No"); else if (minCount + 1 <= maxNum && maxNum <= minCount + (maxCount / 2)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long maxNum = nums.Max(); long minNum = nums.Min(); long minCount = 0; //小さい数の猫の数 long maxCount = 0; for (long i = 0; i < n; i++) { if (nums[i] == minNum) minCount++; } maxCount = n - minCount; if (maxNum - minNum >= 2) Console.WriteLine("No"); else if (maxNum - minNum == 0) { if (maxNum <= n / 2 || maxNum == n - 1) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else if (maxNum - minNum == 1) { if (maxCount == 1) Console.WriteLine("No"); else if (minCount + 1 <= maxNum && maxNum <= minCount + (maxCount / 2)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203]]
8
254
6
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Grand016 { public class AGC016B_ColorfulHats { public static void Main(string[] args) { // 整数の入力 int catNum = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 string[] hatNumText = Console.ReadLine().Split(' '); int[] hatNum = new int[catNum]; for (int i = 0; i < catNum; i++) { hatNum[i] = int.Parse(hatNumText[i]); } Array.Sort(hatNum); int minHatTypeNum = hatNum[0]; int maxHatTypeNum = hatNum[hatNum.Length - 1]; int minCatCnt = hatNum.Count(val => val == minHatTypeNum); int maxCatCnt = hatNum.Count(val => val == maxHatTypeNum); string result = "Yes"; // 色数に2以上の差が付くことはありえない if (maxHatTypeNum - minHatTypeNum > 1) { result = "No"; } if (minHatTypeNum == maxHatTypeNum) { // 全員が同じ値 // 各色に1匹、もしくは各色に2匹以上 // 各色に2匹以上のため、N/2を上回ることはない if (minHatTypeNum > catNum / 2) { result = "No"; } } else { // xとx-1が混在 // 1匹しかいないのが1~x-1組、残りは2匹以上のグループ // 2匹以上のペアはx-単独数できるため、ペアに属する猫は(x-単独数)*2匹以上になる // 1匹しかいない色数(=x-1の数)は、1~x-1の範囲内でないとおかしい if (minCatCnt > minHatTypeNum) { result = "No"; } // 2匹以上グループの猫数は、(x-単独数)*2匹以上でないとおかしい if (maxCatCnt < (maxHatTypeNum - minCatCnt) * 2) { result = "No"; } } // 結果出力 Console.WriteLine(result); } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Grand016 { public class AGC016B_ColorfulHats { public static void Main(string[] args) { // 整数の入力 int catNum = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 string[] hatNumText = Console.ReadLine().Split(' '); int[] hatNum = new int[catNum]; for (int i = 0; i < catNum; i++) { hatNum[i] = int.Parse(hatNumText[i]); } Array.Sort(hatNum); int minHatTypeNum = hatNum[0]; int maxHatTypeNum = hatNum[hatNum.Length - 1]; int minCatCnt = hatNum.Count(val => val == minHatTypeNum); int maxCatCnt = hatNum.Count(val => val == maxHatTypeNum); string result = "Yes"; // 色数に2以上の差が付くことはありえない if (maxHatTypeNum - minHatTypeNum > 1) { result = "No"; } if (minHatTypeNum == maxHatTypeNum) { // 全員が同じ値 // 各色に1匹、もしくは各色に2匹以上 // 各色に2匹以上(x!=N-1)であれば、種類数がN/2を上回ることはない if (minHatTypeNum != catNum - 1 && minHatTypeNum > catNum / 2) { result = "No"; } } else { // xとx-1が混在 // 1匹しかいないのが1~x-1組、残りは2匹以上のグループ // 2匹以上のペアはx-単独数できるため、ペアに属する猫は(x-単独数)*2匹以上になる // 1匹しかいない色数(=x-1の数)は、1~x-1の範囲内でないとおかしい if (minCatCnt > minHatTypeNum) { result = "No"; } // 2匹以上グループの猫数は、(x-単独数)*2匹以上でないとおかしい if (maxCatCnt < (maxHatTypeNum - minCatCnt) * 2) { result = "No"; } } // 結果出力 Console.WriteLine(result); } } }
[["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
270
6
using System; using System.Linq; class Solution { static void Main() { var n = int.Parse(Console.ReadLine()); var cat = Console.ReadLine().Split().Select(int.Parse).ToArray(); var max = cat.Max(); var maxCount = cat.Count(c => c == max); var min = cat.Min(); var minCount = cat.Count(c => c == min); bool ok = false; if (max == min) { // 3 3 3 3 3 3 5 5 5 5 5 5 // a b c a b c a b c d e f if (2 * max <= n || max == n - 1) { ok = true; } } else if (max == min + 1) { // 3 3 4 4 4 4 // a b c d c d if (2 * (max - minCount) <= maxCount) { ok = true; } } Console.WriteLine(ok ? "Yes" : "No"); } }
using System; using System.Linq; class Solution { static void Main() { var n = int.Parse(Console.ReadLine()); var cat = Console.ReadLine().Split().Select(int.Parse).ToArray(); var max = cat.Max(); var maxCount = cat.Count(c => c == max); var min = cat.Min(); var minCount = cat.Count(c => c == min); bool ok = false; if (max == min) { // 3 3 3 3 3 3 5 5 5 5 5 5 // a b c a b c a b c d e f if (2 * max <= n || max == n - 1) { ok = true; } } else if (max == min + 1) { // 3 3 4 4 4 4 // a b c d c d if (minCount <= min && 2 * (max - minCount) <= maxCount) { ok = true; } } Console.WriteLine(ok ? "Yes" : "No"); } }
[["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 17, 98]]
8
184
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int n = sc.nextInt(); int[] a = sc.nextInt(n); Array.Sort(a); if (a[n - 1] - a[0] > 1) { Console.WriteLine("No"); return; } if (a[0] == a[n - 1]) { if (a[0] * 2 <= n || a[0] == n - 1) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { int singleCnt = 0; for (int i = 0; i < n; i++) { if (a[i] == a[0]) singleCnt++; else break; } int doubleCnt = n - singleCnt; int doubleColor = (a[n - 1] - singleCnt); if (doubleCnt < doubleColor * 2 || doubleCnt == 1) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int n = sc.nextInt(); int[] a = sc.nextInt(n); Array.Sort(a); if (a[n - 1] - a[0] > 1) { Console.WriteLine("No"); return; } if (a[0] == a[n - 1]) { if (a[0] * 2 <= n || a[0] == n - 1) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { int singleCnt = 0; for (int i = 0; i < n; i++) { if (a[i] == a[0]) singleCnt++; else break; } int doubleCnt = n - singleCnt; int doubleColor = (a[n - 1] - singleCnt); if (doubleCnt < doubleColor * 2 || doubleColor < 1) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
[["-", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 75, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 18]]
8
1,377
4
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToList(); a.Add(a.Aggregate(0, (x, y) => x ^ y)); var b = Console.ReadLine().Split().Select(int.Parse).ToList(); b.Add(b.Aggregate(0, (x, y) => x ^ y)); if (a.OrderBy(x => x) .Zip(b.OrderBy(x => x), (x, y) => x != y) .Any(x => x)) { Console.WriteLine(-1); return; } var compressed = a.Distinct() .OrderBy(x => x) .Select((elem, count) => new { elem, count }) .ToDictionary(x => x.elem, x => x.count); int sameCount = 0; UnionFind uf = new UnionFind(compressed.Count); for (int i = 0; i < n; i++) { if (a[i] == b[i]) sameCount++; uf.TryUnite(compressed[a[i]], compressed[b[i]]); } //全ての違う変数を動かす+閉路の数だけ動かす必要がある //始点を閉路に組み込めているならば-1 Console.WriteLine((n - sameCount) + uf.AllRepresents.Count(x => 2 <= uf.GetSize(x)) - (b.IndexOf(a.Last()) != n ? 1 : 0)); } } class UnionFind { public int Size { get; private set; } public int GroupCount { get; private set; } List<int> Sizes; List<int> Parent; public UnionFind(int count) { Size = 0; GroupCount = 0; Parent = new List<int>(count); Sizes = new List<int>(count); ExtendSize(count); } public bool TryUnite(int x, int y) { int xp = Find(x); int yp = Find(y); if (yp == xp) return false; if (Sizes[xp] < Sizes[yp]) { var tmp = xp; xp = yp; yp = tmp; } GroupCount--; Parent[yp] = xp; Sizes[xp] += Sizes[yp]; return true; } public IEnumerable<int> AllRepresents => Enumerable.Range(0, Size).Where(x => x == Parent[x]); public int GetSize(int x) => Sizes[Find(x)]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Find(int x) { while (x != Parent[x]) { Parent[x] = Parent[Parent[x]]; x = Parent[x]; } return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ExtendSize(int treeSize) { if (treeSize <= Size) return; Parent.Capacity = treeSize; Sizes.Capacity = treeSize; while (Size < treeSize) { Parent.Add(Size); Sizes.Add(1); Size++; GroupCount++; } } }
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToList(); a.Add(a.Aggregate(0, (x, y) => x ^ y)); var b = Console.ReadLine().Split().Select(int.Parse).ToList(); b.Add(b.Aggregate(0, (x, y) => x ^ y)); if (a.OrderBy(x => x) .Zip(b.OrderBy(x => x), (x, y) => x != y) .Any(x => x)) { Console.WriteLine(-1); return; } var compressed = a.Distinct() .OrderBy(x => x) .Select((elem, count) => new { elem, count }) .ToDictionary(x => x.elem, x => x.count); int sameCount = 0; UnionFind uf = new UnionFind(compressed.Count); for (int i = 0; i < n; i++) { if (a[i] == b[i]) sameCount++; uf.TryUnite(compressed[a[i]], compressed[b[i]]); } //全ての違う変数を動かす+閉路の数だけ動かす必要がある //始点を閉路に組み込めているならば-1 Console.WriteLine((n - sameCount) + uf.AllRepresents.Count(x => 2 <= uf.GetSize(x)) - (n != sameCount && b.IndexOf(a.Last()) != n ? 1 : 0)); } } class UnionFind { public int Size { get; private set; } public int GroupCount { get; private set; } List<int> Sizes; List<int> Parent; public UnionFind(int count) { Size = 0; GroupCount = 0; Parent = new List<int>(count); Sizes = new List<int>(count); ExtendSize(count); } public bool TryUnite(int x, int y) { int xp = Find(x); int yp = Find(y); if (yp == xp) return false; if (Sizes[xp] < Sizes[yp]) { var tmp = xp; xp = yp; yp = tmp; } GroupCount--; Parent[yp] = xp; Sizes[xp] += Sizes[yp]; return true; } public IEnumerable<int> AllRepresents => Enumerable.Range(0, Size).Where(x => x == Parent[x]); public int GetSize(int x) => Sizes[Find(x)]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Find(int x) { while (x != Parent[x]) { Parent[x] = Parent[Parent[x]]; x = Parent[x]; } return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ExtendSize(int treeSize) { if (treeSize <= Size) return; Parent.Capacity = treeSize; Sizes.Capacity = treeSize; while (Size < treeSize) { Parent.Add(Size); Sizes.Add(1); Size++; GroupCount++; } } }
[["+", 12, 23, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 17, 79], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 12, 22], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 17, 98]]
8
742
4
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()); long r = scan.Long(); long g = scan.Long(); long b = scan.Long(); if ((g * 10 + b) % 4 == 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } 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()); long r = scan.Long(); long g = scan.Long(); long b = scan.Long(); if ((g * 10 + b) % 4 == 0) Console.WriteLine("YES"); else Console.WriteLine("NO"); } 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, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
13,695
4
using System; using System.IO.Pipes; using System.Runtime.InteropServices.ComTypes; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var input = Console.ReadLine(); var rgb = input.Split(' '); var i = int.Parse(String.Join("", rgb)); if (i % 4 == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.IO.Pipes; using System.Runtime.InteropServices.ComTypes; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var input = Console.ReadLine(); var rgb = input.Split(' '); var i = int.Parse(String.Join("", rgb)); if (i % 4 == 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
108
4
using System; 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 total = (a * 100) + (b * 10) + c; if (total % 4 != 0) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; 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 total = (a * 100) + (b * 10) + c; if (total % 4 == 0) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60]]
8
123
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc064/tasks/abc064_a public class Q064A { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列配列の入力 string[] inputStrArray = Console.ReadLine().Split(' '); string result = "NO"; if (long.Parse(inputStrArray[0] + inputStrArray[1] + inputStrArray[2]) / 4 == 0) { result = "YES"; } Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc064/tasks/abc064_a public class Q064A { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列配列の入力 string[] inputStrArray = Console.ReadLine().Split(' '); string result = "NO"; if (long.Parse(inputStrArray[0] + inputStrArray[1] + inputStrArray[2]) % 4 == 0) { result = "YES"; } Console.WriteLine(result); Console.Out.Flush(); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109]]
8
155
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { public static void Main(string[] args) { // 文字列配列の入力 string[] inputStrArray = Console.ReadLine().Split(' '); var number = inputStrArray[0] + inputStrArray[1] + inputStrArray[2]; if ((int.Parse(number) % 4) == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { public static void Main(string[] args) { // 文字列配列の入力 string[] inputStrArray = Console.ReadLine().Split(' '); var number = inputStrArray[0] + inputStrArray[1] + inputStrArray[2]; if ((int.Parse(number) % 4) == 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
125
4
using System; using System.Collections.Generic; using System.Globalization; namespace cswork { class Program { public Program() {} Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); void Omame() { cin = new Scanner(); string a = cin.next(); string b = cin.next(); string c = cin.next(); string s = a + b + c; if (int.Parse(s) % 4 == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } static void Main(string[] args) { new Program().Omame(); } public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } } 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; using System.Globalization; namespace cswork { class Program { public Program() {} Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); void Omame() { cin = new Scanner(); string a = cin.next(); string b = cin.next(); string c = cin.next(); string s = a + b + c; if (int.Parse(s) % 4 == 0) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } static void Main(string[] args) { new Program().Omame(); } public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } } 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
444
4
using System; class Test { static void Main(string[] args) { string[] tmp = Console.ReadLine().Split(' '); int r = int.Parse(tmp[0]); int g = int.Parse(tmp[1]); int b = int.Parse(tmp[2]); int calc = 100 * r + 10 * g + b; if (calc % 4 == 0) { Console.WriteLine("YES"); } else { Console.WriteLine("No"); } } }
using System; class Test { static void Main(string[] args) { string[] tmp = Console.ReadLine().Split(' '); int r = int.Parse(tmp[0]); int g = int.Parse(tmp[1]); int b = int.Parse(tmp[2]); int calc = 100 * r + 10 * g + b; if (calc % 4 == 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
119
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC064A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); d = 100 * a + 10 * b + c; if (d % 4 == 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC064A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); d = 100 * a + 10 * b + c; if (d % 4 == 0) Console.WriteLine("YES"); else Console.WriteLine("NO"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
152
4
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 r = cin.nextInt(); var g = cin.nextInt(); var b = cin.nextInt(); var n = 100 * r + g * 10 + b; Console.WriteLine(n % 4 == 0 ? "Yes" : "No"); } } #region library 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; } } public static partial class MathEx { public static int GCD(int n, int m) { return (int)GCD((long)n, m); } public static long GCD(long n, long m) { n = Math.Abs(n); m = Math.Abs(m); while (n != 0) { m %= n; if (m == 0) return n; n %= m; } return m; } public static long LCM(long n, long m) { return (n / GCD(n, m)) * m; } public static bool[] Sieve(int max, List<int> primes = null) { var isPrime = new bool[max + 1]; for (int i = 2; i < isPrime.Length; i++) isPrime[i] = true; for (int i = 2; i * i <= max; i++) if (!isPrime[i]) continue; else for (int j = i * i; j <= max; j += i) isPrime[j] = false; if (primes != null) for (int i = 0; i <= max; i++) if (isPrime[i]) primes.Add(i); return isPrime; } } public static class Combination { public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) { if (k == 1) { foreach (var item in items) yield return new T[] { item }; yield break; } foreach (var item in items) { var leftside = new T[] { item }; var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList(); foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) { yield return leftside.Concat(rightside).ToArray(); } } } } 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 PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } class DP { public static void ChMin(ref int a, int b) { long la = a; long lb = b; ChMin(ref la, lb); } public static bool ChMin(ref long a, long b) { if (a > b) { a = b; return true; } return false; } public static void ChMax(ref int a, int b) { long la = a; long lb = b; ChMax(ref la, lb); } public static bool ChMax(ref long a, long b) { if (a < b) { a = b; return true; } return false; } } 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; } } 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 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 r = cin.nextInt(); var g = cin.nextInt(); var b = cin.nextInt(); var n = 100 * r + g * 10 + b; Console.WriteLine(n % 4 == 0 ? "YES" : "NO"); } } #region library 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; } } public static partial class MathEx { public static int GCD(int n, int m) { return (int)GCD((long)n, m); } public static long GCD(long n, long m) { n = Math.Abs(n); m = Math.Abs(m); while (n != 0) { m %= n; if (m == 0) return n; n %= m; } return m; } public static long LCM(long n, long m) { return (n / GCD(n, m)) * m; } public static bool[] Sieve(int max, List<int> primes = null) { var isPrime = new bool[max + 1]; for (int i = 2; i < isPrime.Length; i++) isPrime[i] = true; for (int i = 2; i * i <= max; i++) if (!isPrime[i]) continue; else for (int j = i * i; j <= max; j += i) isPrime[j] = false; if (primes != null) for (int i = 0; i <= max; i++) if (isPrime[i]) primes.Add(i); return isPrime; } } public static class Combination { public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) { if (k == 1) { foreach (var item in items) yield return new T[] { item }; yield break; } foreach (var item in items) { var leftside = new T[] { item }; var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList(); foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) { yield return leftside.Concat(rightside).ToArray(); } } } } 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 PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } class DP { public static void ChMin(ref int a, int b) { long la = a; long lb = b; ChMin(ref la, lb); } public static bool ChMin(ref long a, long b) { if (a > b) { a = b; return true; } return false; } public static void ChMax(ref int a, int b) { long la = a; long lb = b; ChMax(ref la, lb); } public static bool ChMax(ref long a, long b) { if (a < b) { a = b; return true; } return false; } } 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; } } 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 class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["-", 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
2,173
4
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int r = int.Parse(input[0]); int g = int.Parse(input[1]); int b = int.Parse(input[2]); if ((100 * r + 10 * g + b % 4) == 0) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int r = int.Parse(input[0]); int g = int.Parse(input[1]); int b = int.Parse(input[2]); if ((100 * r + 10 * g + b) % 4 == 0) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25]]
8
116
2
using System; using System.Linq; public class s { public static void Main() { int[] rgb = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); string ans = "NO"; if ((rgb[1] + rgb[2]) % 4 == 0) ans = "YES"; Console.WriteLine(ans); } }
using System; using System.Linq; public class s { public static void Main() { int[] rgb = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); string ans = "NO"; if ((rgb[1] * 10 + rgb[2]) % 4 == 0) ans = "YES"; Console.WriteLine(ans); } }
[["+", 31, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 12, 203]]
8
88
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { private static string Read() { return Console.ReadLine(); } 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); } private static void Yes() { print("Yes"); } private static void No() { print("No"); } private static void print(object obj) { Console.WriteLine(obj); } static void Main(string[] args) { var a = ReadInts(); if ((a[0] * 100 + a[1] * 10 + a[2]) % 4 == 0) { Yes(); } else { No(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { private static string Read() { return Console.ReadLine(); } 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); } private static void Yes() { print("YES"); } private static void No() { print("NO"); } private static void print(object obj) { Console.WriteLine(obj); } static void Main(string[] args) { var a = ReadInts(); if ((a[0] * 100 + a[1] * 10 + a[2]) % 4 == 0) { Yes(); } else { No(); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
293
4
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; internal class Program { static void Main() => CustomMain(); static void Solve() { int a, b, c; ReadMulti(out a, out b, out c); var ans = a * 100 + b * 10 + c % 4 == 0 ? "YES" : "NO"; WriteAnswer(ans); } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); static bool IsOdd(long num) { return (num & 1) == 1; } static bool IsEven(long num) { return (num & 1) == 0; } static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static long RoundUp(long a, long b) { return (a + b - 1) / b; } static void ChangeStdIn() { var path = "./../../TestCase.txt"; var exStdIn = new System.IO.StreamReader(path); Console.SetIn(exStdIn); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; internal class Program { static void Main() => CustomMain(); static void Solve() { int a, b, c; ReadMulti(out a, out b, out c); var ans = (a * 100 + b * 10 + c) % 4 == 0 ? "YES" : "NO"; WriteAnswer(ans); } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); static bool IsOdd(long num) { return (num & 1) == 1; } static bool IsEven(long num) { return (num & 1) == 0; } static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static long RoundUp(long a, long b) { return (a + b - 1) / b; } static void ChangeStdIn() { var path = "./../../TestCase.txt"; var exStdIn = new System.IO.StreamReader(path); Console.SetIn(exStdIn); } }
[["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 25]]
8
789
2
using System; class AtCoder { static void Main(string[] args) { string input = Console.ReadLine().Replace(" ", ""); var s = int.Parse(input) % 4 == 0 ? "Yes" : "No"; Console.WriteLine(s); } }
using System; class AtCoder { static void Main(string[] args) { string input = Console.ReadLine().Replace(" ", ""); var s = int.Parse(input) % 4 == 0 ? "YES" : "NO"; Console.WriteLine(s); } }
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
66
4
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); // Splitで空白で区切って2つ受け取る。 int g = int.Parse(input[1]); int b = int.Parse(input[2]); if (g * 10 + b % 4 == 0) Console.WriteLine("YES"); // WriteLineをWriteとすると、改行なしで出力。 else Console.WriteLine("NO"); } }
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); // Splitで空白で区切って2つ受け取る。 int g = int.Parse(input[1]); int b = int.Parse(input[2]); if ((g * 10 + b) % 4 == 0) Console.WriteLine("YES"); // WriteLineをWriteとすると、改行なしで出力。 else Console.WriteLine("NO"); } }
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25]]
8
91
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) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new MyInputStream(Console.In, ' ')); Console.Out.Flush(); } public void Solve(MyInputStream cin) { var val = cin.ReadInt() * 100 + cin.ReadInt() * 10 + cin.ReadInt(); if (val % 4 == 0) WriteLine("Yes"); else WriteLine("No"); } } public class MyInputStream { private readonly System.IO.TextReader _stream; private char separator = ' '; private Queue<string> inputStream; public MyInputStream(System.IO.TextReader s, char separator = ' ') { this.separator = separator; this._stream = s; inputStream = new Queue<string>(); } public string Read() { 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() { return _stream.ReadLine(); } public int ReadInt() { return int.Parse(Read()); } public long ReadLong() { return long.Parse(Read()); } public double ReadDouble() { 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) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new MyInputStream(Console.In, ' ')); Console.Out.Flush(); } public void Solve(MyInputStream cin) { var val = cin.ReadInt() * 100 + cin.ReadInt() * 10 + cin.ReadInt(); if (val % 4 == 0) WriteLine("YES"); else WriteLine("NO"); } } public class MyInputStream { private readonly System.IO.TextReader _stream; private char separator = ' '; private Queue<string> inputStream; public MyInputStream(System.IO.TextReader s, char separator = ' ') { this.separator = separator; this._stream = s; inputStream = new Queue<string>(); } public string Read() { 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() { return _stream.ReadLine(); } public int ReadInt() { return int.Parse(Read()); } public long ReadLong() { return long.Parse(Read()); } public double ReadDouble() { 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, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
516
4
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { string s = Console.ReadLine().Replace(" ", ""); string ans = "No"; int num = int.Parse(s); if (num % 4 == 0) ans = "Yes"; Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { string s = Console.ReadLine().Replace(" ", ""); string ans = "NO"; int num = int.Parse(s); if (num % 4 == 0) ans = "YES"; Console.WriteLine(ans); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222]]
8
85
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { string Solve(int R, int G, int B) { return (R * 100 + G * 10 + B) % 4 == 0 ? "YES" : "No"; } static void Main() { var NX = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Console.WriteLine(new Program().Solve(NX[0], NX[1], NX[2])); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { string Solve(int R, int G, int B) { return (R * 100 + G * 10 + B) % 4 == 0 ? "YES" : "NO"; } static void Main() { var NX = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Console.WriteLine(new Program().Solve(NX[0], NX[1], NX[2])); } }
[["-", 8, 196, 0, 37, 0, 41, 75, 5, 0, 222], ["+", 8, 196, 0, 37, 0, 41, 75, 5, 0, 222]]
8
132
2
namespace ConsoleApplication { class Program { public static void Main(string[] args) { var parms = System.Console.ReadLine().Split(); System.Console.WriteLine( int.Parse(parms[1]) * 10 + int.Parse(parms[2]) % 4 == 0 ? "YES" : "NO"); } } }
using System; class Program { public static void Main(string[] args) { var parms = System.Console.ReadLine().Split(); System.Console.WriteLine( (int.Parse(parms[1]) * 10 + int.Parse(parms[2])) % 4 == 0 ? "YES" : "NO"); } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 0, 256], ["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 36, 36, 0, 208, 0, 209, 8, 201, 0, 45], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46]]
8
76
5
namespace ConsoleApplication { class Program { public static void Main(string[] args) { var parms = System.Console.ReadLine().Split(); System.Console.WriteLine( int.Parse(parms[1]) * 10 + int.Parse(parms[2]) % 4 == 0 ? "YES" : "NO"); } } }
using System; namespace ConsoleApplication { class Program { public static void Main(string[] args) { var parms = System.Console.ReadLine().Split(); System.Console.WriteLine( (int.Parse(parms[1]) * 10 + int.Parse(parms[2])) % 4 == 0 ? "YES" : "NO"); } } }
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
76
5
using System; class Answer { static void Main() { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = int.Parse(str[2]); int num = a * 100 + b * 10 + c; if (num % 4 == 0) { Console.Write("Yes"); } else { Console.Write("No"); } } }
using System; class Answer { static void Main() { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = int.Parse(str[2]); int num = a * 100 + b * 10 + c; if (num % 4 == 0) { Console.Write("YES"); } else { Console.Write("NO"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
115
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Hello { static void Main() { var n = Console.ReadLine().Split(); //.Where(e => e != ' ').ToArray(); int a = int.Parse(string.Join("", n)); string str = ""; if (a % 4 == 0) { str = "YES"; } else { str = "No"; } Console.WriteLine(str); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Hello { static void Main() { var n = Console.ReadLine().Split(); int a = int.Parse(string.Join("", n)); string str = ""; if (a % 4 == 0) { str = "YES"; } else { str = "NO"; } Console.WriteLine(str); } }
[["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
101
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc64 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int r = int.Parse(str[0]); int g = int.Parse(str[1]); int b = int.Parse(str[2]); int x = r * 100 + g * 10 + b; if (x % 4 == 0) { Console.WriteLine("TES"); } else { Console.WriteLine("NO"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc64 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int r = int.Parse(str[0]); int g = int.Parse(str[1]); int b = int.Parse(str[2]); int x = r * 100 + g * 10 + b; if (x % 4 == 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
147
2
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int x = int.Parse(input[0]); int y = int.Parse(input[1]); if (x == 4 || x == 6 || x == 9 || x == 11) x = 1; else if (x == 2) x = 2; else x = 3; if (y == 4 || y == 6 || y == 9 || y == 11) y = 1; else if (y == 2) y = 2; else y = 3; if (x == y) Console.WriteLine("YES"); else Console.WriteLine("No"); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int x = int.Parse(input[0]); int y = int.Parse(input[1]); if (x == 4 || x == 6 || x == 9 || x == 11) x = 1; else if (x == 2) x = 2; else x = 3; if (y == 4 || y == 6 || y == 9 || y == 11) y = 1; else if (y == 2) y = 2; else y = 3; if (x == y) 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
163
2
using System; using System.Collections.Generic; public class Hello { public static void Main() { string[] s = Console.ReadLine().Split(' '); int x = int.Parse(s[0]); int y = int.Parse(s[1]); var a = new List<int>() { 1, 3, 5, 7, 8, 10, 12 }; var b = new List<int>() { 4, 6, 9, 11 }; if (x == y) { Console.WriteLine("YES"); } else if (a.Contains(x) && a.Contains(y)) { Console.WriteLine("YES"); } else if (b.Contains(x) && b.Contains(y)) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; using System.Collections.Generic; public class Hello { public static void Main() { string[] s = Console.ReadLine().Split(' '); int x = int.Parse(s[0]); int y = int.Parse(s[1]); var a = new List<int>() { 1, 3, 5, 7, 8, 10, 12 }; var b = new List<int>() { 4, 6, 9, 11 }; if (x == y) { Console.WriteLine("Yes"); } else if (a.Contains(x) && a.Contains(y)) { Console.WriteLine("Yes"); } else if (b.Contains(x) && b.Contains(y)) { 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
198
8
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[][] a = { new int[] { 1, 3, 5, 6, 8, 10, 12 }, new int[] { 4, 6, 9, 11 }, new int[] { 2 } }; int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < 3; i++) { if (a[i].Contains(s[0]) && a[i].Contains(s[1])) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[][] a = { new int[] { 1, 3, 5, 7, 8, 10, 12 }, new int[] { 4, 6, 9, 11 }, new int[] { 2 } }; int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < 3; i++) { if (a[i].Contains(s[0]) && a[i].Contains(s[1])) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } }
[["-", 0, 212, 0, 229, 0, 227, 0, 229, 0, 203], ["+", 0, 212, 0, 229, 0, 227, 0, 229, 0, 203]]
8
169
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; public class Program { public static void Main() { Reader reader = new Reader(Console.In); int x = reader.RInt(); int y = reader.Int(); var g1 = new List<int> { 1, 3, 5, 7, 8, 10, 12 }; var g2 = new List<int> { 4, 6, 9, 11 }; if (g1.Any(a => a == x) && g1.Any(a => a == y)) { Console.WriteLine("YES"); } else if (g2.Any(a => a == x) && g2.Any(a => a == y)) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } public class Reader { private readonly TextReader reader; private readonly char separator = ' '; private string[] A = new string[0]; private int i; public Reader(TextReader r) { reader = r; } public string String() { return Set(); } public int Int() { return int.Parse(Set()); } public long Long() { return long.Parse(Set()); } public string RString() { return RSet(); } public int RInt() { return int.Parse(RSet()); } public long RLong() { return long.Parse(RSet()); } public int[] IntArray() { return A.Select(x => int.Parse(x)).ToArray(); } private void Read() { string line = reader.ReadLine(); A = line.Split(separator); i = 0; } private string Set() { return A[i++]; } private string RSet() { Read(); return A[i++]; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; public class Program { public static void Main() { Reader reader = new Reader(Console.In); int x = reader.RInt(); int y = reader.Int(); var g1 = new List<int> { 1, 3, 5, 7, 8, 10, 12 }; var g2 = new List<int> { 4, 6, 9, 11 }; if (g1.Any(a => a == x) && g1.Any(a => a == y)) { Console.WriteLine("Yes"); } else if (g2.Any(a => a == x) && g2.Any(a => a == y)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } public class Reader { private readonly TextReader reader; private readonly char separator = ' '; private string[] A = new string[0]; private int i; public Reader(TextReader r) { reader = r; } public string String() { return Set(); } public int Int() { return int.Parse(Set()); } public long Long() { return long.Parse(Set()); } public string RString() { return RSet(); } public int RInt() { return int.Parse(RSet()); } public long RLong() { return long.Parse(RSet()); } public int[] IntArray() { return A.Select(x => int.Parse(x)).ToArray(); } private void Read() { string line = reader.ReadLine(); A = line.Split(separator); i = 0; } private string Set() { return A[i++]; } private string RSet() { Read(); return A[i++]; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
415
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Hello { public static Hello hello; public static void Main() { hello = new Hello(); hello.Run(); } private string[] ReadInputs() { var line = System.Console.ReadLine(); return line.Split(); } public void Run() { IList<int> groupA = new List<int> { 1, 3, 5, 7, 8, 9, 12 }; IList<int> groupB = new List<int> { 4, 6, 9, 11 }; int[] inputN = ReadInputs().Select(x => int.Parse(x)).ToArray(); string answer = ""; if (inputN.Contains(2)) { if (inputN[0] == inputN[1]) { answer = "Yes"; } else { answer = "No"; } } if ((groupA.Contains(inputN[0]) && groupA.Contains(inputN[1])) || (groupB.Contains(inputN[0]) && groupB.Contains(inputN[1]))) { answer = "Yes"; } else { answer = "No"; } Console.WriteLine(answer); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Hello { public static Hello hello; public static void Main() { hello = new Hello(); hello.Run(); } private string[] ReadInputs() { var line = System.Console.ReadLine(); return line.Split(); } public void Run() { IList<int> groupA = new List<int> { 1, 3, 5, 7, 8, 10, 12 }; IList<int> groupB = new List<int> { 4, 6, 9, 11 }; int[] inputN = ReadInputs().Select(x => int.Parse(x)).ToArray(); string answer = ""; if (inputN.Contains(2)) { if (inputN[0] == inputN[1]) { answer = "Yes"; } else { answer = "No"; } } if ((groupA.Contains(inputN[0]) && groupA.Contains(inputN[1])) || (groupB.Contains(inputN[0]) && groupB.Contains(inputN[1]))) { answer = "Yes"; } else { answer = "No"; } Console.WriteLine(answer); } }
[["-", 0, 200, 0, 212, 0, 230, 10, 229, 0, 203], ["+", 0, 200, 0, 212, 0, 230, 10, 229, 0, 203]]
8
281
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var (H, W) = ReadStream<int, int>(); string frame = ""; for (int i = 0; i < W; i++) { frame += "#"; } WriteLine(frame); for (int i = 0; i < H; i++) { var S = "#" + RString() + "#"; WriteLine(S); } WriteLine(frame); } } class Modular { private const int M = 1000000007; private long value; public Modular(long value = 0) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) => a.value + b.value; public static Modular operator -(Modular a, Modular b) => a.value - b.value; public static Modular operator *(Modular a, Modular b) => a.value * b.value; public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; public static Modular Fac(int n) //階乗 { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Fac(int r, int n) { int temp = 1; for (int i = r; i <= n; i++) { temp = (int)(Math.BigMul(temp, i) % M); } return temp; } public static Modular Ncr(int n, int r) // nCr { return (n < r) ? 0 : (n == r) ? 1 : (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r)) : Fac(n - r + 1, n) / Fac(r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[0], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[0], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var (H, W) = ReadStream<int, int>(); string frame = ""; for (int i = 0; i < W + 2; i++) { frame += "#"; } WriteLine(frame); for (int i = 0; i < H; i++) { var S = "#" + RString() + "#"; WriteLine(S); } WriteLine(frame); } } class Modular { private const int M = 1000000007; private long value; public Modular(long value = 0) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) => a.value + b.value; public static Modular operator -(Modular a, Modular b) => a.value - b.value; public static Modular operator *(Modular a, Modular b) => a.value * b.value; public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; public static Modular Fac(int n) //階乗 { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Fac(int r, int n) { int temp = 1; for (int i = r; i <= n; i++) { temp = (int)(Math.BigMul(temp, i) % M); } return temp; } public static Modular Ncr(int n, int r) // nCr { return (n < r) ? 0 : (n == r) ? 1 : (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r)) : Fac(n - r + 1, n) / Fac(r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[0], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[0], typeof(T4)); return (r1, r2, r3, r4); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
1,189
2
using System; using System.Collections.Generic; using System.Linq; using System.Collections; using System.Linq.Expressions; static class Program { static void Main() { new Magatro().Solve(); } } class Magatro { int H, W; public void Solve() { var line = Console.ReadLine().Split(' '); H = int.Parse(line[0]); W = int.Parse(line[1]); Console.WriteLine(new string('#', W + 2)); for (int i = 0; i < H; i++) { Console.Write("#"); Console.WriteLine(Console.ReadLine()); Console.Write("#"); Console.WriteLine(); } Console.WriteLine(new string('#', W + 2)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Collections; using System.Linq.Expressions; static class Program { static void Main() { new Magatro().Solve(); } } class Magatro { int H, W; public void Solve() { var line = Console.ReadLine().Split(' '); H = int.Parse(line[0]); W = int.Parse(line[1]); Console.WriteLine(new string('#', W + 2)); for (int i = 0; i < H; i++) { Console.Write("#"); Console.Write(Console.ReadLine()); Console.Write("#"); Console.WriteLine(); } Console.WriteLine(new string('#', W + 2)); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
8
189
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var p = Input().ToInt(); var h = p[0]; var w = p[1]; for (int i = 0; i < w + 2; i++) Console.Write("#"); for (int i = 0; i < h; i++) { var s = Console.ReadLine(); Console.WriteLine("#{0}#", s); } for (int i = 0; i < w + 2; i++) Console.Write("#"); Console.WriteLine(); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var p = Input().ToInt(); var h = p[0]; var w = p[1]; for (int i = 0; i < w + 2; i++) Console.Write("#"); Console.WriteLine(); for (int i = 0; i < h; i++) { var s = Console.ReadLine(); Console.WriteLine("#{0}#", s); } for (int i = 0; i < w + 2; i++) Console.Write("#"); Console.WriteLine(); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
364
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var o = Ints; var H = o[0]; var W = o[1]; Write(new StringBuilder().Append('#', W + 2)); for (int i = 0; i < H; ++i) { Console.Write('#'); Console.Write(Str); Console.Write('#'); } Write(new StringBuilder().Append('#', W + 2)); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long 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) { 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) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var o = Ints; var H = o[0]; var W = o[1]; Write(new StringBuilder().Append('#', W + 2)); for (int i = 0; i < H; ++i) { Console.Write('#'); Console.Write(Str); Console.Write("#\n"); } Write(new StringBuilder().Append('#', W + 2)); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long 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) { 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) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 44]]
8
991
5
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var r = ReadIntArray(); var H = r[0]; var W = r[1]; List<string> row = new List<string>(); row.Add(string.Concat(Enumerable.Repeat("#", W + 1).ToArray())); for (int i = 0; i < H; i++) { var line = Read(); row.Add("#" + line + "#"); } row.Add(string.Concat(Enumerable.Repeat("#", W + 1).ToArray())); foreach (var item in row) { Console.WriteLine(item); } } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var r = ReadIntArray(); var H = r[0]; var W = r[1]; List<string> row = new List<string>(); row.Add(string.Concat(Enumerable.Repeat("#", W + 2).ToArray())); for (int i = 0; i < H; i++) { var line = Read(); row.Add("#" + line + "#"); } row.Add(string.Concat(Enumerable.Repeat("#", W + 2).ToArray())); foreach (var item in row) { Console.WriteLine(item); } } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
[["-", 205, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
372
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { var tmp = ReadIntArray(); int h = tmp[0], w = tmp[1]; string s = new string('#', w); WriteLine(s); for (int i = 0; i < h; i++) { Write('#'); Write(ReadLine()); WriteLine('#'); } WriteLine(s); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { var tmp = ReadIntArray(); int h = tmp[0], w = tmp[1]; string s = new string('#', w + 2); WriteLine(s); for (int i = 0; i < h; i++) { Write('#'); Write(ReadLine()); WriteLine('#'); } WriteLine(s); } }
[["+", 0, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 12, 203]]
8
165
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { SolveA(); // SolveB(); // SolveC(); // SolveD(); } private const long MOD = 1000000007; static void SolveA() { var o = ReadAndParseIntArr(); int h = o[0]; int w = o[1]; var a = new string[h]; for (int i = 0; i < h; ++i) { a[i] = Console.ReadLine(); } var list = new List<string>(); list.Add(GetSharp(w)); for (int i = 0; i < h; ++i) { sb.Clear(); sb.Append("#"); sb.Append(a[i]); sb.Append("#"); list.Add(sb.ToString()); } list.Add(GetSharp(w)); foreach (string sz in list) { Console.WriteLine(sz); } } private static StringBuilder sb = new StringBuilder(); private static string GetSharp(int w) { sb.Clear(); for (int i = 0; i < w; ++i) { sb.Append("#"); } return sb.ToString(); } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { SolveA(); // SolveB(); // SolveC(); // SolveD(); } private const long MOD = 1000000007; static void SolveA() { var o = ReadAndParseIntArr(); int h = o[0]; int w = o[1]; var a = new string[h]; for (int i = 0; i < h; ++i) { a[i] = Console.ReadLine(); } var list = new List<string>(); list.Add(GetSharp(w)); for (int i = 0; i < h; ++i) { sb.Clear(); sb.Append("#"); sb.Append(a[i]); sb.Append("#"); list.Add(sb.ToString()); } list.Add(GetSharp(w)); foreach (string sz in list) { Console.WriteLine(sz); } } private static StringBuilder sb = new StringBuilder(); private static string GetSharp(int w) { w += 2; sb.Clear(); for (int i = 0; i < w; ++i) { sb.Append("#"); } return sb.ToString(); } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
586
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var temp = (Console.ReadLine().Split(' ')); var height = int.Parse(temp[0]); var width = int.Parse(temp[1]); var data = new string[height]; for (int i = 0; i < height; i++) { data[i] = Console.ReadLine(); } for (int i = 0; i < width + 2; i++) Console.Write('*'); Console.WriteLine(); for (int i = 0; i < height; i++) Console.WriteLine("*" + data[i] + "*"); for (int i = 0; i < width + 2; i++) Console.Write('*'); Console.WriteLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var temp = (Console.ReadLine().Split(' ')); var height = int.Parse(temp[0]); var width = int.Parse(temp[1]); var data = new string[height]; for (int i = 0; i < height; i++) { data[i] = Console.ReadLine(); } for (int i = 0; i < width + 2; i++) Console.Write('#'); Console.WriteLine(); for (int i = 0; i < height; i++) Console.WriteLine("#" + data[i] + "#"); for (int i = 0; i < width + 2; i++) Console.Write('#'); Console.WriteLine(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 28, 0, 16, 31, 16, 31, 5, 0, 222], ["+", 0, 28, 0, 16, 31, 16, 31, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222]]
8
220
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderTest { public class Program { public static void Main(string[] args) { string[] s = Console.ReadLine().Split(); int h = int.Parse(s[0]); int w = int.Parse(s[1]); string hf = string.Concat(Enumerable.Repeat("#", w)); Console.WriteLine(hf); for (int i = 0; i < h; i++) { string p = Console.ReadLine(); Console.WriteLine("#" + p + "#"); } Console.WriteLine(hf); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderTest { public class Program { public static void Main(string[] args) { string[] s = Console.ReadLine().Split(); int h = int.Parse(s[0]); int w = int.Parse(s[1]); string hf = string.Concat(Enumerable.Repeat("#", w + 2)); Console.WriteLine(hf); for (int i = 0; i < h; i++) { string p = Console.ReadLine(); Console.WriteLine("#" + p + "#"); } Console.WriteLine(hf); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
162
2
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); Read(); } static void Solve() { var HW = Sarray(); var H = HW[0]; var W = HW[1]; if (H % 3 == 0 || W % 3 == 0) { WriteLine(0); return; } var ans = Min(H, W); for (var i = 1; i < W; ++i) { var men = new long[3]; men[0] = H * i; men[1] = (H / 2) * (W - i); men[2] = (H - H / 2) * (W - i); ans = Min(ans, men.Max() - men.Min()); } for (var i = 1; i < H; ++i) { var men = new long[3]; men[0] = H * i; men[1] = (W / 2) * (H - i); men[2] = (W - W / 2) * (H - i); ans = Min(ans, men.Max() - men.Min()); } WriteLine(ans); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); Read(); } static void Solve() { var HW = Sarray(); var H = HW[0]; var W = HW[1]; if (H % 3 == 0 || W % 3 == 0) { WriteLine(0); return; } var ans = Min(H, W); for (var i = 1; i < W; ++i) { var men = new long[3]; men[0] = H * i; men[1] = (H / 2) * (W - i); men[2] = (H - H / 2) * (W - i); ans = Min(ans, men.Max() - men.Min()); } for (var i = 1; i < H; ++i) { var men = new long[3]; men[0] = W * i; men[1] = (W / 2) * (H - i); men[2] = (W - W / 2) * (H - i); ans = Min(ans, men.Max() - men.Min()); } WriteLine(ans); } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22]]
8
409
2
using System; using System.Linq; using static System.Math; class C { static void Main() { var a = Console.ReadLine().Split().Select(long.Parse).ToArray(); long h = a[0], w = a[1]; if (h % 3 == 0 || w % 3 == 0) { Console.WriteLine(0); return; } var m = Min(h > 3 ? w : long.MaxValue, w > 3 ? h : long.MaxValue); m = Min(m, Divide(h, w)); m = Min(m, Divide(w, h)); Console.WriteLine(m); } static long Divide(long h, long w) { var h2 = h / 2; var m = long.MaxValue; for (long v = (w + 1) / 2, v2 = w - v; v > 0; v--, v2++) { var ss = new[] { h * v, h2 * v2, (h2 + 1) * v2 }; Array.Sort(ss); m = Min(m, ss[2] - ss[0]); } return m; } }
using System; using System.Linq; using static System.Math; class C { static void Main() { var a = Console.ReadLine().Split().Select(long.Parse).ToArray(); long h = a[0], w = a[1]; if (h % 3 == 0 || w % 3 == 0) { Console.WriteLine(0); return; } var m = Min(h > 3 ? w : long.MaxValue, w > 3 ? h : long.MaxValue); m = Min(m, Divide(h, w)); m = Min(m, Divide(w, h)); Console.WriteLine(m); } static long Divide(long h, long w) { var h2 = h / 2; var m = long.MaxValue; for (long v = (w + 1) / 2, v2 = w - v; v > 0; v--, v2++) { var ss = new[] { h * v, h2 * v2, (h - h2) * v2 }; Array.Sort(ss); m = Min(m, ss[2] - ss[0]); } return m; } }
[["+", 0, 229, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 229, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 229, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 229, 0, 16, 31, 23, 0, 16, 12, 203]]
8
258
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 AtCorder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var H = cin.ReadInt; var W = cin.ReadInt; var p = new long[3]; var ans = long.MaxValue; if (H % 3 == 0 || W % 3 == 0) { WriteLine(0); return; } for (int i = 1; i <= W - 1; i++) { p[0] = i * H; var w = (W - i) / 2; p[1] = w * H; p[2] = H * (W - i - w); if (ans > p.Max() - p.Min()) ans = p.Max() - p.Min(); } for (int i = 1; i <= W - 1; i++) { p[0] = H * i; var h = H / 2; p[1] = (W - i) * h; p[2] = (W - i) * (H - h); if (ans > p.Max() - p.Min()) ans = p.Max() - p.Min(); } for (int i = 0; i <= H - 1; i++) { p[0] = W * i; var h = (H - i) / 2; p[1] = W * h; p[2] = W * (H - i - h); if (ans > p.Max() - p.Min()) ans = p.Max() - p.Min(); } for (int i = 0; i <= H - 1; i++) { p[0] = W * i; var w = W / 2; p[1] = (H - i) * w; p[2] = (H - i) * (W - w); if (ans > p.Max() - p.Min()) ans = p.Max() - p.Min(); } WriteLine(ans); } public long C(int X, int Y) { if (Y == 0 || Y == X) { return 1; } if (X < Y) { return 0; } var Pascal = new long[X + 1, X + 1]; for (int i = 0; i <= X; i++) { Pascal[i, 0] = 1L; Pascal[i, i] = 1L; } for (int i = 2; i <= X; i++) { for (int j = 1; j < i; j++) { Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1]; } } return Pascal[X, Y]; } 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 AtCorder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var H = cin.ReadLong; var W = cin.ReadLong; var p = new long[3]; var ans = long.MaxValue; if (H % 3 == 0 || W % 3 == 0) { WriteLine(0); return; } for (long i = 1; i <= W - 1; i++) { p[0] = i * H; var w = (W - i) / 2; p[1] = w * H; p[2] = H * (W - i - w); if (ans > p.Max() - p.Min()) ans = p.Max() - p.Min(); } for (long i = 1; i <= W - 1; i++) { p[0] = H * i; var h = H / 2; p[1] = (W - i) * h; p[2] = (W - i) * (H - h); if (ans > p.Max() - p.Min()) ans = p.Max() - p.Min(); } for (long i = 0; i <= H - 1; i++) { p[0] = W * i; var h = (H - i) / 2; p[1] = W * h; p[2] = W * (H - i - h); if (ans > p.Max() - p.Min()) ans = p.Max() - p.Min(); } for (long i = 0; i <= H - 1; i++) { p[0] = W * i; var w = W / 2; p[1] = (H - i) * w; p[2] = (H - i) * (W - w); if (ans > p.Max() - p.Min()) ans = p.Max() - p.Min(); } WriteLine(ans); } public long C(int X, int Y) { if (Y == 0 || Y == X) { return 1; } if (X < Y) { return 0; } var Pascal = new long[X + 1, X + 1]; for (int i = 0; i <= X; i++) { Pascal[i, 0] = 1L; Pascal[i, i] = 1L; } for (int i = 2; i <= X; i++) { for (int j = 1; j < i; j++) { Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1]; } } return Pascal[X, Y]; } 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, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
8
1,008
12
using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var h = long.Parse(line[0]); var w = long.Parse(line[1]); if (h % 3 == 0 | w % 3 == 0) { Console.WriteLine(0); goto end; } var r1 = Math.Min(getDD3(h, w), getDD3(w, h)); var r2 = Math.Min(getD3(h, w), getD3(w, h)); var r3 = Math.Min(r1, r2); Console.WriteLine(r3); end:; } public static long getDD3(long a, long b) { var b1 = b / 2; var b2 = b - b1; var ret = 9999999999999999L; for (int i = 1; i < a; i++) { var x = getABSmin(b1 * (a - i), b2 * (a - i), b * i); ret = Math.Min(ret, x); } return ret; } public static long getABSmin(long a, long b, long c) { var ar = new long[3]; ar[0] = a; ar[1] = b; ar[2] = c; return ar.Max() - ar.Min(); } public static long getD3(long a, long b) { var ret = 9999999999999L; for (int i = 1; i <= b - 2; i++) { var w1 = (b - i) / 2; var w2 = b - w1; ret = Math.Min(ret, getABSmin(w1, w2, i)); } return ret * a; } }
using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var h = long.Parse(line[0]); var w = long.Parse(line[1]); if (h % 3 == 0 | w % 3 == 0) { Console.WriteLine(0); goto end; } var r1 = Math.Min(getDD3(h, w), getDD3(w, h)); var r2 = Math.Min(getD3(h, w), getD3(w, h)); var r3 = Math.Min(r1, r2); Console.WriteLine(r3); end:; } public static long getDD3(long a, long b) { var b1 = b / 2; var b2 = b - b1; var ret = 9999999999999999L; for (int i = 1; i < a; i++) { var x = getABSmin(b1 * (a - i), b2 * (a - i), b * i); ret = Math.Min(ret, x); } return ret; } public static long getABSmin(long a, long b, long c) { var ar = new long[3]; ar[0] = a; ar[1] = b; ar[2] = c; return ar.Max() - ar.Min(); } public static long getD3(long a, long b) { var ret = 9999999999999L; for (int i = 1; i <= b - 2; i++) { var w1 = (b - i) / 2; var w2 = b - i - w1; ret = Math.Min(ret, getABSmin(w1, w2, i)); } return ret * a; } }
[["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33]]
8
385
2
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class MainClass { public static void Main(string[] args) { var x = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var ans = Ans(x); x = new[] { x[1], x[0] }; ans = Math.Min(ans, Ans(x)); Console.WriteLine(ans); } static long Ans(long[] x) { var area = new long[3]; var result = long.MaxValue; if (x[0] % 3 == 0 || x[1] % 3 == 0) return 0; else { for (int i = 1; i < x[0]; i++) { area[0] = i * x[1]; area[1] = x[1] * ((x[0] - i) / 2); area[2] = x[0] * x[1] - area[0] - area[1]; var hoge = Max(area) - min(area); if (hoge < result) result = hoge; area[1] = (x[0] - i) * (x[1] / 2); area[2] = x[0] * x[1] - area[0] - area[1]; hoge = Max(area) - min(area); if (hoge < result) result = hoge; } } return result; } public static long Max(long[] a) { long max = a[0]; for (int i = 1; i < a.Length; i++) { if (a[i] > max) max = a[i]; } return max; } public static long min(long[] a) { long min = (int)a[0]; for (int i = 1; i < a.Length; i++) { if (a[i] < min) min = a[i]; } return min; } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class MainClass { public static void Main(string[] args) { var x = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var ans = Ans(x); x = new[] { x[1], x[0] }; ans = Math.Min(ans, Ans(x)); Console.WriteLine(ans); } static long Ans(long[] x) { var area = new long[3]; var result = long.MaxValue; if (x[0] % 3 == 0 || x[1] % 3 == 0) return 0; else { for (int i = 1; i < x[0]; i++) { area[0] = i * x[1]; area[1] = x[1] * ((x[0] - i) / 2); area[2] = x[0] * x[1] - area[0] - area[1]; var hoge = Max(area) - min(area); if (hoge < result) result = hoge; area[1] = (x[0] - i) * (x[1] / 2); area[2] = x[0] * x[1] - area[0] - area[1]; hoge = Max(area) - min(area); if (hoge < result) result = hoge; } } return result; } public static long Max(long[] a) { var max = a[0]; for (int i = 1; i < a.Length; i++) { if (a[i] > max) max = a[i]; } return max; } public static long min(long[] a) { var min = a[0]; for (int i = 1; i < a.Length; i++) { if (a[i] < min) min = a[i]; } return min; } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 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
453
7
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var N = ReadInt(); var a = ReadArrayInt(); var aSum = new long[a.Length + 1]; for (int i = 1; i < aSum.Length; i++) aSum[i] = aSum[i - 1] + a[i - 1]; var min = new PriorityQueue<int>((i, j) => i - j); var max = new PriorityQueue<int>((i, j) => j - i); for (int i = 0; i < N; i++) min.Enqueue(a[i]); var minS = new long[N + 1]; for (int i = N; i < 2 * N; i++) { min.Enqueue(a[i]); minS[i - N + 1] += minS[i - N] + min.Dequeue(); } for (int i = 2 * N; i < a.Length; i++) max.Enqueue(a[i]); var maxS = new long[N + 1]; for (int i = 2 * N - 1; i >= N; i--) { max.Enqueue(a[i]); maxS[i - N] += maxS[i - N + 1] + max.Dequeue(); } var ans = long.MinValue; for (int i = 0; i < N; i++) { var minT = aSum[i + N] - minS[i]; var maxT = aSum[3 * N] - aSum[i + N] - maxS[i]; if (minT - maxT > ans) ans = minT - maxT; } Console.WriteLine(ans); Console.ReadLine(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } class PriorityQueue<T> { readonly List<T> heap; readonly Comparison<T> compare; int size; public PriorityQueue(Comparison<T> compare) { heap = new List<T>(); this.compare = compare; } public void Enqueue(T val) { heap.Add(val); int i = size++; while (i > 0) { int p = (i - 1) >> 1; if (compare(heap[p], val) <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = val; } public T Dequeue() { T ret = heap[0]; T x = heap[--size]; int i = 0; while ((i << 1) + 1 < size) { int a = (i << 1) + 1; int b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } }
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var N = ReadInt(); var a = ReadArrayInt(); var aSum = new long[a.Length + 1]; for (int i = 1; i < aSum.Length; i++) aSum[i] = aSum[i - 1] + a[i - 1]; var min = new PriorityQueue<int>((i, j) => i - j); var max = new PriorityQueue<int>((i, j) => j - i); for (int i = 0; i < N; i++) min.Enqueue(a[i]); var minS = new long[N + 1]; for (int i = N; i < 2 * N; i++) { min.Enqueue(a[i]); minS[i - N + 1] += minS[i - N] + min.Dequeue(); } for (int i = 2 * N; i < a.Length; i++) max.Enqueue(a[i]); var maxS = new long[N + 1]; for (int i = 2 * N - 1; i >= N; i--) { max.Enqueue(a[i]); maxS[i - N] += maxS[i - N + 1] + max.Dequeue(); } var ans = long.MinValue; for (int i = 0; i <= N; i++) { var minT = aSum[i + N] - minS[i]; var maxT = aSum[3 * N] - aSum[i + N] - maxS[i]; if (minT - maxT > ans) ans = minT - maxT; } Console.WriteLine(ans); Console.ReadLine(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } class PriorityQueue<T> { readonly List<T> heap; readonly Comparison<T> compare; int size; public PriorityQueue(Comparison<T> compare) { heap = new List<T>(); this.compare = compare; } public void Enqueue(T val) { heap.Add(val); int i = size++; while (i > 0) { int p = (i - 1) >> 1; if (compare(heap[p], val) <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = val; } public T Dequeue() { T ret = heap[0]; T x = heap[--size]; int i = 0; while ((i << 1) + 1 < size) { int a = (i << 1) + 1; int b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
823
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { checked { var H = sc.ReadLong(); var W = sc.ReadLong(); if (W % 3 == 0 || H % 3 == 0) { Console.WriteLine(0); return; } var ans = long.MaxValue; for (int ix = 0; ix < 2; ix++) { var X = Math.Max(H, W); var Y = Math.Min(H, W); if (ix == 1) { X = Math.Min(H, W); Y = Math.Max(H, W); } for (int i = 1; i <= X / 2; i++) { var a = i * Y; var j = Math.Max(X - i, Y); var k = Math.Min(X - i, Y); long b; long c; if (j % 2 == 0 || k % 2 == 0) { b = j * k / 2; c = b; } else { b = (j + 1) / 2 * k; c = j / 2 * k; } var area = Math.Abs(a - b); area = Math.Max(area, Math.Abs(a - c)); area = Math.Max(area, Math.Abs(b - c)); ans = Math.Min(ans, area); } Console.WriteLine(ans); } } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { checked { var H = sc.ReadLong(); var W = sc.ReadLong(); if (W % 3 == 0 || H % 3 == 0) { Console.WriteLine(0); return; } var ans = long.MaxValue; for (int ix = 0; ix < 2; ix++) { var X = Math.Max(H, W); var Y = Math.Min(H, W); if (ix == 1) { X = Math.Min(H, W); Y = Math.Max(H, W); } for (int i = 1; i <= X / 2; i++) { var a = i * Y; var j = Math.Max(X - i, Y); var k = Math.Min(X - i, Y); long b; long c; if (j % 2 == 0 || k % 2 == 0) { b = j * k / 2; c = b; } else { b = (j + 1) / 2 * k; c = j / 2 * k; } var area = Math.Abs(a - b); area = Math.Max(area, Math.Abs(a - c)); area = Math.Max(area, Math.Abs(b - c)); ans = Math.Min(ans, area); } } Console.WriteLine(ans); } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["+", 0, 287, 0, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 287, 0, 196, 0, 7, 8, 196, 0, 46]]
8
1,305
2
using System; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.IO; #region code challenges entry point #if !SOLVER_ATWORKSPACE class Program { static void Main(string[] args) { using ( var output = new CC.BP.FormattedStreamWriter( Console .OpenStandardOutput())) using (var input = new CC.BP.BufferedStreamReader( Console .OpenStandardInput())) new CC .ConcreteSolver(input, output) .Do(); } } #endif #endregion #region code helpers boilerplate namespace CC.BP { class BufferedStreamReader : StreamReader { const int QUEUE_INITSIZE = 1000; public BufferedStreamReader(String fileName) : base(fileName) {} public BufferedStreamReader(Stream stream) : base(stream) {} private Queue<string> buffer = new Queue<string>(QUEUE_INITSIZE); public override string ReadLine() { if (buffer.Count > 0) throw new InvalidOperationException("must read from buffer first"); return base.ReadLine(); } public string ReadToken() { while (buffer.Count == 0) { base.ReadLine() .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .ToList() .ForEach((t) => { buffer.Enqueue(t); }); } return buffer.Dequeue(); } public void ResetBuffer() { buffer = new Queue<string>(QUEUE_INITSIZE); } } class FormattedStreamWriter : StreamWriter { public FormattedStreamWriter(Stream stream) : base(stream) {} public FormattedStreamWriter(string filePath) : base(filePath) {} public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } } static class IOExtensions { public static string String(this BufferedStreamReader reader) { return reader.ReadToken(); } public static string[] StringArray(this BufferedStreamReader reader, int n) { var array = new string[n]; for (int i = 0; i < n; ++i) { array[i] = reader.ReadToken(); } return array; } public static int Int(this BufferedStreamReader reader) { return int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static int[] IntArray(this BufferedStreamReader reader, int n) { var array = new int[n]; for (int i = 0; i < n; ++i) { array[i] = int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static uint UnsignedInt(this BufferedStreamReader reader) { return uint.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static long Long(this BufferedStreamReader reader) { return long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static long[] LongArray(this BufferedStreamReader reader, int n) { var array = new long[n]; for (int i = 0; i < n; ++i) { array[i] = long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static ulong UnsignedLong(this BufferedStreamReader reader) { return ulong.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static double Double(this BufferedStreamReader reader) { return double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static double[] DoubleArray(this BufferedStreamReader reader, int n) { var array = new double[n]; for (int i = 0; i < n; ++i) { array[i] = double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static decimal Decimal(this BufferedStreamReader reader) { return decimal.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static decimal[] DecimalArray(this BufferedStreamReader reader, int n) { var array = new decimal[n]; for (int i = 0; i < n; ++i) { array[i] = decimal.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static void ArrayLine<T>(this FormattedStreamWriter writer, T[] array, int n, string format = "{0}", string separator = " ") { for (int i = 0; i < n; ++i) { if (i > 0) writer.Write(separator); writer.Write(format, array[i]); } writer.WriteLine(); } public static void ArrayLine<T>(this FormattedStreamWriter writer, T[] array, string format = "{0}", string separator = " ") { writer.ArrayLine(array, array.Length, format, separator); } } abstract class BaseSolver { public static T[][] Create2DArray<T>(int dim1, int dim2) { var res = new T[dim1][]; for (int i = 0; i < dim1; ++i) res[i] = new T[dim2]; return res; } public static T[][][] Create3DArray<T>(int dim1, int dim2, int dim3) { var res = new T[dim1][][]; for (int i = 0; i < dim1; ++i) res[i] = Create2DArray<T>(dim2, dim3); return res; } public static T[][][][] Create4DArray<T>(int dim1, int dim2, int dim3, int dim4) { var res = new T[dim1][][][]; for (int i = 0; i < dim1; ++i) res[i] = Create3DArray<T>(dim2, dim3, dim4); return res; } public abstract void Do(); } } #endregion namespace CC { using CC.BP; class ConcreteSolver : BaseSolver { private readonly BufferedStreamReader read; private readonly FormattedStreamWriter write; public ConcreteSolver(BufferedStreamReader read, FormattedStreamWriter write) { this.read = read; this.write = write; } public long Solve(int h, int w) { var res = long.MaxValue; if (h % 3 == 0) res = 0; else res = 1L * w * ((h + 1) / 3) - 1L * w * (h / 3); if (h > 1) { for (int i = 1; i < w; ++i) { long b = 1L * h * i; var l1 = 1L * (w - i) * (h / 2); var l2 = 1L * (w - i) * ((h + 1) / 2); var m1 = Math.Max(l1, l2); var m2 = Math.Min(l1, l2); res = Math.Min(res, Math.Max(b, m1) - Math.Min(b, m2)); } } return res; } public override void Do() { var h = read.Int(); var w = read.Int(); write.WriteLine(Math.Min(Solve(h, w), Solve(w, h))); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.IO; #region code challenges entry point #if !SOLVER_ATWORKSPACE class Program { static void Main(string[] args) { using ( var output = new CC.BP.FormattedStreamWriter( Console .OpenStandardOutput())) using (var input = new CC.BP.BufferedStreamReader( Console .OpenStandardInput())) new CC .ConcreteSolver(input, output) .Do(); } } #endif #endregion #region code helpers boilerplate namespace CC.BP { class BufferedStreamReader : StreamReader { const int QUEUE_INITSIZE = 1000; public BufferedStreamReader(String fileName) : base(fileName) {} public BufferedStreamReader(Stream stream) : base(stream) {} private Queue<string> buffer = new Queue<string>(QUEUE_INITSIZE); public override string ReadLine() { if (buffer.Count > 0) throw new InvalidOperationException("must read from buffer first"); return base.ReadLine(); } public string ReadToken() { while (buffer.Count == 0) { base.ReadLine() .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .ToList() .ForEach((t) => { buffer.Enqueue(t); }); } return buffer.Dequeue(); } public void ResetBuffer() { buffer = new Queue<string>(QUEUE_INITSIZE); } } class FormattedStreamWriter : StreamWriter { public FormattedStreamWriter(Stream stream) : base(stream) {} public FormattedStreamWriter(string filePath) : base(filePath) {} public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } } static class IOExtensions { public static string String(this BufferedStreamReader reader) { return reader.ReadToken(); } public static string[] StringArray(this BufferedStreamReader reader, int n) { var array = new string[n]; for (int i = 0; i < n; ++i) { array[i] = reader.ReadToken(); } return array; } public static int Int(this BufferedStreamReader reader) { return int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static int[] IntArray(this BufferedStreamReader reader, int n) { var array = new int[n]; for (int i = 0; i < n; ++i) { array[i] = int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static uint UnsignedInt(this BufferedStreamReader reader) { return uint.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static long Long(this BufferedStreamReader reader) { return long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static long[] LongArray(this BufferedStreamReader reader, int n) { var array = new long[n]; for (int i = 0; i < n; ++i) { array[i] = long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static ulong UnsignedLong(this BufferedStreamReader reader) { return ulong.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static double Double(this BufferedStreamReader reader) { return double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static double[] DoubleArray(this BufferedStreamReader reader, int n) { var array = new double[n]; for (int i = 0; i < n; ++i) { array[i] = double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static decimal Decimal(this BufferedStreamReader reader) { return decimal.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static decimal[] DecimalArray(this BufferedStreamReader reader, int n) { var array = new decimal[n]; for (int i = 0; i < n; ++i) { array[i] = decimal.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static void ArrayLine<T>(this FormattedStreamWriter writer, T[] array, int n, string format = "{0}", string separator = " ") { for (int i = 0; i < n; ++i) { if (i > 0) writer.Write(separator); writer.Write(format, array[i]); } writer.WriteLine(); } public static void ArrayLine<T>(this FormattedStreamWriter writer, T[] array, string format = "{0}", string separator = " ") { writer.ArrayLine(array, array.Length, format, separator); } } abstract class BaseSolver { public static T[][] Create2DArray<T>(int dim1, int dim2) { var res = new T[dim1][]; for (int i = 0; i < dim1; ++i) res[i] = new T[dim2]; return res; } public static T[][][] Create3DArray<T>(int dim1, int dim2, int dim3) { var res = new T[dim1][][]; for (int i = 0; i < dim1; ++i) res[i] = Create2DArray<T>(dim2, dim3); return res; } public static T[][][][] Create4DArray<T>(int dim1, int dim2, int dim3, int dim4) { var res = new T[dim1][][][]; for (int i = 0; i < dim1; ++i) res[i] = Create3DArray<T>(dim2, dim3, dim4); return res; } public abstract void Do(); } } #endregion namespace CC { using CC.BP; class ConcreteSolver : BaseSolver { private readonly BufferedStreamReader read; private readonly FormattedStreamWriter write; public ConcreteSolver(BufferedStreamReader read, FormattedStreamWriter write) { this.read = read; this.write = write; } public long Solve(int h, int w) { var res = long.MaxValue; if (h % 3 == 0) res = 0; else res = 1L * w * ((h + 2) / 3) - 1L * w * (h / 3); if (h > 1) { for (int i = 1; i < w; ++i) { long b = 1L * h * i; var l1 = 1L * (w - i) * (h / 2); var l2 = 1L * (w - i) * ((h + 1) / 2); var m1 = Math.Max(l1, l2); var m2 = Math.Min(l1, l2); res = Math.Min(res, Math.Max(b, m1) - Math.Min(b, m2)); } } return res; } public override void Do() { var h = read.Int(); var w = read.Int(); write.WriteLine(Math.Min(Solve(h, w), Solve(w, h))); } } }
[["-", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203]]
8
1,463
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC061A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a <= c && c <= b) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ACB61A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a <= c && c <= b) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.ReadKey(); } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
144
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Lesson06 { public static void Main() { string num = Console.ReadLine(); string[] nums = num.Split(' '); int A = int.Parse(nums[0]); int B = int.Parse(nums[1]); int C = int.Parse(nums[2]); if (A <= C && C <= B) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Lesson06 { public static void Main() { string num = Console.ReadLine(); string[] nums = num.Split(' '); int A = int.Parse(nums[0]); int B = int.Parse(nums[1]); int C = int.Parse(nums[2]); if (A <= C && C <= B) { 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
135
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC061A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (c >= a && c <= b) Console.WriteLine("YES"); else Console.WriteLine("NO"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC061A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (c >= a && c <= b) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
140
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC061A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a <= c || c <= b && -100 <= a || c <= 100) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC061A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a <= c && c <= b && -100 <= a && c <= 100) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
8
149
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_061A { class Program { static void Main(string[] args) { int A, B, C; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); C = int.Parse(word[2]); if (C < B && C > A) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_061A { class Program { static void Main(string[] args) { int A, B, C; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); C = int.Parse(word[2]); if (C <= B && C >= A) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20]]
8
140
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC061A { class Program { static void Main(string[] args) { int a, b, c, d, f; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a <= c) if (b >= c) Console.WriteLine("Yes"); else { Console.WriteLine("No"); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC061A { class Program { static void Main(string[] args) { int a, b, c, d, f; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a <= c && b >= c) Console.WriteLine("Yes"); else { Console.WriteLine("No"); } Console.ReadKey(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 57, 0, 121], ["-", 0, 195, 8, 196, 0, 57, 64, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
8
148
4
using System; namespace ConsoleApp21 { class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int A = int.Parse(line[0]); int B = int.Parse(line[1]); int C = int.Parse(line[2]); string rtn = "No"; if (A < C && C < B) { rtn = "Yes"; } Console.WriteLine(rtn); } } }
using System; namespace ConsoleApp21 { class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int A = int.Parse(line[0]); int B = int.Parse(line[1]); int C = int.Parse(line[2]); string rtn = "No"; if (A <= C && C <= B) { rtn = "Yes"; } Console.WriteLine(rtn); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
111
4
using System; using static System.Console; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var a = InputNumList(); WriteLine(a[0] < a[2] && a[2] < a[1] ? "Yes" : "No"); } static int InputNum() { return int.Parse(ReadLine()); } static List<int> InputNumList() { return ReadLine().Split(' ').Select(int.Parse).ToList(); } } }
using System; using static System.Console; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var a = InputNumList(); WriteLine(a[0] <= a[2] && a[2] <= a[1] ? "Yes" : "No"); } static int InputNum() { return int.Parse(ReadLine()); } static List<int> InputNumList() { return ReadLine().Split(' ').Select(int.Parse).ToList(); } } }
[["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 18], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 19], ["-", 0, 28, 0, 41, 15, 16, 12, 16, 17, 18], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 19]]
8
128
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 AtCorder { 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; if (C >= A && C <= B) { WriteLine("YES"); } else { WriteLine("NO"); } } public long C(int X, int Y) { if (Y == 0 || Y == X) { return 1; } if (X < Y) { return 0; } var Pascal = new long[X + 1, X + 1]; for (int i = 0; i <= X; i++) { Pascal[i, 0] = 1L; Pascal[i, i] = 1L; } for (int i = 2; i <= X; i++) { for (int j = 1; j < i; j++) { Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1]; } } return Pascal[X, Y]; } 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 AtCorder { 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; if (C >= A && C <= B) { WriteLine("Yes"); } else { WriteLine("No"); } } public long C(int X, int Y) { if (Y == 0 || Y == X) { return 1; } if (X < Y) { return 0; } var Pascal = new long[X + 1, X + 1]; for (int i = 0; i <= X; i++) { Pascal[i, 0] = 1L; Pascal[i, i] = 1L; } for (int i = 2; i <= X; i++) { for (int j = 1; j < i; j++) { Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1]; } } return Pascal[X, Y]; } 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, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
628
4
using System; namespace ABC061A_BetweenTwoIntegers { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int min = int.Parse(input[0]); int max = int.Parse(input[1]); int target = int.Parse(input[2]); bool result = false; if (min <= target && max >= target) { result = true; } string output = "NO"; if (result) { output = "YES"; } Console.Write(output); } } }
using System; namespace ABC061A_BetweenTwoIntegers { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int min = int.Parse(input[0]); int max = int.Parse(input[1]); int target = int.Parse(input[2]); bool result = false; if (min <= target && max >= target) { result = true; } string output = "No"; if (result) { output = "Yes"; } Console.Write(output); } } }
[["-", 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
126
4
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int[] S = Input.ScanIntArray(); Console.WriteLine((S[0] <= S[1]) && (S[1] <= S[2]) ? "Yes" : "No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.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 long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int[] S = Input.ScanIntArray(); Console.WriteLine((S[0] <= S[2]) && (S[2] <= S[1]) ? "Yes" : "No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.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 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, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 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
549
6
using System; using System.Collections; using System.Collections.Generic; using System.Text; using static MyIO; public class A { public static void Main() { int A = GetInt(); int B = GetInt(); int C = GetInt(); Console.WriteLine(((C >= A) && (C <= B)) ? "YES" : "NO"); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using static MyIO; public class A { public static void Main() { int A = GetInt(); int B = GetInt(); int C = GetInt(); Console.WriteLine(((C >= A) && (C <= B)) ? "Yes" : "No"); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
[["-", 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
231
4
using System; namespace ConsoleApp1 { 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[1]); if (C >= A) { if (B >= C) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); } } } }
using System; namespace ConsoleApp1 { 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]); if (C >= A) { if (B >= C) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); } } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
128
2
using System; public class Hello { static void Main() { char[] words = Console.ReadLine().ToCharArray(); bool result = true; for (int i = 0; i < words.Length - 1; i++) { for (int j = i + 1; j < words.Length; j++) { if (words[i] == words[j]) { result = false; break; } } if (result == false) { break; } } if (result == false) { Console.WriteLine("yes"); } else { Console.WriteLine("no"); } } }
using System; public class Hello { static void Main() { char[] words = Console.ReadLine().ToCharArray(); bool result = true; for (int i = 0; i < words.Length - 1; i++) { for (int j = i + 1; j < words.Length; j++) { // Console.WriteLine("{0}, {1}", words[i], words[j]); //同じ文字があったら、ループを抜ける。noと表示 if (words[i] == words[j]) { result = false; break; } } if (result == false) { break; } } if (result == true) { //同じ文字が含まれていないとき Console.WriteLine("yes"); } else { //同じ文字が含まれているとき Console.WriteLine("no"); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 15, 16, 12, 211, 0, 146]]
8
134
2
using System; using System.Linq; namespace practice { class Program { static void Main(string[] args) { var input = Console.ReadLine(); var isDuplicated = input.Distinct().Count() == input.Length; if (isDuplicated) { Console.WriteLine("no"); } else { Console.WriteLine("yes"); } } } }
using System; using System.Linq; namespace practice { class Program { static void Main(string[] args) { var input = Console.ReadLine(); var isDuplicated = input.Distinct().Count() == input.Length; if (isDuplicated) { 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
80
4
using System; using System.Collections.Generic; using System.Linq; namespace _075c { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] s = new int[N]; for (int i = 0; i < N; i++) { s[i] = int.Parse(Console.ReadLine()); } int ans = 0; Array.Sort(s); int j = 0; if (s.Sum() % 10 == 0) { ans = s.Sum(); } else { while (j < N) { if (s[j] % 10 == 0) { j++; continue; } else { s[j] = 0; ans = s.Sum(); break; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace _075c { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] s = new int[N]; for (int i = 0; i < N; i++) { s[i] = int.Parse(Console.ReadLine()); } int ans = 0; Array.Sort(s); int j = 0; if (s.Sum() % 10 != 0) { ans = s.Sum(); } else { while (j < N) { if (s[j] % 10 == 0) { j++; continue; } else { s[j] = 0; ans = s.Sum(); break; } } } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79]]
8
186
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 AtCorder { 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 s = cin.ReadIntArray(N); Array.Sort(s); var ans = s.Sum(); var i = 0; while (ans % 10 == 0 && i != N) { if (s[i] % 10 != 0) { ans -= s[i]; } i++; } if (ans == s.Sum()) { WriteLine(0); } else { WriteLine(ans); } } 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 AtCorder { 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 s = cin.ReadIntArray(N); Array.Sort(s); var ans = s.Sum(); var i = 0; while (ans % 10 == 0 && i != N) { if (s[i] % 10 != 0) { ans -= s[i]; } i++; } if (ans == s.Sum() && ans % 10 == 0) { WriteLine(0); } else { WriteLine(ans); } } 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, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
524
6
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Runtime.Remoting.Messaging; using System.Security.Principal; using System.Text; class Simple { private long N, A, B; private long[] h; void Solve() { // input N = io.Int; A = io.Int; B = io.Int; h = new long[N]; for (int i = 0; i < N; ++i) h[i] = io.Int; // cal var diff = A = B; Func<long, bool> isOK = (num) => { var damaged = B * num; var addNum = 0L; for (int i = 0; i < N; ++i) { long left = h[i] - damaged; if (left > 0) addNum += left / diff + (left % diff == 0 ? 0 : 1); } return addNum <= num; }; var ans = binarySearch(h, -1, (long)1e9 + 5, isOK); // ret Console.WriteLine(ans); } long binarySearch(long[] a, long ng, long ok, Func<long, bool> check) { while (ok - ng > 1) { long mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } return ok; } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Runtime.Remoting.Messaging; using System.Security.Principal; using System.Text; class Simple { private long N, A, B; private long[] h; void Solve() { // input N = io.Int; A = io.Int; B = io.Int; h = new long[N]; for (int i = 0; i < N; ++i) h[i] = io.Int; // cal var diff = A - B; Func<long, bool> isOK = (num) => { var damaged = B * num; var addNum = 0L; for (int i = 0; i < N; ++i) { var left = h[i] - damaged; if (left > 0) addNum += left / diff + (left % diff == 0 ? 0 : 1); } return addNum <= num; }; var ans = binarySearch(h, -1, (long)1e9 + 5, isOK); // ret Console.WriteLine(ans); } long binarySearch(long[] a, long ng, long ok, Func<long, bool> check) { while (ok - ng > 1) { long mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } return ok; } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
[["-", 0, 200, 0, 212, 0, 11, 0, 202, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217]]
8
565
4
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 static long n = long.Parse(input[0]); static long a = long.Parse(input[1]); static long b = long.Parse(input[2]); static long[] nums = new long[n]; static void Main() { for (long i = 0; i < n; i++) { nums[i] = long.Parse(Console.ReadLine()); } // Array.Sort(nums); Console.WriteLine(Search(1, 100000000000)); } static long Search(long min, long max) //二分探索法で最小値を求める { while (true) { long mid = min + (max - min) / 2; if (Check(mid)) max = mid; //さらに小さくても成り立つかも else max = mid; if (max - min <= 1) { if (Check(min)) { return min; //最小値で成り立つかの確認を優先 } else { return max; } break; } } } static bool Check(long testNum) { long attackCount = 0; long[] testNums = new long[n]; for (long i = 0; i < n; i++) { testNums[i] = nums[i] - b * testNum; } for (long i = 0; i < n; i++) { if (testNums[i] > 0) { attackCount += (testNums[i] + a - b - 1) / (a - b); } } if (attackCount <= testNum) return true; return false; } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 static long n = long.Parse(input[0]); static long a = long.Parse(input[1]); static long b = long.Parse(input[2]); static long[] nums = new long[n]; static void Main() { for (long i = 0; i < n; i++) { nums[i] = long.Parse(Console.ReadLine()); } // Array.Sort(nums); Console.WriteLine(Search(1, 1000000000)); } static long Search(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) { long attackCount = 0; long[] testNums = new long[n]; for (long i = 0; i < n; i++) { testNums[i] = nums[i] - b * testNum; } for (long i = 0; i < n; i++) { if (testNums[i] > 0) { attackCount += (testNums[i] + a - b - 1) / (a - b); } } // Console.WriteLine(attackCount+" "+ testNum); if (attackCount <= testNum) return true; return false; } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22]]
8
341
4
using System; using System.IO; using System.Linq; using System.Collections.Generic; public class Program { public void Proc() { long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); int mamonoCount = (int)inpt[0]; this.BigDamage = inpt[1]; this.SmallDamage = inpt[2]; SortedDictionary<long, int> mons = new SortedDictionary<long, int>(); for (int i = 0; i < mamonoCount; i++) { long mon = long.Parse(Reader.ReadLine()); if (mons.ContainsKey(mon)) { mons[mon]++; } else { mons.Add(mon, 1); } } long minKaisu = mons.First().Key / BigDamage; long maxKaisu = mons.Last().Key / SmallDamage + 1; long ans = GetAns(minKaisu, maxKaisu, mons); Console.WriteLine(ans); } private long GetAns(long min, long max, SortedDictionary<long, int> dic) { if (max - min <= 1) { if (CanBuild(min, dic)) { return min; } return max; } long mid = (max + min) / 2; if (CanBuild(mid, dic)) { return GetAns(min, mid, dic); } else { return GetAns(mid, max, dic); } } private bool CanBuild(long target, SortedDictionary<long, int> dic) { long diff = BigDamage - SmallDamage; long tmp = (long)dic.Where(a => a.Key > SmallDamage * target) .Select(a => Math.Ceiling((decimal)a.Key - (SmallDamage * target) / (BigDamage - SmallDamage)) * a.Value) .Sum(); return tmp <= target; } private long SmallDamage; private long BigDamage; 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 1 900000000 900000000 1000000000 1000000000 1000000000 "; } 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; public class Program { public void Proc() { long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); int mamonoCount = (int)inpt[0]; this.BigDamage = inpt[1]; this.SmallDamage = inpt[2]; SortedDictionary<long, int> mons = new SortedDictionary<long, int>(); for (int i = 0; i < mamonoCount; i++) { long mon = long.Parse(Reader.ReadLine()); if (mons.ContainsKey(mon)) { mons[mon]++; } else { mons.Add(mon, 1); } } long minKaisu = mons.First().Key / BigDamage; long maxKaisu = mons.Last().Key / SmallDamage + 1; long ans = GetAns(minKaisu, maxKaisu, mons); Console.WriteLine(ans); } private long GetAns(long min, long max, SortedDictionary<long, int> dic) { if (max - min <= 1) { if (CanBuild(min, dic)) { return min; } return max; } long mid = (max + min) / 2; if (CanBuild(mid, dic)) { return GetAns(min, mid, dic); } else { return GetAns(mid, max, dic); } } private bool CanBuild(long target, SortedDictionary<long, int> dic) { long diff = BigDamage - SmallDamage; long tmp = (long)dic.Where(a => a.Key > SmallDamage * target) .Select(a => Math.Ceiling( ((decimal)a.Key - (SmallDamage * target)) / (BigDamage - SmallDamage)) * a.Value) .Sum(); return tmp <= target; } private long SmallDamage; private long BigDamage; 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 = @" 2 10 4 20 20 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["+", 0, 16, 31, 23, 0, 16, 31, 74, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
8
518
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; // using Edge = Pair<long, int>; using System.Text; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); // WriteLine(Solve()); } static int num; static void Solve() { long k; Input.Make(out num, out k); var ar = Input.ar1D(num); var qq = new long[num + 1]; var s = 0L; for (var i = 1; i <= num; i++) qq[i] = (s = s + ar[i - 1]) - k * i; WriteLine(Inversion(qq)); } public static long Inversion(long[] ar) { var dic = new Dictionary<long, int>(); var d = 0; var aar = new int[ar.Length]; Array.Copy(ar, aar, ar.Length); Array.Sort(aar); //座圧 foreach (var v in aar) if (!dic.ContainsKey(v)) dic[v] = ++d; var seg = new SegmentTree<int>(ar.Length + 1, 0, (a, b) => a + b, (a, b) => a + b); // var bit = new BIT(num + 2); var res = 0L; for (var i = 0; i < ar.Length; i++) { res += seg.Query(0, dic[ar[i]] + 1); seg.Update(dic[ar[i]], 1); // res+=bit[dic[ar[i]]]; // bit.add(dic[ar[i]], 1); } return res; } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[] ar1D(int n) => Enumerable.Repeat(0, n).Select(_ => num).ToArray(); public static long[] arL1D(int n) => Enumerable.Repeat(0, n).Select(_ => numL).ToArray(); public static string[] strs(int n) => Enumerable.Repeat(0, n).Select(_ => read).ToArray(); public static int[][] ar2D(int n) => Enumerable.Repeat(0, n).Select(_ => ar).ToArray(); public static long[][] arL2D(int n) => Enumerable.Repeat(0, n).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static string[] Make<T1, T2>(out T1 v1, out T2 v2) { var r = read.Trim().Split(' '); v1 = getValue<T1>(r[0]); v2 = getValue<T2>(r[1]); return r; } public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { var r = Make(out v1, out v2); v3 = getValue<T3>(r[2]); return r; } public static string[] Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { var r = Make(out v1, out v2, out v3); v4 = getValue<T4>(r[3]); return r; } public static string[] Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { var r = Make(out v1, out v2, out v3, out v4); v5 = getValue<T5>(r[4]); return r; } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class SegmentTree<T> { private readonly T[] item; private readonly int _num; private readonly Func<T, T, T> _func; private readonly Func<T, T, T> updateFunc; private readonly T _init; private int Parent(int index) => (index - 1) >> 1; private int Left(int index) => (index << 1) + 1; private int Right(int index) => (index + 1) << 1; public T this[int i] { get { return item[i + _num - 1]; } set { item[i + _num - 1] = value; } } public SegmentTree(int num, T init, Func<T, T, T> func, Func<T, T, T> updateFunc = null) { _func = func; _num = 1; _init = init; this.updateFunc = updateFunc ?? ((T val1, T val2) => val2); while (_num <= num) _num *= 2; item = new T[2 * _num - 1]; for (var i = 0; i < 2 * _num - 1; i++) item[i] = init; } public void Update(int index, T value) { index += _num - 1; item[index] = updateFunc(item[index], value); while (index > 0) { index = Parent(index); item[index] = _func(item[Left(index)], item[Right(index)]); } } public void Update(int left, int right, T value) => Update(left, right, 0, 0, _num, value); private void Update(int left, int right, int k, int l, int r, T value) { if (r <= left || right <= l) return; if (left <= l && r <= right) item[k] = updateFunc(item[k], value); else { Update(left, right, Left(k), l, (l + r) >> 1, value); Update(left, right, Right(k), (l + r) >> 1, r, value); } } public void All_Update() { for (int i = _num - 2; i >= 0; i--) item[i] = _func(item[Left(i)], item[Right(i)]); } public T Query(int index) { index += _num - 1; var value = _func(_init, item[index]); while (index > 0) { index = Parent(index); value = _func(value, item[index]); } return value; } //[left,right) public T Query(int left, int right) => Query(left, right, 0, 0, _num); private T Query(int left, int right, int k, int l, int r) { if (r <= left || right <= l) return _init; if (left <= l && r <= right) return item[k]; else return _func(Query(left, right, Left(k), l, (l + r) >> 1), Query(left, right, Right(k), (l + r) >> 1, r)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; // using Edge = Pair<long, int>; using System.Text; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); // WriteLine(Solve()); } static int num; static void Solve() { long k; Input.Make(out num, out k); var ar = Input.ar1D(num); var qq = new long[num + 1]; var s = 0L; for (var i = 1; i <= num; i++) qq[i] = (s = s + ar[i - 1]) - k * i; WriteLine(Inversion(qq)); } public static long Inversion(long[] ar) { var dic = new Dictionary<long, int>(); var d = 0; var aar = new long[ar.Length]; Array.Copy(ar, aar, ar.Length); Array.Sort(aar); //座圧 foreach (var v in aar) if (!dic.ContainsKey(v)) dic[v] = ++d; var seg = new SegmentTree<int>(ar.Length + 1, 0, (a, b) => a + b, (a, b) => a + b); // var bit = new BIT(num + 2); var res = 0L; for (var i = 0; i < ar.Length; i++) { res += seg.Query(0, dic[ar[i]] + 1); seg.Update(dic[ar[i]], 1); // res+=bit[dic[ar[i]]]; // bit.add(dic[ar[i]], 1); } return res; } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[] ar1D(int n) => Enumerable.Repeat(0, n).Select(_ => num).ToArray(); public static long[] arL1D(int n) => Enumerable.Repeat(0, n).Select(_ => numL).ToArray(); public static string[] strs(int n) => Enumerable.Repeat(0, n).Select(_ => read).ToArray(); public static int[][] ar2D(int n) => Enumerable.Repeat(0, n).Select(_ => ar).ToArray(); public static long[][] arL2D(int n) => Enumerable.Repeat(0, n).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static string[] Make<T1, T2>(out T1 v1, out T2 v2) { var r = read.Trim().Split(' '); v1 = getValue<T1>(r[0]); v2 = getValue<T2>(r[1]); return r; } public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { var r = Make(out v1, out v2); v3 = getValue<T3>(r[2]); return r; } public static string[] Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { var r = Make(out v1, out v2, out v3); v4 = getValue<T4>(r[3]); return r; } public static string[] Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { var r = Make(out v1, out v2, out v3, out v4); v5 = getValue<T5>(r[4]); return r; } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class SegmentTree<T> { private readonly T[] item; private readonly int _num; private readonly Func<T, T, T> _func; private readonly Func<T, T, T> updateFunc; private readonly T _init; private int Parent(int index) => (index - 1) >> 1; private int Left(int index) => (index << 1) + 1; private int Right(int index) => (index + 1) << 1; public T this[int i] { get { return item[i + _num - 1]; } set { item[i + _num - 1] = value; } } public SegmentTree(int num, T init, Func<T, T, T> func, Func<T, T, T> updateFunc = null) { _func = func; _num = 1; _init = init; this.updateFunc = updateFunc ?? ((T val1, T val2) => val2); while (_num <= num) _num *= 2; item = new T[2 * _num - 1]; for (var i = 0; i < 2 * _num - 1; i++) item[i] = init; } public void Update(int index, T value) { index += _num - 1; item[index] = updateFunc(item[index], value); while (index > 0) { index = Parent(index); item[index] = _func(item[Left(index)], item[Right(index)]); } } public void Update(int left, int right, T value) => Update(left, right, 0, 0, _num, value); private void Update(int left, int right, int k, int l, int r, T value) { if (r <= left || right <= l) return; if (left <= l && r <= right) item[k] = updateFunc(item[k], value); else { Update(left, right, Left(k), l, (l + r) >> 1, value); Update(left, right, Right(k), (l + r) >> 1, r, value); } } public void All_Update() { for (int i = _num - 2; i >= 0; i--) item[i] = _func(item[Left(i)], item[Right(i)]); } public T Query(int index) { index += _num - 1; var value = _func(_init, item[index]); while (index > 0) { index = Parent(index); value = _func(value, item[index]); } return value; } //[left,right) public T Query(int left, int right) => Query(left, right, 0, 0, _num); private T Query(int left, int right, int k, int l, int r) { if (r <= left || right <= l) return _init; if (left <= l && r <= right) return item[k]; else return _func(Query(left, right, Left(k), l, (l + r) >> 1), Query(left, right, Right(k), (l + r) >> 1, r)); } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
1,810
2
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nk[0]; var k = nk[1]; long[] accums = new long[n + 1]; for (int i = 1; i < accums.Length; i++) accums[i] = accums[i - 1] + int.Parse(Console.ReadLine()) - k; var list = accums.Distinct().ToList(); throw new Exception(); SegmentTree<int> segTree = new SegmentTree<int>(list.Count, 0, (x, y) => x + y); long res = 0; for (int i = 0; i < accums.Length; i++) { var ind = list.BinarySearch(accums[i]); res += segTree.Query(0, ind); segTree.Operate(ind, 1); } Console.WriteLine(res); } } class SegmentTree<T> { public int Size { get; private set; } T IdentityElement; T[] Data; Func<T, T, T> Merge; int LeafCount; public SegmentTree(int size, T identityElement, Func<T, T, T> merge) : this(Enumerable.Repeat(identityElement, size).ToArray(), identityElement, merge) {} public SegmentTree(T[] elems, T identityElement, Func<T, T, T> merge) { Size = elems.Length; Merge = merge; IdentityElement = identityElement; LeafCount = 1; while (LeafCount < elems.Length) LeafCount <<= 1; Data = new T[LeafCount * 2]; elems.CopyTo(Data, LeafCount); for (int i = LeafCount - 1; i >= 1; i--) Data[i] = Merge(Data[i * 2], Data[i * 2 + 1]); } public T this[int index] { get { return Data[LeafCount + index]; } set { Update(index, value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int i, T x) { i += LeafCount; Data[i] = x; while (0 < (i >>= 1)) Data[i] = Merge(Data[i * 2], Data[i * 2 + 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Operate(int i, T x) { i += LeafCount; Data[i] = Merge(Data[i], x); while (0 < (i >>= 1)) Data[i] = Merge(Data[i * 2], Data[i * 2 + 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int l, int r) { l += LeafCount; T lRes = IdentityElement; r += LeafCount; T rRes = IdentityElement; while (l <= r) { if (l % 2 == 1) lRes = Merge(lRes, Data[l]); if (r % 2 == 0) rRes = Merge(Data[r], rRes); l = (l + 1) / 2; r = (r - 1) / 2; } return Merge(lRes, rRes); } }
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nk[0]; var k = nk[1]; long[] accums = new long[n + 1]; for (int i = 1; i < accums.Length; i++) accums[i] = accums[i - 1] + int.Parse(Console.ReadLine()) - k; var list = accums.Distinct().ToList(); list.Sort(); SegmentTree<int> segTree = new SegmentTree<int>(list.Count, 0, (x, y) => x + y); long res = 0; for (int i = 0; i < accums.Length; i++) { var ind = list.BinarySearch(accums[i]); res += segTree.Query(0, ind); segTree.Operate(ind, 1); } Console.WriteLine(res); } } class SegmentTree<T> { public int Size { get; private set; } T IdentityElement; T[] Data; Func<T, T, T> Merge; int LeafCount; public SegmentTree(int size, T identityElement, Func<T, T, T> merge) : this(Enumerable.Repeat(identityElement, size).ToArray(), identityElement, merge) {} public SegmentTree(T[] elems, T identityElement, Func<T, T, T> merge) { Size = elems.Length; Merge = merge; IdentityElement = identityElement; LeafCount = 1; while (LeafCount < elems.Length) LeafCount <<= 1; Data = new T[LeafCount * 2]; elems.CopyTo(Data, LeafCount); for (int i = LeafCount - 1; i >= 1; i--) Data[i] = Merge(Data[i * 2], Data[i * 2 + 1]); } public T this[int index] { get { return Data[LeafCount + index]; } set { Update(index, value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int i, T x) { i += LeafCount; Data[i] = x; while (0 < (i >>= 1)) Data[i] = Merge(Data[i * 2], Data[i * 2 + 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Operate(int i, T x) { i += LeafCount; Data[i] = Merge(Data[i], x); while (0 < (i >>= 1)) Data[i] = Merge(Data[i * 2], Data[i * 2 + 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int l, int r) { l += LeafCount; T lRes = IdentityElement; r += LeafCount; T rRes = IdentityElement; while (l <= r) { if (l % 2 == 1) lRes = Merge(lRes, Data[l]); if (r % 2 == 0) rRes = Merge(Data[r], rRes); l = (l + 1) / 2; r = (r - 1) / 2; } return Merge(lRes, rRes); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 293, 0, 294], ["-", 0, 195, 8, 196, 0, 293, 0, 230, 0, 228], ["-", 0, 195, 8, 196, 0, 293, 0, 230, 39, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
8
771
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Mirrored { class Program { static void Main(string[] args) { decimal ans = 0; decimal D = decimal.Parse(Console.ReadLine()); if (D % 9 != 0) { Console.WriteLine(0); Console.ReadLine(); return; } int ketaD = D.ToString().Length; D /= 9; for (int i = ketaD; i < 2 * ketaD; i++) { ans += chkNumber(i, D); } Console.WriteLine(ans); Console.ReadLine(); } static decimal chkNumber(int keta, decimal target) { decimal ans = 0; bool ret = false; List<decimal> insu = new List<decimal>(); int n = keta / 2; bool arbitrary = keta % 2 == 0 ? false : true; for (int i = 0; i < n; i++) { insu.Add( ((decimal)Math.Pow(10, keta - (i + 1)) - (decimal)Math.Pow(10, i)) / 9); } List<decimal> corr = new List<decimal>(); for (int i = 0; i < insu.Count; i++) { corr.Add(target / (decimal)Math.Pow(10, i) % 10); target = target - corr[i] * insu[i]; if (target == 0) { ret = true; break; } } if (ret) { for (int i = 0; i < corr.Count; i++) { if (i == 0) ans = 9 - corr[i]; else { ans *= 10 - (decimal)Math.Abs(corr[i]); } } if (arbitrary) ans *= 10; } else ans = 0; return ans; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Mirrored { class Program { static void Main(string[] args) { decimal ans = 0; decimal D = decimal.Parse(Console.ReadLine()); if (D % 9 != 0) { Console.WriteLine(0); Console.ReadLine(); return; } int ketaD = D.ToString().Length; D /= 9; for (int i = ketaD; i <= 2 * ketaD; i++) { ans += chkNumber(i, D); } Console.WriteLine(ans); Console.ReadLine(); } static decimal chkNumber(int keta, decimal target) { decimal ans = 0; bool ret = false; List<decimal> insu = new List<decimal>(); int n = keta / 2; bool arbitrary = keta % 2 == 0 ? false : true; for (int i = 0; i < n; i++) { insu.Add( ((decimal)Math.Pow(10, keta - (i + 1)) - (decimal)Math.Pow(10, i)) / 9); } List<decimal> corr = new List<decimal>(); for (int i = 0; i < insu.Count; i++) { corr.Add(target / (decimal)Math.Pow(10, i) % 10); target = target - corr[i] * insu[i]; if (target == 0) { ret = true; // break; } } if (ret) { for (int i = 0; i < corr.Count; i++) { if (i == 0) ans = 9 - corr[i]; else { ans *= 10 - (decimal)Math.Abs(corr[i]); } } if (arbitrary) ans *= 10; } else ans = 0; return ans; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
412
4
using System; using System.Text; using System.Collections.Generic; using System.Collections; using System.Linq; using E = System.Linq.Enumerable; class Program { static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray(); static long mod = 1000000007; static void Main(string[] args) { var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var N = NM[0]; var A = NM[1]; var B = NM[2]; if (A > B || (A == B && N == 1)) { Console.WriteLine(0); } else { Console.WriteLine((B - A) * (N - 2) + 1); } } }
using System; using System.Text; using System.Collections.Generic; using System.Collections; using System.Linq; using E = System.Linq.Enumerable; class Program { static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray(); static long mod = 1000000007; static void Main(string[] args) { var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var N = NM[0]; var A = NM[1]; var B = NM[2]; if (A > B || (A != B && N == 1)) { Console.WriteLine(0); } else { Console.WriteLine((B - A) * (N - 2) + 1); } } }
[["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 79]]
8
172
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); Out.Flush(); } } } public class Solve { public static void Answer() { var nab = IO.RSInt; var n = nab[0]; var a = nab[1]; var b = nab[2]; long min = a * (n - 1) + b; long max = b * (n - 1) + a; WriteLine(Max(max - min + 1, 0)); } } public struct Pair { public Pair(int a, int b) { this.a = a; this.b = b; } public int a; public int b; } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); Out.Flush(); } } } public class Solve { public static void Answer() { var nab = IO.RSLong; var n = nab[0]; var a = nab[1]; var b = nab[2]; long min = a * (n - 1) + b; long max = b * (n - 1) + a; WriteLine(Max(max - min + 1, 0)); } } public struct Pair { public Pair(int a, int b) { this.a = a; this.b = b; } public int a; public int b; } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
577
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp11 { class Class62 { static void Main() { var I = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = I[0]; var A = I[1]; var B = I[2]; long ans = (N - 2) * (B - A); if (N == 1) { Console.WriteLine(B == A ? 1 : 0); return; } Console.WriteLine(ans >= 0 ? ans + 1 : 0); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp11 { class Class62 { static void Main() { var I = Console.ReadLine().Split().Select(long.Parse).ToArray(); var N = I[0]; var A = I[1]; var B = I[2]; long ans = (N - 2) * (B - A); if (N == 1) { Console.WriteLine(B == A ? 1 : 0); return; } Console.WriteLine(ans >= 0 ? ans + 1 : 0); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
143
2
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; public static class P { public static void Main() { var nab = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nab[0]; var a = nab[1]; var b = nab[2]; if (n == 1) { if (a != b) { Console.WriteLine(0); return; } Console.WriteLine(1); return; } if (a <= b) Console.WriteLine((b - a) * (n - 2) + 1); else Console.WriteLine(0); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; public static class P { public static void Main() { var nab = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nab[0]; var a = nab[1]; var b = nab[2]; if (n == 1) { if (a != b) { Console.WriteLine(0); return; } Console.WriteLine(1); return; } if (a <= b) Console.WriteLine((b - a) * (n - 2) + 1); else Console.WriteLine(0); } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
189
2
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[] NAB = Console.ReadLine().Split().Select(int.Parse).ToArray(); int maxsum = NAB[2] * (NAB[0] - 1) + NAB[1]; int minsum = NAB[1] * (NAB[0] - 1) + NAB[2]; if (NAB[0] == 1) { if (NAB[1] == NAB[2]) { Console.WriteLine(1); } else { Console.WriteLine(0); } } else if (NAB[1] > NAB[2]) Console.WriteLine(0); else { Console.WriteLine(maxsum - minsum + 1); } } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { long[] NAB = Console.ReadLine().Split().Select(long.Parse).ToArray(); long maxsum = NAB[2] * (NAB[0] - 1) + NAB[1]; long minsum = NAB[1] * (NAB[0] - 1) + NAB[2]; if (NAB[0] == 1) { if (NAB[1] == NAB[2]) { Console.WriteLine(1); } else { Console.WriteLine(0); } } else if (NAB[1] > NAB[2]) Console.WriteLine(0); else { Console.WriteLine(maxsum - minsum + 1); } } }
[["-", 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]]
8
172
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { // 方針 // int[] num = inta(); if (num[0] == 1) { if (num[1] == num[2]) { WriteLine(1); } else { WriteLine(0); } } else if (num[1] > num[2]) { WriteLine(0); } else if (num[1] == num[2]) { WriteLine(1); } else { long a = num[1] + num[2] + (num[1] * (num[0] - 2)); long b = num[1] + num[2] + (num[2] * (num[0] - 2)); WriteLine(b - a + 1); } } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue() // スタック -> 深さ優先 ??? // var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek() // stack.Count // if (list?.Count > 0) リストが空でもnullでもない // ソート // list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート // StringComparer.Ordinal とは // 出力 // foreach(var a int list){ WriteLine(a); } より // WriteLine(string.Join("\n", list)); が速い // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false}; // Console.SetOut(sw); // foreach(var k in list[num-1]){ // WriteLine(k); // } // Console.Out.Flush();
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { // 方針 // long[] num = longa(); if (num[0] == 1) { if (num[1] == num[2]) { WriteLine(1); } else { WriteLine(0); } } else if (num[1] > num[2]) { WriteLine(0); } else if (num[1] == num[2]) { WriteLine(1); } else { long a = num[1] + num[2] + (num[1] * (num[0] - 2)); long b = num[1] + num[2] + (num[2] * (num[0] - 2)); WriteLine(b - a + 1); } } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue() // スタック -> 深さ優先 ??? // var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek() // stack.Count // if (list?.Count > 0) リストが空でもnullでもない // ソート // list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート // StringComparer.Ordinal とは // 出力 // foreach(var a int list){ WriteLine(a); } より // WriteLine(string.Join("\n", list)); が速い // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false}; // Console.SetOut(sw); // foreach(var k in list[num-1]){ // WriteLine(k); // } // Console.Out.Flush();
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22]]
8
967
4
using System; using System.Linq; namespace AGC015 { class A { static void Main(string[] args) { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int A = input[1]; int B = input[2]; if (N == 1) { if (A == B) { Console.WriteLine(1); return; } else { Console.WriteLine(0); return; } } else { if (B < A) { Console.WriteLine(0); return; } else Console.WriteLine((B - A) * (N - 2) + 1); } } } }
using System; using System.Linq; namespace AGC015 { class A { static void Main(string[] args) { long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = input[0]; long A = input[1]; long B = input[2]; if (N == 1) { if (A == B) { Console.WriteLine(1); return; } else { Console.WriteLine(0); return; } } else { if (B < A) { Console.WriteLine(0); return; } else Console.WriteLine((B - A) * (N - 2) + 1); } } } }
[["-", 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]]
8
154
10
using System; using System.Linq; class A { static void Main() { var h = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = h[0], a = h[1], b = h[2]; Console.WriteLine(Math.Max((n - 2) * (b - a) + 1, 0)); } }
using System; using System.Linq; class A { static void Main() { var h = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = h[0], a = h[1], b = h[2]; Console.WriteLine(Math.Max((n - 2) * (b - a) + 1, 0)); } }
[["-", 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]]
8
91
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AGC015A { class Program { static void Solve(Input input) { var n = input.NextInt(); var a = input.NextInt(); var b = input.NextInt(); Console.WriteLine(calc(n, a, b)); } private static long calc(int n, int a, int b) { if (a > b) { return 0; } if (n == 1 && a != b) { return 0; } // 最小と最大は必ず使う代わりに // それ以外はすべてaで埋めるパターンからbで埋めるパターンにより // (n-2)*aから(n-2)*bまでのすべての組み合わせが考えられる return b * (n - 2) - a * (n - 2) + 1; } #region Competitive Template public static void Main(string[] args) { var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する static readonly char[] separator = { ' ', '\r', '\n' }; public bool IsEof { get; set; } Queue<string> q { get; set; } StreamReader sr; public Input(string path = "") { IsEof = false; q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public string[] Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToArray(); public int[] NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToArray(); public long[] NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToArray(); public double[] NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToArray(); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AGC015A { class Program { static void Solve(Input input) { var n = input.NextInt(); var a = input.NextInt(); var b = input.NextInt(); Console.WriteLine(calc(n, a, b)); } private static long calc(long n, long a, long b) { if (a > b) { return 0; } if (n == 1 && a != b) { return 0; } // 最小と最大は必ず使う代わりに // それ以外はすべてaで埋めるパターンからbで埋めるパターンにより // (n-2)*aから(n-2)*bまでのすべての組み合わせが考えられる return b * (n - 2) - a * (n - 2) + 1; } #region Competitive Template public static void Main(string[] args) { var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する static readonly char[] separator = { ' ', '\r', '\n' }; public bool IsEof { get; set; } Queue<string> q { get; set; } StreamReader sr; public Input(string path = "") { IsEof = false; q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public string[] Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToArray(); public int[] NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToArray(); public long[] NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToArray(); public double[] NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToArray(); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } } #endregion } }
[["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199]]
8
907
6
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var nab = Array.ConvertAll(ReadLine().Split(' '), int.Parse); if (nab[1] > nab[2]) { WriteLine(0); return; } if (nab[0] == 1 && nab[1] == nab[2]) { WriteLine(1); return; } else if (nab[0] == 1) { WriteLine(0); return; } WriteLine((long)((nab[0] - 2) * (nab[2] - nab[1]) + 1)); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var nab = Array.ConvertAll(ReadLine().Split(' '), int.Parse); if (nab[1] > nab[2]) { WriteLine(0); return; } if (nab[0] == 1 && nab[1] == nab[2]) { WriteLine(1); return; } else if (nab[0] == 1) { WriteLine(0); return; } WriteLine((long)(nab[0] - 2) * (nab[2] - nab[1]) + 1); } }
[["-", 51, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25]]
8
170
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { long n, a, b; ReadMulti(out n, out a, out b); if (b < a) { WriteAnswer(0); return; } if (n == 1) { if (a == b) { WriteAnswer(1); } else { WriteAnswer(0); } return; } WriteAnswer((n - 2) * (b - a + 1) - 1); } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む global::Common.ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); static bool IsOdd(long num) { return (num & 1) == 1; } static bool IsEven(long num) { return (num & 1) == 0; } static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { long n, a, b; ReadMulti(out n, out a, out b); if (b < a) { WriteAnswer(0); return; } if (n == 1) { if (a == b) { WriteAnswer(1); } else { WriteAnswer(0); } return; } WriteAnswer((n - 2) * (b - a) + 1); } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む global::Common.ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); static bool IsOdd(long num) { return (num & 1) == 1; } static bool IsEven(long num) { return (num & 1) == 0; } static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } } }
[["-", 0, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
774
4
using System; using System.Collections.Generic; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { Solve(); } private const int MOD = 1000000007; static void Solve() { var nab = ReadAndParseIntArr(); long n = nab[0]; long a = nab[1]; long b = nab[2]; if (a >= b) { Console.WriteLine(0); return; } if (n == 1 && a != b) { Console.WriteLine(0); return; } if (n == 1 && a == b) { Console.WriteLine(1); return; } long min = a * (n - 1) + b; long max = b * (n - 1) + a; long ans = max - min + 1; Console.WriteLine(ans); } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int 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 int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int 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 int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { Solve(); } private const int MOD = 1000000007; static void Solve() { var nab = ReadAndParseIntArr(); long n = nab[0]; long a = nab[1]; long b = nab[2]; if (a > b) { Console.WriteLine(0); return; } if (n == 1 && a != b) { Console.WriteLine(0); return; } if (n == 1 && a == b) { Console.WriteLine(1); return; } long min = a * (n - 1) + b; long max = b * (n - 1) + a; long ans = max - min + 1; Console.WriteLine(ans); } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int 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 int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int 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 int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
783
2
using System; using System.Collections.Generic; using static System.Console; class Program { static void Main() { var n = NextInt(); var a = NextInt(); var b = NextInt(); WriteLine(Math.Max(0, (b - a) * (n - 2) + 1)); } static int NextInt() { return int.Parse(NextString()); } 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 n = NextInt(); var a = NextInt(); var b = NextInt(); WriteLine(Math.Max(0, (long)(b - a) * (n - 2) + 1)); } static int NextInt() { return int.Parse(NextString()); } 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, 28, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 16, 31, 16, 31, 74, 51, 23, 0, 24]]
8
175
3